1 package org.simantics.document.linking.ge;
\r
3 import java.util.ArrayList;
\r
4 import java.util.Collection;
\r
6 import org.simantics.db.ReadGraph;
\r
7 import org.simantics.db.Resource;
\r
8 import org.simantics.db.exception.DatabaseException;
\r
9 import org.simantics.db.layer0.variable.StandardGraphChildVariable;
\r
10 import org.simantics.db.layer0.variable.Variable;
\r
11 import org.simantics.document.linking.ontology.DocumentLink;
\r
12 import org.simantics.layer0.Layer0;
\r
15 * Rule for browsing all document links in a model.
\r
17 * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
\r
20 public class ModelChildRule implements org.simantics.browsing.ui.model.children.ChildRule{
\r
22 private ObjectChildRule objectChildRule;
\r
23 private PropertyChildRule propertyChildRule;
\r
24 private boolean showOnlyCheckable = false; // show only removed old old links
\r
26 public ModelChildRule(ReadGraph graph, Resource r) {
\r
27 DocumentLink sl = DocumentLink.getInstance(graph);
\r
28 showOnlyCheckable = sl.ModelViewpointBrowseContext2_ChildRule.equals(r);
\r
29 objectChildRule = new ObjectChildRule();
\r
30 propertyChildRule = new PropertyChildRule(false);
\r
31 objectChildRule.setShowOnlyCheckable(showOnlyCheckable);
\r
32 propertyChildRule.setShowOnlyCheckable(showOnlyCheckable);
\r
36 public boolean isCompatible(Class<?> contentType) {
\r
37 return contentType.equals(Resource.class) || contentType.equals(Variable.class);
\r
41 public Collection<?> getChildren(ReadGraph graph, Object obj)
\r
42 throws DatabaseException {
\r
44 ArrayList<Object> children = new ArrayList<Object>();
\r
47 Resource resource = null;
\r
48 Variable variable = null;
\r
49 if (obj instanceof Resource) {
\r
50 resource = (Resource)obj;
\r
52 variable = graph.adapt(resource, Variable.class);
\r
53 } catch (Throwable t) {
\r
56 children.add(new StandardGraphChildVariable(variable,null, resource));
\r
59 variable = (Variable)obj;
\r
60 resource = variable.getPossibleRepresents(graph);
\r
64 DocumentLink sl = DocumentLink.getInstance(graph);
\r
65 if (graph.isInstanceOf(resource, sl.Source))
\r
67 Layer0 l0 = Layer0.getInstance(graph);
\r
68 // children.addAll(graph.getObjects(resource, l0.ConsistsOf));
\r
69 for (Resource r : graph.getObjects(resource, l0.ConsistsOf)) {
\r
70 Variable v = new StandardGraphChildVariable(variable,null, r);
\r
71 if (hasLinkedChildren(graph, v))
\r
74 children.addAll(objectChildRule.getChildren(graph, variable));
\r
75 children.addAll(propertyChildRule.getChildren(graph, variable));
\r
81 private boolean hasLinkedChildren(ReadGraph graph, Variable variable) throws DatabaseException {
\r
82 if (getLinkChildren(graph, variable).size() > 0)
\r
84 Collection<Variable> children = getObjectChildren(graph, variable);
\r
85 if (children.size() == 0)
\r
88 for (Variable child : children) {
\r
89 if (hasLinkedChildren(graph, child))
\r
96 private Collection<Variable> getObjectChildren(ReadGraph graph, Variable variable) throws DatabaseException{
\r
97 ArrayList<Variable> children = new ArrayList<Variable>();
\r
98 Layer0 l0 = Layer0.getInstance(graph);
\r
99 for (Resource r : graph.getObjects(variable.getRepresents(graph), l0.ConsistsOf)) {
\r
100 children.add(new StandardGraphChildVariable(variable,null, r));
\r
105 private Collection<?> getLinkChildren(ReadGraph graph, Variable variable) throws DatabaseException{
\r
106 ArrayList<Object> children = new ArrayList<Object>();
\r
107 children.addAll(objectChildRule.getChildren(graph, variable));
\r
108 children.addAll(propertyChildRule.getChildren(graph, variable));
\r
113 public Collection<?> getParents(ReadGraph graph, Object child)
\r
114 throws DatabaseException {
\r
115 return new ArrayList<Resource>();
\r