Commit | Line | Data |
---|---|---|
203f982e | 1 | /******************************************************************************* |
0a08e17d | 2 | * Copyright (c) 2014, 2016 Ericsson |
203f982e BH |
3 | * |
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 | |
8 | * | |
9 | * Contributors: | |
10 | * Bernd Hufmann - Initial API and implementation | |
11 | *******************************************************************************/ | |
2bdf0193 | 12 | package org.eclipse.tracecompass.internal.tmf.core.filter; |
203f982e BH |
13 | |
14 | import java.util.List; | |
15 | ||
aa353506 | 16 | import org.eclipse.jdt.annotation.NonNull; |
2bdf0193 AM |
17 | import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; |
18 | import org.eclipse.tracecompass.tmf.core.event.collapse.ITmfCollapsibleEvent; | |
19 | import org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode; | |
203f982e BH |
20 | |
21 | /** | |
22 | * Stateful filter that compares consecutive events for collapsing feature. | |
23 | * | |
24 | * Usage of this class in conjunction with other {@link ITmfFilterTreeNode} | |
25 | * filters is not supported. Will throw {@link UnsupportedOperationException} | |
26 | * in that case. | |
27 | * | |
28 | * @author Bernd Hufmann | |
29 | */ | |
30 | public class TmfCollapseFilter implements ITmfFilterTreeNode { | |
31 | ||
32 | private static final String COLLAPSE_NODE_NAME = "Collapse"; //$NON-NLS-1$ | |
33 | ||
34 | private ITmfCollapsibleEvent fPrevEvent = null; | |
35 | ||
36 | @Override | |
37 | public boolean matches(ITmfEvent event) { | |
38 | ||
39 | if (fPrevEvent != null) { | |
40 | if (event instanceof ITmfCollapsibleEvent) { | |
41 | boolean isCollapsible = fPrevEvent.isCollapsibleWith(event); | |
42 | fPrevEvent = (ITmfCollapsibleEvent) event; | |
43 | if (isCollapsible) { | |
44 | return false; | |
45 | } | |
46 | } else { | |
47 | fPrevEvent = null; | |
48 | } | |
49 | } else { | |
50 | if (event instanceof ITmfCollapsibleEvent) { | |
51 | fPrevEvent = (ITmfCollapsibleEvent) event; | |
52 | } | |
53 | } | |
54 | return true; | |
55 | } | |
56 | ||
57 | @Override | |
58 | public ITmfFilterTreeNode getParent() { | |
59 | return null; | |
60 | } | |
61 | ||
62 | @Override | |
63 | public String getNodeName() { | |
64 | return COLLAPSE_NODE_NAME; | |
65 | } | |
66 | ||
67 | @Override | |
68 | public boolean hasChildren() { | |
69 | return false; | |
70 | } | |
71 | ||
72 | @Override | |
73 | public int getChildrenCount() { | |
74 | return 0; | |
75 | } | |
76 | ||
77 | @Override | |
aa353506 AM |
78 | public @NonNull ITmfFilterTreeNode[] getChildren() { |
79 | return new @NonNull ITmfFilterTreeNode[0]; | |
203f982e BH |
80 | } |
81 | ||
82 | @Override | |
83 | public ITmfFilterTreeNode getChild(int index) { | |
84 | throw new UnsupportedOperationException(); | |
85 | } | |
86 | ||
87 | @Override | |
88 | public ITmfFilterTreeNode remove() { | |
89 | throw new UnsupportedOperationException(); | |
90 | } | |
91 | ||
92 | @Override | |
93 | public ITmfFilterTreeNode removeChild(ITmfFilterTreeNode node) { | |
94 | throw new UnsupportedOperationException(); | |
95 | } | |
96 | ||
97 | @Override | |
98 | public int addChild(ITmfFilterTreeNode node) { | |
99 | throw new UnsupportedOperationException(); | |
100 | } | |
101 | ||
102 | @Override | |
103 | public ITmfFilterTreeNode replaceChild(int index, ITmfFilterTreeNode node) { | |
104 | throw new UnsupportedOperationException(); | |
105 | } | |
106 | ||
107 | @Override | |
108 | public void setParent(ITmfFilterTreeNode parent) { | |
109 | } | |
110 | ||
111 | @Override | |
112 | public List<String> getValidChildren() { | |
113 | throw new UnsupportedOperationException(); | |
114 | } | |
115 | ||
0a08e17d PT |
116 | @Override |
117 | public String toString() { | |
118 | return COLLAPSE_NODE_NAME; | |
119 | } | |
120 | ||
e883975e PT |
121 | @Override |
122 | public String toString(boolean explicit) { | |
123 | return COLLAPSE_NODE_NAME + " [" + fPrevEvent + ']'; //$NON-NLS-1$ | |
124 | } | |
125 | ||
203f982e BH |
126 | @Override |
127 | public ITmfFilterTreeNode clone() { | |
128 | return new TmfCollapseFilter(); | |
129 | } | |
130 | } |