1 package org.simantics.spreadsheet.graph.celleditor;
3 import java.util.function.Consumer;
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;
18 public class GraphCellEditorAdapter implements CellEditor<Write> {
20 protected final Variable cell;
22 public GraphCellEditorAdapter(Variable cell) {
26 public <T> void edit(WriteGraph graph, Transaction<Write> transaction, String location, String property, T value, Binding binding) throws DatabaseException {
30 public <T> void edit(WriteGraph graph, Transaction<Write> transaction, String location, Variant value) throws DatabaseException {
34 public <T> void copy(WriteGraph graph, Transaction<Write> transaction, String location, MutableVariant variant) throws DatabaseException {
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() {
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);
47 callback.accept(null);
54 public void edit(Transaction<Write> transaction, final String location, final Variant value, Consumer<?> callback) {
55 SpreadsheetUtils.schedule(transaction, new WriteRequest() {
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);
62 callback.accept(null);
69 public void copy(Transaction<Write> transaction, final String location, final MutableVariant variant, Consumer<?> callback) {
70 SpreadsheetUtils.schedule(transaction, new WriteRequest() {
73 public void perform(WriteGraph graph) throws DatabaseException {
74 copy(graph, transaction, location, variant);
81 public Transaction<Write> startTransaction(OperationMode mode) {
82 return SpreadsheetUtils.startTransaction(mode);