Merge branch 'master' into lttng_2_0_control_dev
[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.IMarker;
19 import org.eclipse.core.resources.IResource;
20 import org.eclipse.core.runtime.CoreException;
21 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
22 import org.eclipse.linuxtools.tmf.core.filter.ITmfFilter;
23
24 public class TimeChartDecorationProvider {
25
26 private IResource fResource;
27 private Set<Long> fBookmarksSet = new HashSet<Long>();
28 private ITmfFilter fFilterFilter;
29 private ITmfFilter fSearchFilter;
30
31 public TimeChartDecorationProvider(IResource resource) {
32 fResource = resource;
33 refreshBookmarks();
34 }
35
36 public IResource getResource() {
37 return fResource;
38 }
39
40 public boolean isBookmark(long rank) {
41 return fBookmarksSet.contains(rank);
42 }
43
44 public void refreshBookmarks() {
45 try {
46 fBookmarksSet.clear();
47 for (IMarker bookmark : fResource.findMarkers(IMarker.BOOKMARK, false, IResource.DEPTH_ZERO)) {
48 int location = bookmark.getAttribute(IMarker.LOCATION, -1);
49 if (location != -1) {
50 Long rank = (long) location;
51 fBookmarksSet.add(rank);
52 }
53 }
54 } catch (CoreException e) {
55 e.printStackTrace();
56 }
57 }
58
59 public void filterApplied(ITmfFilter filter) {
60 fFilterFilter = filter;
61 }
62
63 public boolean isVisible(ITmfEvent event) {
64 if (fFilterFilter != null) {
65 return fFilterFilter.matches(event);
66 }
67 return true;
68 }
69
70 public void searchApplied(ITmfFilter filter) {
71 fSearchFilter = filter;
72 }
73
74 public boolean isSearchMatch(ITmfEvent event) {
75 if (fSearchFilter != null) {
76 return fSearchFilter.matches(event);
77 }
78 return false;
79 }
80
81 }
This page took 0.034692 seconds and 6 git commands to generate.