1 package org.simantics.selectionview;
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.HashSet;
7 import org.simantics.browsing.ui.model.children.ChildRule;
8 import org.simantics.databoard.Bindings;
9 import org.simantics.db.ReadGraph;
10 import org.simantics.db.Resource;
11 import org.simantics.db.exception.DatabaseException;
12 import org.simantics.db.layer0.variable.Variable;
13 import org.simantics.modeling.ModelingResources;
15 public class VariablePropertyCategoryRule implements ChildRule {
17 final private ArrayList<String> requiredProperties = new ArrayList<String>();
20 public VariablePropertyCategoryRule(ReadGraph graph, Resource rule) throws DatabaseException {
22 ModelingResources MOD = ModelingResources.getInstance(graph);
23 for(Resource r : graph.getObjects(rule, MOD.ModelingBrowseContext_VariablePropertyRule_RequireProperty)) {
24 String name = graph.getValue(r, Bindings.STRING);
25 requiredProperties.add(name);
33 public boolean isCompatible(Class<?> contentType) {
34 return contentType.equals(Variable.class);
38 public Collection<?> getChildren(ReadGraph graph, Object parent) throws DatabaseException {
40 HashSet<CategoryNode> result = new HashSet<CategoryNode>();
42 props: for(Variable property : ((Variable)parent).getProperties(graph)) {
44 for(String req : requiredProperties) {
45 if(property.getPossibleProperty(graph, req) == null) continue props;
48 Variable info = property.getPossibleProperty(graph, SelectionVariables.PROPERTY_INFO);
51 Variable special = SelectionViewUtils.getSpecialCategory(graph, rule, info);
52 if(special != null) info = special;
54 Boolean hidden = info.getPossiblePropertyValue(graph, SelectionVariables.CATEGORY_HIDDEN, Bindings.BOOLEAN);
55 if(hidden != null && hidden) continue;
56 String name = info.getPossiblePropertyValue(graph, SelectionVariables.CATEGORY_NAME, Bindings.STRING);
57 if(name == null) continue;
58 String sortName = info.getPossiblePropertyValue(graph, SelectionVariables.CATEGORY_SORTING_NAME, Bindings.STRING);
59 result.add(new CategoryNodeImpl(name, sortName));
70 public Collection<?> getParents(ReadGraph graph, Object child)
71 throws DatabaseException {