]> gerrit.simantics Code Review - simantics/platform.git/blob
ae22581a2d3076769268dc33d078790e74d8980f
[simantics/platform.git] /
1 package org.simantics.spreadsheet.graph.celleditor;
2
3 import java.util.function.Consumer;
4
5 import org.simantics.databoard.binding.Binding;
6 import org.simantics.databoard.binding.mutable.MutableVariant;
7 import org.simantics.databoard.binding.mutable.Variant;
8 import org.simantics.db.WriteGraph;
9 import org.simantics.db.common.request.WriteRequest;
10 import org.simantics.db.exception.DatabaseException;
11 import org.simantics.db.layer0.util.Layer0Utils;
12 import org.simantics.db.layer0.variable.Variable;
13 import org.simantics.db.request.Write;
14 import org.simantics.spreadsheet.CellEditor;
15 import org.simantics.spreadsheet.ClientModel.OperationMode;
16 import org.simantics.spreadsheet.util.SpreadsheetUtils;
17
18 public class GraphCellEditorAdapter implements CellEditor<Write> {
19
20     protected final Variable cell;
21
22     public GraphCellEditorAdapter(Variable cell) {
23         this.cell = cell;
24     }
25     
26         public <T> void edit(WriteGraph graph, Transaction<Write> transaction, String location, String property, T value, Binding binding) throws DatabaseException {
27                 
28         }
29         
30         public <T> void edit(WriteGraph graph, Transaction<Write> transaction, String location, Variant value) throws DatabaseException {
31                 
32         }
33         
34         public <T> void copy(WriteGraph graph, Transaction<Write> transaction, String location, MutableVariant variant) throws DatabaseException {
35                 
36         }
37
38         @Override
39         public <T> void edit(Transaction<Write> transaction, final String location, final String property, final T value, final Binding binding, Consumer<?> callback) {
40                 SpreadsheetUtils.schedule(transaction, new WriteRequest() {
41
42                         @Override
43                         public void perform(WriteGraph graph) throws DatabaseException {
44                                 edit(graph, transaction, location, property, value, binding);
45                                 Layer0Utils.addCommentMetadata(graph, "Modified cell in location " + location + " with value " + value);
46                                 if (callback != null)
47                                     callback.accept(null);
48                         }
49                         
50                 });
51         }
52
53         @Override
54         public void edit(Transaction<Write> transaction, final String location, final Variant value, Consumer<?> callback) {
55                 SpreadsheetUtils.schedule(transaction, new WriteRequest() {
56
57                         @Override
58                         public void perform(WriteGraph graph) throws DatabaseException {
59                                 edit(graph, transaction, location, value);
60                                 Layer0Utils.addCommentMetadata(graph, "Modified cell on location " + location + " with value " + value);
61                                 if (callback != null)
62                                     callback.accept(null);
63                         }
64                         
65                 });
66         }
67
68         @Override
69         public void copy(Transaction<Write> transaction, final String location, final MutableVariant variant, Consumer<?> callback) {
70                 SpreadsheetUtils.schedule(transaction, new WriteRequest() {
71
72                         @Override
73                         public void perform(WriteGraph graph) throws DatabaseException {
74                                 copy(graph, transaction, location, variant);
75                         }
76                         
77                 });
78         }
79         
80         @Override
81         public Transaction<Write> startTransaction(OperationMode mode) {
82                 return SpreadsheetUtils.startTransaction(mode);
83         }
84
85 }