]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.document.linking.ui/src/org/simantics/document/linking/ge/ModelChildRule.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.document.linking.ui / src / org / simantics / document / linking / ge / ModelChildRule.java
index b8c5b841c8675386e09866dc85ccc4f5034eb91f..be2535495dbab78f8999b7205c662e968a0754d0 100644 (file)
-package org.simantics.document.linking.ge;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Collection;\r
-\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.variable.StandardGraphChildVariable;\r
-import org.simantics.db.layer0.variable.Variable;\r
-import org.simantics.document.linking.ontology.DocumentLink;\r
-import org.simantics.layer0.Layer0;\r
-\r
-/**\r
- * Rule for browsing all document links in a model.\r
- * \r
- * @author Marko Luukkainen <marko.luukkainen@vtt.fi>\r
- *\r
- */\r
-public class ModelChildRule implements org.simantics.browsing.ui.model.children.ChildRule{\r
-       \r
-       private ObjectChildRule objectChildRule;\r
-       private PropertyChildRule propertyChildRule;\r
-       private boolean showOnlyCheckable = false; // show only removed old old links\r
-       \r
-       public ModelChildRule(ReadGraph graph, Resource r) {\r
-               DocumentLink sl = DocumentLink.getInstance(graph);\r
-               showOnlyCheckable = sl.ModelViewpointBrowseContext2_ChildRule.equals(r);\r
-               objectChildRule = new ObjectChildRule();\r
-               propertyChildRule = new PropertyChildRule(false);\r
-               objectChildRule.setShowOnlyCheckable(showOnlyCheckable);\r
-               propertyChildRule.setShowOnlyCheckable(showOnlyCheckable);\r
-       }\r
-       \r
-       @Override\r
-       public boolean isCompatible(Class<?> contentType) {\r
-               return contentType.equals(Resource.class) || contentType.equals(Variable.class);\r
-       }\r
-       \r
-       @Override\r
-       public Collection<?> getChildren(ReadGraph graph, Object obj)\r
-                       throws DatabaseException {\r
-\r
-               ArrayList<Object> children = new ArrayList<Object>();\r
-               \r
-\r
-               Resource resource = null;\r
-               Variable variable = null;\r
-               if (obj instanceof Resource) {\r
-                       resource = (Resource)obj;\r
-                       try {\r
-                               variable = graph.adapt(resource, Variable.class);\r
-                       } catch (Throwable t) {\r
-                               return children;\r
-                       }\r
-                       children.add(new StandardGraphChildVariable(variable,null,  resource));\r
-                       return children;\r
-               } else {\r
-                       variable = (Variable)obj;\r
-                       resource = variable.getPossibleRepresents(graph);\r
-               }\r
-               \r
-       \r
-               DocumentLink sl = DocumentLink.getInstance(graph);\r
-               if (graph.isInstanceOf(resource, sl.Source))\r
-                       return children;\r
-               Layer0 l0 = Layer0.getInstance(graph);\r
-//             children.addAll(graph.getObjects(resource, l0.ConsistsOf));\r
-               for (Resource  r : graph.getObjects(resource, l0.ConsistsOf)) {\r
-                       Variable v = new StandardGraphChildVariable(variable,null,  r);\r
-                       if (hasLinkedChildren(graph, v))\r
-                               children.add(v);\r
-               }\r
-               children.addAll(objectChildRule.getChildren(graph, variable));\r
-               children.addAll(propertyChildRule.getChildren(graph, variable));\r
-               \r
-\r
-               return children;\r
-       }\r
-       \r
-       private boolean hasLinkedChildren(ReadGraph graph, Variable variable) throws DatabaseException {\r
-               if (getLinkChildren(graph, variable).size() > 0)\r
-                       return true;\r
-               Collection<Variable> children = getObjectChildren(graph, variable);\r
-               if (children.size() == 0)\r
-                       return false;\r
-               \r
-               for (Variable child : children) {\r
-                       if (hasLinkedChildren(graph, child))\r
-                               return true;\r
-               }\r
-               return false;\r
-                       \r
-       }\r
-       \r
-       private Collection<Variable> getObjectChildren(ReadGraph graph, Variable variable) throws DatabaseException{\r
-               ArrayList<Variable> children = new ArrayList<Variable>();\r
-               Layer0 l0 = Layer0.getInstance(graph);\r
-               for (Resource  r : graph.getObjects(variable.getRepresents(graph), l0.ConsistsOf)) {\r
-                       children.add(new StandardGraphChildVariable(variable,null, r));\r
-               }\r
-               return children;\r
-       }\r
-       \r
-       private Collection<?> getLinkChildren(ReadGraph graph, Variable variable) throws DatabaseException{\r
-               ArrayList<Object> children = new ArrayList<Object>();\r
-               children.addAll(objectChildRule.getChildren(graph, variable));\r
-               children.addAll(propertyChildRule.getChildren(graph, variable));\r
-               return children;\r
-       }\r
-       \r
-       @Override\r
-       public Collection<?> getParents(ReadGraph graph, Object child)\r
-                       throws DatabaseException {\r
-               return new ArrayList<Resource>();\r
-       }\r
-\r
-}\r
+package org.simantics.document.linking.ge;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.variable.StandardGraphChildVariable;
+import org.simantics.db.layer0.variable.Variable;
+import org.simantics.document.linking.ontology.DocumentLink;
+import org.simantics.layer0.Layer0;
+
+/**
+ * Rule for browsing all document links in a model.
+ * 
+ * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
+ *
+ */
+public class ModelChildRule implements org.simantics.browsing.ui.model.children.ChildRule{
+       
+       private ObjectChildRule objectChildRule;
+       private PropertyChildRule propertyChildRule;
+       private boolean showOnlyCheckable = false; // show only removed old old links
+       
+       public ModelChildRule(ReadGraph graph, Resource r) {
+               DocumentLink sl = DocumentLink.getInstance(graph);
+               showOnlyCheckable = sl.ModelViewpointBrowseContext2_ChildRule.equals(r);
+               objectChildRule = new ObjectChildRule();
+               propertyChildRule = new PropertyChildRule(false);
+               objectChildRule.setShowOnlyCheckable(showOnlyCheckable);
+               propertyChildRule.setShowOnlyCheckable(showOnlyCheckable);
+       }
+       
+       @Override
+       public boolean isCompatible(Class<?> contentType) {
+               return contentType.equals(Resource.class) || contentType.equals(Variable.class);
+       }
+       
+       @Override
+       public Collection<?> getChildren(ReadGraph graph, Object obj)
+                       throws DatabaseException {
+
+               ArrayList<Object> children = new ArrayList<Object>();
+               
+
+               Resource resource = null;
+               Variable variable = null;
+               if (obj instanceof Resource) {
+                       resource = (Resource)obj;
+                       try {
+                               variable = graph.adapt(resource, Variable.class);
+                       } catch (Throwable t) {
+                               return children;
+                       }
+                       children.add(new StandardGraphChildVariable(variable,null,  resource));
+                       return children;
+               } else {
+                       variable = (Variable)obj;
+                       resource = variable.getPossibleRepresents(graph);
+               }
+               
+       
+               DocumentLink sl = DocumentLink.getInstance(graph);
+               if (graph.isInstanceOf(resource, sl.Source))
+                       return children;
+               Layer0 l0 = Layer0.getInstance(graph);
+//             children.addAll(graph.getObjects(resource, l0.ConsistsOf));
+               for (Resource  r : graph.getObjects(resource, l0.ConsistsOf)) {
+                       Variable v = new StandardGraphChildVariable(variable,null,  r);
+                       if (hasLinkedChildren(graph, v))
+                               children.add(v);
+               }
+               children.addAll(objectChildRule.getChildren(graph, variable));
+               children.addAll(propertyChildRule.getChildren(graph, variable));
+               
+
+               return children;
+       }
+       
+       private boolean hasLinkedChildren(ReadGraph graph, Variable variable) throws DatabaseException {
+               if (getLinkChildren(graph, variable).size() > 0)
+                       return true;
+               Collection<Variable> children = getObjectChildren(graph, variable);
+               if (children.size() == 0)
+                       return false;
+               
+               for (Variable child : children) {
+                       if (hasLinkedChildren(graph, child))
+                               return true;
+               }
+               return false;
+                       
+       }
+       
+       private Collection<Variable> getObjectChildren(ReadGraph graph, Variable variable) throws DatabaseException{
+               ArrayList<Variable> children = new ArrayList<Variable>();
+               Layer0 l0 = Layer0.getInstance(graph);
+               for (Resource  r : graph.getObjects(variable.getRepresents(graph), l0.ConsistsOf)) {
+                       children.add(new StandardGraphChildVariable(variable,null, r));
+               }
+               return children;
+       }
+       
+       private Collection<?> getLinkChildren(ReadGraph graph, Variable variable) throws DatabaseException{
+               ArrayList<Object> children = new ArrayList<Object>();
+               children.addAll(objectChildRule.getChildren(graph, variable));
+               children.addAll(propertyChildRule.getChildren(graph, variable));
+               return children;
+       }
+       
+       @Override
+       public Collection<?> getParents(ReadGraph graph, Object child)
+                       throws DatabaseException {
+               return new ArrayList<Resource>();
+       }
+
+}