import java.util.List;
public class TreeParent extends TreeObject {
- private List<TreeObject> children;
+ private List<Object> children;
private boolean loaded;
public TreeParent(String name) {
super(name);
- children = new ArrayList<TreeObject>();
+ children = new ArrayList<Object>();
loaded = false;
}
- public synchronized void addChild(TreeObject child) {
+ public synchronized void addChild(Object child) {
loaded = true;
children.add(child);
- child.setParent(this);
+ // bsinou: was 'if (child instanceof TreeParent)'
+ if (child instanceof TreeObject)
+ ((TreeObject) child).setParent(this);
}
- public synchronized void removeChild(TreeObject child) {
+ public synchronized void removeChild(Object child) {
children.remove(child);
- child.setParent(null);
+ if (child instanceof TreeParent)
+ ((TreeParent) child).setParent(null);
+ // TODO: clear subtree recursively
}
public synchronized void clearChildren() {
loaded = false;
children.clear();
+ // TODO: clear also the objects
}
- public synchronized TreeObject[] getChildren() {
- return (TreeObject[]) children.toArray(new TreeObject[children.size()]);
+ public synchronized Object[] getChildren() {
+ return children.toArray(new Object[children.size()]);
}
public synchronized boolean hasChildren() {
return children.size() > 0;
}
- public TreeObject getChildByName(String name) {
- for (TreeObject child : children) {
- if (child.getName().equals(name))
+ public Object getChildByName(String name) {
+ for (Object child : children) {
+ if (child.toString().equals(name))
return child;
}
return null;