1 /*******************************************************************************
\r
2 * Copyright (c) 2007 VTT Technical Research Centre of Finland and others.
\r
3 * All rights reserved. This program and the accompanying materials
\r
4 * are made available under the terms of the Eclipse Public License v1.0
\r
5 * which accompanies this distribution, and is available at
\r
6 * http://www.eclipse.org/legal/epl-v10.html
\r
9 * VTT Technical Research Centre of Finland - initial API and implementation
\r
10 *******************************************************************************/
\r
11 package org.simantics.processeditor.stubs;
\r
13 import org.simantics.db.Resource;
\r
14 import org.simantics.db.ResourceContainer;
\r
15 import org.simantics.db.Statement;
\r
16 import org.simantics.db.Graph;
\r
17 import org.simantics.db.ResourceContainer;
\r
18 import org.simantics.layer0.utils.ResourceDoesNotSatisfyAssumptionException;
\r
19 import org.simantics.layer0.utils.IEntity;
\r
20 import org.simantics.layer0.utils.internal.Entity;
\r
21 import org.simantics.layer0.utils.instantiation.InstanceFactory;
\r
22 import java.util.Collection;
\r
23 import java.util.ArrayList;
\r
25 public class PBSNode extends Entity implements IPBSNode {
\r
27 public PBSNode(Graph graph, ResourceContainer resourceContainer) {
\r
28 super(graph, resourceContainer.getResource());
\r
31 public PBSNode(IEntity entity) {
\r
32 super(entity.getGraph(), entity.getResource());
\r
35 public Graph getGraph() {
\r
39 public static PBSNode createDefault(Graph graph) {
\r
40 return new PBSNode(graph, InstanceFactory.instantiate(graph, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).PBSNode));
\r
43 public static boolean isInstance(IEntity entity) {
\r
44 Graph graph = entity.getGraph();
\r
45 Resource type = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).PBSNode;
\r
46 return graph.isInstanceOf(entity.getResource(), type);
\r
50 public Resource getResource() {
\r
54 public PBSNode toPBSNode() {
\r
58 public org.simantics.processeditor.stubs.PBSNode getParentStructure() {
\r
59 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasParentStructure);
\r
60 if(statements.length > 1)
\r
61 throw new ResourceDoesNotSatisfyAssumptionException("Wrong number (" + statements.length + ") of statements.");
\r
62 if(statements.length == 0)
\r
64 return new org.simantics.processeditor.stubs.PBSNode(graph, statements[0].getObject());
\r
67 public void addParentStructure(ResourceContainer v) {
\r
68 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasParentStructure, v.getResource());
\r
71 public void setParentStructure(ResourceContainer v) {
\r
72 Resource predicate = org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasParentStructure;
\r
73 graph.removeStatements(resource, predicate);
\r
74 graph.addStatement(resource, predicate, v.getResource());
\r
77 public Collection<org.simantics.processeditor.stubs.PBSNode> getChildStructure() {
\r
78 Statement[] statements = graph.getStatements(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasChildStructure);
\r
79 Collection<org.simantics.processeditor.stubs.PBSNode> ret = new ArrayList<org.simantics.processeditor.stubs.PBSNode>(statements.length);
\r
80 for(Statement s : statements)
\r
81 ret.add(new org.simantics.processeditor.stubs.PBSNode(graph, s.getObject()));
\r
85 public void addChildStructure(ResourceContainer v) {
\r
86 graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasChildStructure, v.getResource());
\r