]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/adapter/CellVariable.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.spreadsheet.graph / src / org / simantics / spreadsheet / graph / adapter / CellVariable.java
diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/adapter/CellVariable.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/adapter/CellVariable.java
new file mode 100644 (file)
index 0000000..151f668
--- /dev/null
@@ -0,0 +1,52 @@
+package org.simantics.spreadsheet.graph.adapter;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.variable.StandardGraphChildVariable;\r
+import org.simantics.db.layer0.variable.Variable;\r
+import org.simantics.spreadsheet.common.cell.VariableCellEditor;\r
+\r
+public class CellVariable extends StandardGraphChildVariable {\r
+\r
+       public CellVariable(Variable parent, Resource resource) throws DatabaseException {\r
+               super(parent, null, resource);\r
+       }\r
+       \r
+       @Override\r
+       public String getLabel(ReadGraph graph) throws DatabaseException {\r
+               return null;\r
+       }\r
+       \r
+    @SuppressWarnings("unchecked")\r
+    protected <T> T tryAdapt(ReadGraph graph, Class<T> clazz) throws DatabaseException {\r
+       if(VariableCellEditor.class == clazz) {\r
+               return (T)new VariableCellEditor() {\r
+                               \r
+                               @Override\r
+                               public void edit(WriteGraph graph, Variable cell, String text) throws DatabaseException {\r
+                               }\r
+                               \r
+                               @Override\r
+                               public void copy(WriteGraph graph, Variable cell, String location) throws DatabaseException {\r
+                               }\r
+                               \r
+                       };\r
+       }\r
+       return null;\r
+    }\r
+\r
+    @Override\r
+    public <T> T adapt(ReadGraph graph, Class<T> clazz) throws DatabaseException {\r
+        T t = tryAdapt(graph, clazz);\r
+        return t != null ? t : super.adapt(graph, clazz);\r
+    }\r
+\r
+    @Override\r
+    public <T> T adaptPossible(ReadGraph graph, Class<T> clazz) throws DatabaseException {\r
+        T t = tryAdapt(graph, clazz);\r
+        return t != null ?  t : super.adaptPossible(graph, clazz);\r
+    }\r
+\r
+}\r