]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/TreeParent.java
26bdbe615135a0bd9a6b0a76ad6280623c07de84
2 * Copyright (C) 2007-2012 Mathieu Baudier
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.eclipse
.ui
;
18 import java
.util
.ArrayList
;
19 import java
.util
.List
;
21 /** Parent / children semantic to be used for simple UI Tree structure */
22 public class TreeParent
{
24 private TreeParent parent
;
26 private List
<Object
> children
;
28 /** False until at least one child has been added, then true until cleared */
29 private boolean loaded
= false;
31 public TreeParent(String name
) {
33 children
= new ArrayList
<Object
>();
36 public synchronized void addChild(Object child
) {
39 if (child
instanceof TreeParent
)
40 ((TreeParent
) child
).setParent(this);
44 * Remove this child. The child is disposed.
46 public synchronized void removeChild(Object child
) {
47 children
.remove(child
);
48 if (child
instanceof TreeParent
) {
49 ((TreeParent
) child
).dispose();
53 public synchronized void clearChildren() {
54 for (Object obj
: children
) {
55 if (obj
instanceof TreeParent
)
56 ((TreeParent
) obj
).dispose();
63 * If overridden, <code>super.dispose()</code> must be called, typically
64 * after custom cleaning.
66 public synchronized void dispose() {
72 public synchronized Object
[] getChildren() {
73 return children
.toArray(new Object
[children
.size()]);
76 @SuppressWarnings("unchecked")
77 public synchronized <T
> List
<T
> getChildrenOfType(Class
<T
> clss
) {
78 List
<T
> lst
= new ArrayList
<T
>();
79 for (Object obj
: children
) {
80 if (clss
.isAssignableFrom(obj
.getClass()))
86 public synchronized boolean hasChildren() {
87 return children
.size() > 0;
90 public Object
getChildByName(String name
) {
91 for (Object child
: children
) {
92 if (child
.toString().equals(name
))
98 public synchronized Boolean
isLoaded() {
102 public String
getName() {
106 public void setParent(TreeParent parent
) {
107 this.parent
= parent
;
110 public TreeParent
getParent() {
114 public String
toString() {
118 public int compareTo(TreeParent o
) {
119 return name
.compareTo(o
.name
);
123 public int hashCode() {
124 return name
.hashCode();
128 public boolean equals(Object obj
) {
129 return name
.equals(obj
.toString());