]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/ComponentTypeViewerPropertyInfo.java
Added editable unit for derived properties
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / componentTypeEditor / ComponentTypeViewerPropertyInfo.java
1 package org.simantics.modeling.ui.componentTypeEditor;
2
3 import org.simantics.databoard.annotations.Optional;
4 import org.simantics.databoard.type.NumberType;
5 import org.simantics.db.Resource;
6 import org.simantics.utils.strings.AlphanumComparator;
7 import org.simantics.utils.strings.StringUtils;
8
9 public class ComponentTypeViewerPropertyInfo implements Comparable<ComponentTypeViewerPropertyInfo> {
10     public Resource resource;
11     public String name;
12     public String type;
13     public String defaultValue;
14     public String label;
15     public String description;
16     @Optional
17     public String expression;
18     @Optional
19     public String valid;
20     @Optional
21     public NumberType numberType;
22     @Optional
23     public String unit;
24     public boolean immutable;
25     public Object sectionSpecificData; 
26
27     public ComponentTypeViewerPropertyInfo(Resource resource, String name, String type, String defaultValue, NumberType numberType, String unit, String label, String description, String expression, String valid, boolean immutable) {
28         this.resource = resource;
29         this.name = name;
30         this.type = type;
31         this.defaultValue = defaultValue;
32         this.numberType = numberType;
33         this.unit = unit;
34         this.label = label;
35         this.description = description;
36         this.expression = expression;
37         this.valid = valid;
38         this.immutable = immutable;
39     }
40
41     @Override
42     public int compareTo(ComponentTypeViewerPropertyInfo o) {
43         return AlphanumComparator.CASE_INSENSITIVE_COMPARATOR.compare(name, (o.name));
44     }
45
46     @Override
47     public int hashCode() {
48         final int prime = 31;
49         int result = 1;
50         result = prime * result
51                 + ((defaultValue == null) ? 0 : defaultValue.hashCode());
52         result = prime * result
53                 + ((description == null) ? 0 : description.hashCode());
54         result = prime * result
55                 + ((expression == null) ? 0 : expression.hashCode());
56         result = prime * result + (immutable ? 1231 : 1237);
57         result = prime * result + ((label == null) ? 0 : label.hashCode());
58         result = prime * result + ((name == null) ? 0 : name.hashCode());
59         result = prime * result
60                 + ((numberType == null) ? 0 : numberType.hashCode());
61         result = prime * result
62                 + ((resource == null) ? 0 : resource.hashCode());
63         result = prime * result + ((sectionSpecificData == null) ? 0
64                 : sectionSpecificData.hashCode());
65         result = prime * result + ((type == null) ? 0 : type.hashCode());
66         result = prime * result + ((unit == null) ? 0 : unit.hashCode());
67         result = prime * result + ((valid == null) ? 0 : valid.hashCode());
68         return result;
69     }
70
71     @Override
72     public boolean equals(Object obj) {
73         if (this == obj)
74             return true;
75         if (obj == null)
76             return false;
77         if (getClass() != obj.getClass())
78             return false;
79         ComponentTypeViewerPropertyInfo other = (ComponentTypeViewerPropertyInfo) obj;
80         if (defaultValue == null) {
81             if (other.defaultValue != null)
82                 return false;
83         } else if (!defaultValue.equals(other.defaultValue))
84             return false;
85         if (description == null) {
86             if (other.description != null)
87                 return false;
88         } else if (!description.equals(other.description))
89             return false;
90         if (expression == null) {
91             if (other.expression != null)
92                 return false;
93         } else if (!expression.equals(other.expression))
94             return false;
95         if (immutable != other.immutable)
96             return false;
97         if (label == null) {
98             if (other.label != null)
99                 return false;
100         } else if (!label.equals(other.label))
101             return false;
102         if (name == null) {
103             if (other.name != null)
104                 return false;
105         } else if (!name.equals(other.name))
106             return false;
107         if (numberType == null) {
108             if (other.numberType != null)
109                 return false;
110         } else if (!numberType.equals(other.numberType))
111             return false;
112         if (resource == null) {
113             if (other.resource != null)
114                 return false;
115         } else if (!resource.equals(other.resource))
116             return false;
117         if (sectionSpecificData == null) {
118             if (other.sectionSpecificData != null)
119                 return false;
120         } else if (!sectionSpecificData.equals(other.sectionSpecificData))
121             return false;
122         if (type == null) {
123             if (other.type != null)
124                 return false;
125         } else if (!type.equals(other.type))
126             return false;
127         if (unit == null) {
128             if (other.unit != null)
129                 return false;
130         } else if (!unit.equals(other.unit))
131             return false;
132         if (valid == null) {
133             if (other.valid != null)
134                 return false;
135         } else if (!valid.equals(other.valid))
136             return false;
137         return true;
138     }
139
140     public String unitString() {
141         String result = numberType == null ? null : numberType.getUnit();
142         if (result == null)
143             result = unit;
144         return StringUtils.safeString(result);
145     }
146
147     public String rangeString() {
148         return StringUtils.safeString(numberType == null ? null : numberType.getRangeStr());
149     }
150
151 }