Commit | Line | Data |
---|---|---|
6e512b93 ASL |
1 | /******************************************************************************* |
2 | * Copyright (c) 2009, 2010 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 | * Francois Chouinard - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.lttng.ui.views.project.model; | |
14 | ||
15 | import java.util.ArrayList; | |
16 | import java.util.List; | |
17 | ||
18 | /** | |
19 | * <b><u>LTTngProjectTreeNode</u></b> | |
20 | * <p> | |
21 | * TODO: Implement me. Please. | |
22 | */ | |
23 | public abstract class LTTngProjectTreeNode implements ILTTngProjectTreeNode { | |
24 | ||
25 | protected ILTTngProjectTreeNode fParent = null; | |
26 | protected List<ILTTngProjectTreeNode> fChildren = null; | |
27 | ||
28 | // ------------------------------------------------------------------------ | |
29 | // Constructor | |
30 | // ------------------------------------------------------------------------ | |
31 | ||
32 | public LTTngProjectTreeNode(ILTTngProjectTreeNode parent) { | |
33 | fParent = parent; | |
34 | fChildren = new ArrayList<ILTTngProjectTreeNode>(); | |
35 | } | |
36 | ||
37 | @Override | |
38 | public String toString() { | |
39 | return getName(); | |
40 | } | |
41 | ||
42 | // ------------------------------------------------------------------------ | |
43 | // ILTTngProjectTreeNode | |
44 | // ------------------------------------------------------------------------ | |
45 | ||
d4011df2 | 46 | @Override |
6e512b93 ASL |
47 | public ILTTngProjectTreeNode getParent() { |
48 | return fParent; | |
49 | } | |
50 | ||
d4011df2 | 51 | @Override |
6e512b93 ASL |
52 | public boolean hasChildren() { |
53 | return fChildren.size() > 0; | |
54 | } | |
55 | ||
d4011df2 | 56 | @Override |
6e512b93 ASL |
57 | public List<ILTTngProjectTreeNode> getChildren() { |
58 | return fChildren; | |
59 | } | |
60 | ||
d4011df2 | 61 | @Override |
6e512b93 ASL |
62 | public abstract void refreshChildren(); |
63 | ||
d4011df2 | 64 | @Override |
6e512b93 ASL |
65 | public void refresh() { |
66 | fParent.refresh(); | |
67 | } | |
68 | ||
d4011df2 | 69 | @Override |
6e512b93 ASL |
70 | public void removeChild(ILTTngProjectTreeNode child) { |
71 | for (ILTTngProjectTreeNode node : fChildren) { | |
72 | if (node == child) { | |
73 | node.removeChildren(); | |
74 | // We can do it since we are returning right away | |
75 | fChildren.remove(node); | |
76 | return; | |
77 | } | |
78 | } | |
79 | } | |
80 | ||
d4011df2 | 81 | @Override |
6e512b93 ASL |
82 | public void removeChildren() { |
83 | for (ILTTngProjectTreeNode node : fChildren) { | |
84 | node.removeChildren(); | |
85 | } | |
86 | fChildren.clear(); | |
87 | } | |
88 | ||
89 | } |