Ignore:
Timestamp:
2017-09-06T02:03:14+02:00 (2 years ago)
Author:
Don-vip
Message:

see #15229 - see #15182 - see #13036 - remove GUI stuff from Command and DeleteCommand

Location:
trunk/src/org/openstreetmap/josm/command
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/command/Command.java

    r12726 r12749  
    22package org.openstreetmap.josm.command;
    33
    4 import java.awt.GridBagLayout;
    54import java.util.ArrayList;
    65import java.util.Collection;
     
    109import java.util.Map.Entry;
    1110import java.util.Objects;
    12 
    13 import javax.swing.JOptionPane;
    14 import javax.swing.JPanel;
    1511
    1612import org.openstreetmap.josm.Main;
     
    2420import org.openstreetmap.josm.data.osm.Way;
    2521import org.openstreetmap.josm.data.osm.visitor.AbstractVisitor;
    26 import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil;
    2722import org.openstreetmap.josm.gui.MainApplication;
    2823import org.openstreetmap.josm.gui.layer.Layer;
    2924import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    30 import org.openstreetmap.josm.gui.widgets.JMultilineLabel;
    3125import org.openstreetmap.josm.tools.CheckParameterUtil;
    3226
     
    304298
    305299    /**
    306      * Check whether user is about to operate on data outside of the download area.
    307      * Request confirmation if he is.
    308      *
    309      * @param operation the operation name which is used for setting some preferences
    310      * @param dialogTitle the title of the dialog being displayed
    311      * @param outsideDialogMessage the message text to be displayed when data is outside of the download area
    312      * @param incompleteDialogMessage the message text to be displayed when data is incomplete
    313      * @param primitives the primitives to operate on
    314      * @param ignore {@code null} or a primitive to be ignored
    315      * @return true, if operating on outlying primitives is OK; false, otherwise
    316      */
    317     public static boolean checkAndConfirmOutlyingOperation(String operation,
    318             String dialogTitle, String outsideDialogMessage, String incompleteDialogMessage,
    319             Collection<? extends OsmPrimitive> primitives,
    320             Collection<? extends OsmPrimitive> ignore) {
    321         int checkRes = checkOutlyingOrIncompleteOperation(primitives, ignore);
    322         if ((checkRes & IS_OUTSIDE) != 0) {
    323             JPanel msg = new JPanel(new GridBagLayout());
    324             msg.add(new JMultilineLabel("<html>" + outsideDialogMessage + "</html>"));
    325             boolean answer = ConditionalOptionPaneUtil.showConfirmationDialog(
    326                     operation + "_outside_nodes",
    327                     Main.parent,
    328                     msg,
    329                     dialogTitle,
    330                     JOptionPane.YES_NO_OPTION,
    331                     JOptionPane.QUESTION_MESSAGE,
    332                     JOptionPane.YES_OPTION);
    333             if (!answer)
    334                 return false;
    335         }
    336         if ((checkRes & IS_INCOMPLETE) != 0) {
    337             JPanel msg = new JPanel(new GridBagLayout());
    338             msg.add(new JMultilineLabel("<html>" + incompleteDialogMessage + "</html>"));
    339             boolean answer = ConditionalOptionPaneUtil.showConfirmationDialog(
    340                     operation + "_incomplete",
    341                     Main.parent,
    342                     msg,
    343                     dialogTitle,
    344                     JOptionPane.YES_NO_OPTION,
    345                     JOptionPane.QUESTION_MESSAGE,
    346                     JOptionPane.YES_OPTION);
    347             if (!answer)
    348                 return false;
    349         }
    350         return true;
    351     }
    352 
    353     /**
    354300     * Ensures that all primitives that are participating in this command belong to the affected data set.
    355301     *
  • trunk/src/org/openstreetmap/josm/command/DeleteCommand.java

    r12726 r12749  
    8080
    8181    /**
     82     * Called when a deletion operation must be checked and confirmed by user.
     83     * @since 12749
     84     */
     85    @FunctionalInterface
     86    public interface DeletionCallback {
     87        /**
     88         * Check whether user is about to delete data outside of the download area.
     89         * Request confirmation if he is.
     90         * @param primitives the primitives to operate on
     91         * @param ignore {@code null} or a primitive to be ignored
     92         * @return true, if operating on outlying primitives is OK; false, otherwise
     93         */
     94        boolean checkAndConfirmOutlyingDelete(Collection<? extends OsmPrimitive> primitives, Collection<? extends OsmPrimitive> ignore);
     95    }
     96
     97    private static DeletionCallback callback;
     98
     99    /**
     100     * Sets the global {@link DeletionCallback}.
     101     * @param deletionCallback the new {@code DeletionCallback}. Must not be null
     102     * @throws NullPointerException if {@code deletionCallback} is null
     103     * @since 12749
     104     */
     105    public static void setDeletionCallback(DeletionCallback deletionCallback) {
     106        callback = Objects.requireNonNull(deletionCallback);
     107    }
     108
     109    /**
    82110     * The primitives that get deleted.
    83111     */
     
    325353        if (parents.isEmpty())
    326354            return null;
    327         if (!silent && !checkAndConfirmOutlyingDelete(parents, null))
     355        if (!silent && !callback.checkAndConfirmOutlyingDelete(parents, null))
    328356            return null;
    329357        return new DeleteCommand(parents.iterator().next().getDataSet(), parents);
     
    526554        }
    527555
    528         if (!silent && !checkAndConfirmOutlyingDelete(
     556        if (!silent && !callback.checkAndConfirmOutlyingDelete(
    529557                primitivesToDelete, Utils.filteredCollection(primitivesToDelete, Way.class)))
    530558            return null;
     
    628656            return split != null ? split.getCommand() : null;
    629657        }
    630     }
    631 
    632     public static boolean checkAndConfirmOutlyingDelete(Collection<? extends OsmPrimitive> primitives,
    633             Collection<? extends OsmPrimitive> ignore) {
    634         return Command.checkAndConfirmOutlyingOperation("delete",
    635                 tr("Delete confirmation"),
    636                 tr("You are about to delete nodes outside of the area you have downloaded."
    637                         + "<br>"
    638                         + "This can cause problems because other objects (that you do not see) might use them."
    639                         + "<br>"
    640                         + "Do you really want to delete?"),
    641                 tr("You are about to delete incomplete objects."
    642                         + "<br>"
    643                         + "This will cause problems because you don''t see the real object."
    644                         + "<br>" + "Do you really want to delete?"),
    645                 primitives, ignore);
    646658    }
    647659
Note: See TracChangeset for help on using the changeset viewer.