1 /*******************************************************************************
2 * Copyright (c) 2010, 2016 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
.tracecompass
.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
.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
;
28 * Provider for decorations in the time chart view
31 * @author Patrick Tasse
33 public class TimeChartDecorationProvider
{
35 private final IFile fBookmarksFile
;
36 private final Set
<Long
> fBookmarksSet
= new HashSet
<>();
37 private ITmfFilter fFilterFilter
;
38 private ITmfFilter fSearchFilter
;
43 * @param bookmarksFile
44 * Bookmark file associated with the trace
46 public TimeChartDecorationProvider(IFile bookmarksFile
) {
47 fBookmarksFile
= bookmarksFile
;
52 * Retrieve the bookmark file that was assigned to this provider
54 * @return The bookmark file
56 public IFile
getBookmarksFile() {
57 return fBookmarksFile
;
61 * Verify if the selected rank has a bookmark assigned to it.
64 * The rank to check for
65 * @return If there is a bookmark there
67 public boolean isBookmark(long rank
) {
68 return fBookmarksSet
.contains(rank
);
72 * Refresh the bookmark display.
74 public void refreshBookmarks() {
76 fBookmarksSet
.clear();
77 if (fBookmarksFile
== null) {
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);
85 String rankString
= bookmark
.getAttribute(ITmfMarker
.MARKER_RANK
, (String
) null);
87 rank
= Long
.parseLong(rankString
);
88 } catch (NumberFormatException e
) {
93 fBookmarksSet
.add(rank
);
96 } catch (CoreException e
) {
97 Activator
.getDefault().logError("Error refreshing bookmarks", e
); //$NON-NLS-1$
102 * Notify that a filter is now applied on the view.
105 * The filter that was applied
107 public void filterApplied(ITmfFilter filter
) {
108 fFilterFilter
= filter
;
112 * Check if an event is currently visible in the view or not.
115 * The event to check for
116 * @return If the event is visible or not
118 public boolean isVisible(ITmfEvent event
) {
119 if (fFilterFilter
!= null) {
120 return fFilterFilter
.matches(event
);
126 * Notify that a search is applied on the view.
129 * The search filter that was applied
131 public void searchApplied(ITmfFilter filter
) {
132 fSearchFilter
= filter
;
136 * Verify if the currently active search filter applies to the given event
140 * The event to check for
141 * @return If the event matches
143 public boolean isSearchMatch(ITmfEvent event
) {
144 if (fSearchFilter
!= null) {
145 return fSearchFilter
.matches(event
);