Bug 378401: Implementation of time graph widget.
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / timechart / TimeChartDecorationProvider.java
1 /*******************************************************************************
2 * Copyright (c) 2010 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.ui.views.timechart;
14
15 import java.util.HashSet;
16 import java.util.Set;
17
18 import org.eclipse.core.resources.IFile;
19 import org.eclipse.core.resources.IMarker;
20 import org.eclipse.core.resources.IResource;
21 import org.eclipse.core.runtime.CoreException;
22 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
23 import org.eclipse.linuxtools.tmf.core.filter.ITmfFilter;
24
25 public class TimeChartDecorationProvider {
26
27 private IFile fBookmarksFile;
28 private Set<Long> fBookmarksSet = new HashSet<Long>();
29 private ITmfFilter fFilterFilter;
30 private ITmfFilter fSearchFilter;
31
32 public TimeChartDecorationProvider(IFile bookmarksFile) {
33 fBookmarksFile = bookmarksFile;
34 refreshBookmarks();
35 }
36
37 public IFile getBookmarksFile() {
38 return fBookmarksFile;
39 }
40
41 public boolean isBookmark(long rank) {
42 return fBookmarksSet.contains(rank);
43 }
44
45 public void refreshBookmarks() {
46 try {
47 fBookmarksSet.clear();
48 for (IMarker bookmark : fBookmarksFile.findMarkers(IMarker.BOOKMARK, false, IResource.DEPTH_ZERO)) {
49 int location = bookmark.getAttribute(IMarker.LOCATION, -1);
50 if (location != -1) {
51 Long rank = (long) location;
52 fBookmarksSet.add(rank);
53 }
54 }
55 } catch (CoreException e) {
56 e.printStackTrace();
57 }
58 }
59
60 public void filterApplied(ITmfFilter filter) {
61 fFilterFilter = filter;
62 }
63
64 public boolean isVisible(ITmfEvent event) {
65 if (fFilterFilter != null) {
66 return fFilterFilter.matches(event);
67 }
68 return true;
69 }
70
71 public void searchApplied(ITmfFilter filter) {
72 fSearchFilter = filter;
73 }
74
75 public boolean isSearchMatch(ITmfEvent event) {
76 if (fSearchFilter != null) {
77 return fSearchFilter.matches(event);
78 }
79 return false;
80 }
81
82 }
This page took 0.031667 seconds and 5 git commands to generate.