1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.dialogs.relation.actions;
|
---|
3 |
|
---|
4 | import java.util.ArrayList;
|
---|
5 | import java.util.Collections;
|
---|
6 | import java.util.List;
|
---|
7 |
|
---|
8 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
9 | import org.openstreetmap.josm.data.osm.Relation;
|
---|
10 | import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil;
|
---|
11 | import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor;
|
---|
12 | import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor.AddAbortException;
|
---|
13 |
|
---|
14 | /**
|
---|
15 | * Abstract superclass of "Add from selection" actions.
|
---|
16 | * @since 9496
|
---|
17 | */
|
---|
18 | abstract class AddFromSelectionAction extends AbstractRelationEditorAction {
|
---|
19 | private static final long serialVersionUID = 1L;
|
---|
20 |
|
---|
21 | protected AddFromSelectionAction(IRelationEditorActionAccess editorAccess,
|
---|
22 | IRelationEditorUpdateOn... updateOn) {
|
---|
23 | super(editorAccess, updateOn);
|
---|
24 | }
|
---|
25 |
|
---|
26 | protected boolean isPotentialDuplicate(OsmPrimitive primitive) {
|
---|
27 | return editorAccess.getMemberTableModel().hasMembersReferringTo(Collections.singleton(primitive));
|
---|
28 | }
|
---|
29 |
|
---|
30 | protected List<OsmPrimitive> filterConfirmedPrimitives(List<OsmPrimitive> primitives) throws AddAbortException {
|
---|
31 | if (primitives == null || primitives.isEmpty())
|
---|
32 | return primitives;
|
---|
33 | List<OsmPrimitive> ret = new ArrayList<>();
|
---|
34 | ConditionalOptionPaneUtil.startBulkOperation("add_primitive_to_relation");
|
---|
35 | for (OsmPrimitive primitive : primitives) {
|
---|
36 | if (primitive instanceof Relation && editorAccess.getEditor().getRelation() != null && editorAccess.getEditor().getRelation().equals(primitive)) {
|
---|
37 | GenericRelationEditor.warnOfCircularReferences(primitive);
|
---|
38 | continue;
|
---|
39 | }
|
---|
40 | if (isPotentialDuplicate(primitive)) {
|
---|
41 | if (GenericRelationEditor.confirmAddingPrimitive(primitive)) {
|
---|
42 | ret.add(primitive);
|
---|
43 | }
|
---|
44 | } else {
|
---|
45 | ret.add(primitive);
|
---|
46 | }
|
---|
47 | }
|
---|
48 | ConditionalOptionPaneUtil.endBulkOperation("add_primitive_to_relation");
|
---|
49 | return ret;
|
---|
50 | }
|
---|
51 | }
|
---|