]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.selectionview/src/org/simantics/selectionview/DisplayPropertyVariableAdapter.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.selectionview / src / org / simantics / selectionview / DisplayPropertyVariableAdapter.java
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 (file)
index 0000000..a0e30e9
--- /dev/null
@@ -0,0 +1,35 @@
+package org.simantics.selectionview;\r
+\r
+import org.simantics.databoard.Datatypes;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.adaption.SimpleContextualAdapter;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.variable.ConstantValueStandardGraphPropertyVariable;\r
+import org.simantics.db.layer0.variable.ModelledVariablePropertyDescriptor;\r
+import org.simantics.db.layer0.variable.Variable;\r
+import org.simantics.db.layer0.variable.Variables;\r
+\r
+public class DisplayPropertyVariableAdapter extends SimpleContextualAdapter<Variable, ModelledVariablePropertyDescriptor> {\r
+       \r
+    public String getDisplayProperty(ReadGraph graph, Variable property) throws DatabaseException {\r
+       Resource predicate = property.getPossiblePredicateResource(graph);\r
+       if(predicate == null) return property.getName(graph);\r
+       return Variables.getVariable(graph, graph.getURI(predicate)).getLabel(graph);\r
+//        Variable predicate = property.getPossiblePropertyValue(graph, Variables.PREDICATE);\r
+//        if(predicate == null) return property.getName(graph);\r
+//        else return predicate.getPropertyValue(graph, Variables.LABEL);\r
+    }\r
+       \r
+       @Override\r
+       public Variable adapt(ReadGraph graph, Resource source, ModelledVariablePropertyDescriptor context) throws DatabaseException {\r
+               \r
+       String value = getDisplayProperty(graph, context.getVariable());\r
+       return new ConstantValueStandardGraphPropertyVariable(graph, context.getVariable(), \r
+                       context.getSubject(),\r
+                       SelectionViewResources.getInstance(graph).HasDisplayProperty,\r
+                       value != null ? value : "", Datatypes.STRING);\r
+               \r
+       }\r
+\r
+}\r