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