X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.selectionview%2Fsrc%2Forg%2Fsimantics%2Fselectionview%2FVariablePropertyCategoryRule.java;fp=bundles%2Forg.simantics.selectionview%2Fsrc%2Forg%2Fsimantics%2Fselectionview%2FVariablePropertyCategoryRule.java;h=307c2e750f452c7348b13bb7a6bb93609013cb9e;hp=0000000000000000000000000000000000000000;hb=969bd23cab98a79ca9101af33334000879fb60c5;hpb=866dba5cd5a3929bbeae85991796acb212338a08 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 index 000000000..307c2e750 --- /dev/null +++ b/bundles/org.simantics.selectionview/src/org/simantics/selectionview/VariablePropertyCategoryRule.java @@ -0,0 +1,75 @@ +package org.simantics.selectionview; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; + +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.modeling.ModelingResources; + +public class VariablePropertyCategoryRule implements ChildRule { + + final private ArrayList requiredProperties = new ArrayList(); + final Resource rule; + + public VariablePropertyCategoryRule(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); + } + + this.rule = rule; + + } + + @Override + public boolean isCompatible(Class contentType) { + return contentType.equals(Variable.class); + } + + @Override + public Collection getChildren(ReadGraph graph, Object parent) throws DatabaseException { + + HashSet result = new HashSet(); + + props: for(Variable property : ((Variable)parent).getProperties(graph)) { + + for(String req : requiredProperties) { + if(property.getPossibleProperty(graph, req) == null) continue props; + } + + Variable info = property.getPossibleProperty(graph, SelectionVariables.PROPERTY_INFO); + if(info != null) { + + Variable special = SelectionViewUtils.getSpecialCategory(graph, rule, info); + if(special != null) info = special; + + Boolean hidden = info.getPossiblePropertyValue(graph, SelectionVariables.CATEGORY_HIDDEN, Bindings.BOOLEAN); + if(hidden != null && hidden) continue; + String name = info.getPossiblePropertyValue(graph, SelectionVariables.CATEGORY_NAME, Bindings.STRING); + if(name == null) continue; + String sortName = info.getPossiblePropertyValue(graph, SelectionVariables.CATEGORY_SORTING_NAME, Bindings.STRING); + result.add(new CategoryNodeImpl(name, sortName)); + + } + + } + + return result; + + } + + @Override + public Collection getParents(ReadGraph graph, Object child) + throws DatabaseException { + return null; + } + +}