]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.document.linking.ui/src/org/simantics/document/linking/ge/ObjectChildRule.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.document.linking.ui / src / org / simantics / document / linking / ge / ObjectChildRule.java
index 76e3fe1cf2c0e4ba44b6420bb463919527866612..0f21c78d102dd0a12ae843960742b9d8f124ab6f 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.document.linking.utils.SourceLinkUtil;\r
-\r
-/**\r
- * A rule for browsing document links of an object. Properties are not included.\r
- * \r
- * @author Marko Luukkainen <marko.luukkainen@vtt.fi>\r
- *\r
- */\r
-public class ObjectChildRule implements org.simantics.browsing.ui.model.children.ChildRule{\r
-       \r
-       private boolean showOnlyCheckable = false;\r
-       \r
-       @Override\r
-       public boolean isCompatible(Class<?> contentType) {\r
-               return contentType.equals(Resource.class) || contentType.equals(Variable.class);\r
-       }\r
-       \r
-       public void setShowOnlyCheckable(boolean showOnlyCheckable) {\r
-               this.showOnlyCheckable = showOnlyCheckable;\r
-       }\r
-       \r
-       @Override\r
-       public Collection<?> getChildren(ReadGraph graph, Object obj)\r
-                       throws DatabaseException {\r
-\r
-               ArrayList<Variable> children = new ArrayList<Variable>();\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
-               \r
-               \r
-               //find sources declared on parentResource using consernsRelation\r
-               Variable parentVariable = variable.getParent(graph);\r
-               Resource parentRes = null;\r
-               Resource relation = null;\r
-               if (parentVariable != null) {\r
-                       parentRes = parentVariable.getPossibleRepresents(graph);\r
-                       relation = variable.getPossiblePredicateResource(graph);\r
-               }\r
-               \r
-               if (parentRes != null && relation != null) {\r
-                       Collection<Resource> sources = graph.getObjects(parentRes, sl.hasSource);\r
-                       for (Resource source : sources) {\r
-                               Resource rel = graph.getPossibleObject(source, sl.consernsRelation);\r
-                               if (rel != null && rel.equals(relation)) {\r
-                                       if (showOnlyCheckable && \r
-                                               (SourceLinkUtil.isValidSource(graph, source) &&\r
-                                                SourceLinkUtil.isUpToDateSource(graph, source)))\r
-                                               continue;\r
-                                       children.add(new StandardGraphChildVariable(variable, null, source));\r
-                               }\r
-                       }\r
-               }\r
-               //find sources declared on this resource, ie. sources that do not have consernsRelation.\r
-               Collection<Resource> sources = graph.getObjects(resource, sl.hasSource);\r
-               for (Resource source : sources) {\r
-                       Resource rel = graph.getPossibleObject(source, sl.consernsRelation);\r
-                       if (rel == null) {\r
-                               if (showOnlyCheckable && \r
-                                  (SourceLinkUtil.isValidSource(graph, source) &&\r
-                                   SourceLinkUtil.isUpToDateSource(graph, source)))\r
-                                       continue;\r
-                               children.add(new StandardGraphChildVariable(variable, null, source));\r
-                       }\r
-               }\r
-               while (children.remove(variable)) {\r
-                       \r
-               }\r
-               \r
-\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.document.linking.utils.SourceLinkUtil;
+
+/**
+ * A rule for browsing document links of an object. Properties are not included.
+ * 
+ * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
+ *
+ */
+public class ObjectChildRule implements org.simantics.browsing.ui.model.children.ChildRule{
+       
+       private boolean showOnlyCheckable = false;
+       
+       @Override
+       public boolean isCompatible(Class<?> contentType) {
+               return contentType.equals(Resource.class) || contentType.equals(Variable.class);
+       }
+       
+       public void setShowOnlyCheckable(boolean showOnlyCheckable) {
+               this.showOnlyCheckable = showOnlyCheckable;
+       }
+       
+       @Override
+       public Collection<?> getChildren(ReadGraph graph, Object obj)
+                       throws DatabaseException {
+
+               ArrayList<Variable> children = new ArrayList<Variable>();
+               
+
+               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;
+               
+               
+               //find sources declared on parentResource using consernsRelation
+               Variable parentVariable = variable.getParent(graph);
+               Resource parentRes = null;
+               Resource relation = null;
+               if (parentVariable != null) {
+                       parentRes = parentVariable.getPossibleRepresents(graph);
+                       relation = variable.getPossiblePredicateResource(graph);
+               }
+               
+               if (parentRes != null && relation != null) {
+                       Collection<Resource> sources = graph.getObjects(parentRes, sl.hasSource);
+                       for (Resource source : sources) {
+                               Resource rel = graph.getPossibleObject(source, sl.consernsRelation);
+                               if (rel != null && rel.equals(relation)) {
+                                       if (showOnlyCheckable && 
+                                               (SourceLinkUtil.isValidSource(graph, source) &&
+                                                SourceLinkUtil.isUpToDateSource(graph, source)))
+                                               continue;
+                                       children.add(new StandardGraphChildVariable(variable, null, source));
+                               }
+                       }
+               }
+               //find sources declared on this resource, ie. sources that do not have consernsRelation.
+               Collection<Resource> sources = graph.getObjects(resource, sl.hasSource);
+               for (Resource source : sources) {
+                       Resource rel = graph.getPossibleObject(source, sl.consernsRelation);
+                       if (rel == null) {
+                               if (showOnlyCheckable && 
+                                  (SourceLinkUtil.isValidSource(graph, source) &&
+                                   SourceLinkUtil.isUpToDateSource(graph, source)))
+                                       continue;
+                               children.add(new StandardGraphChildVariable(variable, null, source));
+                       }
+               }
+               while (children.remove(variable)) {
+                       
+               }
+               
+
+               return children;
+       }
+       
+       @Override
+       public Collection<?> getParents(ReadGraph graph, Object child)
+                       throws DatabaseException {
+               return new ArrayList<Resource>();
+       }
+
+}