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.proconf.g3d.shapeeditor.common;
\r
13 import java.util.Collection;
\r
15 import org.simantics.db.Builtins;
\r
16 import org.simantics.db.Resource;
\r
17 import org.simantics.layer0.utils.Statement;
\r
18 import org.simantics.layer0.utils.IEntity;
\r
19 import org.simantics.layer0.utils.viewpoints.AcceptDecision;
\r
20 import org.simantics.layer0.utils.viewpoints.AcceptRule;
\r
21 import org.simantics.layer0.utils.viewpoints.PlainStateFactory;
\r
22 import org.simantics.layer0.utils.viewpoints.ResourceViewpoint;
\r
23 import org.simantics.layer0.utils.viewpoints.State;
\r
24 import org.simantics.layer0.utils.viewpoints.StateFactory;
\r
25 import org.simantics.layer0.utils.viewpoints.TraversalDecision;
\r
26 import org.simantics.layer0.utils.viewpoints.TraversalRule;
\r
27 import org.simantics.layer0.utils.viewpoints.rules.AcceptAllResourceAcceptRule;
\r
28 import org.simantics.proconf.g3d.shapeeditor.ShapeEditorResources;
\r
31 public class ViewpointGenerator {
\r
33 public static ResourceViewpoint createStuctureViewpoint() {
\r
34 StateFactory f = new PlainStateFactory();
\r
35 final State rootState = f.newState();
\r
36 final State projectState = f.newState();
\r
37 final State libraryState = f.newState();
\r
39 return new ResourceViewpoint(new TraversalRule() {
\r
41 public TraversalDecision makeTraversalDecision(State state,
\r
42 Statement statement) {
\r
43 Builtins b = statement.getGraph().getBuiltins();
\r
44 if (state.equals(rootState)) {
\r
45 if (!statement.getPredicate().equals(b.ConsistsOf))
\r
46 return TraversalDecision.stopTraversal;
\r
47 //if (!statement.getObject().isInstanceOf(b.Project))
\r
48 // return TraversalDecision.stopTraversal;
\r
49 return TraversalDecision.continueTraversal(projectState);
\r
50 } else if (state.equals(projectState)) {
\r
51 if (!statement.getPredicate().equals(b.ConsistsOf))
\r
52 return TraversalDecision.stopTraversal;
\r
53 //if (!statement.getObject().isInstanceOf(b.Library))
\r
54 // return TraversalDecision.stopTraversal;
\r
55 return TraversalDecision.continueTraversal(libraryState);
\r
56 } else if (state.equals(libraryState)) {
\r
57 if (!statement.getPredicate().equals(b.ConsistsOf)
\r
58 && !statement.getPredicate().isSubrelationOf(
\r
59 ShapeEditorResources.g3dResource.HasChild))
\r
60 return TraversalDecision.stopTraversal;
\r
61 return TraversalDecision.continueTraversal(libraryState);
\r
63 return TraversalDecision.stopTraversal;
\r
67 public boolean areAllStatesRelevant() {
\r
72 public Collection<State> relevantStates() {
\r
75 }, new AcceptAllResourceAcceptRule(), rootState);
\r
78 public static ResourceViewpoint createObjectStructureViewpoint() {
\r
79 StateFactory f = new PlainStateFactory();
\r
80 final State rootState = f.newState();
\r
82 return new ResourceViewpoint(new TraversalRule() {
\r
84 public TraversalDecision makeTraversalDecision(State state,
\r
85 Statement statement) {
\r
86 if (state.equals(rootState)) {
\r
87 if (!statement.getPredicate().isSubrelationOf(
\r
88 ShapeEditorResources.g3dResource.HasChild))
\r
89 return TraversalDecision.stopTraversal;
\r
90 return TraversalDecision.continueTraversal(rootState);
\r
92 return TraversalDecision.stopTraversal;
\r
96 public boolean areAllStatesRelevant() {
\r
101 public Collection<State> relevantStates() {
\r
104 }, new AcceptAllResourceAcceptRule(), rootState);
\r
107 public static ResourceViewpoint createObjectSizingParameterViewpoint(Resource modelToParameterRelation) {
\r
108 StateFactory f = new PlainStateFactory();
\r
109 final State rootState = f.newState();
\r
110 final State endState = f.newState();
\r
111 final Resource relation = modelToParameterRelation;
\r
113 return new ResourceViewpoint(new TraversalRule() {
\r
115 public TraversalDecision makeTraversalDecision(State state,
\r
116 Statement statement) {
\r
117 if (state.equals(rootState)) {
\r
118 if (!statement.getPredicate().isSubrelationOf(relation))
\r
119 return TraversalDecision.stopTraversal;
\r
120 return TraversalDecision.continueTraversal(endState);
\r
122 return TraversalDecision.stopTraversal;
\r
126 public boolean areAllStatesRelevant() {
\r
131 public Collection<State> relevantStates() {
\r
134 }, new AcceptAllResourceAcceptRule(), rootState);
\r
137 public static ResourceViewpoint createViewpoint() {
\r
138 StateFactory f = new PlainStateFactory();
\r
139 final State rootState = f.newState();
\r
140 final State projectState = f.newState();
\r
141 final State libraryState = f.newState();
\r
143 return new ResourceViewpoint(new TraversalRule() {
\r
145 public TraversalDecision makeTraversalDecision(State state, Statement statement) {
\r
146 Builtins b = statement.getGraph().getBuiltins();
\r
147 if (state.equals(rootState)) {
\r
148 if (statement.getObject().isInstanceOf(b.Ontology))
\r
149 return TraversalDecision.stopTraversal;
\r
150 if(!statement.getPredicate().equals(b.ConsistsOf))
\r
151 return TraversalDecision.stopTraversal;
\r
152 return TraversalDecision.continueTraversal(projectState);
\r
153 } else if (state.equals(projectState)) {
\r
154 if(!statement.getPredicate().equals(b.ConsistsOf))
\r
155 return TraversalDecision.stopTraversal;
\r
156 return TraversalDecision.continueTraversal(libraryState);
\r
157 } else if (state.equals(libraryState)) {
\r
158 if(!statement.getPredicate().equals(b.ConsistsOf))
\r
159 return TraversalDecision.stopTraversal;
\r
160 return TraversalDecision.continueTraversal(libraryState);
\r
162 return TraversalDecision.stopTraversal;
\r
166 public boolean areAllStatesRelevant() {
\r
171 public Collection<State> relevantStates() {
\r
174 }, new AcceptRule<IEntity>() {
\r
176 public AcceptDecision makeAcceptDecision(State state, IEntity obj) {
\r
177 Builtins b = obj.getGraph().getBuiltins();
\r
178 //NOSEResource nr = NOSEResource.getInstance(obj.getGraph());
\r
179 if(obj.isInstanceOf(b.Project)) return AcceptDecision.REJECT;
\r
180 else if (obj.isInstanceOf(b.Ontology)) return AcceptDecision.REJECT;
\r
181 else return AcceptDecision.ACCEPT;
\r
185 public boolean areAllStatesRelevant() {
\r
190 public Collection<State> relevantStates() {
\r