1 package org.simantics.selectionview;
\r
3 import org.simantics.databoard.Datatypes;
\r
4 import org.simantics.db.ReadGraph;
\r
5 import org.simantics.db.Resource;
\r
6 import org.simantics.db.common.adaption.SimpleContextualAdapter;
\r
7 import org.simantics.db.exception.DatabaseException;
\r
8 import org.simantics.db.layer0.variable.ConstantValueStandardGraphPropertyVariable;
\r
9 import org.simantics.db.layer0.variable.ModelledVariablePropertyDescriptor;
\r
10 import org.simantics.db.layer0.variable.Variable;
\r
11 import org.simantics.db.layer0.variable.Variables;
\r
13 public class DisplayPropertyVariableAdapter extends SimpleContextualAdapter<Variable, ModelledVariablePropertyDescriptor> {
\r
15 public String getDisplayProperty(ReadGraph graph, Variable property) throws DatabaseException {
\r
16 Resource predicate = property.getPossiblePredicateResource(graph);
\r
17 if(predicate == null) return property.getName(graph);
\r
18 return Variables.getVariable(graph, graph.getURI(predicate)).getLabel(graph);
\r
19 // Variable predicate = property.getPossiblePropertyValue(graph, Variables.PREDICATE);
\r
20 // if(predicate == null) return property.getName(graph);
\r
21 // else return predicate.getPropertyValue(graph, Variables.LABEL);
\r
25 public Variable adapt(ReadGraph graph, Resource source, ModelledVariablePropertyDescriptor context) throws DatabaseException {
\r
27 String value = getDisplayProperty(graph, context.getVariable());
\r
28 return new ConstantValueStandardGraphPropertyVariable(graph, context.getVariable(),
\r
29 context.getSubject(),
\r
30 SelectionViewResources.getInstance(graph).HasDisplayProperty,
\r
31 value != null ? value : "", Datatypes.STRING);
\r