1 /*******************************************************************************
2 * Copyright (c) 2010, 2013 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
<>();
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 if (fBookmarksFile
== null) {
79 for (IMarker bookmark
: fBookmarksFile
.findMarkers(
80 IMarker
.BOOKMARK
, false, IResource
.DEPTH_ZERO
)) {
81 int location
= bookmark
.getAttribute(IMarker
.LOCATION
, -1);
83 Long rank
= (long) location
;
84 fBookmarksSet
.add(rank
);
87 } catch (CoreException e
) {
88 Activator
.getDefault().logError("Error refreshing bookmarks", e
); //$NON-NLS-1$
93 * Notify that a filter is now applied on the view.
96 * The filter that was applied
98 public void filterApplied(ITmfFilter filter
) {
99 fFilterFilter
= filter
;
103 * Check if an event is currently visible in the view or not.
106 * The event to check for
107 * @return If the event is visible or not
109 public boolean isVisible(ITmfEvent event
) {
110 if (fFilterFilter
!= null) {
111 return fFilterFilter
.matches(event
);
117 * Notify that a search is applied on the view.
120 * The search filter that was applied
122 public void searchApplied(ITmfFilter filter
) {
123 fSearchFilter
= filter
;
127 * Verify if the currently active search filter applies to the given event
131 * The event to check for
132 * @return If the event matches
134 public boolean isSearchMatch(ITmfEvent event
) {
135 if (fSearchFilter
!= null) {
136 return fSearchFilter
.matches(event
);