]> gerrit.simantics Code Review - simantics/platform.git/blob
caa6dc23f4602d10589187018c99f66a9f1f9a24
[simantics/platform.git] /
1 package org.simantics.spreadsheet.graph;
2
3 import java.util.Collections;
4 import java.util.HashSet;
5 import java.util.Map;
6 import java.util.Set;
7
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;
14
15 @SuppressWarnings("rawtypes")
16 public class SpreadsheetNodeManager extends StandardNodeManager<SheetNode, SpreadsheetBook> {
17
18     public SpreadsheetNodeManager(SpreadsheetRealm realm) {
19         super(realm, realm.getEngine());
20     }
21
22     static final Set<String> COMPONENT_CLASS = Collections.singleton(StructuralResource2.URIs.Component);
23
24     @Override
25     public Set<String> getClassifications(SheetNode node) throws NodeManagerException {
26         checkThreadAccess();
27         if(isRoot(node))
28             return COMPONENT_CLASS;
29         else
30             return Collections.emptySet();
31     }
32
33     @Override
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;
45         } else {
46             return null;
47         }
48     }
49     
50     //Custom setValue logic for SpreadsheetNodeManager - calls the setValueAndFireSelectedListeners
51     @Override
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);
55     }
56     
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<>();
60         
61         SpreadsheetCell sscell = null;
62         if(node instanceof SpreadsheetCell) {
63                 sscell = (SpreadsheetCell)node;
64         } else if (node instanceof SpreadsheetCellContent) {
65                 sscell = ((SpreadsheetCellContent)node).cell;
66         }
67                         
68         if(sscell != null) {
69                 Set<SpreadsheetCell> result = ((SpreadsheetRealm)super.getRealm()).getEngine().invalidate(sscell);
70                 dirty.addAll(result);
71         }
72                         
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"));
77         }
78         
79         return dirtyNodeContents;
80     }
81 }