1 /*******************************************************************************
2 * Copyright (c) 2010, 2012 Ericsson
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
10 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.timechart
;
15 import java
.util
.HashSet
;
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
;
27 * Provider for decorations in the time chart view
30 * @author Patrick Tasse
32 public class TimeChartDecorationProvider
{
34 private final IFile fBookmarksFile
;
35 private final Set
<Long
> fBookmarksSet
= new HashSet
<Long
>();
36 private ITmfFilter fFilterFilter
;
37 private ITmfFilter fSearchFilter
;
42 * @param bookmarksFile
43 * Bookmark file associated with the trace
45 public TimeChartDecorationProvider(IFile bookmarksFile
) {
46 fBookmarksFile
= bookmarksFile
;
51 * Retrieve the bookmark file that was assigned to this provider
53 * @return The bookmark file
55 public IFile
getBookmarksFile() {
56 return fBookmarksFile
;
60 * Verify if the selected rank has a bookmark assigned to it.
63 * The rank to check for
64 * @return If there is a bookmark there
66 public boolean isBookmark(long rank
) {
67 return fBookmarksSet
.contains(rank
);
71 * Refresh the bookmark display.
73 public void refreshBookmarks() {
75 fBookmarksSet
.clear();
76 for (IMarker bookmark
: fBookmarksFile
.findMarkers(
77 IMarker
.BOOKMARK
, false, IResource
.DEPTH_ZERO
)) {
78 int location
= bookmark
.getAttribute(IMarker
.LOCATION
, -1);
80 Long rank
= (long) location
;
81 fBookmarksSet
.add(rank
);
84 } catch (CoreException e
) {
85 Activator
.getDefault().logError("Error refreshing bookmarks", e
); //$NON-NLS-1$
90 * Notify that a filter is now applied on the view.
93 * The filter that was applied
95 public void filterApplied(ITmfFilter filter
) {
96 fFilterFilter
= filter
;
100 * Check if an event is currently visible in the view or not.
103 * The event to check for
104 * @return If the event is visible or not
106 public boolean isVisible(ITmfEvent event
) {
107 if (fFilterFilter
!= null) {
108 return fFilterFilter
.matches(event
);
114 * Notify that a search is applied on the view.
117 * The search filter that was applied
119 public void searchApplied(ITmfFilter filter
) {
120 fSearchFilter
= filter
;
124 * Verify if the currently active search filter applies to the given event
128 * The event to check for
129 * @return If the event matches
131 public boolean isSearchMatch(ITmfEvent event
) {
132 if (fSearchFilter
!= null) {
133 return fSearchFilter
.matches(event
);