Changeset 19196 in josm
- Timestamp:
- 2024-08-16T14:19:50+02:00 (3 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/RequestHandler.java
r18801 r19196 14 14 import java.util.Map; 15 15 import java.util.Set; 16 import java.util.concurrent.locks.ReentrantLock; 16 17 import java.util.function.Function; 17 18 import java.util.function.Supplier; … … 27 28 import org.openstreetmap.josm.data.preferences.IntegerProperty; 28 29 import org.openstreetmap.josm.gui.MainApplication; 30 import org.openstreetmap.josm.gui.util.GuiHelper; 29 31 import org.openstreetmap.josm.io.OsmApiException; 30 32 import org.openstreetmap.josm.io.remotecontrol.PermissionPrefWithDefault; … … 47 49 /** preference to define OSM download timeout in seconds */ 48 50 public static final IntegerProperty OSM_DOWNLOAD_TIMEOUT = new IntegerProperty("remotecontrol.osm.download.timeout", 5*60); 51 /** A lock to ensure that messages are shown in the order the commands were sent from the server (see #23821) */ 52 private static final ReentrantLock MESSAGE_LOCK = new ReentrantLock(true); 49 53 50 54 protected static final Pattern SPLITTER_COMMA = Pattern.compile(",\\s*"); … … 98 102 * Handle a specific command sent as remote control. 99 103 * Any time-consuming operation must be performed asynchronously to avoid delaying the HTTP response. 100 * 104 * <p> 101 105 * This method of the subclass will do the real work. 102 106 * … … 109 113 * Get a specific message to ask the user for permission for the operation 110 114 * requested via remote control. 111 * 115 * <p> 112 116 * This message will be displayed to the user if the preference 113 117 * remotecontrol.always-confirm is true. … … 121 125 * preference to individually allow the requested operation and an error 122 126 * message to be displayed when a disabled operation is requested. 123 * 127 * <p> 124 128 * Default is not to check any special preference. Override this in a 125 129 * subclass to define permission preference and error message. … … 201 205 * If yes, display specific confirmation message. 202 206 */ 203 if ( GLOBAL_CONFIRMATION.get()) {207 if (Boolean.TRUE.equals(GLOBAL_CONFIRMATION.get())) { 204 208 // Ensure dialog box does not exceed main window size 205 int maxWidth = (int) Math.max(200, MainApplication.getMainFrame().getWidth() * 0.6);206 String message = "<html><div>" + getPermissionMessage() +209 final int maxWidth = (int) Math.max(200, MainApplication.getMainFrame().getWidth() * 0.6); 210 final String message = "<html><div>" + getPermissionMessage() + 207 211 "<br/>" + tr("Do you want to allow this?") + "</div></html>"; 208 JLabel label = new JLabel(message); 209 if (label.getPreferredSize().width > maxWidth) { 210 label.setText(message.replaceFirst("<div>", "<div style=\"width:" + maxWidth + "px;\">")); 212 final Object[] choices = {tr("Yes, always"), tr("Yes, once"), tr("No")}; 213 final int choice; 214 // The ordering of the requests can be important, so we use a fair lock to ensure ordering 215 // Note that the EDT will be more than happy to show multiple dialogs without blocking. 216 try { 217 MESSAGE_LOCK.lock(); 218 final Integer tChoice = GuiHelper.runInEDTAndWaitAndReturn(() -> { 219 final JLabel label = new JLabel(message); 220 if (label.getPreferredSize().width > maxWidth) { 221 label.setText(message.replaceFirst("<div>", "<div style=\"width:" + maxWidth + "px;\">")); 222 } 223 return JOptionPane.showOptionDialog(MainApplication.getMainFrame(), label, tr("Confirm Remote Control action"), 224 JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, choices, choices[1]); 225 }); 226 if (tChoice == null) { 227 // I have no clue how this would ever happen, but just in case. 228 throw new RequestHandlerForbiddenException(MessageFormat.format("RemoteControl: ''{0}'' forbidden due to NPE", myCommand)); 229 } 230 choice = tChoice; 231 } finally { 232 MESSAGE_LOCK.unlock(); 211 233 } 212 Object[] choices = {tr("Yes, always"), tr("Yes, once"), tr("No")};213 int choice = JOptionPane.showOptionDialog(MainApplication.getMainFrame(), label, tr("Confirm Remote Control action"),214 JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, choices, choices[1]);215 234 if (choice != JOptionPane.YES_OPTION && choice != JOptionPane.NO_OPTION) { // Yes/no refer to always/once 216 235 String err = MessageFormat.format("RemoteControl: ''{0}'' forbidden by user''s choice", myCommand); … … 240 259 * Parse the request parameters as key=value pairs. 241 260 * The result will be stored in {@code this.args}. 242 * 261 * <p> 243 262 * Can be overridden by subclass. 244 263 * @throws URISyntaxException if request URL is invalid
Note:
See TracChangeset
for help on using the changeset viewer.