source: josm/trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/AddFromSelectionAction.java @ 14027

Last change on this file since 14027 was 14027, checked in by michael2402, 5 months ago

See #16388: New mechanism for plugins to register relation editor actions.

File size: 2.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.dialogs.relation.actions;
3
4import java.util.ArrayList;
5import java.util.Collections;
6import java.util.List;
7
8import org.openstreetmap.josm.data.osm.OsmPrimitive;
9import org.openstreetmap.josm.data.osm.Relation;
10import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil;
11import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor;
12import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor.AddAbortException;
13
14/**
15 * Abstract superclass of "Add from selection" actions.
16 * @since 9496
17 */
18abstract 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}
Note: See TracBrowser for help on using the repository browser.