1 package org.simantics.views.swt.client.base;
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.Hashtable;
9 import org.eclipse.jface.resource.ResourceManager;
10 import org.eclipse.swt.widgets.Composite;
11 import org.eclipse.swt.widgets.Control;
12 import org.eclipse.ui.IWorkbenchSite;
13 import org.simantics.scenegraph.INode;
14 import org.simantics.scenegraph.ParentNode;
16 public abstract class SWTParentNode extends ParentNode<ISWTViewNode> implements ISWTViewNode {
18 private boolean disposed = false;
20 private static final long serialVersionUID = -3548136282051185971L;
22 static class M implements Map<String, INode> {
24 ArrayList<INode> list = new ArrayList<>();
25 Hashtable<String, INode> table = new Hashtable<>();
33 public boolean containsKey(Object arg0) {
34 return table.containsKey(arg0);
37 public boolean containsValue(Object arg0) {
38 return table.containsValue(arg0);
41 public Set<java.util.Map.Entry<String, INode>> entrySet() {
42 return table.entrySet();
45 public INode get(Object arg0) {
46 return table.get(arg0);
49 public boolean isEmpty() {
50 return table.isEmpty();
53 public Set<String> keySet() {
54 return table.keySet();
57 public INode put(String arg0, INode arg1) {
58 INode exist = table.put(arg0, arg1);
59 if(exist != null) list.remove(exist);
64 public void putAll(Map<? extends String, ? extends INode> arg0) {
65 for(Map.Entry<? extends String, ? extends INode> entry : arg0.entrySet())
66 put(entry.getKey(), entry.getValue());
69 public INode remove(Object arg0) {
70 INode node = table.remove(arg0);
71 if(node != null) list.remove(node);
79 public Collection<INode> values() {
86 public SWTRoot getRootNode() {
87 ParentNode<?> root = super.getRootNode();
88 return (root instanceof SWTRoot) ? (SWTRoot) root : null;
91 public ResourceManager getResourceManager() {
92 SWTRoot root = getRootNode();
94 throw new IllegalStateException(this + " not attached to SWTRoot root node");
95 return root.getResourceManager();
98 public ResourceManager peekResourceManager() {
99 SWTRoot root = getRootNode();
100 return root != null ? root.peekResourceManager() : null;
104 final public void asyncRemoveNode(INode node) {
109 protected Map<String, INode> createChildMap(int initialCapacity) {
113 protected void createChildComposites() {
114 createChildComposites((Composite)getControl());
117 protected void createChildComposites(Composite composite) {
118 for(ISWTViewNode node : getNodes()) node.createControls(composite);
122 public Control getControl() {
127 public IWorkbenchSite getSite() {
129 ParentNode<?> parentNode = getParent();
130 ISWTViewNode swtParent = (ISWTViewNode)parentNode;
131 return swtParent.getSite();
135 public Collection<ISWTViewNode> getChildComposites() {
140 public boolean isNodeDisposed() {
144 public void dispose() {
145 assert(!isNodeDisposed());
146 for(ISWTViewNode child : getChildComposites())