X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.views.swt.client%2Fsrc%2Forg%2Fsimantics%2Fviews%2Fswt%2Fclient%2Fbase%2FSWTParentNode.java;h=3fc213126d50b03b9cd5f14e27dfe65b13e60939;hb=HEAD;hp=92a3d121cbbde7be3531d9b6d98223025d9c4d6f;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.views.swt.client/src/org/simantics/views/swt/client/base/SWTParentNode.java b/bundles/org.simantics.views.swt.client/src/org/simantics/views/swt/client/base/SWTParentNode.java index 92a3d121c..3fc213126 100644 --- a/bundles/org.simantics.views.swt.client/src/org/simantics/views/swt/client/base/SWTParentNode.java +++ b/bundles/org.simantics.views.swt.client/src/org/simantics/views/swt/client/base/SWTParentNode.java @@ -1,152 +1,152 @@ -package org.simantics.views.swt.client.base; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Hashtable; -import java.util.Map; -import java.util.Set; - -import org.eclipse.jface.resource.ResourceManager; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.ui.IWorkbenchSite; -import org.simantics.scenegraph.INode; -import org.simantics.scenegraph.ParentNode; - -abstract public class SWTParentNode extends ParentNode implements ISWTViewNode { - - private boolean disposed = false; - - private static final long serialVersionUID = -3548136282051185971L; - - class M implements Map { - - ArrayList list = new ArrayList(); - Hashtable table = new Hashtable(); - - @Override - public void clear() { - table.clear(); - list.clear(); - } - @Override - public boolean containsKey(Object arg0) { - return table.containsKey(arg0); - } - @Override - public boolean containsValue(Object arg0) { - return table.containsValue(arg0); - } - @Override - public Set> entrySet() { - return table.entrySet(); - } - @Override - public ISWTViewNode get(Object arg0) { - return table.get(arg0); - } - @Override - public boolean isEmpty() { - return table.isEmpty(); - } - @Override - public Set keySet() { - return table.keySet(); - } - @Override - public ISWTViewNode put(String arg0, ISWTViewNode arg1) { - ISWTViewNode exist = table.put(arg0, arg1); - if(exist != null) list.remove(exist); - list.add(arg1); - return exist; - } - @Override - public void putAll(Map arg0) { - for(Map.Entry entry : arg0.entrySet()) - put(entry.getKey(), entry.getValue()); - } - @Override - public ISWTViewNode remove(Object arg0) { - ISWTViewNode node = table.remove(arg0); - if(node != null) list.remove(node); - return node; - } - @Override - public int size() { - return table.size(); - } - @Override - public Collection values() { - return list; - } - - } - - @Override - public SWTRoot getRootNode() { - ParentNode root = super.getRootNode(); - return (root instanceof SWTRoot) ? (SWTRoot) root : null; - } - - public ResourceManager getResourceManager() { - SWTRoot root = getRootNode(); - if (root == null) - throw new IllegalStateException(this + " not attached to SWTRoot root node"); - return root.getResourceManager(); - } - - public ResourceManager peekResourceManager() { - SWTRoot root = getRootNode(); - return root != null ? root.peekResourceManager() : null; - } - - @Override - final public void asyncRemoveNode(INode node) { - throw new Error(); - } - - @Override - protected Map createChildMap() { - return new M(); - } - - protected void createChildComposites() { - createChildComposites((Composite)getControl()); - } - - protected void createChildComposites(Composite composite) { - for(ISWTViewNode node : children.values()) node.createControls(composite); - } - - @Override - public Control getControl() { - return null; - } - - @Override - public IWorkbenchSite getSite() { - - ParentNode parentNode = getParent(); - ISWTViewNode swtParent = (ISWTViewNode)parentNode; - return swtParent.getSite(); - - } - - public Collection getChildComposites() { - return children.values(); - } - - @Override - public boolean isNodeDisposed() { - return disposed; - } - - public void dispose() { - assert(!isNodeDisposed()); - for(ISWTViewNode child : getChildComposites()) - child.dispose(); - cleanup(); - disposed = true; - } - -} +package org.simantics.views.swt.client.base; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Hashtable; +import java.util.Map; +import java.util.Set; + +import org.eclipse.jface.resource.ResourceManager; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.ui.IWorkbenchSite; +import org.simantics.scenegraph.INode; +import org.simantics.scenegraph.ParentNode; + +public abstract class SWTParentNode extends ParentNode implements ISWTViewNode { + + private boolean disposed = false; + + private static final long serialVersionUID = -3548136282051185971L; + + static class M implements Map { + + ArrayList list = new ArrayList<>(); + Hashtable table = new Hashtable<>(); + + @Override + public void clear() { + table.clear(); + list.clear(); + } + @Override + public boolean containsKey(Object arg0) { + return table.containsKey(arg0); + } + @Override + public boolean containsValue(Object arg0) { + return table.containsValue(arg0); + } + @Override + public Set> entrySet() { + return table.entrySet(); + } + @Override + public INode get(Object arg0) { + return table.get(arg0); + } + @Override + public boolean isEmpty() { + return table.isEmpty(); + } + @Override + public Set keySet() { + return table.keySet(); + } + @Override + public INode put(String arg0, INode arg1) { + INode exist = table.put(arg0, arg1); + if(exist != null) list.remove(exist); + list.add(arg1); + return exist; + } + @Override + public void putAll(Map arg0) { + for(Map.Entry entry : arg0.entrySet()) + put(entry.getKey(), entry.getValue()); + } + @Override + public INode remove(Object arg0) { + INode node = table.remove(arg0); + if(node != null) list.remove(node); + return node; + } + @Override + public int size() { + return table.size(); + } + @Override + public Collection values() { + return list; + } + + } + + @Override + public SWTRoot getRootNode() { + ParentNode root = super.getRootNode(); + return (root instanceof SWTRoot) ? (SWTRoot) root : null; + } + + public ResourceManager getResourceManager() { + SWTRoot root = getRootNode(); + if (root == null) + throw new IllegalStateException(this + " not attached to SWTRoot root node"); + return root.getResourceManager(); + } + + public ResourceManager peekResourceManager() { + SWTRoot root = getRootNode(); + return root != null ? root.peekResourceManager() : null; + } + + @Override + final public void asyncRemoveNode(INode node) { + throw new Error(); + } + + @Override + protected Map createChildMap(int initialCapacity) { + return new M(); + } + + protected void createChildComposites() { + createChildComposites((Composite)getControl()); + } + + protected void createChildComposites(Composite composite) { + for(ISWTViewNode node : getNodes()) node.createControls(composite); + } + + @Override + public Control getControl() { + return null; + } + + @Override + public IWorkbenchSite getSite() { + + ParentNode parentNode = getParent(); + ISWTViewNode swtParent = (ISWTViewNode)parentNode; + return swtParent.getSite(); + + } + + public Collection getChildComposites() { + return getNodes(); + } + + @Override + public boolean isNodeDisposed() { + return disposed; + } + + public void dispose() { + assert(!isNodeDisposed()); + for(ISWTViewNode child : getChildComposites()) + child.dispose(); + cleanup(); + disposed = true; + } + +}