1 package org.simantics.spreadsheet.graph;
3 import java.util.Collections;
4 import java.util.HashSet;
8 import org.simantics.databoard.binding.Binding;
9 import org.simantics.layer0.Layer0;
10 import org.simantics.simulator.toolkit.StandardNodeManager;
11 import org.simantics.simulator.variable.exceptions.NodeManagerException;
12 import org.simantics.spreadsheet.resource.SpreadsheetResource;
13 import org.simantics.structural.stubs.StructuralResource2;
15 @SuppressWarnings("rawtypes")
16 public class SpreadsheetNodeManager extends StandardNodeManager<SheetNode, SpreadsheetBook> {
18 public SpreadsheetNodeManager(SpreadsheetRealm realm) {
19 super(realm, realm.getEngine());
22 static final Set<String> COMPONENT_CLASS = Collections.singleton(StructuralResource2.URIs.Component);
25 public Set<String> getClassifications(SheetNode node) throws NodeManagerException {
28 return COMPONENT_CLASS;
30 return Collections.emptySet();
34 public String getPropertyURI(SheetNode parent, SheetNode property) {
35 if(property instanceof SpreadsheetCellContent) {
36 return SpreadsheetResource.URIs.Cell_content;
37 } else if(property instanceof SpreadsheetTypeNode) {
38 return Layer0.URIs.typeURI;
39 } else if(property instanceof SpreadsheetCellContentExpression) {
40 return Layer0.URIs.SCLValue_expression;
41 } else if (property instanceof SpreadsheetCellStyle) {
42 return SpreadsheetResource.URIs.Cell_style;
43 } else if (property instanceof SpreadsheetCellEditable){
44 return SpreadsheetResource.URIs.Cell_editable;
50 //Custom setValue logic for SpreadsheetNodeManager - calls the setValueAndFireSelectedListeners
52 public void setValue(SheetNode node, Object value, Binding binding) throws NodeManagerException {
53 Set<SheetNode> dirtyNodeContents = findDirtyNodeContents(node);
54 super.setValueAndFireSelectedListeners(node, value, binding, dirtyNodeContents);
57 //Find the cells that are used by this cell and their SpreadsheetContents, so that they can be marked as dirty later
58 public Set<SheetNode> findDirtyNodeContents(SheetNode node){
59 Set<SheetNode> dirty = new HashSet<>();
61 SpreadsheetCell sscell = null;
62 if(node instanceof SpreadsheetCell) {
63 sscell = (SpreadsheetCell)node;
64 } else if (node instanceof SpreadsheetCellContent) {
65 sscell = ((SpreadsheetCellContent)node).cell;
69 Set<SpreadsheetCell> result = ((SpreadsheetRealm)super.getRealm()).getEngine().invalidate(sscell);
73 Set<SheetNode> dirtyNodeContents = new HashSet<>();
74 for(SheetNode cell : dirty) {
75 Map<String, SheetNode> properties = cell.getProperties();
76 dirtyNodeContents.add((SpreadsheetCellContent)properties.get("content"));
79 return dirtyNodeContents;