]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.selectionview/src/org/simantics/selectionview/VariablePropertyCategoryRule.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.selectionview / src / org / simantics / selectionview / VariablePropertyCategoryRule.java
diff --git a/bundles/org.simantics.selectionview/src/org/simantics/selectionview/VariablePropertyCategoryRule.java b/bundles/org.simantics.selectionview/src/org/simantics/selectionview/VariablePropertyCategoryRule.java
new file mode 100644 (file)
index 0000000..307c2e7
--- /dev/null
@@ -0,0 +1,75 @@
+package org.simantics.selectionview;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+import java.util.HashSet;\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.modeling.ModelingResources;\r
+\r
+public class VariablePropertyCategoryRule implements ChildRule {\r
+\r
+       final private ArrayList<String> requiredProperties = new ArrayList<String>();\r
+       final Resource rule;\r
+       \r
+       public VariablePropertyCategoryRule(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
+               \r
+               this.rule = rule;\r
+               \r
+       }\r
+       \r
+    @Override\r
+    public boolean isCompatible(Class<?> contentType) {\r
+        return contentType.equals(Variable.class);\r
+    }\r
+\r
+    @Override\r
+    public Collection<?> getChildren(ReadGraph graph, Object parent) throws DatabaseException {\r
+       \r
+       HashSet<CategoryNode> result = new HashSet<CategoryNode>();\r
+\r
+       props: for(Variable property : ((Variable)parent).getProperties(graph)) {\r
+\r
+               for(String req : requiredProperties) {\r
+                       if(property.getPossibleProperty(graph, req) == null) continue props;\r
+               }\r
+               \r
+               Variable info = property.getPossibleProperty(graph, SelectionVariables.PROPERTY_INFO);\r
+               if(info != null) {\r
+                       \r
+                       Variable special = SelectionViewUtils.getSpecialCategory(graph, rule, info);\r
+                       if(special != null) info = special;\r
+                       \r
+                       Boolean hidden = info.getPossiblePropertyValue(graph, SelectionVariables.CATEGORY_HIDDEN, Bindings.BOOLEAN);\r
+                       if(hidden != null && hidden) continue;\r
+                       String name = info.getPossiblePropertyValue(graph, SelectionVariables.CATEGORY_NAME, Bindings.STRING);\r
+                       if(name == null) continue;\r
+                       String sortName = info.getPossiblePropertyValue(graph, SelectionVariables.CATEGORY_SORTING_NAME, Bindings.STRING);\r
+                       result.add(new CategoryNodeImpl(name, sortName));\r
+                       \r
+               }\r
+                               \r
+       }\r
+       \r
+        return result;\r
+        \r
+    }\r
+\r
+    @Override\r
+    public Collection<?> getParents(ReadGraph graph, Object child)\r
+            throws DatabaseException {\r
+       return null;\r
+    }\r
+\r
+}\r