| [32395] | 1 | // License: GPL. For details, see LICENSE file.
|
|---|
| [25670] | 2 | package relcontext.actions;
|
|---|
| 3 |
|
|---|
| 4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
|---|
| [32395] | 5 |
|
|---|
| [25670] | 6 | import java.awt.event.ActionEvent;
|
|---|
| [28813] | 7 | import java.util.Collections;
|
|---|
| [32395] | 8 |
|
|---|
| [25670] | 9 | import javax.swing.AbstractAction;
|
|---|
| [32395] | 10 |
|
|---|
| [28813] | 11 | import org.openstreetmap.josm.command.Command;
|
|---|
| [25670] | 12 | import org.openstreetmap.josm.command.DeleteCommand;
|
|---|
| [34551] | 13 | import org.openstreetmap.josm.data.UndoRedoHandler;
|
|---|
| [25670] | 14 | import org.openstreetmap.josm.data.osm.Relation;
|
|---|
| 15 | import org.openstreetmap.josm.tools.ImageProvider;
|
|---|
| [32395] | 16 |
|
|---|
| [25670] | 17 | import relcontext.ChosenRelation;
|
|---|
| 18 | import relcontext.ChosenRelationListener;
|
|---|
| 19 |
|
|---|
| 20 | public class DeleteChosenRelationAction extends AbstractAction implements ChosenRelationListener {
|
|---|
| [36102] | 21 | private final ChosenRelation rel;
|
|---|
| [25670] | 22 |
|
|---|
| [32395] | 23 | public DeleteChosenRelationAction(ChosenRelation rel) {
|
|---|
| [25696] | 24 | super(tr("Delete relation"));
|
|---|
| [25670] | 25 | putValue(SMALL_ICON, ImageProvider.get("dialogs", "delete"));
|
|---|
| 26 | this.rel = rel;
|
|---|
| 27 | rel.addChosenRelationListener(this);
|
|---|
| [25711] | 28 | setEnabled(rel.get() != null);
|
|---|
| [25670] | 29 | }
|
|---|
| 30 |
|
|---|
| [32395] | 31 | @Override
|
|---|
| 32 | public void actionPerformed(ActionEvent e) {
|
|---|
| [25670] | 33 | Relation r = rel.get();
|
|---|
| 34 | rel.clear();
|
|---|
| [33694] | 35 | Command c = DeleteCommand.delete(Collections.singleton(r), true, true);
|
|---|
| [32398] | 36 | if (c != null) {
|
|---|
| [34551] | 37 | UndoRedoHandler.getInstance().add(c);
|
|---|
| [32395] | 38 | }
|
|---|
| [25670] | 39 | }
|
|---|
| 40 |
|
|---|
| [32395] | 41 | @Override
|
|---|
| 42 | public void chosenRelationChanged(Relation oldRelation, Relation newRelation) {
|
|---|
| [25670] | 43 | setEnabled(newRelation != null);
|
|---|
| 44 | }
|
|---|
| 45 | }
|
|---|