Commit | Line | Data |
---|---|---|
ce62370f FC |
1 | /*******************************************************************************\r |
2 | * Copyright (c) 2010 Ericsson\r | |
013a5f1c | 3 | *\r |
ce62370f FC |
4 | * All rights reserved. This program and the accompanying materials are\r |
5 | * made available under the terms of the Eclipse Public License v1.0 which\r | |
6 | * accompanies this distribution, and is available at\r | |
7 | * http://www.eclipse.org/legal/epl-v10.html\r | |
013a5f1c | 8 | *\r |
ce62370f FC |
9 | * Contributors:\r |
10 | * Patrick Tasse - Initial API and implementation\r | |
11 | *******************************************************************************/\r | |
12 | \r | |
13 | package org.eclipse.linuxtools.tmf.ui.views.timechart;\r | |
14 | \r | |
15 | import java.util.HashSet;\r | |
16 | import java.util.Set;\r | |
17 | \r | |
a1091415 | 18 | import org.eclipse.core.resources.IFile;\r |
ce62370f FC |
19 | import org.eclipse.core.resources.IMarker;\r |
20 | import org.eclipse.core.resources.IResource;\r | |
21 | import org.eclipse.core.runtime.CoreException;\r | |
8fd82db5 | 22 | import org.eclipse.linuxtools.internal.tmf.ui.Activator;\r |
72f1e62a | 23 | import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;\r |
6c13869b | 24 | import org.eclipse.linuxtools.tmf.core.filter.ITmfFilter;\r |
ce62370f | 25 | \r |
013a5f1c AM |
26 | /**\r |
27 | * Provider for decorations in the time chart view\r | |
28 | *\r | |
29 | * @version 1.0\r | |
30 | * @author Patrick Tasse\r | |
31 | */\r | |
ce62370f FC |
32 | public class TimeChartDecorationProvider {\r |
33 | \r | |
013a5f1c AM |
34 | private final IFile fBookmarksFile;\r |
35 | private final Set<Long> fBookmarksSet = new HashSet<Long>();\r | |
ce62370f FC |
36 | private ITmfFilter fFilterFilter;\r |
37 | private ITmfFilter fSearchFilter;\r | |
38 | \r | |
20ff3b75 AM |
39 | /**\r |
40 | * Constructor\r | |
41 | *\r | |
42 | * @param bookmarksFile\r | |
43 | * Bookmark file associated with the trace\r | |
44 | */\r | |
45 | public TimeChartDecorationProvider(IFile bookmarksFile) {\r | |
46 | fBookmarksFile = bookmarksFile;\r | |
47 | refreshBookmarks();\r | |
ce62370f FC |
48 | }\r |
49 | \r | |
20ff3b75 AM |
50 | /**\r |
51 | * Retrieve the bookmark file that was assigned to this provider\r | |
52 | *\r | |
53 | * @return The bookmark file\r | |
54 | */\r | |
55 | public IFile getBookmarksFile() {\r | |
56 | return fBookmarksFile;\r | |
57 | }\r | |
013a5f1c | 58 | \r |
20ff3b75 AM |
59 | /**\r |
60 | * Verify if the selected rank has a bookmark assigned to it.\r | |
61 | *\r | |
62 | * @param rank\r | |
63 | * The rank to check for\r | |
64 | * @return If there is a bookmark there\r | |
65 | */\r | |
66 | public boolean isBookmark(long rank) {\r | |
67 | return fBookmarksSet.contains(rank);\r | |
ce62370f | 68 | }\r |
013a5f1c | 69 | \r |
20ff3b75 AM |
70 | /**\r |
71 | * Refresh the bookmark display.\r | |
72 | */\r | |
73 | public void refreshBookmarks() {\r | |
74 | try {\r | |
75 | fBookmarksSet.clear();\r | |
76 | for (IMarker bookmark : fBookmarksFile.findMarkers(\r | |
77 | IMarker.BOOKMARK, false, IResource.DEPTH_ZERO)) {\r | |
78 | int location = bookmark.getAttribute(IMarker.LOCATION, -1);\r | |
79 | if (location != -1) {\r | |
80 | Long rank = (long) location;\r | |
81 | fBookmarksSet.add(rank);\r | |
82 | }\r | |
83 | }\r | |
ce62370f | 84 | } catch (CoreException e) {\r |
8fd82db5 | 85 | Activator.getDefault().logError("Error refreshing bookmarks", e); //$NON-NLS-1$\r |
ce62370f FC |
86 | }\r |
87 | }\r | |
88 | \r | |
20ff3b75 AM |
89 | /**\r |
90 | * Notify that a filter is now applied on the view.\r | |
91 | *\r | |
92 | * @param filter\r | |
93 | * The filter that was applied\r | |
94 | */\r | |
95 | public void filterApplied(ITmfFilter filter) {\r | |
96 | fFilterFilter = filter;\r | |
ce62370f FC |
97 | }\r |
98 | \r | |
20ff3b75 AM |
99 | /**\r |
100 | * Check if an event is currently visible in the view or not.\r | |
101 | *\r | |
102 | * @param event\r | |
103 | * The event to check for\r | |
104 | * @return If the event is visible or not\r | |
105 | */\r | |
106 | public boolean isVisible(ITmfEvent event) {\r | |
107 | if (fFilterFilter != null) {\r | |
108 | return fFilterFilter.matches(event);\r | |
109 | }\r | |
110 | return true;\r | |
111 | }\r | |
013a5f1c | 112 | \r |
20ff3b75 AM |
113 | /**\r |
114 | * Notify that a search is applied on the view.\r | |
115 | *\r | |
116 | * @param filter\r | |
117 | * The search filter that was applied\r | |
118 | */\r | |
119 | public void searchApplied(ITmfFilter filter) {\r | |
120 | fSearchFilter = filter;\r | |
ce62370f | 121 | }\r |
013a5f1c | 122 | \r |
20ff3b75 AM |
123 | /**\r |
124 | * Verify if the currently active search filter applies to the given event\r | |
125 | * or not.\r | |
126 | *\r | |
127 | * @param event\r | |
128 | * The event to check for\r | |
129 | * @return If the event matches\r | |
130 | */\r | |
131 | public boolean isSearchMatch(ITmfEvent event) {\r | |
132 | if (fSearchFilter != null) {\r | |
133 | return fSearchFilter.matches(event);\r | |
134 | }\r | |
135 | return false;\r | |
136 | }\r | |
013a5f1c | 137 | \r |
ce62370f | 138 | }\r |