import org.simantics.layer0.Layer0;
import org.simantics.scl.runtime.function.Function1;
import org.simantics.scl.runtime.tuple.Tuple;
-import org.simantics.spreadsheet.CellEditor;
-import org.simantics.spreadsheet.CellEditor.Transaction;
import org.simantics.spreadsheet.ClientModel;
-import org.simantics.spreadsheet.ClientModel.OperationMode;
+import org.simantics.spreadsheet.OperationMode;
import org.simantics.spreadsheet.Range;
import org.simantics.spreadsheet.Spreadsheets;
+import org.simantics.spreadsheet.Transaction;
import org.simantics.spreadsheet.common.TableCell;
import org.simantics.spreadsheet.common.cell.StringCellParser;
import org.simantics.spreadsheet.resource.SpreadsheetResource;
-import org.simantics.spreadsheet.synchronization.LineContentBean;
import org.simantics.utils.datastructures.Pair;
public class SpreadsheetUtils {
return true;
}
- public static void schedule(CellEditor.Transaction<?> transaction, Write write) {
+ public static void schedule(Transaction<?> transaction, Write write) {
if(transaction == null) {
return new TransactionImpl(mode);
}
- static class TransactionImpl implements CellEditor.Transaction<Write> {
+ static class TransactionImpl implements Transaction<Write> {
private ArrayList<Write> writes = new ArrayList<>();
private final OperationMode mode;
include "Document/All"
include "File"
+
+effect SpreadsheetTransaction
+ "spreadsheetTransaction"
+ "org.simantics.spreadsheet.Transaction"
+
importJava "org.simantics.spreadsheet.graph.ExternalRef" where
data ExternalRef
importJava "org.simantics.spreadsheet.common.TableCell" where
data TableCell
+importJava "java.util.function.Consumer" where
+ data Consumer
+
+importJava "org.simantics.spreadsheet.CellEditor" where
+ data CellEditor
+ startTransaction :: CellEditor -> OperationMode -> <Proc> Transaction
+ @JavaName "edit"
+ editProperty_ :: CellEditor -> String -> String -> a -> Binding a -> Maybe Consumer -> <SpreadsheetTransaction> ()
+ @JavaName "edit"
+ editContent :: CellEditor -> String -> Variant -> Maybe Consumer -> <SpreadsheetTransaction> ()
+
+@inline
+editProperty :: Serializable a => CellEditor -> String -> String -> a -> Maybe Consumer -> <SpreadsheetTransaction> ()
+editProperty editor location property value consumer = editProperty_ editor location property value binding consumer
+
+importJava "org.simantics.spreadsheet.OperationMode" where
+ data OperationMode
+ OPERATION :: OperationMode
+ EDIT_MODE :: OperationMode
+
+importJava "org.simantics.spreadsheet.Transaction" where
+ data Transaction
+ commit :: Transaction -> <Proc> ()
+
importJava "org.simantics.spreadsheet.common.TreeTableCell" where
data TreeTableCell
invalidateAll :: Variable -> <ReadGraph> ()
extRefVariable :: Variable -> <ReadGraph> Variant
extRefActiveVariable :: Variable -> <ReadGraph> Variant
+ cellEditor :: Resource -> <ReadGraph> CellEditor
+ syncExec :: CellEditor -> OperationMode -> (<SpreadsheetTransaction, Proc> a) -> <Proc> a
+ cellColumn :: Variable -> <ReadGraph> Integer
+
+importJava "org.simantics.spreadsheet.Spreadsheets" where
+ cellName :: Integer -> Integer -> String
importJava "org.simantics.spreadsheet.util.SpreadsheetUtils" where
createSheet :: Resource -> String -> <WriteGraph> Resource
setSCLLine :: Resource -> Integer -> String -> <WriteGraph> ()
sheetRun :: Resource -> Variable -> <ReadGraph> Variable
+sheetRunDefault :: Resource -> <ReadGraph> Variable
+sheetRunDefault sheet = sheetRun sheet (resourceVariable sheet)
+
importJava "org.simantics.spreadsheet.graph.SpreadsheetSessionManager" where
removeSpreadsheetSession :: Variable -> <Proc, WriteGraph> ()
import org.simantics.spreadsheet.Adaptable;
import org.simantics.spreadsheet.CellEditor;
import org.simantics.spreadsheet.ClientModel;
-import org.simantics.spreadsheet.ClientModel.OperationMode;
+import org.simantics.spreadsheet.OperationMode;
import org.simantics.spreadsheet.SheetCommands;
+import org.simantics.spreadsheet.Transaction;
import org.simantics.spreadsheet.event.model.RemoveCellHandler;
import org.simantics.spreadsheet.resource.SpreadsheetResource;
import org.simantics.spreadsheet.solver.SheetNode;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.exception.ServiceException;
import org.simantics.db.layer0.util.Layer0Utils;
+import org.simantics.db.layer0.variable.StandardGraphChildVariable;
import org.simantics.db.layer0.variable.Variable;
import org.simantics.db.layer0.variable.Variables;
import org.simantics.db.procedure.Listener;
import org.simantics.db.service.ClusteringSupport;
import org.simantics.layer0.Layer0;
+import org.simantics.scl.compiler.commands.CommandSession;
+import org.simantics.scl.runtime.SCLContext;
+import org.simantics.scl.runtime.function.Function;
+import org.simantics.scl.runtime.tuple.Tuple0;
import org.simantics.scl.runtime.tuple.Tuple2;
import org.simantics.simulator.toolkit.StandardRealm;
+import org.simantics.spreadsheet.CellEditor;
import org.simantics.spreadsheet.ExternalRef;
+import org.simantics.spreadsheet.OperationMode;
import org.simantics.spreadsheet.Range;
import org.simantics.spreadsheet.Spreadsheets;
+import org.simantics.spreadsheet.Transaction;
import org.simantics.spreadsheet.graph.synchronization.SpreadsheetSynchronizationEventHandler;
import org.simantics.spreadsheet.resource.SpreadsheetResource;
import org.simantics.spreadsheet.solver.SheetNode;
import org.simantics.spreadsheet.solver.SpreadsheetBook;
+import org.simantics.spreadsheet.solver.SpreadsheetCell;
import org.simantics.spreadsheet.solver.SpreadsheetEngine;
import org.simantics.spreadsheet.solver.SpreadsheetLine;
import org.simantics.spreadsheet.solver.SpreadsheetStyle;
}
+ public static CellEditor cellEditor(ReadGraph graph, Resource sheet) throws DatabaseException {
+ SpreadsheetResource SHEET = SpreadsheetResource.getInstance(graph);
+ Variable sheetVariable = Variables.getVariable(graph, sheet);
+ return sheetVariable.getPropertyValue(graph, SHEET.cellEditor);
+ }
+
+ public static final String SPREADSHEET_TRANSACTION = "spreadsheetTransaction";
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ public static Object syncExec(CellEditor editor, OperationMode mode, Function fun) throws InterruptedException {
+
+ Transaction tr = editor.startTransaction(mode);
+
+ SCLContext context = SCLContext.getCurrent();
+ Transaction oldTransaction = (Transaction)context.put(SPREADSHEET_TRANSACTION, tr);
+
+ Object result = null;
+
+ try {
+
+ result = fun.apply(Tuple0.INSTANCE);
+
+ } finally {
+
+ tr.commit();
+
+ context.put(SPREADSHEET_TRANSACTION, oldTransaction);
+
+ }
+
+ return result;
+
+ }
+
+ public static int cellColumn(ReadGraph graph, Variable cell) {
+ if(cell instanceof StandardGraphChildVariable) {
+ StandardGraphChildVariable sgcv = (StandardGraphChildVariable)cell;
+ SpreadsheetCell sc = (SpreadsheetCell)sgcv.node.node;
+ return sc.getColumn();
+ }
+ throw new IllegalStateException("Expected StandardGraphChildVariable, got " + cell.getClass().getName());
+ }
+
}
import org.simantics.db.layer0.variable.Variable;
import org.simantics.db.request.Write;
import org.simantics.spreadsheet.CellEditor;
-import org.simantics.spreadsheet.ClientModel.OperationMode;
+import org.simantics.spreadsheet.OperationMode;
+import org.simantics.spreadsheet.Transaction;
import org.simantics.spreadsheet.util.SpreadsheetUtils;
public class GraphCellEditorAdapter implements CellEditor<Write> {
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;
}
};
+
+ 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);
}
import org.simantics.spreadsheet.ClientModel;
import org.simantics.spreadsheet.ClientModel.ClientModelListener;
-import org.simantics.spreadsheet.ClientModel.OperationMode;
+import org.simantics.spreadsheet.OperationMode;
import org.simantics.spreadsheet.Spreadsheets;
import org.simantics.spreadsheet.solver.SpreadsheetStyle;
import org.simantics.spreadsheet.util.SpreadsheetUtils;
import org.simantics.databoard.binding.mutable.Variant;
import org.simantics.spreadsheet.Adaptable;
import org.simantics.spreadsheet.CellEditor;
-import org.simantics.spreadsheet.CellEditor.Transaction;
import org.simantics.spreadsheet.ClientModel;
-import org.simantics.spreadsheet.ClientModel.OperationMode;
+import org.simantics.spreadsheet.OperationMode;
import org.simantics.spreadsheet.Range;
import org.simantics.spreadsheet.Spreadsheets;
+import org.simantics.spreadsheet.Transaction;
import org.simantics.spreadsheet.common.cell.StringCellParser;
import org.simantics.spreadsheet.util.SpreadsheetUtils;
import org.simantics.utils.threads.logger.ITask;
import org.simantics.scenegraph.swing.JScrollPaneSG;
import org.simantics.spreadsheet.Adaptable;
import org.simantics.spreadsheet.CellEditor;
-import org.simantics.spreadsheet.CellEditor.Transaction;
import org.simantics.spreadsheet.ClientModel;
-import org.simantics.spreadsheet.ClientModel.OperationMode;
+import org.simantics.spreadsheet.OperationMode;
import org.simantics.spreadsheet.SheetCommands;
import org.simantics.spreadsheet.Spreadsheets;
+import org.simantics.spreadsheet.Transaction;
import org.simantics.spreadsheet.common.cell.Parsers;
import org.simantics.spreadsheet.common.cell.StringCellParser;
import org.simantics.spreadsheet.event.model.RemoveCellHandler;
import org.simantics.scenegraph.swing.JTableSG;
import org.simantics.spreadsheet.CellEditor;
import org.simantics.spreadsheet.ClientModel;
-import org.simantics.spreadsheet.ClientModel.OperationMode;
+import org.simantics.spreadsheet.OperationMode;
public class SpreadsheetTable extends JTableSG {
*******************************************************************************/
package org.simantics.spreadsheet;
-import java.util.List;
import java.util.function.Consumer;
import org.simantics.databoard.binding.Binding;
import org.simantics.databoard.binding.mutable.MutableVariant;
import org.simantics.databoard.binding.mutable.Variant;
-import org.simantics.spreadsheet.ClientModel.OperationMode;
public interface CellEditor<O> {
- public interface Transaction<O> {
-
- void setContext(Object context);
-
- Object getContext();
-
- void add(O operation);
-
- /*
- * Applies the operations collected with this transaction
- *
- */
- void commit();
-
- boolean isOperationMode();
-
- List<Object> needSynchronization();
-
- void needSynchronization(Object synchronizable);
- }
-
/*
* Sets the given property of the given cell
*
public interface ClientModel extends CellModifier {
- public enum OperationMode {
- OPERATION,
- EDIT_MODE
- }
-
public interface ClientModelListener {
public void rows(int amount);
--- /dev/null
+package org.simantics.spreadsheet;
+
+public enum OperationMode {
+ OPERATION,
+ EDIT_MODE
+}
\ No newline at end of file
--- /dev/null
+package org.simantics.spreadsheet;
+
+import java.util.List;
+
+public interface Transaction<O> {
+
+ void setContext(Object context);
+
+ Object getContext();
+
+ void add(O operation);
+
+ /*
+ * Applies the operations collected with this transaction
+ *
+ */
+ void commit();
+
+ boolean isOperationMode();
+
+ List<Object> needSynchronization();
+
+ void needSynchronization(Object synchronizable);
+}
\ No newline at end of file
public void setContent(Object newContent) {
this.content = newContent;
}
+
+ public int getColumn() {
+ return column;
+ }
@Override
public String getName() {