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.Notification;
|
---|
20 | import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor;
|
---|
21 | import org.openstreetmap.josm.gui.util.GuiHelper;
|
---|
22 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * Add all objects selected in the current dataset after the last member of relation(s).
|
---|
26 | * @since 5799
|
---|
27 | */
|
---|
28 | public class AddSelectionToRelations extends AbstractRelationAction implements SelectionChangedListener {
|
---|
29 | /**
|
---|
30 | * Constructs a new <code>AddSelectionToRelation</code>.
|
---|
31 | */
|
---|
32 | public AddSelectionToRelations() {
|
---|
33 | putValue(SMALL_ICON, ImageProvider.get("dialogs/conflict", "copyendright"));
|
---|
34 | putValue(SHORT_DESCRIPTION, tr("Add all objects selected in the current dataset after the last member"));
|
---|
35 | }
|
---|
36 |
|
---|
37 | @Override
|
---|
38 | public void actionPerformed(ActionEvent e) {
|
---|
39 | Collection<Command> cmds = new LinkedList<>();
|
---|
40 | for (Relation orig : relations) {
|
---|
41 | Command c = GenericRelationEditor.addPrimitivesToRelation(orig, Main.main.getCurrentDataSet().getSelected());
|
---|
42 | if (c != null) {
|
---|
43 | cmds.add(c);
|
---|
44 | }
|
---|
45 | }
|
---|
46 | if (!cmds.isEmpty()) {
|
---|
47 | Main.main.undoRedo.add(new SequenceCommand(tr("Add selection to relation"), cmds));
|
---|
48 | new Notification(
|
---|
49 | "<html>"+
|
---|
50 | tr("{0}Add selection to relation{1}: Verify every single relation to avoid damage!", "<strong>", "</strong>")+
|
---|
51 | "</html>")
|
---|
52 | .setIcon(JOptionPane.WARNING_MESSAGE)
|
---|
53 | .show();
|
---|
54 | }
|
---|
55 | }
|
---|
56 |
|
---|
57 | @Override
|
---|
58 | public void updateEnabledState() {
|
---|
59 | putValue(NAME, trn("Add selection to {0} relation", "Add selection to {0} relations",
|
---|
60 | relations.size(), relations.size()));
|
---|
61 | }
|
---|
62 |
|
---|
63 | @Override
|
---|
64 | public void selectionChanged(final Collection<? extends OsmPrimitive> newSelection) {
|
---|
65 | GuiHelper.runInEDT(new Runnable() {
|
---|
66 | @Override
|
---|
67 | public void run() {
|
---|
68 | setEnabled(newSelection != null && !newSelection.isEmpty());
|
---|
69 | }
|
---|
70 | });
|
---|
71 | }
|
---|
72 | }
|
---|