Changeset 12749 in josm
- Timestamp:
- 2017-09-06T02:03:14+02:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/DeleteAction.java
r12630 r12749 46 46 setEnabled(selection != null && !selection.isEmpty()); 47 47 } 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 } 48 72 } -
trunk/src/org/openstreetmap/josm/actions/JoinAreasAction.java
r12728 r12749 505 505 506 506 // 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"), 508 508 trn("The selected way has nodes outside of the downloaded data region.", 509 509 "The selected ways have nodes outside of the downloaded data region.", -
trunk/src/org/openstreetmap/josm/actions/JosmAction.java
r12675 r12749 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.GridBagLayout; 6 7 import java.awt.event.KeyEvent; 7 8 import java.util.Collection; … … 11 12 12 13 import javax.swing.AbstractAction; 14 import javax.swing.JOptionPane; 15 import javax.swing.JPanel; 13 16 14 17 import org.openstreetmap.josm.Main; 18 import org.openstreetmap.josm.command.Command; 15 19 import org.openstreetmap.josm.data.SelectionChangedListener; 16 20 import org.openstreetmap.josm.data.osm.DataSet; … … 18 22 import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode; 19 23 import org.openstreetmap.josm.data.osm.event.SelectionEventManager; 24 import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil; 20 25 import org.openstreetmap.josm.gui.MainApplication; 21 26 import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent; … … 27 32 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener; 28 33 import org.openstreetmap.josm.gui.progress.swing.PleaseWaitProgressMonitor; 34 import org.openstreetmap.josm.gui.widgets.JMultilineLabel; 29 35 import org.openstreetmap.josm.tools.Destroyable; 30 36 import org.openstreetmap.josm.tools.ImageProvider; … … 394 400 } 395 401 } 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 } 396 451 } -
trunk/src/org/openstreetmap/josm/actions/SimplifyWayAction.java
r12641 r12749 53 53 54 54 protected boolean confirmWayWithNodesOutsideBoundingBox(List<? extends OsmPrimitive> primitives) { 55 return Delete Command.checkAndConfirmOutlyingDelete(primitives, null);55 return DeleteAction.checkAndConfirmOutlyingDelete(primitives, null); 56 56 } 57 57 -
trunk/src/org/openstreetmap/josm/actions/UnGlueAction.java
r12726 r12749 663 663 if (selectedNode != null) 664 664 primitives.add(selectedNode); 665 final boolean ok = Command.checkAndConfirmOutlyingOperation("unglue",665 final boolean ok = checkAndConfirmOutlyingOperation("unglue", 666 666 tr("Unglue confirmation"), 667 667 tr("You are about to unglue nodes outside of the area you have downloaded." -
trunk/src/org/openstreetmap/josm/command/Command.java
r12726 r12749 2 2 package org.openstreetmap.josm.command; 3 3 4 import java.awt.GridBagLayout;5 4 import java.util.ArrayList; 6 5 import java.util.Collection; … … 10 9 import java.util.Map.Entry; 11 10 import java.util.Objects; 12 13 import javax.swing.JOptionPane;14 import javax.swing.JPanel;15 11 16 12 import org.openstreetmap.josm.Main; … … 24 20 import org.openstreetmap.josm.data.osm.Way; 25 21 import org.openstreetmap.josm.data.osm.visitor.AbstractVisitor; 26 import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil;27 22 import org.openstreetmap.josm.gui.MainApplication; 28 23 import org.openstreetmap.josm.gui.layer.Layer; 29 24 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 30 import org.openstreetmap.josm.gui.widgets.JMultilineLabel;31 25 import org.openstreetmap.josm.tools.CheckParameterUtil; 32 26 … … 304 298 305 299 /** 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 preferences310 * @param dialogTitle the title of the dialog being displayed311 * @param outsideDialogMessage the message text to be displayed when data is outside of the download area312 * @param incompleteDialogMessage the message text to be displayed when data is incomplete313 * @param primitives the primitives to operate on314 * @param ignore {@code null} or a primitive to be ignored315 * @return true, if operating on outlying primitives is OK; false, otherwise316 */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 /**354 300 * Ensures that all primitives that are participating in this command belong to the affected data set. 355 301 * -
trunk/src/org/openstreetmap/josm/command/DeleteCommand.java
r12726 r12749 80 80 81 81 /** 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 /** 82 110 * The primitives that get deleted. 83 111 */ … … 325 353 if (parents.isEmpty()) 326 354 return null; 327 if (!silent && !checkAndConfirmOutlyingDelete(parents, null)) 355 if (!silent && !callback.checkAndConfirmOutlyingDelete(parents, null)) 328 356 return null; 329 357 return new DeleteCommand(parents.iterator().next().getDataSet(), parents); … … 526 554 } 527 555 528 if (!silent && !checkAndConfirmOutlyingDelete( 556 if (!silent && !callback.checkAndConfirmOutlyingDelete( 529 557 primitivesToDelete, Utils.filteredCollection(primitivesToDelete, Way.class))) 530 558 return null; … … 628 656 return split != null ? split.getCommand() : null; 629 657 } 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);646 658 } 647 659 -
trunk/src/org/openstreetmap/josm/gui/MainApplication.java
r12744 r12749 59 59 import org.openstreetmap.gui.jmapviewer.FeatureAdapter; 60 60 import org.openstreetmap.josm.Main; 61 import org.openstreetmap.josm.actions.DeleteAction; 61 62 import org.openstreetmap.josm.actions.JosmAction; 62 63 import org.openstreetmap.josm.actions.OpenFileAction; … … 70 71 import org.openstreetmap.josm.actions.mapmode.DrawAction; 71 72 import org.openstreetmap.josm.actions.search.SearchAction; 73 import org.openstreetmap.josm.command.DeleteCommand; 72 74 import org.openstreetmap.josm.data.Bounds; 73 75 import org.openstreetmap.josm.data.UndoRedoHandler; … … 853 855 OAuthAccessTokenHolder.getInstance().init(Main.pref, CredentialsManager.getInstance()); 854 856 857 setupCallbacks(); 858 855 859 final SplashScreen splash = GuiHelper.runInEDTAndWaitAndReturn(SplashScreen::new); 856 860 final SplashScreen.SplashProgressMonitor monitor = splash.getProgressMonitor(); … … 959 963 } 960 964 } 965 } 966 967 static void setupCallbacks() { 968 DeleteCommand.setDeletionCallback(DeleteAction::checkAndConfirmOutlyingDelete); 961 969 } 962 970
Note:
See TracChangeset
for help on using the changeset viewer.