X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.selectionview%2Fsrc%2Forg%2Fsimantics%2Fselectionview%2FDisplayPropertyVariableAdapter.java;fp=bundles%2Forg.simantics.selectionview%2Fsrc%2Forg%2Fsimantics%2Fselectionview%2FDisplayPropertyVariableAdapter.java;h=a0e30e994e6058957af239686b4b223b4b6d023c;hp=0000000000000000000000000000000000000000;hb=969bd23cab98a79ca9101af33334000879fb60c5;hpb=866dba5cd5a3929bbeae85991796acb212338a08 diff --git a/bundles/org.simantics.selectionview/src/org/simantics/selectionview/DisplayPropertyVariableAdapter.java b/bundles/org.simantics.selectionview/src/org/simantics/selectionview/DisplayPropertyVariableAdapter.java new file mode 100644 index 000000000..a0e30e994 --- /dev/null +++ b/bundles/org.simantics.selectionview/src/org/simantics/selectionview/DisplayPropertyVariableAdapter.java @@ -0,0 +1,35 @@ +package org.simantics.selectionview; + +import org.simantics.databoard.Datatypes; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.adaption.SimpleContextualAdapter; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.ConstantValueStandardGraphPropertyVariable; +import org.simantics.db.layer0.variable.ModelledVariablePropertyDescriptor; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.db.layer0.variable.Variables; + +public class DisplayPropertyVariableAdapter extends SimpleContextualAdapter { + + public String getDisplayProperty(ReadGraph graph, Variable property) throws DatabaseException { + Resource predicate = property.getPossiblePredicateResource(graph); + if(predicate == null) return property.getName(graph); + return Variables.getVariable(graph, graph.getURI(predicate)).getLabel(graph); +// Variable predicate = property.getPossiblePropertyValue(graph, Variables.PREDICATE); +// if(predicate == null) return property.getName(graph); +// else return predicate.getPropertyValue(graph, Variables.LABEL); + } + + @Override + public Variable adapt(ReadGraph graph, Resource source, ModelledVariablePropertyDescriptor context) throws DatabaseException { + + String value = getDisplayProperty(graph, context.getVariable()); + return new ConstantValueStandardGraphPropertyVariable(graph, context.getVariable(), + context.getSubject(), + SelectionViewResources.getInstance(graph).HasDisplayProperty, + value != null ? value : "", Datatypes.STRING); + + } + +}