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