]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/viewpoint/VariablePropertyRule.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / viewpoint / VariablePropertyRule.java
index 0323cfad4ece25174d560676b7840c67a4899419..08400f78763d1465282b3654da9ede9a9449e808 100644 (file)
-package org.simantics.modeling.ui.viewpoint;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Collection;\r
-import java.util.Collections;\r
-\r
-import org.simantics.browsing.ui.model.children.ChildRule;\r
-import org.simantics.databoard.Bindings;\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.Variable;\r
-import org.simantics.db.layer0.variable.Variables;\r
-import org.simantics.db.layer0.variable.Variables.Role;\r
-import org.simantics.layer0.Layer0;\r
-import org.simantics.modeling.ModelingResources;\r
-import org.simantics.selectionview.SelectionViewResources;\r
-\r
-public class VariablePropertyRule implements ChildRule {\r
-\r
-       final private ArrayList<String> requiredProperties = new ArrayList<String>();\r
-       final private ArrayList<String> filteredProperties = new ArrayList<String>();\r
-       \r
-       public VariablePropertyRule(ReadGraph graph, Resource rule) throws DatabaseException {\r
-\r
-               ModelingResources MOD = ModelingResources.getInstance(graph);\r
-               for(Resource r : graph.getObjects(rule, MOD.ModelingBrowseContext_VariablePropertyRule_RequireProperty)) {\r
-                       String name = graph.getValue(r, Bindings.STRING);\r
-                       requiredProperties.add(name);\r
-               }\r
-               for(Resource r : graph.getObjects(rule, MOD.ModelingBrowseContext_VariablePropertyRule_FilterProperty)) {\r
-                       String name = graph.getValue(r, Bindings.STRING);\r
-                       filteredProperties.add(name);\r
-               }\r
-               \r
-       }\r
-       \r
-    @Override\r
-    public boolean isCompatible(Class<?> contentType) {\r
-        return contentType.equals(Variable.class);\r
-    }\r
-\r
-    private boolean validate(ReadGraph graph, Variable parent, Variable child) throws DatabaseException {\r
-       \r
-       Resource predicate = child.getPossiblePredicateResource(graph);\r
-       if(predicate == null) return true;\r
-       \r
-       Layer0 L0 = Layer0.getInstance(graph);\r
-       if(L0.HasName.equals(predicate) || L0.HasLabel.equals(predicate)) {\r
-            Role role = parent.getRole(graph);\r
-            if(role == Role.PROPERTY) return false;\r
-       }\r
-       return true;\r
-    }\r
-    \r
-    @Override\r
-    public Collection<?> getChildren(ReadGraph graph, Object parent_)\r
-            throws DatabaseException {\r
-       \r
-       Variable parent = (Variable)parent_;\r
-       \r
-       ArrayList<Variable> result = new ArrayList<Variable>();\r
-\r
-       Collection<Variable> properties = parent.getProperties(graph);\r
-       ArrayList<Resource> propertiesPredicates = new ArrayList<Resource>();\r
-       for (Variable property : properties) {\r
-           Resource r = property.getPossiblePredicateResource(graph);\r
-           if (r != null)\r
-               propertiesPredicates.add(r);\r
-       }\r
-       \r
-       Layer0 L0 = Layer0.getInstance(graph);\r
-       SelectionViewResources SEL = SelectionViewResources.getInstance(graph);\r
-       \r
-       props: for(Variable property : properties) {\r
-               \r
-           if (isUnder(graph, L0, SEL, property, propertiesPredicates)) continue props;\r
-           \r
-           Boolean hidden = property.getPossiblePropertyValue(graph, SEL.hidden, Bindings.BOOLEAN);\r
-           if(hidden != null && hidden) continue props;\r
-           \r
-               for(String req : requiredProperties) if(property.getPossibleProperty(graph, req) == null) continue props;\r
-\r
-               for(String req : filteredProperties) if(property.getName(graph).equals(req)) continue props;\r
-\r
-               if(!validate(graph, parent, property)) continue;\r
-                               \r
-               //System.err.println("add " + property.getURI(graph));\r
-               \r
-               result.add(property);\r
-                               \r
-       }\r
-       \r
-       Resource predicateResource = parent.getPossiblePredicateResource(graph);\r
-       if (predicateResource != null) {\r
-               Collection<Resource> underOfs = graph.getObjects(predicateResource, SEL.UnderOf);\r
-               if (!underOfs.isEmpty()) {\r
-                   Collection<Variable> siblings = parent.getParent(graph).getProperties(graph);\r
-                   for (Variable sibling : siblings) {\r
-                       Resource r = sibling.getPossiblePredicateResource(graph);\r
-                       if (r != null) {\r
-                        if (underOfs.contains(r))\r
-                            result.add(sibling);\r
-                       }\r
-                   }\r
-               }\r
-       }\r
-       \r
-       if(isUnderProperty(graph, parent)) {\r
-               Collection<Variable> children = parent.getChildren(graph);\r
-               for(Variable child : children) {\r
-                   result.add(child);\r
-               }\r
-       }\r
-       \r
-        return result;\r
-    }\r
-    \r
-    private boolean isUnderProperty(ReadGraph graph, Variable variable) throws DatabaseException {\r
-       Role role = variable.getRole(graph);\r
-       if(Role.PROPERTY.equals(role)) {\r
-               return true;\r
-       }\r
-       Variable parent = variable.getParent(graph);\r
-       if(parent == null) return false;\r
-       else return isUnderProperty(graph, parent);\r
-       \r
-    }\r
-\r
-    private boolean isUnder(ReadGraph graph, Layer0 L0, SelectionViewResources SEL, Variable property, ArrayList<Resource> propertiesPredicates) throws DatabaseException {\r
-        Resource predicate = property.getPossiblePredicateResource(graph);\r
-        if (predicate == null)\r
-            return false;\r
-        Collection<Resource> shownUnders = graph.getObjects(predicate, SEL.IsShownUnder);\r
-        return !Collections.disjoint(propertiesPredicates, shownUnders);\r
-    }\r
-    \r
-    @Override\r
-    public Collection<?> getParents(ReadGraph graph, Object child)\r
-            throws DatabaseException {\r
-        Variable parent = ((Variable)child).getParent(graph);\r
-        if(parent == null)\r
-            return Collections.emptyList();\r
-        else\r
-            return Collections.singleton(parent);\r
-    }\r
-\r
-}\r
+package org.simantics.modeling.ui.viewpoint;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+
+import org.simantics.browsing.ui.model.children.ChildRule;
+import org.simantics.databoard.Bindings;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.variable.Variable;
+import org.simantics.db.layer0.variable.Variables;
+import org.simantics.db.layer0.variable.Variables.Role;
+import org.simantics.layer0.Layer0;
+import org.simantics.modeling.ModelingResources;
+import org.simantics.selectionview.SelectionViewResources;
+
+public class VariablePropertyRule implements ChildRule {
+
+       final private ArrayList<String> requiredProperties = new ArrayList<String>();
+       final private ArrayList<String> filteredProperties = new ArrayList<String>();
+       
+       public VariablePropertyRule(ReadGraph graph, Resource rule) throws DatabaseException {
+
+               ModelingResources MOD = ModelingResources.getInstance(graph);
+               for(Resource r : graph.getObjects(rule, MOD.ModelingBrowseContext_VariablePropertyRule_RequireProperty)) {
+                       String name = graph.getValue(r, Bindings.STRING);
+                       requiredProperties.add(name);
+               }
+               for(Resource r : graph.getObjects(rule, MOD.ModelingBrowseContext_VariablePropertyRule_FilterProperty)) {
+                       String name = graph.getValue(r, Bindings.STRING);
+                       filteredProperties.add(name);
+               }
+               
+       }
+       
+    @Override
+    public boolean isCompatible(Class<?> contentType) {
+        return contentType.equals(Variable.class);
+    }
+
+    private boolean validate(ReadGraph graph, Variable parent, Variable child) throws DatabaseException {
+       
+       Resource predicate = child.getPossiblePredicateResource(graph);
+       if(predicate == null) return true;
+       
+       Layer0 L0 = Layer0.getInstance(graph);
+       if(L0.HasName.equals(predicate) || L0.HasLabel.equals(predicate)) {
+            Role role = parent.getRole(graph);
+            if(role == Role.PROPERTY) return false;
+       }
+       return true;
+    }
+    
+    @Override
+    public Collection<?> getChildren(ReadGraph graph, Object parent_)
+            throws DatabaseException {
+       
+       Variable parent = (Variable)parent_;
+       
+       ArrayList<Variable> result = new ArrayList<Variable>();
+
+       Collection<Variable> properties = parent.getProperties(graph);
+       ArrayList<Resource> propertiesPredicates = new ArrayList<Resource>();
+       for (Variable property : properties) {
+           Resource r = property.getPossiblePredicateResource(graph);
+           if (r != null)
+               propertiesPredicates.add(r);
+       }
+       
+       Layer0 L0 = Layer0.getInstance(graph);
+       SelectionViewResources SEL = SelectionViewResources.getInstance(graph);
+       
+       props: for(Variable property : properties) {
+               
+           if (isUnder(graph, L0, SEL, property, propertiesPredicates)) continue props;
+           
+           Boolean hidden = property.getPossiblePropertyValue(graph, SEL.hidden, Bindings.BOOLEAN);
+           if(hidden != null && hidden) continue props;
+           
+               for(String req : requiredProperties) if(property.getPossibleProperty(graph, req) == null) continue props;
+
+               for(String req : filteredProperties) if(property.getName(graph).equals(req)) continue props;
+
+               if(!validate(graph, parent, property)) continue;
+                               
+               //System.err.println("add " + property.getURI(graph));
+               
+               result.add(property);
+                               
+       }
+       
+       Resource predicateResource = parent.getPossiblePredicateResource(graph);
+       if (predicateResource != null) {
+               Collection<Resource> underOfs = graph.getObjects(predicateResource, SEL.UnderOf);
+               if (!underOfs.isEmpty()) {
+                   Collection<Variable> siblings = parent.getParent(graph).getProperties(graph);
+                   for (Variable sibling : siblings) {
+                       Resource r = sibling.getPossiblePredicateResource(graph);
+                       if (r != null) {
+                        if (underOfs.contains(r))
+                            result.add(sibling);
+                       }
+                   }
+               }
+       }
+       
+       if(isUnderProperty(graph, parent)) {
+               Collection<Variable> children = parent.getChildren(graph);
+               for(Variable child : children) {
+                   result.add(child);
+               }
+       }
+       
+        return result;
+    }
+    
+    private boolean isUnderProperty(ReadGraph graph, Variable variable) throws DatabaseException {
+       Role role = variable.getRole(graph);
+       if(Role.PROPERTY.equals(role)) {
+               return true;
+       }
+       Variable parent = variable.getParent(graph);
+       if(parent == null) return false;
+       else return isUnderProperty(graph, parent);
+       
+    }
+
+    private boolean isUnder(ReadGraph graph, Layer0 L0, SelectionViewResources SEL, Variable property, ArrayList<Resource> propertiesPredicates) throws DatabaseException {
+        Resource predicate = property.getPossiblePredicateResource(graph);
+        if (predicate == null)
+            return false;
+        Collection<Resource> shownUnders = graph.getObjects(predicate, SEL.IsShownUnder);
+        return !Collections.disjoint(propertiesPredicates, shownUnders);
+    }
+    
+    @Override
+    public Collection<?> getParents(ReadGraph graph, Object child)
+            throws DatabaseException {
+        Variable parent = ((Variable)child).getParent(graph);
+        if(parent == null)
+            return Collections.emptyList();
+        else
+            return Collections.singleton(parent);
+    }
+
+}