]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/ExternalRefData.java
Adopt spreadsheet changes made in Balas development
[simantics/platform.git] / bundles / org.simantics.spreadsheet / src / org / simantics / spreadsheet / solver / ExternalRefData.java
1 package org.simantics.spreadsheet.solver;
2
3 import org.simantics.databoard.binding.mutable.Variant;
4 import org.simantics.spreadsheet.ExternalRef;
5 import org.simantics.spreadsheet.ExternalRef.ExternalRefListener;
6
7 class ExternalRefData implements ExternalRefListener {
8     
9     final private SpreadsheetBook book;
10     final private long referenceKey;
11     final private ExternalRef ref;
12     private boolean isDisposed = false;
13     private Variant value = SpreadsheetBook.DEFAULT_VALUE;
14     
15     public ExternalRefData(SpreadsheetBook book, long referenceKey, ExternalRef ref) {
16         this.book = book;
17         this.referenceKey = referenceKey;
18         this.ref = ref;
19         ref.listen(book.context, this);
20     }
21     
22     public Variant getContent() {
23         return value;
24     }
25     
26     public ExternalRef getRef() {
27         return ref;
28     }
29
30     @Override
31     public void newValue(Variant newVariant) {
32         SpreadsheetCell cell = book.cellByReferenceKey(referenceKey);
33         if(cell.getContent() instanceof SpreadsheetSCLConstant) {
34             SpreadsheetSCLConstant ssc = (SpreadsheetSCLConstant)cell.getContent();
35             Object content = ssc.getContent();
36             if(content.equals(ref)) {
37                 value = newVariant;
38                 book.fireChanges(book.invalidate(cell));
39                 return;
40             }
41         }
42         isDisposed = true;
43     }
44
45     @Override
46     public boolean isDisposed() {
47         if(isDisposed)
48             return true;
49         return book.isDisposed();
50     }
51     
52 }