]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.selectionview/src/org/simantics/selectionview/VariablePropertyCategoryRule.java
Revert "Default property editing restores assertions"
[simantics/platform.git] / bundles / org.simantics.selectionview / src / org / simantics / selectionview / VariablePropertyCategoryRule.java
1 package org.simantics.selectionview;
2
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.HashSet;
6
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;
14
15 public class VariablePropertyCategoryRule implements ChildRule {
16
17         final private ArrayList<String> requiredProperties = new ArrayList<String>();
18         final Resource rule;
19         
20         public VariablePropertyCategoryRule(ReadGraph graph, Resource rule) throws DatabaseException {
21
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);
26                 }
27                 
28                 this.rule = rule;
29                 
30         }
31         
32     @Override
33     public boolean isCompatible(Class<?> contentType) {
34         return contentType.equals(Variable.class);
35     }
36
37     @Override
38     public Collection<?> getChildren(ReadGraph graph, Object parent) throws DatabaseException {
39         
40         HashSet<CategoryNode> result = new HashSet<CategoryNode>();
41
42         props: for(Variable property : ((Variable)parent).getProperties(graph)) {
43
44                 for(String req : requiredProperties) {
45                         if(property.getPossibleProperty(graph, req) == null) continue props;
46                 }
47                 
48                 Variable info = property.getPossibleProperty(graph, SelectionVariables.PROPERTY_INFO);
49                 if(info != null) {
50                         
51                         Variable special = SelectionViewUtils.getSpecialCategory(graph, rule, info);
52                         if(special != null) info = special;
53                         
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));
60                         
61                 }
62                                 
63         }
64         
65         return result;
66         
67     }
68
69     @Override
70     public Collection<?> getParents(ReadGraph graph, Object child)
71             throws DatabaseException {
72         return null;
73     }
74
75 }