Revision 44189 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/feature/impl/DefaultEditableFeatureAttributeDescriptor.java

View differences:

DefaultEditableFeatureAttributeDescriptor.java
25 25

  
26 26
import java.text.DateFormat;
27 27
import java.util.HashMap;
28
import java.util.Objects;
28 29
import org.apache.commons.lang3.StringUtils;
29 30

  
30 31
import org.cresques.cts.IProjection;
......
40 41
import org.gvsig.fmap.geom.type.GeometryType;
41 42
import org.gvsig.timesupport.Interval;
42 43
import org.gvsig.tools.ToolsLocator;
44
import org.gvsig.tools.dataTypes.DataType;
43 45
import org.gvsig.tools.evaluator.Evaluator;
44 46

  
45 47
public class DefaultEditableFeatureAttributeDescriptor extends
......
101 103
    }
102 104

  
103 105
    public EditableFeatureAttributeDescriptor setAllowNull(boolean allowNull) {
106
        updateStrongChanges(this.allowNull, allowNull);
104 107
        this.allowNull = allowNull;
105
        if (!isComputed()) {
106
            hasStrongChanges = true;
107
        }
108 108
        return this;
109 109
    }
110 110

  
111 111
    public EditableFeatureAttributeDescriptor setDataType(int type) {
112
        updateStrongChanges(this.dataType, type);
112 113
        this.dataType = ToolsLocator.getDataTypesManager().get(type);
113
        if (!isComputed()) {
114
            hasStrongChanges = true;
115
        }
116 114
        return this;
117 115
    }
118 116

  
119 117
    public EditableFeatureAttributeDescriptor setDefaultValue(
120 118
        Object defaultValue) {
119
        updateStrongChanges(this.defaultValue, defaultValue);
121 120
        this.defaultValue = defaultValue;
122
        if (!isComputed()) {
123
            hasStrongChanges = true;
124
        }
125 121
        return this;
126 122
    }
127 123

  
128 124
    public EditableFeatureAttributeDescriptor setEvaluator(Evaluator evaluator) {
129
        if (this.evaluator != null && evaluator == null) {
130
            hasStrongChanges = true;
131
        }
125
        updateStrongChanges(this.evaluator, evaluator);
132 126
        this.evaluator = evaluator;
133 127
        return this;
134 128
    }
......
155 149

  
156 150
    public EditableFeatureAttributeDescriptor setGeometryType(
157 151
        GeometryType geometryType) {
152
        updateStrongChanges(this.geomType, geometryType);
158 153
        this.geomType = geometryType;
159 154
        this.geometryType = this.geomType.getType();
160 155
        this.geometrySubType = this.geomType.getSubType();
161
        if (!isComputed()) {
162
            hasStrongChanges = true;
163
        }
164 156
        return this;
165 157
    }
166 158

  
......
174 166

  
175 167
    public EditableFeatureAttributeDescriptor setIsPrimaryKey(
176 168
        boolean isPrimaryKey) {
169
        updateStrongChanges(this.primaryKey, primaryKey);
177 170
        this.primaryKey = isPrimaryKey;
178
        if (!isComputed()) {
179
            hasStrongChanges = true;
180
        }
181 171
        return this;
182 172
    }
183 173

  
184 174
    public EditableFeatureAttributeDescriptor setIsReadOnly(boolean isReadOnly) {
175
        updateStrongChanges(this.readOnly, readOnly);
185 176
        this.readOnly = isReadOnly;
186
        if (!isComputed()) {
187
            hasStrongChanges = true;
188
        }
189 177
        return this;
190 178
    }
191 179

  
192 180
    public EditableFeatureAttributeDescriptor setMaximumOccurrences(
193 181
        int maximumOccurrences) {
182
        updateStrongChanges(this.maximumOccurrences, maximumOccurrences);
194 183
        this.maximumOccurrences = maximumOccurrences;
195
        if (!isComputed()) {
196
            hasStrongChanges = true;
197
        }
198 184
        return this;
199 185
    }
200 186

  
201 187
    public EditableFeatureAttributeDescriptor setMinimumOccurrences(
202 188
        int minimumOccurrences) {
189
        updateStrongChanges(this.minimumOccurrences, minimumOccurrences);
203 190
        this.minimumOccurrences = minimumOccurrences;
204
        if (!isComputed()) {
205
            hasStrongChanges = true;
206
        }
207 191
        return this;
208 192
    }
209 193

  
......
230 214
    }
231 215

  
232 216
    public EditableFeatureAttributeDescriptor setObjectClass(Class theClass) {
217
        updateStrongChanges(this.objectClass, theClass);
233 218
        this.objectClass = theClass;
234
        if (!isComputed()) {
235
            hasStrongChanges = true;
236
        }
237 219
        return this;
238 220
    }
239 221

  
240 222
    public EditableFeatureAttributeDescriptor setPrecision(int precision) {
223
        updateStrongChanges(this.precision, precision);
241 224
        this.precision = precision;
242
        if (!isComputed()) {
243
            hasStrongChanges = true;
244
        }
245 225
        return this;
246 226
    }
247 227

  
248 228
    public EditableFeatureAttributeDescriptor setSRS(IProjection SRS) {
229
        updateStrongChanges(this.SRS, SRS);
249 230
        this.SRS = SRS;
250
        if (!isComputed()) {
251
            hasStrongChanges = true;
252
        }
253 231
        return this;
254 232
    }
255 233

  
256 234
    public EditableFeatureAttributeDescriptor setInterval(Interval interval) {
235
        updateStrongChanges(this.getInterval(), interval);
257 236
        super.setInterval(interval);
258
        if (!isComputed()) {
259
            hasStrongChanges = true;
260
        }
261 237
        return this;
262 238
    }
263 239

  
264 240
    public EditableFeatureAttributeDescriptor setSize(int size) {
241
        updateStrongChanges(this.size, size);
265 242
        this.size = size;
266
        if (!isComputed()) {
267
            hasStrongChanges = true;
268
        }
269 243
        return this;
270 244
    }
271 245

  
......
291 265
    }
292 266
    
293 267
    public EditableFeatureAttributeDescriptor setIsTime(boolean isTime) {
268
        updateStrongChanges(this.isTime, isTime);
294 269
        this.isTime = isTime;
295
        if (!isComputed()) {
296
            hasStrongChanges = true;
297
        }
298 270
        return this;
299 271
    }
300 272

  
......
304 276
    }
305 277

  
306 278
    public EditableFeatureAttributeDescriptor setIsIndexed(boolean isIndexed) {
279
        updateStrongChanges(this.indexed, isIndexed);
307 280
        this.indexed = isIndexed;
308
        if (!isComputed()) {
309
            hasStrongChanges = true;
310
        }
311 281
        return this;
312 282
    }
313 283
    
314 284
    public EditableFeatureAttributeDescriptor setAllowIndexDuplicateds(boolean allowDuplicateds) {
285
        updateStrongChanges(this.allowIndexDuplicateds, allowDuplicateds);
315 286
        this.allowIndexDuplicateds = allowDuplicateds;
316
        if (!isComputed()) {
317
            hasStrongChanges = true;
318
        }
319 287
        return this;
320 288
    }
321 289

  
322 290
    public EditableFeatureAttributeDescriptor setIsIndexAscending(boolean ascending) {
291
        updateStrongChanges(this.isIndexAscending, ascending);
323 292
        this.isIndexAscending = ascending;
324
        if (!isComputed()) {
325
            hasStrongChanges = true;
326
        }
327 293
        return this;
328 294
    }
329 295

  
......
332 298
        super.setDataProfileName(dataProfile);
333 299
        return this;
334 300
    }
335
    
301

  
302
    private void updateStrongChanges(int previous, int newvalue) {
303
        if( isComputed() ) {
304
            return;
305
        }
306
        if( previous == newvalue ) {
307
            return;
308
        }
309
        this.hasStrongChanges = true;
310
    }
311

  
312
    private void updateStrongChanges(DataType previous, int newvalue) {
313
        if( isComputed() ) {
314
            return;
315
        }
316
        if( previous!=null ) {
317
            if( previous.getType() == newvalue ) {
318
                return;
319
            }
320
        }
321
        this.hasStrongChanges = true;
322
    }
323

  
324
    private void updateStrongChanges(boolean previous, boolean newvalue) {
325
        if( isComputed() ) {
326
            return;
327
        }
328
        if( previous == newvalue ) {
329
            return;
330
        }
331
        this.hasStrongChanges = true;
332
    }
333

  
334
    private void updateStrongChanges(Object previous, Object newvalue) {
335
        if( isComputed() ) {
336
            return;
337
        }
338
        if( Objects.equals(newvalue, previous) ) {
339
            return;
340
        }
341
        this.hasStrongChanges = true;
342
    }
336 343
}

Also available in: Unified diff