Changeset 12749 in josm for trunk/src/org/openstreetmap/josm


Ignore:
Timestamp:
2017-09-06T02:03:14+02:00 (7 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
Files:
8 edited

Legend:

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

    r12630 r12749  
    4646        setEnabled(selection != null && !selection.isEmpty());
    4747    }
     48
     49    /**
     50     * Check whether user is about to delete data outside of the download area.
     51     * Request confirmation if he is.
     52     * @param primitives the primitives to operate on
     53     * @param ignore {@code null} or a primitive to be ignored
     54     * @return true, if operating on outlying primitives is OK; false, otherwise
     55     * @since 12749 (moved from DeleteCommand)
     56     */
     57    public static boolean checkAndConfirmOutlyingDelete(Collection<? extends OsmPrimitive> primitives,
     58            Collection<? extends OsmPrimitive> ignore) {
     59        return checkAndConfirmOutlyingOperation("delete",
     60                tr("Delete confirmation"),
     61                tr("You are about to delete nodes outside of the area you have downloaded."
     62                        + "<br>"
     63                        + "This can cause problems because other objects (that you do not see) might use them."
     64                        + "<br>"
     65                        + "Do you really want to delete?"),
     66                tr("You are about to delete incomplete objects."
     67                        + "<br>"
     68                        + "This will cause problems because you don''t see the real object."
     69                        + "<br>" + "Do you really want to delete?"),
     70                primitives, ignore);
     71    }
    4872}
  • trunk/src/org/openstreetmap/josm/actions/JoinAreasAction.java

    r12728 r12749  
    505505
    506506        // TODO: Only display this warning when nodes outside dataSourceArea are deleted
    507         boolean ok = Command.checkAndConfirmOutlyingOperation("joinarea", tr("Join area confirmation"),
     507        boolean ok = checkAndConfirmOutlyingOperation("joinarea", tr("Join area confirmation"),
    508508                trn("The selected way has nodes outside of the downloaded data region.",
    509509                    "The selected ways have nodes outside of the downloaded data region.",
  • trunk/src/org/openstreetmap/josm/actions/JosmAction.java

    r12675 r12749  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import java.awt.GridBagLayout;
    67import java.awt.event.KeyEvent;
    78import java.util.Collection;
     
    1112
    1213import javax.swing.AbstractAction;
     14import javax.swing.JOptionPane;
     15import javax.swing.JPanel;
    1316
    1417import org.openstreetmap.josm.Main;
     18import org.openstreetmap.josm.command.Command;
    1519import org.openstreetmap.josm.data.SelectionChangedListener;
    1620import org.openstreetmap.josm.data.osm.DataSet;
     
    1822import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode;
    1923import org.openstreetmap.josm.data.osm.event.SelectionEventManager;
     24import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil;
    2025import org.openstreetmap.josm.gui.MainApplication;
    2126import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent;
     
    2732import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
    2833import org.openstreetmap.josm.gui.progress.swing.PleaseWaitProgressMonitor;
     34import org.openstreetmap.josm.gui.widgets.JMultilineLabel;
    2935import org.openstreetmap.josm.tools.Destroyable;
    3036import org.openstreetmap.josm.tools.ImageProvider;
     
    394400        }
    395401    }
     402
     403    /**
     404     * Check whether user is about to operate on data outside of the download area.
     405     * Request confirmation if he is.
     406     *
     407     * @param operation the operation name which is used for setting some preferences
     408     * @param dialogTitle the title of the dialog being displayed
     409     * @param outsideDialogMessage the message text to be displayed when data is outside of the download area
     410     * @param incompleteDialogMessage the message text to be displayed when data is incomplete
     411     * @param primitives the primitives to operate on
     412     * @param ignore {@code null} or a primitive to be ignored
     413     * @return true, if operating on outlying primitives is OK; false, otherwise
     414     * @since 12749 (moved from Command)
     415     */
     416    public static boolean checkAndConfirmOutlyingOperation(String operation,
     417            String dialogTitle, String outsideDialogMessage, String incompleteDialogMessage,
     418            Collection<? extends OsmPrimitive> primitives,
     419            Collection<? extends OsmPrimitive> ignore) {
     420        int checkRes = Command.checkOutlyingOrIncompleteOperation(primitives, ignore);
     421        if ((checkRes & Command.IS_OUTSIDE) != 0) {
     422            JPanel msg = new JPanel(new GridBagLayout());
     423            msg.add(new JMultilineLabel("<html>" + outsideDialogMessage + "</html>"));
     424            boolean answer = ConditionalOptionPaneUtil.showConfirmationDialog(
     425                    operation + "_outside_nodes",
     426                    Main.parent,
     427                    msg,
     428                    dialogTitle,
     429                    JOptionPane.YES_NO_OPTION,
     430                    JOptionPane.QUESTION_MESSAGE,
     431                    JOptionPane.YES_OPTION);
     432            if (!answer)
     433                return false;
     434        }
     435        if ((checkRes & Command.IS_INCOMPLETE) != 0) {
     436            JPanel msg = new JPanel(new GridBagLayout());
     437            msg.add(new JMultilineLabel("<html>" + incompleteDialogMessage + "</html>"));
     438            boolean answer = ConditionalOptionPaneUtil.showConfirmationDialog(
     439                    operation + "_incomplete",
     440                    Main.parent,
     441                    msg,
     442                    dialogTitle,
     443                    JOptionPane.YES_NO_OPTION,
     444                    JOptionPane.QUESTION_MESSAGE,
     445                    JOptionPane.YES_OPTION);
     446            if (!answer)
     447                return false;
     448        }
     449        return true;
     450    }
    396451}
  • trunk/src/org/openstreetmap/josm/actions/SimplifyWayAction.java

    r12641 r12749  
    5353
    5454    protected boolean confirmWayWithNodesOutsideBoundingBox(List<? extends OsmPrimitive> primitives) {
    55         return DeleteCommand.checkAndConfirmOutlyingDelete(primitives, null);
     55        return DeleteAction.checkAndConfirmOutlyingDelete(primitives, null);
    5656    }
    5757
  • trunk/src/org/openstreetmap/josm/actions/UnGlueAction.java

    r12726 r12749  
    663663        if (selectedNode != null)
    664664            primitives.add(selectedNode);
    665         final boolean ok = Command.checkAndConfirmOutlyingOperation("unglue",
     665        final boolean ok = checkAndConfirmOutlyingOperation("unglue",
    666666                tr("Unglue confirmation"),
    667667                tr("You are about to unglue nodes outside of the area you have downloaded."
  • 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
  • trunk/src/org/openstreetmap/josm/gui/MainApplication.java

    r12744 r12749  
    5959import org.openstreetmap.gui.jmapviewer.FeatureAdapter;
    6060import org.openstreetmap.josm.Main;
     61import org.openstreetmap.josm.actions.DeleteAction;
    6162import org.openstreetmap.josm.actions.JosmAction;
    6263import org.openstreetmap.josm.actions.OpenFileAction;
     
    7071import org.openstreetmap.josm.actions.mapmode.DrawAction;
    7172import org.openstreetmap.josm.actions.search.SearchAction;
     73import org.openstreetmap.josm.command.DeleteCommand;
    7274import org.openstreetmap.josm.data.Bounds;
    7375import org.openstreetmap.josm.data.UndoRedoHandler;
     
    853855        OAuthAccessTokenHolder.getInstance().init(Main.pref, CredentialsManager.getInstance());
    854856
     857        setupCallbacks();
     858
    855859        final SplashScreen splash = GuiHelper.runInEDTAndWaitAndReturn(SplashScreen::new);
    856860        final SplashScreen.SplashProgressMonitor monitor = splash.getProgressMonitor();
     
    959963            }
    960964        }
     965    }
     966
     967    static void setupCallbacks() {
     968        DeleteCommand.setDeletionCallback(DeleteAction::checkAndConfirmOutlyingDelete);
    961969    }
    962970
Note: See TracChangeset for help on using the changeset viewer.