Revision 2616 org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.split/src/main/java/org/gvsig/vectorediting/lib/prov/split/SplitEditingProvider.java

View differences:

SplitEditingProvider.java
28 28
import java.util.HashMap;
29 29
import java.util.List;
30 30
import java.util.Map;
31

  
32 31
import org.gvsig.fmap.dal.exception.DataException;
33 32
import org.gvsig.fmap.dal.feature.EditableFeature;
34 33
import org.gvsig.fmap.dal.feature.Feature;
......
49 48
import org.gvsig.fmap.geom.type.GeometryType;
50 49
import org.gvsig.tools.ToolsLocator;
51 50
import org.gvsig.tools.dispose.DisposableIterator;
51
import org.gvsig.tools.dispose.DisposeUtils;
52 52
import org.gvsig.tools.dynobject.DynObject;
53 53
import org.gvsig.tools.exception.BaseException;
54 54
import org.gvsig.tools.service.spi.ProviderServices;
55
import org.gvsig.tools.visitor.VisitCanceledException;
56
import org.gvsig.tools.visitor.Visitor;
57 55
import org.gvsig.vectorediting.lib.api.DrawingStatus;
58 56
import org.gvsig.vectorediting.lib.api.EditingServiceParameter;
59 57
import org.gvsig.vectorediting.lib.api.exceptions.DrawServiceException;
......
77 75
public class SplitEditingProvider extends AbstractEditingProvider implements
78 76
    EditingProvider {
79 77

  
80
    private EditingServiceParameter selection;
78
    private final EditingServiceParameter selection;
81 79

  
82
    private EditingServiceParameter splitGeometry;
80
    private final EditingServiceParameter splitGeometry;
83 81

  
84
    private FeatureStore featureStore;
82
    private final FeatureStore featureStore;
85 83

  
86 84
    private Map<EditingServiceParameter, Object> values;
87 85

  
88 86
    /**
89 87
     * Default constructor.
90 88
     *
91
     * @param providerServices
89
     * @param services
92 90
     *            available services for this provider
93 91
     * @param parameters
94 92
     *            of this provider
......
110 108
                EditingServiceParameter.TYPE.GEOMETRY);
111 109
    }
112 110

  
111
    @Override
113 112
    public EditingServiceParameter next() {
114 113
        if (values.get(selection) == null) {
115 114
            return selection;
......
119 118
        return null;
120 119
    }
121 120

  
121
    @Override
122 122
    public DrawingStatus getDrawingStatus(Point mousePosition)
123 123
        throws DrawServiceException {
124 124
        return null;
125 125
    }
126 126

  
127
    @Override
127 128
    public void stop() throws StopServiceException {
128 129
        if (values != null) {
129 130
            values.clear();
130 131
        }
131 132
    }
132 133

  
134
    @Override
133 135
    public List<EditingServiceParameter> getParameters() {
134 136
        List<EditingServiceParameter> parameters =
135
            new ArrayList<EditingServiceParameter>();
137
            new ArrayList<>();
136 138
        parameters.add(selection);
137 139
        parameters.add(splitGeometry);
138 140
        return parameters;
......
143 145
        validateAndInsertValue(parameter, value);
144 146
    }
145 147

  
148
    @Override
146 149
    public void setValue(Object value) throws InvalidEntryException {
147 150
        EditingServiceParameter parameter = next();
148 151
        validateAndInsertValue(parameter, value);
......
158 161
                FeatureSelection featureSelection = (FeatureSelection) value;
159 162

  
160 163
                try {
161
                    featureSelection.accept(new Visitor() {
162

  
163
                        public void visit(Object obj)
164
                            throws VisitCanceledException, BaseException {
165
                            Feature feature = (Feature) obj;
166
                            Geometry geometry = feature.getDefaultGeometry();
167
                            GeometryType geoType = geometry.getGeometryType();
168

  
169
                            if (geoType.isTypeOf(POINT)
164
                    featureSelection.accept((Object obj) -> {
165
                        Feature feature = (Feature) obj;
166
                        Geometry geometry = feature.getDefaultGeometry();
167
                        GeometryType geoType = geometry.getGeometryType();
168
                        
169
                        if (geoType.isTypeOf(POINT)
170 170
                                || geoType.isTypeOf(MULTIPOINT)) {
171
                                throw new InvalidEntryException(null);
172
                            }
171
                            throw new InvalidEntryException(null);
173 172
                        }
174 173
                    });
175 174

  
......
208 207
            (FeatureSelection) values.get(selection);
209 208

  
210 209
        try {
211
            featureSelection.accept(new Visitor() {
212

  
213
                public void visit(Object obj) throws VisitCanceledException,
214
                    BaseException {
215
                    Feature feature = (Feature) obj;
216
                    Geometry geometry = feature.getDefaultGeometry();
217

  
218
                    Geometry intersection = geometry.intersection(curve);
219

  
220
                    if (intersection == null
210
            featureSelection.accept((Object obj) -> {
211
                Feature feature = (Feature) obj;
212
                Geometry geometry = feature.getDefaultGeometry();
213
                
214
                Geometry intersection = geometry.intersection(curve);
215
                
216
                if (intersection == null
221 217
                        || (!intersection.getGeometryType().isTypeOf(POINT)
222 218
                        && !intersection.getGeometryType().isTypeOf(MULTIPOINT)
223 219
                        && !intersection.getGeometryType().isTypeOf(CURVE)
224 220
                        && !intersection.getGeometryType().isTypeOf(MULTICURVE))) {
225
                        throw new VectorEditingException();
226
                    }
221
                    throw new VectorEditingException();
227 222
                }
228 223
            });
229 224
            return true;
......
232 227
        }
233 228
    }
234 229

  
230
    @Override
235 231
    public Geometry finish() throws FinishServiceException {
236 232
        return null;
237 233
    }
238 234

  
235
    @Override
239 236
    public void finishAndStore() throws FinishServiceException {
240 237

  
241 238
        if (values != null) {
......
336 333
            } catch (BaseException e) {
337 334
                throw new FinishServiceException(e);
338 335
            } finally {
339
                it.dispose();
340
                featureSelection.dispose();
336
                DisposeUtils.disposeQuietly(it);
337
                DisposeUtils.disposeQuietly(featureSelection);
341 338
            }
342 339
        }
343 340
    }
......
366 363
        return null;
367 364
    }
368 365

  
366
    @Override
369 367
    public void start() throws StartServiceException, InvalidEntryException {
370
        values = new HashMap<EditingServiceParameter, Object>();
368
        values = new HashMap<>();
371 369
        FeatureSelection selected = null;
372 370
        if (featureStore != null) {
373 371
            try {
......
381 379
        }
382 380
    }
383 381

  
382
    @Override
384 383
    public String getName() {
385 384
        return SplitEditingProviderFactory.PROVIDER_NAME;
386 385
    }

Also available in: Unified diff