1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.actions.relation;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 | import static org.openstreetmap.josm.tools.I18n.trn;
|
---|
6 |
|
---|
7 | import java.awt.event.ActionEvent;
|
---|
8 | import java.util.Collection;
|
---|
9 | import java.util.LinkedList;
|
---|
10 |
|
---|
11 | import javax.swing.JOptionPane;
|
---|
12 |
|
---|
13 | import org.openstreetmap.josm.Main;
|
---|
14 | import org.openstreetmap.josm.command.Command;
|
---|
15 | import org.openstreetmap.josm.command.SequenceCommand;
|
---|
16 | import org.openstreetmap.josm.data.SelectionChangedListener;
|
---|
17 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
18 | import org.openstreetmap.josm.data.osm.Relation;
|
---|
19 | import org.openstreetmap.josm.gui.MainApplication;
|
---|
20 | import org.openstreetmap.josm.gui.Notification;
|
---|
21 | import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor;
|
---|
22 | import org.openstreetmap.josm.gui.util.GuiHelper;
|
---|
23 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Add all objects selected in the current dataset after the last member of relation(s).
|
---|
27 | * @since 5799
|
---|
28 | */
|
---|
29 | public class AddSelectionToRelations extends AbstractRelationAction implements SelectionChangedListener {
|
---|
30 | /**
|
---|
31 | * Constructs a new <code>AddSelectionToRelation</code>.
|
---|
32 | */
|
---|
33 | public AddSelectionToRelations() {
|
---|
34 | putValue(SMALL_ICON, ImageProvider.get("dialogs/conflict", "copyendright"));
|
---|
35 | putValue(SHORT_DESCRIPTION, tr("Add all objects selected in the current dataset after the last member"));
|
---|
36 | }
|
---|
37 |
|
---|
38 | @Override
|
---|
39 | public void actionPerformed(ActionEvent e) {
|
---|
40 | Collection<Command> cmds = new LinkedList<>();
|
---|
41 | for (Relation orig : relations) {
|
---|
42 | Command c = GenericRelationEditor.addPrimitivesToRelation(orig, MainApplication.getLayerManager().getEditDataSet().getSelected());
|
---|
43 | if (c != null) {
|
---|
44 | cmds.add(c);
|
---|
45 | }
|
---|
46 | }
|
---|
47 | if (!cmds.isEmpty()) {
|
---|
48 | Main.main.undoRedo.add(new SequenceCommand(tr("Add selection to relation"), cmds));
|
---|
49 | new Notification(
|
---|
50 | "<html>"+
|
---|
51 | tr("{0}Add selection to relation{1}: Verify every single relation to avoid damage!", "<strong>", "</strong>")+
|
---|
52 | "</html>")
|
---|
53 | .setIcon(JOptionPane.WARNING_MESSAGE)
|
---|
54 | .show();
|
---|
55 | }
|
---|
56 | }
|
---|
57 |
|
---|
58 | @Override
|
---|
59 | public void updateEnabledState() {
|
---|
60 | putValue(NAME, trn("Add selection to {0} relation", "Add selection to {0} relations",
|
---|
61 | relations.size(), relations.size()));
|
---|
62 | }
|
---|
63 |
|
---|
64 | @Override
|
---|
65 | public void selectionChanged(final Collection<? extends OsmPrimitive> newSelection) {
|
---|
66 | GuiHelper.runInEDT(() -> setEnabled(newSelection != null && !newSelection.isEmpty()));
|
---|
67 | }
|
---|
68 | }
|
---|