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