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