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