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 | |
18 | import org.eclipse.core.resources.IMarker;\r | |
19 | import org.eclipse.core.resources.IResource;\r | |
20 | import org.eclipse.core.runtime.CoreException;\r | |
21 | import org.eclipse.linuxtools.tmf.event.TmfEvent;\r | |
22 | import org.eclipse.linuxtools.tmf.filter.ITmfFilter;\r | |
23 | \r | |
24 | public class TimeChartDecorationProvider {\r | |
25 | \r | |
26 | private IResource fResource;\r | |
27 | private Set<Long> fBookmarksSet = new HashSet<Long>();\r | |
28 | private ITmfFilter fFilterFilter;\r | |
29 | private ITmfFilter fSearchFilter;\r | |
30 | \r | |
31 | public TimeChartDecorationProvider(IResource resource) {\r | |
32 | fResource = resource;\r | |
33 | refreshBookmarks();\r | |
34 | }\r | |
35 | \r | |
36 | public IResource getResource() {\r | |
37 | return fResource;\r | |
38 | }\r | |
39 | \r | |
40 | public boolean isBookmark(long rank) {\r | |
41 | return fBookmarksSet.contains(rank);\r | |
42 | }\r | |
43 | \r | |
44 | public void refreshBookmarks() {\r | |
45 | try {\r | |
46 | fBookmarksSet.clear();\r | |
47 | for (IMarker bookmark : fResource.findMarkers(IMarker.BOOKMARK, false, IResource.DEPTH_ZERO)) {\r | |
48 | int location = bookmark.getAttribute(IMarker.LOCATION, -1);\r | |
49 | if (location != -1) {\r | |
50 | Long rank = (long) location;\r | |
51 | fBookmarksSet.add(rank);\r | |
52 | }\r | |
53 | }\r | |
54 | } catch (CoreException e) {\r | |
55 | e.printStackTrace();\r | |
56 | }\r | |
57 | }\r | |
58 | \r | |
59 | public void filterApplied(ITmfFilter filter) {\r | |
60 | fFilterFilter = filter;\r | |
61 | }\r | |
62 | \r | |
63 | public boolean isVisible(TmfEvent event) {\r | |
64 | if (fFilterFilter != null) {\r | |
65 | return fFilterFilter.matches(event);\r | |
66 | }\r | |
67 | return true;\r | |
68 | }\r | |
69 | \r | |
70 | public void searchApplied(ITmfFilter filter) {\r | |
71 | fSearchFilter = filter;\r | |
72 | }\r | |
73 | \r | |
74 | public boolean isSearchMatch(TmfEvent event) {\r | |
75 | if (fSearchFilter != null) {\r | |
76 | return fSearchFilter.matches(event);\r | |
77 | }\r | |
78 | return false;\r | |
79 | }\r | |
80 | \r | |
81 | }\r |