/******************************************************************************* * Copyright (c) 2012, 2013 Association for Decentralized Information Management in * Industry THTH ry. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ 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 || name.equals(this.name)) 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) { if (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(); } }