import org.simantics.db.common.request.BinaryRead;
import org.simantics.db.common.request.ObjectsWithType;
import org.simantics.db.common.request.UnaryRead;
+import org.simantics.db.common.request.WriteRequest;
import org.simantics.db.common.utils.LiteralFileUtil;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.exception.ServiceException;
});
}
+ @Override
+ public void modify(Object context, Variant newValue) {
+
+ Simantics.getSession().asyncRequest(new WriteRequest() {
+
+ @Override
+ public void perform(WriteGraph graph) throws DatabaseException {
+ Variable variable = Variables.getVariable(graph, uri);
+ variable.setValue(graph, newValue);
+ }
+ });
+
+ }
+
}
public static Variant extRefActiveVariable(ReadGraph graph, Variable var) throws DatabaseException {
});
}
+ @Override
+ public void modify(Object context, Variant newValue) {
+
+ Simantics.getSession().asyncRequest(new WriteRequest() {
+
+ @Override
+ public void perform(WriteGraph graph) throws DatabaseException {
+ Variable contextVariable = Variables.getVariable(graph, (String)context);
+ Variable configVariable = Variables.getVariable(graph,uri);
+ Variable activeVariable = Variables.switchPossibleContext(graph, configVariable, contextVariable.getRepresents(graph));
+ if(activeVariable == null) return;
+ activeVariable.setValue(graph, newValue.getValue(), newValue.getBinding());
+ }
+ });
+
+ }
+
}
public static CellEditor cellEditor(ReadGraph graph, Resource sheet) throws DatabaseException {
public SpreadsheetNodeManager(SpreadsheetRealm realm) {
super(realm, realm.getEngine());
- new Exception().printStackTrace();
realm.getEngine().registerListener(new SpreadsheetBookListener() {
@Override
@Override
public void run() {
for(SpreadsheetCell cell : cells) {
- System.err.println("Modification in cell " + cell.getName());
refreshVariable(new SpreadsheetCellContent(cell));
Object content = cell.getContent();
if(content instanceof SpreadsheetFormula || content instanceof SpreadsheetSCLConstant)
StandardRealm<SheetNode, SpreadsheetBook> realm = SpreadsheetSessionManager.getInstance().getOrCreateRealm(graph, sessionName);
SpreadsheetBook book = realm.getEngine();
SpreadsheetCell sc = book.get(sheet.getName(graph), r.startRow, r.startColumn);
- sc.setContent(value);
+ //sc.setContent(value);
realm.asyncExec(new Runnable() {
@Override
if (style != null)
styleId = graph.getPossibleRelatedValue(style, SR.Style_id, Bindings.INTEGER);
if (styleId == null) {
- System.err.println("Style " + style + " has no ID or either cell "+ repr + " has no style attached to it !!");
styleId = SpreadsheetStyle.empty().getStyleId();
}
}
if (runCell != null) {
- System.out.println("All.edit " + runCell.getURI(graph));
runCell.setPropertyValue(graph, SHEET.Cell_content, value, Bindings.VARIANT);
}
}
}
public void listen(Object context, ExternalRefListener listener);
+ public void modify(Object context, Variant newValue);
}
--- /dev/null
+package org.simantics.spreadsheet.solver;
+
+import org.simantics.databoard.binding.mutable.Variant;
+import org.simantics.spreadsheet.ExternalRef;
+
+public class ExternalRefConstant implements ExternalRef {
+
+ final private Variant constant;
+
+ public ExternalRefConstant(Variant constant) {
+ this.constant = constant;
+ }
+
+ @Override
+ public void listen(Object context, ExternalRefListener listener) {
+ listener.newValue(constant);
+ }
+
+ @Override
+ public void modify(Object context, Variant newValue) {
+ }
+
+}
+
--- /dev/null
+package org.simantics.spreadsheet.solver;
+
+import org.simantics.databoard.binding.mutable.Variant;
+import org.simantics.spreadsheet.ExternalRef;
+import org.simantics.spreadsheet.ExternalRef.ExternalRefListener;
+
+class ExternalRefData implements ExternalRefListener {
+
+ final private SpreadsheetBook book;
+ final private long referenceKey;
+ final private ExternalRef ref;
+ private boolean isDisposed = false;
+ private Variant value = SpreadsheetBook.DEFAULT_VALUE;
+
+ public ExternalRefData(SpreadsheetBook book, long referenceKey, ExternalRef ref) {
+ this.book = book;
+ this.referenceKey = referenceKey;
+ this.ref = ref;
+ ref.listen(book.context, this);
+ }
+
+ public Variant getContent() {
+ return value;
+ }
+
+ public ExternalRef getRef() {
+ return ref;
+ }
+
+ @Override
+ public void newValue(Variant newVariant) {
+ SpreadsheetCell cell = book.cellByReferenceKey(referenceKey);
+ if(cell.getContent() instanceof SpreadsheetSCLConstant) {
+ SpreadsheetSCLConstant ssc = (SpreadsheetSCLConstant)cell.getContent();
+ Object content = ssc.getContent();
+ if(content.equals(ref)) {
+ value = newVariant;
+ book.fireChanges(book.invalidate(cell));
+ return;
+ }
+ }
+ isDisposed = true;
+ }
+
+ @Override
+ public boolean isDisposed() {
+ if(isDisposed)
+ return true;
+ return book.isDisposed();
+ }
+
+}
\ No newline at end of file
import org.simantics.simulator.toolkit.StandardNodeManagerSupport;
import org.simantics.simulator.variable.exceptions.NodeManagerException;
import org.simantics.spreadsheet.ExternalRef;
-import org.simantics.spreadsheet.ExternalRef.ExternalRefListener;
import org.simantics.spreadsheet.SpreadsheetCellStyle;
import org.simantics.spreadsheet.SpreadsheetVisitor;
import org.simantics.spreadsheet.solver.formula.SpreadsheetEvaluationEnvironment;
private SpreadsheetMapping mapping;
- private String context;
+ String context;
private int idCounter = 1;
Object content = scc.cell.evaluate(SpreadsheetEvaluationEnvironment.getInstance(this));
if(content == null) return Variant.ofInstance("");
if(content instanceof Variant) return content;
+ if(content instanceof ExternalRefData) return ((ExternalRefData)content).getContent();
else return Variant.ofInstance(content);
} catch (Throwable t) {
t.printStackTrace();
}
} else if (node instanceof SpreadsheetCellContentExpression) {
SpreadsheetCellContentExpression scce = (SpreadsheetCellContentExpression)node;
- if (scce.cell.content instanceof SpreadsheetFormula) {
- SpreadsheetFormula formula = (SpreadsheetFormula)scce.cell.content;
+ if (scce.cell.getContent() instanceof SpreadsheetFormula) {
+ SpreadsheetFormula formula = (SpreadsheetFormula)scce.cell.getContent();
return formula.expression;
- } else if (scce.cell.content instanceof SpreadsheetSCLConstant) {
- SpreadsheetSCLConstant sclConstant = (SpreadsheetSCLConstant) scce.cell.content;
- return "=" + sclConstant.expression;
+ } else if (scce.cell.getContent() instanceof SpreadsheetSCLConstant) {
+ SpreadsheetSCLConstant sclConstant = (SpreadsheetSCLConstant) scce.cell.getContent();
+ return "=" + sclConstant.getExpression();
} else {
- System.out.println("Broken SpreadsheetCellContentExpression possibly due to overwriting an existing expression with a constant or something else (current content is " + scce.cell.content + ")");
- if (scce.cell.content instanceof Variant) {
- return scce.cell.content;
+ System.out.println("Broken SpreadsheetCellContentExpression possibly due to overwriting an existing expression with a constant or something else (current content is " + scce.cell.getContent() + ")");
+ if (scce.cell.getContent() instanceof Variant) {
+ return scce.cell.getContent();
} else {
- return Variant.ofInstance(scce.cell.content);
+ return Variant.ofInstance(scce.cell.getContent());
}
}
} else if (node instanceof SpreadsheetTypeNode) {
@Override
public void setEngineValue(SheetNode node, Object value) {
+
+ SpreadsheetCellContent scc = (SpreadsheetCellContent)node;
+
+ Object content = scc.cell.evaluate(SpreadsheetEvaluationEnvironment.getInstance(this));
+ System.err.println("content2: " + content);
+ if (content instanceof Variant) {
+ scc.cell.setContent(value);
+ } else if (content instanceof ExternalRefData) {
+ ExternalRefData erd = (ExternalRefData)content;
+ erd.getRef().modify(context, (Variant)value);
+ } else {
+ throw new IllegalStateException("Unable to set cell value");
+ }
+
}
@Override
v.visit(this);
}
- private SpreadsheetCell cellByReferenceKey(long ref) {
+ SpreadsheetCell cellByReferenceKey(long ref) {
long sheet = ref >> 40;
long row = (ref >> 20) & 0xFFFFF;
long col = (ref) & 0xFFFFF;
return iterationEnabled;
}
- static Variant DEFAULT = Variant.ofInstance("Pending external reference");
-
- class ExternalRefData {
- private Variant value = DEFAULT;
- public ExternalRefData(long referenceKey, ExternalRef ref) {
- ref.listen(context, new ExternalRefListener() {
-
- boolean isDisposed = false;
-
- @Override
- public void newValue(Variant newVariant) {
- SpreadsheetCell cell = cellByReferenceKey(referenceKey);
- if(cell.content instanceof SpreadsheetSCLConstant) {
- SpreadsheetSCLConstant ssc = (SpreadsheetSCLConstant)cell.content;
- if(ssc.content.equals(ref)) {
- value = newVariant;
- fireChanges(invalidate(cell));
- return;
- }
- }
- isDisposed = true;
- }
- @Override
- public boolean isDisposed() {
- if(isDisposed)
- return true;
- return SpreadsheetBook.this.isDisposed();
- }
- });
- }
- }
+ static Variant DEFAULT_VALUE = Variant.ofInstance("Pending external reference");
private Map<ExternalRef,ExternalRefData> externalRefMap = new HashMap<>();
void registerListening(long referenceKey, ExternalRef ref) {
ExternalRefData data = externalRefMap.get(ref);
if(data == null) {
- data = new ExternalRefData(referenceKey, ref);
+ data = new ExternalRefData(this, referenceKey, ref);
externalRefMap.put(ref, data);
} else {
// Already registered
}
}
- Variant getExternalRefValue(long referenceKey, ExternalRef ref) {
+ ExternalRefData getExternalRefValue(long referenceKey, ExternalRef ref) {
ExternalRefData data = externalRefMap.get(ref);
if(data == null) {
registerListening(referenceKey, ref);
- return DEFAULT;
+ return new ExternalRefData(this, referenceKey, new ExternalRefConstant(DEFAULT_VALUE));
}
- return data.value;
+ return data;
}
public boolean isDisposed() {
final private SpreadsheetLine line;
final private int column;
int style;
- Object content;
+ private Object content;
final private Map<String, SheetNode> properties;
public SpreadsheetCell(SpreadsheetLine line, int column) {
return (T)f.result;
} else if (content instanceof SpreadsheetSCLConstant) {
SpreadsheetSCLConstant sclConstant = (SpreadsheetSCLConstant) content;
- if(sclConstant.content instanceof Variant) {
- Variant v = (Variant)sclConstant.content;
- return (T) sclConstant.content;
- } else if (sclConstant.content instanceof ExternalRef) {
- return (T)env.getBook().getExternalRefValue(makeReferenceKey(), (ExternalRef)sclConstant.content);
+ Object c = sclConstant.getContent();
+ if(c instanceof Variant) {
+ Variant v = (Variant)c;
+ return (T) c;
+ } else if (c instanceof ExternalRef) {
+ ExternalRefData erd = env.getBook().getExternalRefValue(makeReferenceKey(), (ExternalRef)c);
+ return (T)erd;
} else {
- throw new IllegalStateException();
+ throw new IllegalStateException("Unsupported content " + c);
}
} else {
this.inProgress = false;
}
public boolean editable() {
- if (cell.content == null || cell.content instanceof SpreadsheetFormula || cell.content instanceof SpreadsheetSCLConstant)
+ if (cell.getContent() == null || cell.getContent() instanceof SpreadsheetFormula || cell.getContent() instanceof SpreadsheetSCLConstant)
return false;
- if (cell.content instanceof String) {
- String content = (String) cell.content;
+ if (cell.getContent() instanceof String) {
+ String content = (String) cell.getContent();
if (content.isEmpty())
return false;
}
- if (cell.content instanceof Variant) {
- Variant content = (Variant) cell.content;
+ if (cell.getContent() instanceof Variant) {
+ Variant content = (Variant) cell.getContent();
if (content.getValue() == null)
return false;
if (content.getValue() instanceof String) {
private static final long serialVersionUID = 428064772427245449L;
- public String expression;
- public Object content;
+ private String expression;
+ private Object content;
public static final Binding BINDING = Bindings.getBindingUnchecked(SpreadsheetSCLConstant.class);
this.expression = expression;
}
+ public Object getContent() {
+ return content;
+ }
+
+ public String getExpression() {
+ return expression;
+ }
+
@Override
public String toString() {
return super.toString();
@Override
public void apply(ModuleUpdateContext<SheetLineComponent> context, boolean isCreating,
Map<String, Variant> propertyMap, Map<String, Collection<String>> connectionMap, Variant value) {
- System.err.println("LineUpdater.apply " + value);
+// System.err.println("LineUpdater.apply " + value);
LineCommandBuilder builder = context.<LineCommandBuilder>getConcreteCommand();
try {
LineContentBean valuee = (LineContentBean) value.getValue(LineContentBean.BINDING);