Revision 3838

View differences:

org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.rotate/src/main/java/org/gvsig/vectorediting/lib/prov/rotate/RotateEditingProvider.java
153 153

  
154 154
        this.selectionParameter
155 155
                = new DefaultEditingServiceParameter("selection",
156
                        i18nManager.getTranslation("selection"), TYPE.SELECTION);
156
                        i18nManager.getTranslation("selection"), TYPE.SELECTION).setAllowNull(false);
157 157

  
158 158
        DefaultEditingServiceParameterOptions options = new DefaultEditingServiceParameterOptions()
159 159
                .add(i18nManager.getTranslation(PIVOT_CENTER_ENVELOPE), PIVOT_CENTER_ENVELOPE, i18nManager.getTranslation(KEY_PIVOT_CENTER_ENVELOPE))
......
215 215
                        "_Angle",
216 216
                        i18nManager.getTranslation("_Angle"),
217 217
                        TYPE.VALUE
218
                );
218
                ).setDataType(DataTypes.DOUBLE).setAllowNull(false);
219 219

  
220 220
        this.firstPointParameter
221 221
                = new DefaultEditingServiceParameter(
222 222
                        "Start_of_rotation",
223 223
                        i18nManager.getTranslation("_Start_of_rotation"),
224
                        TYPE.POSITION);
224
                        TYPE.POSITION).setAllowNull(false);
225 225

  
226 226
        this.secondPointParameter
227 227
                = new DefaultEditingServiceParameter(
228 228
                        "_End_of_rotation",
229 229
                        i18nManager.getTranslation("_End_of_rotation"),
230 230
                        TYPE.POSITION
231
                );
231
                ).setAllowNull(false);
232 232

  
233 233
        this.values = new HashMap<>();
234 234

  
......
494 494
    private void validateAndInsertValue(EditingServiceParameter param,
495 495
            Object value) throws InvalidEntryException {
496 496
        if (param == selectionParameter) {
497
            if (value instanceof FeatureSelection) {
498
                values.put(param, value);
499
                this.selectedFeatures = this.getSelectedFeaturesCopy((FeatureSelection) value);
500
            } else {
497
            if (!param.isValidValue(value)) {
501 498
                throw new InvalidEntryException(null);
502 499
            }
500
            values.put(param, value);
501
            this.selectedFeatures = this.getSelectedFeaturesCopy((FeatureSelection) value);
503 502

  
504 503
        } else if (param == modeParameter) {
505
            if(!(value instanceof String)){
504
            if (!param.isValidValue(value)) {
506 505
                throw new InvalidEntryException(null);
507 506
            }
508 507
            String rotateMode = (String) param.getOptions2().getValue(value, param.getDefaultValue());
509 508
            modeParameter.setDefaultValue(rotateMode);
510 509
            values.put(param, rotateMode);
511 510
        } else if (param == separateElementsParameter) {
511
            if (!param.isValidValue(value)) {
512
                throw new InvalidEntryException(null);
513
            }
512 514
            savedSeparateElements = (Boolean) param.getOptions2().getValue(value, param.getDefaultValue());
513 515
            values.put(param, savedSeparateElements);
514 516
        } else if (param == pivotPointParameter) {
517
            if (!param.isValidValue(value)) {
518
                center = null;
519
                throw new InvalidEntryException(null);
520
            }
515 521
            if (value == null) {
516 522
                value = param.getDefaultValue();
517 523
            } 
518 524
            if (value instanceof Point) {
519 525
                values.put(param, value);
520 526
                center = null;
521
            } else if (value instanceof String) {
527
            } else { //String
522 528
                String pivotMode = (String) param.getOptions2().getValue(value, param.getDefaultValue());
523
                if (PIVOT_CENTER_ENVELOPE.equalsIgnoreCase(pivotMode) || PIVOT_CENTROID.equalsIgnoreCase(pivotMode)) {
524
                    center = pivotMode;
525
                    FeatureSelection selected
526
                            = (FeatureSelection) values.get(this.selectionParameter);
527
                    values.put(param, calculatePivot(selected, pivotMode));
528
                } else {
529
                    center = null;
530
                    values.remove(param);
531
                }
532
            } else {
533
                throw new InvalidEntryException(null);
529
                center = pivotMode;
530
                FeatureSelection selected
531
                        = (FeatureSelection) values.get(this.selectionParameter);
532
                values.put(param, calculatePivot(selected, pivotMode));
534 533
            }
535 534
        } else if (param == firstPointParameter) {
536
            if (value instanceof Point) {
537
                if (((Point) value).equals((Point) values.get(pivotPointParameter))) {
538
                    throw new InvalidEntryException(null);
539
                }
540
                values.put(param, value);
541
            } else {
535
            if (!param.isValidValue(value)) {
542 536
                throw new InvalidEntryException(null);
543 537
            }
538
            if (((Point) value).equals((Point) values.get(pivotPointParameter))) {
539
                throw new InvalidEntryException(null);
540
            }
541
            values.put(param, value);
544 542
        } else if (param == secondPointParameter) {
545
            if (value instanceof Point) {
546
                if (((Point) value).equals((Point) values.get(firstPointParameter))
547
                        || ((Point) value).equals((Point) values.get(pivotPointParameter))) {
548
                    throw new InvalidEntryException(null);
549
                }
550
                values.put(param, value);
551
            } else {
543
            if (!param.isValidValue(value)) {
552 544
                throw new InvalidEntryException(null);
553 545
            }
546
            if (((Point) value).equals((Point) values.get(firstPointParameter))
547
                    || ((Point) value).equals((Point) values.get(pivotPointParameter))) {
548
                throw new InvalidEntryException(null);
549
            }
550
            values.put(param, value);
554 551
        } else if (param == angleParameter) {
555
            if (value instanceof Double) {
556
                if ((Double)value == 0.0){
557
                    throw new InvalidEntryException(null);
558
                }
559
                values.put(param, value);
560
            } else {
552
            if (!param.isValidValue(value)) {
561 553
                throw new InvalidEntryException(null);
562 554
            }
555
            Object v = angleParameter.coerceValue(value);
556
            if ((Double)v == 0.0){
557
                throw new InvalidEntryException(null);
558
            }
559
            values.put(param, v);
563 560
        }
564 561
    }
565 562

  
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.api/src/main/java/org/gvsig/vectorediting/lib/api/EditingServiceParameter.java
152 152
    
153 153
    public int getDataType();
154 154

  
155
    public boolean isValidValue(Object value);
156
    
157
    public Object coerceValue(Object value);
158
    
159
    public boolean getAllowNull();
160
    
161

  
155 162
}
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.spi/src/main/java/org/gvsig/vectorediting/lib/spi/DefaultEditingServiceParameter.java
24 24

  
25 25
package org.gvsig.vectorediting.lib.spi;
26 26

  
27
import org.gvsig.vectorediting.lib.api.EditingServiceParameterOptions;
28 27
import java.util.Arrays;
29 28
import java.util.HashSet;
29
import java.util.List;
30 30
import java.util.Map;
31 31
import java.util.Objects;
32 32
import java.util.Set;
33
import org.apache.commons.lang3.StringUtils;
34
import org.gvsig.fmap.dal.feature.FeatureSelection;
33 35
import org.gvsig.fmap.geom.Geometry;
34 36
import org.gvsig.fmap.geom.primitive.Point;
35 37
import org.gvsig.timesupport.DataTypes;
38
import org.gvsig.tools.ToolsLocator;
39
import org.gvsig.tools.dataTypes.CoercionException;
40
import org.gvsig.tools.dataTypes.DataType;
41
import org.gvsig.tools.dataTypes.DataTypesManager;
36 42
import org.gvsig.vectorediting.lib.api.EditingServiceParameter;
43
import org.gvsig.vectorediting.lib.api.EditingServiceParameterOptions;
44
import org.gvsig.vectorediting.lib.api.exceptions.InvalidEntryException;
37 45

  
38 46
public class DefaultEditingServiceParameter implements EditingServiceParameter {
39 47

  
......
54 62
    private boolean optional;
55 63
    
56 64
    private int dataType;
65
    
66
    private boolean allowNull;
57 67

  
58 68
    public DefaultEditingServiceParameter(String theName,
59 69
        String theDescription, TYPE... theTypes) {
......
170 180
        this.defaultValue = theDefaultValue;
171 181
        this.optional = optional;
172 182
        this.dataType = DataTypes.STRING;
183
        this.allowNull = true;
173 184
    }
174 185

  
175 186
    @Override
......
260 271
    public int getDataType() {
261 272
        return this.dataType;
262 273
    }
274

  
275
    public DefaultEditingServiceParameter setAllowNull(boolean allowNull) {
276
        this.allowNull = allowNull;
277
        return this;
278
    }
279

  
280
    public boolean getAllowNull() {
281
        return allowNull;
282
    }
263 283
    
284
    @Override
285
    public boolean isValidValue(Object value) {
286
        if(value == null){
287
            return this.allowNull;
288
        }
289
        
290
        for (TYPE type : this.types) {
291
            switch (type){
292
                case GEOMETRY:
293
                    if (value instanceof Geometry){
294
                        return true;
295
                    }
296
                    break;
297
                case POSITION:
298
                    if (value instanceof Point){
299
                        return true;
300
                    }
301
                    break;
302
                case LIST_POSITIONS:
303
                    if (value instanceof Point){
304
                        return true;
305
                    }
306
                    break;
307
                case OPTION:
308
                    try{
309
                        Object v = (value instanceof String && StringUtils.isBlank((String)value))?this.defaultValue:null;
310
                        this.options2.getValue(value, v);
311
                        return true;
312
                    } catch (InvalidEntryException ex){
313
                        //DO NOTHING
314
                    }
315
                    break;
316
                case SELECTION:
317
                    if (value instanceof FeatureSelection) {
318
                        return true;
319
                    }
320
                    break;
321
                case MULTILAYER_SELECTION:
322
                    if (value instanceof Geometry || value instanceof List){
323
                        return true;
324
                    }
325
                    break;
326
                case DISTANCE:
327
                    if (value instanceof Double){
328
                        return true;
329
                    }
330
                    break;
331
                case CLIPBOARD:
332
                    return true;
333
                case VALUE:
334
                    DataTypesManager manager = ToolsLocator.getDataTypesManager();
335
                    DataType dtype = manager.get(dataType);
336
                    if (!dtype.isObject()) {
337
                        try {
338
                            Object v = dtype.coerce(value);
339
                            return true;
340
                        } catch (CoercionException ex) {
341
                            //DO NOTHING;
342
                        }
343
                    }
344
                    break;
345
            }
346
        }
347
        return false;
348
    }
349

  
350
    @Override
351
    public Object coerceValue(Object value) {
352
        DataTypesManager manager = ToolsLocator.getDataTypesManager();
353
        DataType dtype = manager.get(dataType);
354
        try {
355
            Object v = dtype.coerce(value);
356
            return v;
357
        } catch (CoercionException ex) {
358
            throw new IllegalArgumentException("Illegal value '"+Objects.toString(value)+"' for parameter '"+this.getName()+"'", ex);
359
        }
360
    }
264 361
    
362
    
363
    
265 364

  
266 365
}

Also available in: Unified diff