]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.proconf.processeditor/src/org/simantics/processeditor/stubs/PBSNode.java
git-svn-id: https://www.simantics.org/svn/simantics/3d/branches/dev@7344 ac1ea38d...
[simantics/3d.git] / org.simantics.proconf.processeditor / src / org / simantics / processeditor / stubs / PBSNode.java
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
7  *\r
8  * Contributors:\r
9  *     VTT Technical Research Centre of Finland - initial API and implementation\r
10  *******************************************************************************/\r
11 package org.simantics.processeditor.stubs;\r
12 \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
24 \r
25 public class PBSNode extends Entity implements IPBSNode {\r
26     \r
27     public PBSNode(Graph graph, ResourceContainer resourceContainer) {\r
28         super(graph, resourceContainer.getResource());\r
29     }\r
30     \r
31     public PBSNode(IEntity entity) {\r
32         super(entity.getGraph(), entity.getResource());\r
33     }\r
34     \r
35     public Graph getGraph() {\r
36         return graph;\r
37     }\r
38     \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
41     }\r
42     \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
47     }\r
48     \r
49     @Override\r
50     public Resource getResource() {\r
51         return resource;\r
52     }\r
53     \r
54     public PBSNode toPBSNode() {\r
55         return this;\r
56     }\r
57     \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
63             return null;\r
64         return new org.simantics.processeditor.stubs.PBSNode(graph, statements[0].getObject());\r
65     }\r
66     \r
67     public void addParentStructure(ResourceContainer v) {\r
68         graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasParentStructure, v.getResource());\r
69     }\r
70     \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
75     }\r
76     \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
82         return ret;\r
83     }\r
84     \r
85     public void addChildStructure(ResourceContainer v) {\r
86         graph.addStatement(resource, org.simantics.processeditor.stubs.Plant3DResource.getInstance(graph).HasChildStructure, v.getResource());\r
87     }\r
88     \r
89 }\r
90 \r