Revision 3067 org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.splitline/src/main/java/org/gvsig/vectorediting/lib/prov/splitline/SplitLineEditingProvider.java
SplitLineEditingProvider.java | ||
---|---|---|
26 | 26 |
|
27 | 27 |
import java.util.ArrayList; |
28 | 28 |
import java.util.Arrays; |
29 |
import java.util.Collections; |
|
29 | 30 |
import java.util.HashMap; |
30 | 31 |
import java.util.List; |
31 | 32 |
import java.util.Map; |
... | ... | |
47 | 48 |
import org.gvsig.fmap.geom.primitive.Primitive; |
48 | 49 |
import org.gvsig.fmap.geom.type.GeometryType; |
49 | 50 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
50 |
import org.gvsig.tools.ToolsLocator; |
|
51 |
import org.gvsig.tools.dispose.DisposableIterator; |
|
52 |
import org.gvsig.tools.dispose.DisposeUtils; |
|
53 | 51 |
import org.gvsig.tools.dynobject.DynObject; |
54 | 52 |
import org.gvsig.tools.exception.BaseException; |
55 | 53 |
import org.gvsig.tools.locator.LocatorException; |
... | ... | |
88 | 86 |
|
89 | 87 |
private Map<EditingServiceParameter, Object> values; |
90 | 88 |
|
89 |
private List<Feature> selectedFeatures; |
|
90 |
|
|
91 | 91 |
/** |
92 | 92 |
* Default constructor. |
93 | 93 |
* |
... | ... | |
135 | 135 |
ISymbol auxiliaryLineSymbolEditing = editingProviderManager.getSymbol("auxiliary-line-symbol-editing"); |
136 | 136 |
|
137 | 137 |
|
138 |
FeatureSelection featureSelection = |
|
139 |
(FeatureSelection) values.get(selection); |
|
140 |
|
|
141 |
DisposableIterator it = null; |
|
142 | 138 |
try { |
143 | 139 |
|
144 | 140 |
EditingProviderServices editingProviderService = |
145 | 141 |
(EditingProviderServices) getProviderServices(); |
146 | 142 |
|
147 | 143 |
int subtype = editingProviderService.getSubType(featureStore); |
148 |
|
|
149 |
it = featureSelection.fastIterator(); |
|
150 |
while (it.hasNext()) { |
|
151 |
|
|
152 |
Feature feature = (Feature) it.next(); |
|
153 |
|
|
144 |
for (Feature feature : selectedFeatures) { |
|
154 | 145 |
ISymbol previewSymbol = this.getPreviewSymbol(feature); |
155 | 146 |
|
156 | 147 |
Geometry lineToSplit = |
... | ... | |
167 | 158 |
} |
168 | 159 |
} catch (Exception e) { |
169 | 160 |
throw new DrawServiceException(e); |
170 |
} finally { |
|
171 |
DisposeUtils.disposeQuietly(it); |
|
172 | 161 |
} |
173 | 162 |
return drawingStatus; |
174 | 163 |
} |
... | ... | |
198 | 187 |
if (values != null) { |
199 | 188 |
values.clear(); |
200 | 189 |
} |
190 |
this.selectedFeatures = Collections.EMPTY_LIST; |
|
201 | 191 |
} |
202 | 192 |
|
203 | 193 |
@Override |
... | ... | |
230 | 220 |
|
231 | 221 |
FeatureSelection feautureSelection = (FeatureSelection) value; |
232 | 222 |
if (feautureSelection.getSelectedCount() == 1) { |
233 |
|
|
234 | 223 |
try { |
235 |
feautureSelection.accept((Object obj) -> { |
|
236 |
Feature feature = (Feature) obj; |
|
237 |
Geometry geometry = |
|
238 |
feature.getDefaultGeometry(); |
|
239 |
GeometryType geoType = |
|
240 |
geometry.getGeometryType(); |
|
241 |
|
|
242 |
if (geoType.isTypeOf(Geometry.TYPES.CURVE)) { |
|
243 |
|
|
224 |
for (Feature feature : selectedFeatures) { |
|
225 |
Geometry geometry = feature.getDefaultGeometry(); |
|
226 |
GeometryType geoType = geometry.getGeometryType(); |
|
227 |
if (geoType.isTypeOf(Geometry.TYPES.CURVE)) { |
|
244 | 228 |
if (isAnArcClosed((Curve) geometry)) { |
245 | 229 |
throw new InvalidEntryException(null); |
246 | 230 |
} else { |
247 | 231 |
values.put(selection, value); |
232 |
this.selectedFeatures = this.getSelectedFeaturesCopy(feautureSelection); |
|
248 | 233 |
} |
249 | 234 |
|
250 |
} else if (geoType |
|
251 |
.isTypeOf(Geometry.TYPES.MULTICURVE)) { |
|
252 |
|
|
253 |
MultiCurve multiCurve = |
|
254 |
(MultiCurve) geometry; |
|
255 |
|
|
256 |
for (int i = 0; i < multiCurve |
|
257 |
.getPrimitivesNumber(); i++) { |
|
258 |
if (isAnArcClosed((Curve) multiCurve |
|
259 |
.getPrimitiveAt(i))) { |
|
260 |
throw new InvalidEntryException( |
|
261 |
null); |
|
235 |
} else if (geoType.isTypeOf(Geometry.TYPES.MULTICURVE)) { |
|
236 |
MultiCurve multiCurve = (MultiCurve) geometry; |
|
237 |
for (int i = 0; i < multiCurve.getPrimitivesNumber(); i++) { |
|
238 |
if (isAnArcClosed((Curve) multiCurve.getPrimitiveAt(i))) { |
|
239 |
throw new InvalidEntryException(null); |
|
262 | 240 |
} |
263 | 241 |
} |
264 | 242 |
values.put(selection, value); |
243 |
this.selectedFeatures = this.getSelectedFeaturesCopy(feautureSelection); |
|
265 | 244 |
} |
266 |
});
|
|
245 |
} |
|
267 | 246 |
return; |
268 | 247 |
} catch (BaseException e) { |
269 | 248 |
throw new InvalidEntryException(e); |
... | ... | |
303 | 282 |
final EditingProviderServices editingProviderService = |
304 | 283 |
(EditingProviderServices) getProviderServices(); |
305 | 284 |
|
306 |
FeatureSelection featureSelection = |
|
307 |
(FeatureSelection) values.get(selection); |
|
308 |
ToolsLocator.getDisposableManager().bind(featureSelection); |
|
309 |
|
|
310 | 285 |
final Point pointValue = (Point) values.get(point); |
311 | 286 |
|
312 | 287 |
try { |
313 |
featureSelection.accept((Object obj) -> { |
|
314 |
Feature feature = (Feature) obj; |
|
315 |
|
|
288 |
for (Feature feature : selectedFeatures) { |
|
316 | 289 |
Geometry lineToSplit = |
317 | 290 |
getLineToSplit(feature.getDefaultGeometry()); |
318 | 291 |
GeometryType geomType = lineToSplit.getGeometryType(); |
... | ... | |
373 | 346 |
} |
374 | 347 |
} |
375 | 348 |
} |
376 |
}); |
|
377 |
|
|
349 |
} |
|
378 | 350 |
featureStore.getFeatureSelection().deselectAll(); |
379 |
featureSelection.dispose(); |
|
380 |
|
|
351 |
this.selectedFeatures = Collections.EMPTY_LIST; |
|
381 | 352 |
} catch (BaseException e) { |
382 | 353 |
throw new FinishServiceException(e); |
383 | 354 |
} |
... | ... | |
460 | 431 |
@Override |
461 | 432 |
public void start() throws StartServiceException, InvalidEntryException { |
462 | 433 |
values = new HashMap<>(); |
463 |
FeatureSelection selected = null;
|
|
434 |
this.selectedFeatures = Collections.EMPTY_LIST;
|
|
464 | 435 |
if (featureStore != null) { |
436 |
FeatureSelection selected = null; |
|
465 | 437 |
try { |
466 |
selected = featureStore.getFeatureSelection();
|
|
438 |
selected = (FeatureSelection) featureStore.getFeatureSelection().clone();
|
|
467 | 439 |
} catch (DataException e) { |
468 | 440 |
throw new StartServiceException(e); |
441 |
} catch (CloneNotSupportedException ex) { |
|
442 |
LOGGER.debug("Can't init selection",ex); |
|
469 | 443 |
} |
470 |
if (selected.getSelectedCount() > 0) { |
|
471 |
setValue(selected); |
|
444 |
if ((selected != null) && (selected.getSelectedCount() > 0)) { |
|
445 |
values.put(selection, selected); |
|
446 |
this.selectedFeatures = this.getSelectedFeaturesCopy(selected); |
|
472 | 447 |
} |
473 | 448 |
} |
474 | 449 |
} |
Also available in: Unified diff