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
9 * VTT Technical Research Centre of Finland - initial API and implementation
\r
10 *******************************************************************************/
\r
11 package org.simantics.processeditor.perspectives;
\r
13 import java.util.Collection;
\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
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
37 return new ResourceViewpoint(new TraversalRule() {
\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
56 return TraversalDecision.stopTraversal;
\r
60 public boolean areAllStatesRelevant() {
\r
65 public Collection<State> relevantStates() {
\r
68 }, new AcceptRule<IEntity>() {
\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
79 public boolean areAllStatesRelevant() {
\r
84 public Collection<State> relevantStates() {
\r
90 public static ResourceViewpoint createObjectStructureViewpoint() {
\r
91 StateFactory f = new PlainStateFactory();
\r
92 final State rootState = f.newState();
\r
94 return new ResourceViewpoint(new TraversalRule() {
\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
104 return TraversalDecision.stopTraversal;
\r
108 public boolean areAllStatesRelevant() {
\r
113 public Collection<State> relevantStates() {
\r
116 }, new AcceptAllResourceAcceptRule(), rootState);
\r