1 package org.simantics.selectionview;
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;
13 public class DisplayPropertyVariableAdapter extends SimpleContextualAdapter<Variable, ModelledVariablePropertyDescriptor> {
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);
25 public Variable adapt(ReadGraph graph, Resource source, ModelledVariablePropertyDescriptor context) throws DatabaseException {
27 String value = getDisplayProperty(graph, context.getVariable());
28 return new ConstantValueStandardGraphPropertyVariable(graph, context.getVariable(),
30 SelectionViewResources.getInstance(graph).HasDisplayProperty,
31 value != null ? value : "", Datatypes.STRING);