Changeset 6600 in josm for trunk


Ignore:
Timestamp:
2014-01-02T23:47:56+01:00 (11 years ago)
Author:
simon04
Message:

see #9492 - Automatically download incomplete relations for "Update Multipolygon"

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/CreateMultipolygonAction.java

    r6597 r6600  
    99import java.util.Arrays;
    1010import java.util.Collection;
     11import java.util.Collections;
    1112import java.util.HashMap;
    1213import java.util.HashSet;
     
    3334import org.openstreetmap.josm.data.osm.Way;
    3435import org.openstreetmap.josm.gui.Notification;
     36import org.openstreetmap.josm.gui.dialogs.relation.DownloadRelationTask;
    3537import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor;
    3638import org.openstreetmap.josm.tools.Pair;
     
    106108                ? getSelectedMultipolygonRelation(selectedWays, selectedRelations)
    107109                : null;
    108         if (multipolygonRelation != null && (multipolygonRelation.isIncomplete() || multipolygonRelation.hasIncompleteMembers())) {
    109             new Notification(
    110                     tr("Cannot update multipolygon since relation is incomplete."))
    111                     .setIcon(JOptionPane.WARNING_MESSAGE)
    112                     .setDuration(Notification.TIME_DEFAULT)
    113                     .show();
    114             return;
    115         }
    116 
    117         final Pair<SequenceCommand, Relation> commandAndRelation = createMultipolygonCommand(selectedWays, multipolygonRelation);
    118         if (commandAndRelation == null) {
    119             return;
    120         }
    121         final Command command = commandAndRelation.a;
    122         final Relation relation = commandAndRelation.b;
    123         Main.main.undoRedo.add(command);
    124 
    125         // Use 'SwingUtilities.invokeLater' to make sure the relationListDialog
    126         // knows about the new relation before we try to select it.
    127         // (Yes, we are already in event dispatch thread. But DatasetEventManager
    128         // uses 'SwingUtilities.invokeLater' to fire events so we have to do
    129         // the same.)
    130         SwingUtilities.invokeLater(new Runnable() {
     110
     111        // runnable to create/update multipolygon relation
     112        final Runnable createOrUpdateMultipolygonTask = new Runnable() {
    131113            @Override
    132114            public void run() {
    133                 Main.map.relationListDialog.selectRelation(relation);
    134                 if (Main.pref.getBoolean("multipoly.show-relation-editor", false)) {
    135                     //Open relation edit window, if set up in preferences
    136                     RelationEditor editor = RelationEditor.getEditor(Main.main.getEditLayer(), relation, null);
    137 
    138                     editor.setModal(true);
    139                     editor.setVisible(true);
     115                final Pair<SequenceCommand, Relation> commandAndRelation = createMultipolygonCommand(selectedWays, multipolygonRelation);
     116                if (commandAndRelation == null) {
     117                    return;
    140118                }
    141             }
    142         });
     119                final Command command = commandAndRelation.a;
     120                final Relation relation = commandAndRelation.b;
     121
     122
     123                // to avoid EDT violations
     124                SwingUtilities.invokeLater(new Runnable() {
     125                    @Override
     126                    public void run() {
     127                        Main.main.undoRedo.add(command);
     128                    }
     129                });
     130
     131                // Use 'SwingUtilities.invokeLater' to make sure the relationListDialog
     132                // knows about the new relation before we try to select it.
     133                // (Yes, we are already in event dispatch thread. But DatasetEventManager
     134                // uses 'SwingUtilities.invokeLater' to fire events so we have to do
     135                // the same.)
     136                SwingUtilities.invokeLater(new Runnable() {
     137                    @Override
     138                    public void run() {
     139                        Main.map.relationListDialog.selectRelation(relation);
     140                        if (Main.pref.getBoolean("multipoly.show-relation-editor", false)) {
     141                            //Open relation edit window, if set up in preferences
     142                            RelationEditor editor = RelationEditor.getEditor(Main.main.getEditLayer(), relation, null);
     143
     144                            editor.setModal(true);
     145                            editor.setVisible(true);
     146                        }
     147                    }
     148                });
     149            }
     150        };
     151
     152        // download incomplete relation if necessary
     153        if (multipolygonRelation != null && (multipolygonRelation.isIncomplete() || multipolygonRelation.hasIncompleteMembers())) {
     154            Main.worker.submit(new DownloadRelationTask(Collections.singleton(multipolygonRelation), Main.main.getEditLayer()));
     155        }
     156        // create/update multipolygon relation
     157        Main.worker.submit(createOrUpdateMultipolygonTask);
    143158
    144159    }
Note: See TracChangeset for help on using the changeset viewer.