]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/TreeParent.java
a086c17aa54ba19b4a293a2f31f7972b42340daf
2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
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.
17 package org
.argeo
.eclipse
.ui
;
19 import java
.util
.ArrayList
;
20 import java
.util
.List
;
22 /** Parent / children semantic to be used for simple UI Tree structure */
23 public class TreeParent
{
25 private TreeParent parent
;
27 private List
<Object
> children
;
29 /** False until at least one child has been added, then true until cleared */
30 private boolean loaded
= false;
32 public TreeParent(String name
) {
34 children
= new ArrayList
<Object
>();
37 public synchronized void addChild(Object child
) {
40 if (child
instanceof TreeParent
)
41 ((TreeParent
) child
).setParent(this);
45 * Remove this child. The child is disposed.
47 public synchronized void removeChild(Object child
) {
48 children
.remove(child
);
49 if (child
instanceof TreeParent
) {
50 ((TreeParent
) child
).dispose();
54 public synchronized void clearChildren() {
55 for (Object obj
: children
) {
56 if (obj
instanceof TreeParent
)
57 ((TreeParent
) obj
).dispose();
64 * If overridden, <code>super.dispose()</code> must be called, typically
65 * after custom cleaning.
67 public synchronized void dispose() {
73 public synchronized Object
[] getChildren() {
74 return children
.toArray(new Object
[children
.size()]);
77 @SuppressWarnings("unchecked")
78 public synchronized <T
> List
<T
> getChildrenOfType(Class
<T
> clss
) {
79 List
<T
> lst
= new ArrayList
<T
>();
80 for (Object obj
: children
) {
81 if (clss
.isAssignableFrom(obj
.getClass()))
87 public synchronized boolean hasChildren() {
88 return children
.size() > 0;
91 public Object
getChildByName(String name
) {
92 for (Object child
: children
) {
93 if (child
.toString().equals(name
))
99 public synchronized Boolean
isLoaded() {
103 public String
getName() {
107 public void setParent(TreeParent parent
) {
108 this.parent
= parent
;
111 public TreeParent
getParent() {
115 public String
toString() {
119 public int compareTo(TreeParent o
) {
120 return name
.compareTo(o
.name
);
124 public int hashCode() {
125 return name
.hashCode();
129 public boolean equals(Object obj
) {
130 return name
.equals(obj
.toString());