8d7a33472494435674fdaa312dde71b02ffa3599
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / tmf / ui / views / timechart / TimeChartDecorationProvider.java
1 /*******************************************************************************
2 * Copyright (c) 2010, 2014 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.tracecompass.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.tracecompass.internal.tmf.ui.Activator;
23 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
24 import org.eclipse.tracecompass.tmf.core.filter.ITmfFilter;
25
26 /**
27 * Provider for decorations in the time chart view
28 *
29 * @version 1.0
30 * @author Patrick Tasse
31 */
32 public class TimeChartDecorationProvider {
33
34 private final IFile fBookmarksFile;
35 private final Set<Long> fBookmarksSet = new HashSet<>();
36 private ITmfFilter fFilterFilter;
37 private ITmfFilter fSearchFilter;
38
39 /**
40 * Constructor
41 *
42 * @param bookmarksFile
43 * Bookmark file associated with the trace
44 */
45 public TimeChartDecorationProvider(IFile bookmarksFile) {
46 fBookmarksFile = bookmarksFile;
47 refreshBookmarks();
48 }
49
50 /**
51 * Retrieve the bookmark file that was assigned to this provider
52 *
53 * @return The bookmark file
54 */
55 public IFile getBookmarksFile() {
56 return fBookmarksFile;
57 }
58
59 /**
60 * Verify if the selected rank has a bookmark assigned to it.
61 *
62 * @param rank
63 * The rank to check for
64 * @return If there is a bookmark there
65 */
66 public boolean isBookmark(long rank) {
67 return fBookmarksSet.contains(rank);
68 }
69
70 /**
71 * Refresh the bookmark display.
72 */
73 public void refreshBookmarks() {
74 try {
75 fBookmarksSet.clear();
76 if (fBookmarksFile == null) {
77 return;
78 }
79 for (IMarker bookmark : fBookmarksFile.findMarkers(
80 IMarker.BOOKMARK, false, IResource.DEPTH_ZERO)) {
81 int location = bookmark.getAttribute(IMarker.LOCATION, -1);
82 if (location != -1) {
83 Long rank = (long) location;
84 fBookmarksSet.add(rank);
85 }
86 }
87 } catch (CoreException e) {
88 Activator.getDefault().logError("Error refreshing bookmarks", e); //$NON-NLS-1$
89 }
90 }
91
92 /**
93 * Notify that a filter is now applied on the view.
94 *
95 * @param filter
96 * The filter that was applied
97 */
98 public void filterApplied(ITmfFilter filter) {
99 fFilterFilter = filter;
100 }
101
102 /**
103 * Check if an event is currently visible in the view or not.
104 *
105 * @param event
106 * The event to check for
107 * @return If the event is visible or not
108 */
109 public boolean isVisible(ITmfEvent event) {
110 if (fFilterFilter != null) {
111 return fFilterFilter.matches(event);
112 }
113 return true;
114 }
115
116 /**
117 * Notify that a search is applied on the view.
118 *
119 * @param filter
120 * The search filter that was applied
121 */
122 public void searchApplied(ITmfFilter filter) {
123 fSearchFilter = filter;
124 }
125
126 /**
127 * Verify if the currently active search filter applies to the given event
128 * or not.
129 *
130 * @param event
131 * The event to check for
132 * @return If the event matches
133 */
134 public boolean isSearchMatch(ITmfEvent event) {
135 if (fSearchFilter != null) {
136 return fSearchFilter.matches(event);
137 }
138 return false;
139 }
140
141 }
This page took 0.038967 seconds and 4 git commands to generate.