Ticket #13491: 13491_v2.patch

File 13491_v2.patch, 4.0 KB (added by GerdP, 10 years ago)
  • src/org/openstreetmap/josm/command/Command.java

     
    242242        return cloneMap.keySet();
    243243    }
    244244
     245    /** IS_OK : operation is okay */
     246    public static int IS_OK = 0;
     247    /** IS_OUTSIDE : operation on element outside of download area */
     248    public static int IS_OUTSIDE   = 1;
     249    /** IS_INCOMPLETE: operation on incomplete target */
     250    public static int IS_INCOMPLET = 2;
    245251    /**
    246252     * Check whether user is about to operate on data outside of the download area.
     253     *
     254     * @param operation the operation name which is used for setting some preferences
     255     * @param primitives the primitives to operate on
     256     * @param ignore {@code null} or a primitive to be ignored
     257     * @return true, if operating on outlying primitives is OK; false, otherwise
     258     */
     259    public static int checkOutlyingOrIncompleteOperation(String operation,
     260            Collection<? extends OsmPrimitive> primitives,
     261            Collection<? extends OsmPrimitive> ignore) {
     262        int res = 0;
     263        for (OsmPrimitive osm : primitives) {
     264            if (osm.isIncomplete()) {
     265                res |= IS_INCOMPLET;
     266            } else if (osm.isOutsideDownloadArea()
     267                    && (ignore == null || !ignore.contains(osm))) {
     268                res |= IS_OUTSIDE;
     269            }
     270        }
     271        return res;
     272    }
     273
     274    /**
     275     * Check whether user is about to operate on data outside of the download area.
    247276     * Request confirmation if he is.
    248277     *
    249278     * @param operation the operation name which is used for setting some preferences
     
    258287            String dialogTitle, String outsideDialogMessage, String incompleteDialogMessage,
    259288            Collection<? extends OsmPrimitive> primitives,
    260289            Collection<? extends OsmPrimitive> ignore) {
    261         boolean outside = false;
    262         boolean incomplete = false;
    263         for (OsmPrimitive osm : primitives) {
    264             if (osm.isIncomplete()) {
    265                 incomplete = true;
    266             } else if (osm.isOutsideDownloadArea()
    267                     && (ignore == null || !ignore.contains(osm))) {
    268                 outside = true;
    269             }
    270         }
    271         if (outside) {
     290        int checkRes = checkOutlyingOrIncompleteOperation(operation, primitives, ignore);
     291        if ((checkRes & IS_OUTSIDE) != 0) {
    272292            JPanel msg = new JPanel(new GridBagLayout());
    273293            msg.add(new JMultilineLabel("<html>" + outsideDialogMessage + "</html>"));
    274294            boolean answer = ConditionalOptionPaneUtil.showConfirmationDialog(
     
    282302            if (!answer)
    283303                return false;
    284304        }
    285         if (incomplete) {
     305        if ((checkRes & IS_INCOMPLET) != 0) {
    286306            JPanel msg = new JPanel(new GridBagLayout());
    287307            msg.add(new JMultilineLabel("<html>" + incompleteDialogMessage + "</html>"));
    288308            boolean answer = ConditionalOptionPaneUtil.showConfirmationDialog(
     
    299319        return true;
    300320    }
    301321
     322
    302323    @Override
    303324    public int hashCode() {
    304325        return Objects.hash(cloneMap, layer);
  • src/org/openstreetmap/josm/data/validation/tests/DuplicateNode.java

     
    407407                target = nodes.iterator().next();
    408408            }
    409409
    410             if (DeleteCommand.checkAndConfirmOutlyingDelete(nodes, Collections.singleton(target)))
     410            if (DeleteCommand.checkOutlyingOrIncompleteOperation("delete", nodes, Collections.singleton(target)) == DeleteCommand.IS_OK)
    411411                return MergeNodesAction.mergeNodes(Main.getLayerManager().getEditLayer(), nodes, target);
    412412        }
    413413