X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=org.simantics.g3d%2Fsrc%2Forg%2Fsimantics%2Fg3d%2Fscenegraph%2Fstructural%2FStructuralParentNode.java;fp=org.simantics.g3d%2Fsrc%2Forg%2Fsimantics%2Fg3d%2Fscenegraph%2Fstructural%2FStructuralParentNode.java;h=d5e41a5cf482c5d7ec55544bccde135882d2b4eb;hb=87b3241ec277ba3d8e414b26186a032c9cdcaeed;hp=0000000000000000000000000000000000000000;hpb=1f0bcd66274375f2278d2e6c486cb28257a5f7b2;p=simantics%2F3d.git diff --git a/org.simantics.g3d/src/org/simantics/g3d/scenegraph/structural/StructuralParentNode.java b/org.simantics.g3d/src/org/simantics/g3d/scenegraph/structural/StructuralParentNode.java new file mode 100644 index 00000000..d5e41a5c --- /dev/null +++ b/org.simantics.g3d/src/org/simantics/g3d/scenegraph/structural/StructuralParentNode.java @@ -0,0 +1,99 @@ +package org.simantics.g3d.scenegraph.structural; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import org.simantics.g3d.ontology.G3D; +import org.simantics.g3d.property.annotations.GetPropertyValue; +import org.simantics.g3d.property.annotations.SetPropertyValue; +import org.simantics.g3d.scenegraph.base.ParentNode; +import org.simantics.layer0.Layer0; +import org.simantics.objmap.graph.annotations.RelatedGetValue; +import org.simantics.objmap.graph.annotations.RelatedSetValue; +import org.simantics.objmap.structural.IStructuralObject; + +public abstract class StructuralParentNode extends ParentNode implements IStructuralNode{ + + private String name; + + + @RelatedGetValue(Layer0.URIs.HasName) + @GetPropertyValue(value = Layer0.URIs.HasName, tabId = "Default", name = "Name") + public String getName() { + return name; + } + + @RelatedSetValue(Layer0.URIs.HasName) + @SetPropertyValue(Layer0.URIs.HasName) + public void setName(String name) { + if (name == null) + return; + this.name = name; + firePropertyChanged(Layer0.URIs.HasName); + } + + @Override + public String toString() { + return getName(); + } + + public boolean isPartOfInstantiatedModel() { + return ctx.size() > 0; + } + + public boolean isExposed() { + if (ctx.size() == 0) + return true; + return getPublishedBy().contains(ctx.get(0)); + } + + @Override + public boolean isInstantiatedModelRoot() { + return ctx.size() == 1 && this.equals(ctx.get(0)); + } + + @Override + public boolean isPublishable() { + return !isPartOfInstantiatedModel(); + } + + private List ctx = new ArrayList(1); + @Override + public List getContext() { + return ctx; + } + + @Override + public void setContext(List object) { + ctx = object; + } + + private List publisher = new ArrayList(1); + + @Override + public void addPublishedBy(IStructuralNode node) { + publisher.add(node); + firePropertyChanged(G3D.URIs.publishes); + } + + @Override + public Collection getPublishedBy() { + return publisher; + } + + @Override + public void removePublishedBy(IStructuralNode node) { + if (publisher.remove(node)) + firePropertyChanged(G3D.URIs.publishes); + } + + @Override + public void remove() { + IStructuralRootNode root = (IStructuralRootNode)getRootNode(); + if (root.getPublished().contains(this)) + root.removePublished(this); + + super.remove(); + } +}