]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/function/All.java
Spreadsheet changes
[simantics/platform.git] / bundles / org.simantics.spreadsheet.graph / src / org / simantics / spreadsheet / graph / function / All.java
index 865a60ebe8c89e0d56eeb95024be98ceda1512e9..bc034086c7d1841eddc76d778b0d9c12e3b80171 100644 (file)
@@ -55,6 +55,7 @@ import org.simantics.spreadsheet.CellEditor;
 import org.simantics.spreadsheet.ClientModel;
 import org.simantics.spreadsheet.Range;
 import org.simantics.spreadsheet.Spreadsheets;
+import org.simantics.spreadsheet.Transaction;
 import org.simantics.spreadsheet.graph.SpreadsheetGraphUtils;
 import org.simantics.spreadsheet.graph.SpreadsheetNodeManager;
 import org.simantics.spreadsheet.graph.SpreadsheetSessionManager;
@@ -560,88 +561,96 @@ public class All {
         }
 
     };
+    
+    public static class DefaultSheetCellEditor extends GraphCellEditorAdapter {
+
+        final public Variable sheet;
+        
+        public DefaultSheetCellEditor(Variable sheet, Variable cell) {
+            super(cell);
+            this.sheet = sheet;
+        }
 
+        @Override
+        public <T> void edit(final Transaction<Write> transaction, final String location, final String property, final T value, final Binding binding, Consumer<?> callback) {
 
-    @SCLValue(type = "ReadGraph -> Resource -> Variable -> CellEditor")
-    public static CellEditor<Write> defaultSheetCellEditor(ReadGraph graph, Resource resource, final Variable context_) throws DatabaseException {
-
-        final Variable sheet = context_.getParent(graph);
-
-        return new GraphCellEditorAdapter(null) {
+            SpreadsheetUtils.schedule(transaction, new WriteRequest() {
 
-            @Override
-            public <T> void edit(final Transaction<Write> transaction, final String location, final String property, final T value, final Binding binding, Consumer<?> callback) {
+                @Override
+                public void perform(WriteGraph graph) throws DatabaseException {
+                    CellEditor<Write> editor = getPossibleCellEditor(graph, location, value == null ? null : new Variant(binding, value));
+                    if (editor == null)
+                        return;
+                    editor.edit(transaction, location, property, value, binding, callback);
+                }
+            });
 
-                SpreadsheetUtils.schedule(transaction, new WriteRequest() {
+        }
 
-                    @Override
-                    public void perform(WriteGraph graph) throws DatabaseException {
-                        CellEditor<Write> editor = getPossibleCellEditor(graph, location, value == null ? null : new Variant(binding, value));
-                        if (editor == null)
-                            return;
-                        editor.edit(transaction, location, property, value, binding, callback);
-                    }
-                });
+        @Override
+        public void edit(final Transaction<Write> transaction, final String location, final Variant value, Consumer<?> callback) {
+            SpreadsheetUtils.schedule(transaction, new WriteRequest() {
 
-            }
+                @Override
+                public void perform(WriteGraph graph) throws DatabaseException {
+                    CellEditor<Write> editor = getPossibleCellEditor(graph, location, value);
+                    if (editor == null)
+                        return;
+                    editor.edit(transaction, location, value, callback);
+                }
+            });
 
-            @Override
-            public void edit(final Transaction<Write> transaction, final String location, final Variant value, Consumer<?> callback) {
-                SpreadsheetUtils.schedule(transaction, new WriteRequest() {
-
-                    @Override
-                    public void perform(WriteGraph graph) throws DatabaseException {
-                        CellEditor<Write> editor = getPossibleCellEditor(graph, location, value);
-                        if (editor == null)
-                            return;
-                        editor.edit(transaction, location, value, callback);
-                    }
-                });
+        }
 
-            }
+        private CellEditor<Write> getPossibleCellEditor(WriteGraph graph, String location, Variant value) throws DatabaseException {
+            SpreadsheetResource SHEET = SpreadsheetResource.getInstance(graph);
+            Range range = Spreadsheets.decodePossibleCellAbsolute(location);
+            if(range == null) return null; //No editor found
 
-            private CellEditor<Write> getPossibleCellEditor(WriteGraph graph, String location, Variant value) throws DatabaseException {
-                SpreadsheetResource SHEET = SpreadsheetResource.getInstance(graph);
-                Range range = Spreadsheets.decodePossibleCellAbsolute(location);
-                if(range == null) return null; //No editor found
-
-                List<Variable> cells = SpreadsheetGraphUtils.possibleConfigurationCellVariables(graph, sheet, range);
-                if (cells.isEmpty()) {
-                    if (value == null) {
-                        return null;
-                    } else {
-                        cells = SpreadsheetGraphUtils.getOrCreateConfigurationCellVariables(graph, sheet, range);
-                    }
+            List<Variable> cells = SpreadsheetGraphUtils.possibleConfigurationCellVariables(graph, sheet, range);
+            if (cells.isEmpty()) {
+                if (value == null) {
+                    return null;
+                } else {
+                    cells = SpreadsheetGraphUtils.getOrCreateConfigurationCellVariables(graph, sheet, range);
                 }
-                if (cells.size() != 1)
-                    throw new DatabaseException("Can edit only one cell at a time!");
-
-                return cells.iterator().next().getPropertyValue(graph, SHEET.cellEditor);
             }
+            if (cells.size() != 1)
+                throw new DatabaseException("Can edit only one cell at a time!");
 
-            @Override
-            public void copy(final Transaction<Write> transaction, final String location, final MutableVariant variant, Consumer<?> callback) {
+            return cells.iterator().next().getPropertyValue(graph, SHEET.cellEditor);
+        }
+
+        @Override
+        public void copy(final Transaction<Write> transaction, final String location, final MutableVariant variant, Consumer<?> callback) {
 
-                SpreadsheetUtils.schedule(transaction, new WriteRequest() {
+            SpreadsheetUtils.schedule(transaction, new WriteRequest() {
 
-                    @Override
-                    public void perform(WriteGraph graph) throws DatabaseException {
+                @Override
+                public void perform(WriteGraph graph) throws DatabaseException {
 
-                        SpreadsheetResource SHEET = SpreadsheetResource.getInstance(graph);
-                        Variable variable = sheet.getPossibleChild(graph, location);
-                        if(variable != null) {
-                            CellEditor<Write> editor = variable.getPossiblePropertyValue(graph, SHEET.cellEditor);
-                            if(editor != null) {
-                                editor.copy(transaction, location, variant, null);
-                            }
+                    SpreadsheetResource SHEET = SpreadsheetResource.getInstance(graph);
+                    Variable variable = sheet.getPossibleChild(graph, location);
+                    if(variable != null) {
+                        CellEditor<Write> editor = variable.getPossiblePropertyValue(graph, SHEET.cellEditor);
+                        if(editor != null) {
+                            editor.copy(transaction, location, variant, null);
                         }
                     }
+                }
 
-                });
+            });
 
-            }
+        }
+        
+    }
 
-        };
+
+    @SCLValue(type = "ReadGraph -> Resource -> Variable -> CellEditor")
+    public static CellEditor<Write> defaultSheetCellEditor(ReadGraph graph, Resource resource, final Variable context_) throws DatabaseException {
+
+        final Variable sheet = context_.getParent(graph);
+        return new DefaultSheetCellEditor(sheet, null);
 
     }