]> gerrit.simantics Code Review - simantics/3d.git/blob
46405d177b69b1a760e32170638a7cb1aec7cfce
[simantics/3d.git] /
1 package org.simantics.processeditor.perspectives;\r
2 \r
3 import java.util.Collection;\r
4 \r
5 import org.simantics.db.Builtins;\r
6 import org.simantics.layer0.utils.IEntity;\r
7 import org.simantics.layer0.utils.Statement;\r
8 import org.simantics.layer0.utils.viewpoints.AcceptDecision;\r
9 import org.simantics.layer0.utils.viewpoints.AcceptRule;\r
10 import org.simantics.layer0.utils.viewpoints.PlainStateFactory;\r
11 import org.simantics.layer0.utils.viewpoints.ResourceViewpoint;\r
12 import org.simantics.layer0.utils.viewpoints.State;\r
13 import org.simantics.layer0.utils.viewpoints.StateFactory;\r
14 import org.simantics.layer0.utils.viewpoints.TraversalDecision;\r
15 import org.simantics.layer0.utils.viewpoints.TraversalRule;\r
16 import org.simantics.layer0.utils.viewpoints.rules.AcceptAllResourceAcceptRule;\r
17 import org.simantics.processeditor.ProcessResource;\r
18 \r
19 \r
20 public class ViewpointGenerator {\r
21         public static ResourceViewpoint createViewpoint() {\r
22                 StateFactory f = new PlainStateFactory();\r
23                 final State rootState = f.newState();\r
24                 final State projectState = f.newState();\r
25                 final State libraryState = f.newState();\r
26                 \r
27                 return new ResourceViewpoint(new TraversalRule() {\r
28                         @Override\r
29                         public TraversalDecision makeTraversalDecision(State state, Statement statement) {\r
30                                 Builtins b = statement.getGraph().getBuiltins();\r
31                                 if (state.equals(rootState)) {\r
32                                         if (statement.getObject().isInstanceOf(b.Ontology))\r
33                                                 return TraversalDecision.stopTraversal;\r
34                                         if(!statement.getPredicate().equals(b.ConsistsOf))\r
35                                                 return TraversalDecision.stopTraversal;\r
36                                         return TraversalDecision.continueTraversal(projectState);\r
37                                 } else if (state.equals(projectState)) {\r
38                                         if(!statement.getPredicate().equals(b.ConsistsOf))\r
39                                                 return TraversalDecision.stopTraversal;\r
40                                         return TraversalDecision.continueTraversal(libraryState);\r
41                                 } else if (state.equals(libraryState)) {\r
42                                         if(!statement.getPredicate().equals(b.ConsistsOf))\r
43                                                 return TraversalDecision.stopTraversal;\r
44                                         return TraversalDecision.continueTraversal(libraryState);\r
45                                 }\r
46                                 return TraversalDecision.stopTraversal;\r
47                         }\r
48                         \r
49                         @Override\r
50                         public boolean areAllStatesRelevant() {\r
51                                 return true;\r
52                         }\r
53                         \r
54                         @Override\r
55                         public Collection<State> relevantStates() {\r
56                                 return null;\r
57                         }\r
58                 }, new AcceptRule<IEntity>() {\r
59                 @Override\r
60                         public AcceptDecision makeAcceptDecision(State state, IEntity obj) {\r
61                                 Builtins b = obj.getGraph().getBuiltins();\r
62                                 //NOSEResource nr = NOSEResource.getInstance(obj.getGraph());\r
63                                 if(obj.isInstanceOf(b.Project)) return AcceptDecision.REJECT;\r
64                                 else if (obj.isInstanceOf(b.Ontology)) return AcceptDecision.REJECT;\r
65                                 else return AcceptDecision.ACCEPT;\r
66                         }\r
67                 \r
68                         @Override\r
69                         public boolean areAllStatesRelevant() {\r
70                                 return true;\r
71                         }\r
72                         \r
73                         @Override\r
74                         public Collection<State> relevantStates() {\r
75                                 return null;\r
76                         }\r
77                 }, rootState);\r
78         }\r
79         \r
80         public static ResourceViewpoint createObjectStructureViewpoint() {\r
81                 StateFactory f = new PlainStateFactory();\r
82                 final State rootState = f.newState();\r
83 \r
84                 return new ResourceViewpoint(new TraversalRule() {\r
85                         @Override\r
86                         public TraversalDecision makeTraversalDecision(State state,\r
87                                         Statement statement) {\r
88                                 if (state.equals(rootState)) {\r
89                                         if (!statement.getPredicate().isSubrelationOf(\r
90                                                         ProcessResource.g3dResource.HasChild))\r
91                                                 return TraversalDecision.stopTraversal;\r
92                                         return TraversalDecision.continueTraversal(rootState);\r
93                                 }\r
94                                 return TraversalDecision.stopTraversal;\r
95                         }\r
96 \r
97                         @Override\r
98                         public boolean areAllStatesRelevant() {\r
99                                 return true;\r
100                         }\r
101 \r
102                         @Override\r
103                         public Collection<State> relevantStates() {\r
104                                 return null;\r
105                         }\r
106                 }, new AcceptAllResourceAcceptRule(), rootState);\r
107         }\r
108 }\r