]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/SpreadsheetCellEditable.java
Adopt spreadsheet changes made in Balas development
[simantics/platform.git] / bundles / org.simantics.spreadsheet / src / org / simantics / spreadsheet / solver / SpreadsheetCellEditable.java
1 package org.simantics.spreadsheet.solver;
2
3 import java.util.Collections;
4 import java.util.Map;
5
6 import org.simantics.databoard.binding.mutable.Variant;
7
8 @SuppressWarnings("rawtypes")
9 public class SpreadsheetCellEditable implements SheetNode {
10
11     private static final long serialVersionUID = -5078387091775971986L;
12     
13     public final SpreadsheetCell cell;
14
15     public SpreadsheetCellEditable(SpreadsheetCell spreadsheetCell) {
16         this.cell = spreadsheetCell;
17     }
18
19     @Override
20     public String getName() {
21         return "editable";
22     }
23
24     @Override
25     public Map getChildren() {
26         return Collections.emptyMap();
27     }
28
29     @Override
30     public Map getProperties() {
31         return Collections.emptyMap();
32     }
33
34     @Override
35     public int hashCode() {
36         final int prime = 31;
37         int result = 1;
38         result = prime * result + ((cell == null) ? 0 : cell.hashCode());
39         return result;
40     }
41
42     @Override
43     public boolean equals(Object obj) {
44         if (this == obj)
45             return true;
46         if (obj == null)
47             return false;
48         if (getClass() != obj.getClass())
49             return false;
50         SpreadsheetCellEditable other = (SpreadsheetCellEditable) obj;
51         if (cell == null) {
52             if (other.cell != null)
53                 return false;
54         } else if (!cell.equals(other.cell))
55             return false;
56         return true;
57     }
58
59     public boolean editable() {
60         if (cell.getContent() == null || cell.getContent() instanceof SpreadsheetFormula || cell.getContent() instanceof SpreadsheetSCLConstant)
61             return false;
62         if (cell.getContent() instanceof String) {
63             String content = (String) cell.getContent();
64             if (content.isEmpty())
65                 return false;
66         }
67         if (cell.getContent() instanceof Variant) {
68             Variant content = (Variant) cell.getContent();
69             if (content.getValue() == null)
70                 return false;
71             if (content.getValue() instanceof String) {
72                 String actualContent = (String) content.getValue();
73                 if (actualContent.isEmpty())
74                     return false;
75             }
76         }
77 //        System.out.println("content is " + cell.content);
78         return true;
79     }
80
81 }