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