]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.selectionview/src/org/simantics/selectionview/DisplayPropertyVariableAdapter.java
Revert "Default property editing restores assertions"
[simantics/platform.git] / bundles / org.simantics.selectionview / src / org / simantics / selectionview / DisplayPropertyVariableAdapter.java
1 package org.simantics.selectionview;
2
3 import org.simantics.databoard.Datatypes;
4 import org.simantics.db.ReadGraph;
5 import org.simantics.db.Resource;
6 import org.simantics.db.common.adaption.SimpleContextualAdapter;
7 import org.simantics.db.exception.DatabaseException;
8 import org.simantics.db.layer0.variable.ConstantValueStandardGraphPropertyVariable;
9 import org.simantics.db.layer0.variable.ModelledVariablePropertyDescriptor;
10 import org.simantics.db.layer0.variable.Variable;
11 import org.simantics.db.layer0.variable.Variables;
12
13 public class DisplayPropertyVariableAdapter extends SimpleContextualAdapter<Variable, ModelledVariablePropertyDescriptor> {
14         
15     public String getDisplayProperty(ReadGraph graph, Variable property) throws DatabaseException {
16         Resource predicate = property.getPossiblePredicateResource(graph);
17         if(predicate == null) return property.getName(graph);
18         return Variables.getVariable(graph, graph.getURI(predicate)).getLabel(graph);
19 //        Variable predicate = property.getPossiblePropertyValue(graph, Variables.PREDICATE);
20 //        if(predicate == null) return property.getName(graph);
21 //        else return predicate.getPropertyValue(graph, Variables.LABEL);
22     }
23         
24         @Override
25         public Variable adapt(ReadGraph graph, Resource source, ModelledVariablePropertyDescriptor context) throws DatabaseException {
26                 
27         String value = getDisplayProperty(graph, context.getVariable());
28         return new ConstantValueStandardGraphPropertyVariable(graph, context.getVariable(), 
29                         context.getSubject(),
30                         SelectionViewResources.getInstance(graph).HasDisplayProperty,
31                         value != null ? value : "", Datatypes.STRING);
32                 
33         }
34
35 }