1 /*******************************************************************************
2 * Copyright (c) 2010 Ericsson
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
10 * Yuriy Vashchuk (yvashchuk@gmail.com) - Initial API and implementation
11 * Patrick Tasse - Refactoring
12 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
;
16 import java
.util
.ArrayList
;
17 import java
.util
.Arrays
;
18 import java
.util
.List
;
20 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEvent
;
23 * <b><u>TmfFilterTreeNode</u></b>
25 * The Filter Tree node
28 public abstract class TmfFilterTreeNode
implements ITmfFilterTreeNode
, Cloneable
{
30 private static final String
[] VALID_CHILDREN
= {
31 TmfFilterEventTypeNode
.NODE_NAME
,
32 TmfFilterAndNode
.NODE_NAME
,
33 TmfFilterOrNode
.NODE_NAME
,
34 TmfFilterContainsNode
.NODE_NAME
,
35 TmfFilterEqualsNode
.NODE_NAME
,
36 TmfFilterMatchesNode
.NODE_NAME
,
37 TmfFilterCompareNode
.NODE_NAME
40 private ITmfFilterTreeNode parent
= null;
41 private ArrayList
<ITmfFilterTreeNode
> children
= new ArrayList
<ITmfFilterTreeNode
>();
43 public TmfFilterTreeNode(final ITmfFilterTreeNode parent
) {
45 parent
.addChild(this);
50 * @see org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode#getParent()
53 public ITmfFilterTreeNode
getParent() {
58 * @see org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode#getNodeName()
61 public abstract String
getNodeName();
64 * @see org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode#hasChildren()
67 public boolean hasChildren() {
68 return (children
.size() > 0);
72 * @see org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode#getChildrenCount()
75 public int getChildrenCount() {
76 return children
.size();
80 * @see org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode#getChildren()
83 public ITmfFilterTreeNode
[] getChildren() {
84 return children
.toArray(new ITmfFilterTreeNode
[0]);
88 * @see org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode#getChild(int)
91 public ITmfFilterTreeNode
getChild(final int index
) throws IndexOutOfBoundsException
{
92 return children
.get(index
);
96 * @see org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode#remove()
99 public ITmfFilterTreeNode
remove() {
100 if (getParent() != null) {
101 getParent().removeChild(this);
108 * @see org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode#removeChild(org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode)
111 public ITmfFilterTreeNode
removeChild(ITmfFilterTreeNode node
) {
112 children
.remove(node
);
113 node
.setParent(null);
118 * @see org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode#addChild(org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode)
121 public int addChild(final ITmfFilterTreeNode node
) {
122 node
.setParent(this);
123 if(children
.add(node
)) {
124 return (children
.size() - 1);
130 * @see org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode#replaceChild(int, org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode)
133 public ITmfFilterTreeNode
replaceChild(final int index
, final ITmfFilterTreeNode node
) throws IndexOutOfBoundsException
{
134 node
.setParent(this);
135 return children
.set(index
, node
);
139 * @see org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode#setParent(org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode)
142 public void setParent(final ITmfFilterTreeNode parent
) {
143 this.parent
= parent
;
148 * @see org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode#matches(org.eclipse.linuxtools.tmf.event.TmfEvent)
151 public abstract boolean matches(TmfEvent event
);
154 * @see org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode#getValidChildren()
156 * By default, all node types are valid children. Override if different.
159 public List
<String
> getValidChildren() {
160 return Arrays
.asList(VALID_CHILDREN
);
164 public ITmfFilterTreeNode
clone() {
166 TmfFilterTreeNode clone
= (TmfFilterTreeNode
) super.clone();
168 clone
.children
= new ArrayList
<ITmfFilterTreeNode
>(children
.size());
169 for (ITmfFilterTreeNode child
: getChildren()) {
170 clone
.addChild(child
.clone());
173 } catch (CloneNotSupportedException e
) {