1 package fi.vtt.simantics.processeditor.perspectives;
\r
3 import java.util.Collection;
\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
18 import fi.vtt.simantics.processeditor.ProcessResource;
\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
27 return new ResourceViewpoint(new TraversalRule() {
\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
46 return TraversalDecision.stopTraversal;
\r
50 public boolean areAllStatesRelevant() {
\r
55 public Collection<State> relevantStates() {
\r
58 }, new AcceptRule<IEntity>() {
\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
69 public boolean areAllStatesRelevant() {
\r
74 public Collection<State> relevantStates() {
\r
80 public static ResourceViewpoint createObjectStructureViewpoint() {
\r
81 StateFactory f = new PlainStateFactory();
\r
82 final State rootState = f.newState();
\r
84 return new ResourceViewpoint(new TraversalRule() {
\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
94 return TraversalDecision.stopTraversal;
\r
98 public boolean areAllStatesRelevant() {
\r
103 public Collection<State> relevantStates() {
\r
106 }, new AcceptAllResourceAcceptRule(), rootState);
\r