Revision 3067 org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.rectangularmatrix/src/main/java/org/gvsig/vectorediting/lib/prov/rectangularmatrix/RectangularMatrixEditingProvider.java
RectangularMatrixEditingProvider.java | ||
---|---|---|
26 | 26 |
|
27 | 27 |
import java.awt.geom.AffineTransform; |
28 | 28 |
import java.util.ArrayList; |
29 |
import java.util.Collections; |
|
29 | 30 |
import java.util.HashMap; |
30 | 31 |
import java.util.List; |
31 | 32 |
import java.util.Map; |
33 |
import org.apache.commons.collections.CollectionUtils; |
|
32 | 34 |
import org.gvsig.fmap.dal.exception.DataException; |
33 | 35 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
34 | 36 |
import org.gvsig.fmap.dal.feature.Feature; |
... | ... | |
98 | 100 |
|
99 | 101 |
private final EditingServiceParameter rowDistance; |
100 | 102 |
|
103 |
private List<Feature> selectedFeatures; |
|
104 |
|
|
101 | 105 |
/** |
102 | 106 |
* Default constructor. |
103 | 107 |
* |
... | ... | |
168 | 172 |
GeometryManager geometryManager = GeometryLocator.getGeometryManager(); |
169 | 173 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
170 | 174 |
|
171 |
FeatureSelection featureSelection = |
|
172 |
(FeatureSelection) values.get(selection); |
|
175 |
// FeatureSelection featureSelection =
|
|
176 |
// (FeatureSelection) values.get(selection);
|
|
173 | 177 |
Integer columnsValue = (Integer) values.get(columns); |
174 | 178 |
Integer rowsValue = (Integer) values.get(rows); |
175 | 179 |
Point basePointValue = (Point) values.get(basePoint); |
176 | 180 |
Double columnDistanceValue = (Double) values.get(columnDistance); |
177 | 181 |
Double rowDistanceValue = (Double) values.get(rowDistance); |
178 | 182 |
|
179 |
if (featureSelection != null && columnsValue != null
|
|
183 |
if ( CollectionUtils.isNotEmpty(selectedFeatures) && columnsValue != null
|
|
180 | 184 |
&& rowsValue != null && basePointValue != null) { |
181 | 185 |
|
182 | 186 |
int subtype = basePointValue.getGeometryType().getSubType(); |
... | ... | |
235 | 239 |
throw new DrawServiceException(e); |
236 | 240 |
} |
237 | 241 |
|
238 |
DisposableIterator it = null; |
|
239 | 242 |
try { |
240 |
it = featureSelection.fastIterator(); |
|
241 |
while (it.hasNext()) { |
|
242 |
Feature feature = (Feature) it.next(); |
|
243 |
|
|
243 |
for (Feature feature : selectedFeatures) { |
|
244 | 244 |
ISymbol previewSymbol = this.getPreviewSymbol(feature); |
245 | 245 |
|
246 | 246 |
Geometry geometry = feature.getDefaultGeometry(); |
... | ... | |
269 | 269 |
} |
270 | 270 |
} catch (BaseException e) { |
271 | 271 |
throw new DrawServiceException(e); |
272 |
} finally { |
|
273 |
DisposeUtils.disposeQuietly(it); |
|
274 | 272 |
} |
275 | 273 |
} |
276 | 274 |
return drawingStatus; |
... | ... | |
335 | 333 |
@Override |
336 | 334 |
public void stop() throws StopServiceException { |
337 | 335 |
values.clear(); |
336 |
this.selectedFeatures = Collections.EMPTY_LIST; |
|
338 | 337 |
} |
339 | 338 |
|
340 | 339 |
@Override |
... | ... | |
368 | 367 |
FeatureSelection featureSelection = (FeatureSelection) value; |
369 | 368 |
if (featureSelection.getSelectedCount() > 0) { |
370 | 369 |
values.put(parameter, featureSelection); |
370 |
this.selectedFeatures = this.getSelectedFeaturesCopy(featureSelection); |
|
371 | 371 |
insertedValue = true; |
372 | 372 |
} |
373 | 373 |
} else if (parameter.equals(columns) || parameter.equals(rows)) { |
... | ... | |
422 | 422 |
@Override |
423 | 423 |
public void finishAndStore() throws FinishServiceException { |
424 | 424 |
|
425 |
FeatureSelection featureSelection = |
|
426 |
(FeatureSelection) values.get(selection); |
|
425 |
// FeatureSelection featureSelection =
|
|
426 |
// (FeatureSelection) values.get(selection);
|
|
427 | 427 |
final Integer columnsValue = (Integer) values.get(columns); |
428 | 428 |
final Integer rowsValue = (Integer) values.get(rows); |
429 | 429 |
final Point basePointValue = (Point) values.get(basePoint); |
... | ... | |
433 | 433 |
final EditingProviderServices editingProviderServices = |
434 | 434 |
(EditingProviderServices) getProviderServices(); |
435 | 435 |
|
436 |
if (featureSelection != null && columnsValue != null
|
|
436 |
if (CollectionUtils.isNotEmpty(selectedFeatures) && columnsValue != null
|
|
437 | 437 |
&& rowsValue != null && basePointValue != null |
438 | 438 |
&& spacingColumnsValue != null && spacingRowsValue != null) { |
439 | 439 |
|
440 | 440 |
try { |
441 |
featureSelection.accept((Object obj) -> { |
|
442 |
Feature feature = (Feature) obj; |
|
441 |
for (Feature feature : selectedFeatures) { |
|
443 | 442 |
Geometry geometry = feature.getDefaultGeometry(); |
444 | 443 |
Geometry[][] matrix = |
445 | 444 |
createRectangularMatrix(geometry, columnsValue, |
... | ... | |
458 | 457 |
featureStore); |
459 | 458 |
} |
460 | 459 |
} |
461 |
});
|
|
460 |
} |
|
462 | 461 |
} catch (BaseException e) { |
463 | 462 |
throw new FinishServiceException(e); |
464 | 463 |
} |
... | ... | |
468 | 467 |
@Override |
469 | 468 |
public void start() throws StartServiceException, InvalidEntryException { |
470 | 469 |
values = new HashMap<>(); |
471 |
FeatureSelection selected = null; |
|
472 |
if (featureStore != null && values.get(selection) == null) { |
|
470 |
this.selectedFeatures = Collections.EMPTY_LIST; |
|
471 |
if (featureStore != null) { |
|
472 |
FeatureSelection selected = null; |
|
473 | 473 |
try { |
474 |
selected = featureStore.getFeatureSelection();
|
|
474 |
selected = (FeatureSelection) featureStore.getFeatureSelection().clone();
|
|
475 | 475 |
} catch (DataException e) { |
476 | 476 |
throw new StartServiceException(e); |
477 |
} catch (CloneNotSupportedException ex) { |
|
478 |
LOGGER.debug("Can't init selection",ex); |
|
477 | 479 |
} |
478 |
if (selected.getSelectedCount() > 0) { |
|
479 |
try { |
|
480 |
setValue(selected); |
|
481 |
} catch (InvalidEntryException e) { |
|
482 |
throw new InvalidEntryException(e); |
|
483 |
} |
|
480 |
if ((selected != null) && (selected.getSelectedCount() > 0)) { |
|
481 |
values.put(selection, selected); |
|
482 |
this.selectedFeatures = this.getSelectedFeaturesCopy(selected); |
|
484 | 483 |
} |
485 | 484 |
} |
486 | 485 |
} |
Also available in: Unified diff