Commit | Line | Data |
---|---|---|
be222f56 PT |
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.internal.tmf.ui.Activator; | |
23 | import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; | |
24 | import org.eclipse.linuxtools.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<Long>(); | |
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 | for (IMarker bookmark : fBookmarksFile.findMarkers( | |
77 | IMarker.BOOKMARK, false, IResource.DEPTH_ZERO)) { | |
78 | int location = bookmark.getAttribute(IMarker.LOCATION, -1); | |
79 | if (location != -1) { | |
80 | Long rank = (long) location; | |
81 | fBookmarksSet.add(rank); | |
82 | } | |
83 | } | |
84 | } catch (CoreException e) { | |
85 | Activator.getDefault().logError("Error refreshing bookmarks", e); //$NON-NLS-1$ | |
86 | } | |
87 | } | |
88 | ||
89 | /** | |
90 | * Notify that a filter is now applied on the view. | |
91 | * | |
92 | * @param filter | |
93 | * The filter that was applied | |
94 | */ | |
95 | public void filterApplied(ITmfFilter filter) { | |
96 | fFilterFilter = filter; | |
97 | } | |
98 | ||
99 | /** | |
100 | * Check if an event is currently visible in the view or not. | |
101 | * | |
102 | * @param event | |
103 | * The event to check for | |
104 | * @return If the event is visible or not | |
105 | */ | |
106 | public boolean isVisible(ITmfEvent event) { | |
107 | if (fFilterFilter != null) { | |
108 | return fFilterFilter.matches(event); | |
109 | } | |
110 | return true; | |
111 | } | |
112 | ||
113 | /** | |
114 | * Notify that a search is applied on the view. | |
115 | * | |
116 | * @param filter | |
117 | * The search filter that was applied | |
118 | */ | |
119 | public void searchApplied(ITmfFilter filter) { | |
120 | fSearchFilter = filter; | |
121 | } | |
122 | ||
123 | /** | |
124 | * Verify if the currently active search filter applies to the given event | |
125 | * or not. | |
126 | * | |
127 | * @param event | |
128 | * The event to check for | |
129 | * @return If the event matches | |
130 | */ | |
131 | public boolean isSearchMatch(ITmfEvent event) { | |
132 | if (fSearchFilter != null) { | |
133 | return fSearchFilter.matches(event); | |
134 | } | |
135 | return false; | |
136 | } | |
137 | ||
138 | } |