Commit | Line | Data |
---|---|---|
ce62370f FC |
1 | /*******************************************************************************\r |
2 | * Copyright (c) 2010 Ericsson\r | |
3 | * \r | |
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 | |
8 | * \r | |
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 FC |
25 | \r |
26 | public class TimeChartDecorationProvider {\r | |
27 | \r | |
a1091415 | 28 | private IFile fBookmarksFile;\r |
ce62370f FC |
29 | private Set<Long> fBookmarksSet = new HashSet<Long>();\r |
30 | private ITmfFilter fFilterFilter;\r | |
31 | private ITmfFilter fSearchFilter;\r | |
32 | \r | |
a1091415 PT |
33 | public TimeChartDecorationProvider(IFile bookmarksFile) {\r |
34 | fBookmarksFile = bookmarksFile;\r | |
ce62370f FC |
35 | refreshBookmarks();\r |
36 | }\r | |
37 | \r | |
a1091415 PT |
38 | public IFile getBookmarksFile() {\r |
39 | return fBookmarksFile;\r | |
ce62370f FC |
40 | }\r |
41 | \r | |
42 | public boolean isBookmark(long rank) {\r | |
43 | return fBookmarksSet.contains(rank);\r | |
44 | }\r | |
45 | \r | |
46 | public void refreshBookmarks() {\r | |
47 | try {\r | |
48 | fBookmarksSet.clear();\r | |
a1091415 | 49 | for (IMarker bookmark : fBookmarksFile.findMarkers(IMarker.BOOKMARK, false, IResource.DEPTH_ZERO)) {\r |
ce62370f FC |
50 | int location = bookmark.getAttribute(IMarker.LOCATION, -1);\r |
51 | if (location != -1) {\r | |
52 | Long rank = (long) location;\r | |
53 | fBookmarksSet.add(rank);\r | |
54 | }\r | |
55 | }\r | |
56 | } catch (CoreException e) {\r | |
8fd82db5 | 57 | Activator.getDefault().logError("Error refreshing bookmarks", e); //$NON-NLS-1$\r |
ce62370f FC |
58 | }\r |
59 | }\r | |
60 | \r | |
61 | public void filterApplied(ITmfFilter filter) {\r | |
62 | fFilterFilter = filter;\r | |
63 | }\r | |
64 | \r | |
72f1e62a | 65 | public boolean isVisible(ITmfEvent event) {\r |
ce62370f FC |
66 | if (fFilterFilter != null) {\r |
67 | return fFilterFilter.matches(event);\r | |
68 | }\r | |
69 | return true;\r | |
70 | }\r | |
71 | \r | |
72 | public void searchApplied(ITmfFilter filter) {\r | |
73 | fSearchFilter = filter;\r | |
74 | }\r | |
75 | \r | |
72f1e62a | 76 | public boolean isSearchMatch(ITmfEvent event) {\r |
ce62370f FC |
77 | if (fSearchFilter != null) {\r |
78 | return fSearchFilter.matches(event);\r | |
79 | }\r | |
80 | return false;\r | |
81 | }\r | |
82 | \r | |
83 | }\r |