Changeset 2319 in josm for trunk


Ignore:
Timestamp:
2009-10-25T18:22:28+01:00 (15 years ago)
Author:
Gubaer
Message:

fixed #3725: JOSM doesn't provide indication during upload that the server is sending 410 Gone errors
Progress dialog now includes a small log window for use cases like this. Use appendLogMessage() on the progress monitor.

Location:
trunk/src/org/openstreetmap/josm
Files:
8 edited

Legend:

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

    r2317 r2319  
    633633                // we tried to delete an already deleted primitive.
    634634                //
    635                 System.out.println(tr("Warning: primitive ''{0}'' is already deleted on the server. Skipping this primitive and retrying to upload.", p.getDisplayName(DefaultNameFormatter.getInstance())));
     635                System.out.println(tr("Warning: object ''{0}'' is already deleted on the server. Skipping this object and retrying to upload.", p.getDisplayName(DefaultNameFormatter.getInstance())));
     636                monitor.appendLogMessage(tr("Object ''{0}'' is already deleted. Skipping object in upload.",p.getDisplayName(DefaultNameFormatter.getInstance())));
    636637                processedPrimitives.addAll(writer.getProcessedPrimitives());
    637638                processedPrimitives.add(p);
     
    648649            writer = new OsmServerWriter();
    649650            try {
    650                 //
    651651                while(true) {
    652652                    try {
    653                         ProgressMonitor monitor = progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false);
    654                         writer.uploadOsm(layer.data.version, toUpload, changeset, monitor);
     653                        getProgressMonitor().subTask(tr("Uploading {0} objects ...", toUpload.size()));
     654                        writer.uploadOsm(layer.data.version, toUpload, changeset, getProgressMonitor().createSubTaskMonitor(1, false));
    655655                        processedPrimitives.addAll(writer.getProcessedPrimitives());
    656                         // if we get here we've successfully uploaded the data. We
    657                         // can exit the loop.
     656                        // if we get here we've successfully uploaded the data. Exit the loop.
    658657                        //
    659658                        break;
     
    672671            } catch (Exception e) {
    673672                if (uploadCancelled) {
    674                     System.out.println("Ignoring exception caught because upload is cancelled. Exception is: " + e.toString());
     673                    System.out.println(tr("Ignoring caught exception because upload is canceled. Exception is: {0}", e.toString()));
    675674                    return;
    676675                }
  • trunk/src/org/openstreetmap/josm/gui/PleaseWaitDialog.java

    r2050 r2319  
    22package org.openstreetmap.josm.gui;
    33
    4 import java.awt.Dialog;
    5 import java.awt.Frame;
     4import static org.openstreetmap.josm.tools.I18n.tr;
     5
     6import java.awt.Component;
     7import java.awt.GridBagConstraints;
    68import java.awt.GridBagLayout;
     9import java.awt.event.ActionListener;
    710import java.awt.event.ComponentEvent;
    811import java.awt.event.ComponentListener;
     
    1316import javax.swing.JDialog;
    1417import javax.swing.JLabel;
     18import javax.swing.JOptionPane;
    1519import javax.swing.JPanel;
    1620import javax.swing.JProgressBar;
     21import javax.swing.JScrollPane;
     22import javax.swing.JTextArea;
    1723import javax.swing.UIManager;
    1824
    1925import org.openstreetmap.josm.Main;
    2026import org.openstreetmap.josm.tools.GBC;
    21 import org.openstreetmap.josm.tools.I18n;
     27import org.openstreetmap.josm.tools.ImageProvider;
    2228
    2329public class PleaseWaitDialog extends JDialog {
     
    2834    private final JLabel customText = new JLabel("");
    2935    public final BoundedRangeModel progress = progressBar.getModel();
    30     public final JButton cancel = new JButton(I18n.tr("Cancel"));
     36    private  JButton btnCancel;
     37    /** the text area and the scroll pane for the log */
     38    private JTextArea taLog = new JTextArea(5,50);
     39    private  JScrollPane spLog;
    3140
    3241    private void initDialog() {
     
    3746        pane.add(customText, GBC.eol().fill(GBC.HORIZONTAL));
    3847        pane.add(progressBar, GBC.eop().fill(GBC.HORIZONTAL));
    39         pane.add(cancel, GBC.eol().anchor(GBC.CENTER));
     48        btnCancel = new JButton(tr("Cancel"));
     49        btnCancel.setIcon(ImageProvider.get("cancel"));
     50        btnCancel.setToolTipText(tr("Click to cancel the current operation"));
     51        pane.add(btnCancel, GBC.eol().anchor(GBC.CENTER));
     52        GridBagConstraints gc = GBC.eol().fill(GBC.BOTH);
     53        gc.weighty = 1.0;
     54        gc.weightx = 1.0;
     55        pane.add(spLog = new JScrollPane(taLog), gc);
     56        spLog.setVisible(false);
    4057        setContentPane(pane);
    4158        //setSize(Main.pref.getInteger("progressdialog.size",600),100);
    4259        setCustomText("");
    43         setLocationRelativeTo(Main.parent);
     60        setLocationRelativeTo(getParent());
    4461        addComponentListener(new ComponentListener() {
    4562            public void componentHidden(ComponentEvent e) {}
     
    5572    }
    5673
    57     public PleaseWaitDialog(Frame parent) {
    58         super(parent, true);
    59         initDialog();
    60     }
    61 
    62     public PleaseWaitDialog(Dialog parent) {
    63         super(parent, true);
     74    public PleaseWaitDialog(Component parent) {
     75        super(JOptionPane.getFrameForComponent(parent), true);
    6476        initDialog();
    6577    }
     
    7082    }
    7183
     84    protected void adjustLayout() {
     85        invalidate();
     86        pack();
     87        setSize(Main.pref.getInteger("progressdialog.size", 600), getSize().height);
     88    }
     89
    7290    /**
    7391     * Sets a custom text line below currentAction. Can be used to display additional information
     
    7593     */
    7694    public void setCustomText(String text) {
    77         if(text.length() == 0) {
     95        if(text == null || text.trim().length() == 0) {
    7896            customText.setVisible(false);
    79             setSize(Main.pref.getInteger("progressdialog.size", 600), 100);
     97            adjustLayout();
    8098            return;
    8199        }
     100        if (!customText.isVisible()) {
     101            customText.setVisible(true);
     102            adjustLayout();
     103        }
     104        customText.setText(text);
     105    }
    82106
    83         customText.setVisible(true);
    84         customText.setText(text);
    85         setSize(Main.pref.getInteger("progressdialog.size", 600), 120);
     107    /**
     108     * Appends a log message to the progress dialog. If the log area isn't visible yet
     109     * it becomes visible. The height of the progress dialog is slightly increased too.
     110     *
     111     * @param message the message to append to the log. Ignore if null or white space only.
     112     */
     113    public void appendLogMessage(String message) {
     114        if (message == null || message.trim().length() ==0 )
     115            return;
     116        if (!spLog.isVisible()) {
     117            spLog.setVisible(true);
     118            taLog.setVisible(true);
     119            adjustLayout();
     120        }
     121        taLog.append(message);
     122        taLog.append("\n");
     123        spLog.getVerticalScrollBar().setValue(spLog.getVerticalScrollBar().getMaximum());
     124    }
     125
     126    /**
     127     * Sets whether the cancel button is enabled or not
     128     *
     129     * @param enabled true, if the cancel button is enabled; false otherwise
     130     */
     131    public void setCancelEnabled(boolean enabled) {
     132        btnCancel.setEnabled(enabled);
     133    }
     134
     135    /**
     136     * Installs a callback for the cancel button. If callback is null, all action listeners
     137     * are removed from the cancel button.
     138     *
     139     * @param callback the cancel callback
     140     */
     141    public void setCancelCallback(ActionListener callback) {
     142        if (callback == null) {
     143            ActionListener[] listeners = btnCancel.getActionListeners();
     144            for (ActionListener l: listeners) {
     145                btnCancel.removeActionListener(l);
     146            }
     147        } else {
     148            btnCancel.addActionListener(callback);
     149        }
    86150    }
    87151}
  • trunk/src/org/openstreetmap/josm/gui/PleaseWaitRunnable.java

    r2025 r2319  
    3939    /**
    4040     * Create the runnable object with a given message for the user.
    41      * @param title Message for user
    42      * @param ignoreException If true, exception will be propaged to calling code. If false then
     41     *
     42     * @param title message for the user
     43     * @param ignoreException If true, exception will be propagated to calling code. If false then
    4344     * exception will be thrown directly in EDT. When this runnable is executed using executor framework
    4445     * then use false unless you read result of task (because exception will get lost if you don't)
     
    5253        this.progressMonitor = progressMonitor == null?new PleaseWaitProgressMonitor(title):progressMonitor;
    5354        this.ignoreException = ignoreException;
    54         this.progressMonitor.addCancelListener(this);
    5555    }
    5656
     
    5858        try {
    5959            try {
     60                progressMonitor.addCancelListener(this);
    6061                progressMonitor.beginTask(title);
    6162                try {
     
    9091            } finally {
    9192                progressMonitor.finishTask();
     93                progressMonitor.removeCancelListener(this);
     94                if (progressMonitor instanceof PleaseWaitProgressMonitor) {
     95                    ((PleaseWaitProgressMonitor)progressMonitor).close();
     96                }
    9297            }
    9398        } catch (final Throwable e) {
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java

    r2301 r2319  
    359359                }
    360360            });
    361             addMouseListener(
    362                     new MouseAdapter() {
    363                         @Override
    364                         public void mouseEntered(MouseEvent e) {
    365                             super.mouseEntered(e);
    366                             System.out.println("requesting focus ...");
    367                             requestFocusInWindow();
    368                         }
    369                     }
    370             );
    371361
    372362            String bounds = Main.pref.get(preferencePrefix+".bounds",null);
  • trunk/src/org/openstreetmap/josm/gui/progress/AbstractProgressMonitor.java

    r1875 r2319  
    6060    protected void checkState(State... expectedStates) {
    6161        for (State s:expectedStates) {
    62             if (s == state) {
     62            if (s == state)
    6363                return;
    64             }
    6564        }
    6665        throw new ProgressException("Expected states are %s but current state is %s", Arrays.asList(expectedStates).toString(), state);
     
    154153            resetState();
    155154        }
     155    }
     156
     157    /**
     158     * Default implementation is empty. Override in subclasses to display the log messages.
     159     */
     160    public void appendLogMessage(String message) {
     161        // do nothing
    156162    }
    157163
     
    327333    private Request getRequest(AbstractProgressMonitor child) {
    328334        for (Request request:requests) {
    329             if (request.originator == child) {
     335            if (request.originator == child)
    330336                return request;
    331             }
    332337        }
    333338        throw new ProgressException("Subtask %s not found", child);
  • trunk/src/org/openstreetmap/josm/gui/progress/NullProgressMonitor.java

    r1812 r2319  
    6060    }
    6161
     62    public void appendLogMessage(String message) {
     63    }
     64
    6265    public void setSilent(boolean value) {
    6366    }
  • trunk/src/org/openstreetmap/josm/gui/progress/PleaseWaitProgressMonitor.java

    r2057 r2319  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.gui.progress;
    3 
    4 import static org.openstreetmap.josm.tools.I18n.tr;
    53
    64import java.awt.Dialog;
     
    1311import java.awt.event.WindowEvent;
    1412import java.awt.event.WindowListener;
    15 import java.lang.reflect.InvocationTargetException;
    1613
    1714import javax.swing.JOptionPane;
     
    3532
    3633    public PleaseWaitProgressMonitor(String windowTitle) {
    37         this(JOptionPane.getFrameForComponent(Main.map));
     34        this(JOptionPane.getFrameForComponent(Main.parent));
    3835        this.windowTitle = windowTitle;
    3936    }
     
    5350        @Override public void windowClosing(WindowEvent e) {
    5451            cancel();
    55             closeDialog();
    5652        }
    5753    };
    58 
    59     private void closeDialog() {
    60         try {
    61             Runnable runnable = new Runnable(){
    62                 public void run() {
    63                 }
    64             };
    65 
    66             // make sure, this is called in the dispatcher thread ASAP
    67             if (EventQueue.isDispatchThread()) {
    68                 runnable.run();
    69             } else {
    70                 EventQueue.invokeAndWait(runnable);
    71             }
    72 
    73         } catch (InterruptedException e) {
    74         } catch (InvocationTargetException e) {
    75             throw new RuntimeException(e);
    76         }
    77     }
    7854
    7955    private void doInEDT(Runnable runnable) {
     
    8561        doInEDT(new Runnable() {
    8662            public void run() {
    87                 if (dialogParent instanceof Frame) {
    88                     dialog = new PleaseWaitDialog((Frame)dialogParent);
    89                 } else if (dialogParent instanceof Dialog) {
    90                     dialog = new PleaseWaitDialog((Dialog)dialogParent);
     63                if (dialogParent instanceof Frame && dialog == null) {
     64                    dialog = new PleaseWaitDialog(dialogParent);
     65                } else if (dialogParent instanceof Dialog && dialog == null) {
     66                    dialog = new PleaseWaitDialog(dialogParent);
    9167                } else
    9268                    throw new ProgressException("PleaseWaitDialog parent must be either Frame or Dialog");
     
    9571                    dialog.setTitle(windowTitle);
    9672                }
    97                 dialog.cancel.setEnabled(true);
     73                dialog.setCancelEnabled(true);
     74                dialog.setCancelCallback(cancelListener);
    9875                dialog.setCustomText("");
    99                 dialog.cancel.addActionListener(cancelListener);
    10076                dialog.addWindowListener(windowListener);
    10177                dialog.progress.setMaximum(PROGRESS_BAR_MAX);
     
    10783    @Override
    10884    public void doFinishTask() {
    109         doInEDT(new Runnable() {
    110             public void run() {
    111                 if (dialog != null) {
    112                     dialog.setVisible(false);
    113                     dialog.dispose();
    114                     dialog.removeWindowListener(windowListener);
    115                     dialog.cancel.removeActionListener(cancelListener);
    116                     if (getErrorMessage() != null) {
    117                         JOptionPane.showMessageDialog(
    118                                 Main.parent, getErrorMessage(),
    119                                 tr("Error"),
    120                                 JOptionPane.ERROR_MESSAGE);
    121                     }
    122                     dialog = null;
    123                 }
    124             }
    125         });
     85        // do nothing
    12686    }
    12787
     
    164124            public void run() {
    165125                if (value && dialog.progress.getValue() == 0) {
    166                     // Enable only if progress is at the begging. Doing intermediate progress in the middle
     126                    // Enable only if progress is at the beginning. Doing intermediate progress in the middle
    167127                    // will hide already reached progress
    168128                    dialog.setIndeterminate(true);
     
    179139    }
    180140
     141    @Override
     142    public void appendLogMessage(final String message) {
     143        doInEDT(new Runnable() {
     144            public void run() {
     145                dialog.appendLogMessage(message);
     146            }
     147        });
     148    }
     149
     150    public void close() {
     151        dialog.setVisible(false);
     152        dialog.setCancelCallback(null);
     153        dialog.removeWindowListener(windowListener);
     154        dialog.dispose();
     155        dialog = null;
     156    }
    181157}
  • trunk/src/org/openstreetmap/josm/gui/progress/ProgressMonitor.java

    r1875 r2319  
    123123    void setErrorMessage(String message);
    124124    String getErrorMessage();
     125
     126    /**
     127     * Appends a message to the log managed by the progress monitor.
     128     *
     129     * @param message the log message. Ignored if null or white space only.
     130     */
     131    void appendLogMessage(String message);
    125132}
Note: See TracChangeset for help on using the changeset viewer.