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