Ticket #15707: no_exception_for_empty_selection3.patch

File no_exception_for_empty_selection3.patch, 3.7 KB (added by skorbut, 8 years ago)
  • src/org/openstreetmap/josm/io/remotecontrol/handler/LoadAndZoomHandler.java

     
    1313import java.util.Set;
    1414import java.util.concurrent.Future;
    1515
     16import javax.swing.JOptionPane;
     17
     18import org.openstreetmap.josm.Main;
    1619import org.openstreetmap.josm.actions.AutoScaleAction;
    1720import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask;
    1821import org.openstreetmap.josm.actions.downloadtasks.DownloadTask;
     
    171174            });
    172175        }
    173176
    174         final Collection<OsmPrimitive> forTagAdd = new HashSet<>();
     177        final Collection<OsmPrimitive> forTagAdd = new HashSet<>(); // these objects will receive tags
    175178        final Bounds bbox = new Bounds(minlat, minlon, maxlat, maxlon);
    176179        if (args.containsKey("select") && PermissionPrefWithDefault.CHANGE_SELECTION.isAllowed()) {
    177180            // select objects after downloading, zoom to selection.
    178181            GuiHelper.executeByMainWorkerInEDT(() -> {
    179                 Set<OsmPrimitive> newSel = new HashSet<>();
     182                Set<OsmPrimitive> newSel = new HashSet<>(); // these objects will be selected later on
    180183                DataSet ds = MainApplication.getLayerManager().getEditDataSet();
    181184                if (ds == null) // e.g. download failed
    182185                    return;
     
    193196                    forTagAdd.addAll(sel);
    194197                }
    195198                toSelect.clear();
    196                 isKeepingCurrentSelection = false;
    197199                ds.setSelected(newSel);
    198200                zoom(newSel, bbox);
    199201                MapFrame map = MainApplication.getMap();
     
    236238            });
    237239        }
    238240
    239         AddTagsDialog.addTags(args, sender, forTagAdd);
     241        // add tags to objects
     242        if (args.containsKey("addtags")) {
     243            // needs to run in EDT since forTagAdd is updated in EDT as well
     244            GuiHelper.executeByMainWorkerInEDT(() -> {
     245                if (!forTagAdd.isEmpty()) {
     246                    AddTagsDialog.addTags(args, sender, forTagAdd);
     247                } else { // something is wrong, forTagAdd should not be empty
     248                    if (isKeepingCurrentSelection) {
     249                        JOptionPane.showMessageDialog(Main.parent,
     250                                tr("You clicked on a JOSM remotecontrol link that would apply tags onto selected objects.\n"
     251                                        + "Since no objects have been selected before this click, no tags were added.\n"
     252                                        + "Select one or more objects and click the link again."),
     253                                tr("No object selected"), JOptionPane.ERROR_MESSAGE);
     254                    } else { // !isKeepingCurrentSelection
     255                        JOptionPane.showMessageDialog(Main.parent,
     256                                tr("You clicked on a JOSM remotecontrol link that would apply tags onto objects.\n"
     257                                        + "Unfortunately that link seems to be broken.\n"
     258                                        + "Technical explanation: the URL query parameter ''select='' or ''search='' has an invalid value.\n"
     259                                        + "Ask someone at the origin of the clicked link to fix this."),
     260                                tr("Invalid query parameter"), JOptionPane.ERROR_MESSAGE);
     261                    }
     262                }
     263            });
     264        }
    240265    }
    241266
    242267    protected void zoom(Collection<OsmPrimitive> primitives, final Bounds bbox) {