Ignore:
Timestamp:
2014-04-12T20:15:09+02:00 (10 years ago)
Author:
bastiK
Message:

applied #9634 - Downloading Referrers Grabs Focus (patch by Balaitous, minor modifications)

File:
1 edited

Legend:

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

    r6448 r6973  
    44import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
    55import static org.openstreetmap.josm.tools.I18n.tr;
    6 import static org.openstreetmap.josm.tools.I18n.trn;
    76
    8 import java.awt.Font;
    9 import java.awt.GridBagLayout;
    107import java.awt.event.ActionEvent;
    118import java.awt.event.KeyEvent;
    12 import java.lang.reflect.InvocationTargetException;
    139import java.util.List;
    14 import java.util.Set;
    15 import java.util.TreeSet;
    16 
    17 import javax.swing.JLabel;
    18 import javax.swing.JOptionPane;
    19 import javax.swing.JPanel;
    20 import javax.swing.JScrollPane;
    21 import javax.swing.SwingUtilities;
    2210
    2311import org.openstreetmap.josm.Main;
    24 import org.openstreetmap.josm.actions.downloadtasks.DownloadReferrersTask;
    25 import org.openstreetmap.josm.data.osm.DataSet;
    26 import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2712import org.openstreetmap.josm.data.osm.PrimitiveId;
    28 import org.openstreetmap.josm.gui.ExtendedDialog;
    2913import org.openstreetmap.josm.gui.download.DownloadObjectDialog;
    30 import org.openstreetmap.josm.gui.io.DownloadPrimitivesTask;
    31 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    32 import org.openstreetmap.josm.gui.widgets.HtmlPanel;
    33 import org.openstreetmap.josm.gui.widgets.JosmTextArea;
    34 import org.openstreetmap.josm.tools.GBC;
     14import org.openstreetmap.josm.gui.io.DownloadPrimitivesWithReferrersTask;
     15import org.openstreetmap.josm.gui.util.GuiHelper;
    3516import org.openstreetmap.josm.tools.Shortcut;
    36 import org.openstreetmap.josm.tools.Utils;
    3717
    3818/**
     
    6343    /**
    6444     * @param newLayer if the data should be downloaded into a new layer
    65      * @param ids
     45     * @param ids List of primitive id to download
    6646     * @param downloadReferrers if the referrers of the object should be downloaded as well, i.e., parent relations, and for nodes, additionally, parent ways
    6747     * @param full if the members of a relation should be downloaded as well
    6848     */
    6949    public static void processItems(boolean newLayer, final List<PrimitiveId> ids, boolean downloadReferrers, boolean full) {
    70         OsmDataLayer layer = getEditLayer();
    71         if ((layer == null) || newLayer) {
    72             layer = new OsmDataLayer(new DataSet(), OsmDataLayer.createNewName(), null);
    73             Main.main.addLayer(layer);
    74         }
    75         final DownloadPrimitivesTask task = new DownloadPrimitivesTask(layer, ids, full);
     50        final DownloadPrimitivesWithReferrersTask task =
     51                new DownloadPrimitivesWithReferrersTask(newLayer, ids, downloadReferrers, full, null);
    7652        Main.worker.submit(task);
    77 
    78         if (downloadReferrers) {
    79             for (PrimitiveId id : ids) {
    80                 Main.worker.submit(new DownloadReferrersTask(layer, id));
    81             }
    82         }
    83 
    84         Runnable showErrorsAndWarnings = new Runnable() {
     53        Main.worker.submit(new Runnable() {
    8554            @Override
    8655            public void run() {
    87                 final Set<PrimitiveId> errs = task.getMissingPrimitives();
    88                 if (errs != null && !errs.isEmpty()) {
    89                     try {
    90                         SwingUtilities.invokeAndWait(new Runnable() {
    91                             @Override
    92                             public void run() {
    93                                 reportProblemDialog(errs,
    94                                         trn("Object could not be downloaded", "Some objects could not be downloaded", errs.size()),
    95                                         trn("One object could not be downloaded.<br>",
    96                                             "{0} objects could not be downloaded.<br>",
    97                                             errs.size(),
    98                                             errs.size())
    99                                         + tr("The server replied with response code 404.<br>"
    100                                             + "This usually means, the server does not know an object with the requested id."),
    101                                         tr("missing objects:"),
    102                                         JOptionPane.ERROR_MESSAGE
    103                                 ).showDialog();
    104                             }
    105                         });
    106                     } catch (InterruptedException ex) {
    107                         Main.warn("InterruptedException while displaying error dialog");
    108                     } catch (InvocationTargetException ex) {
    109                         Main.warn(ex);
    110                     }
    111                 }
    112 
    113                 final Set<PrimitiveId> del = new TreeSet<PrimitiveId>();
    114                 DataSet ds = getCurrentDataSet();
    115                 for (PrimitiveId id : ids) {
    116                     OsmPrimitive osm = ds.getPrimitiveById(id);
    117                     if (osm != null && osm.isDeleted()) {
    118                         del.add(id);
    119                     }
    120                 }
    121                 if (!del.isEmpty()) {
    122                     SwingUtilities.invokeLater(new Runnable() {
     56                final List<PrimitiveId> downloaded = task.getDownloadedId();
     57                if(downloaded != null) {
     58                    GuiHelper.runInEDT(new Runnable() {
    12359                        @Override
    12460                        public void run() {
    125                             reportProblemDialog(del,
    126                                     trn("Object deleted", "Objects deleted", del.size()),
    127                                     trn(
    128                                         "One downloaded object is deleted.",
    129                                         "{0} downloaded objects are deleted.",
    130                                         del.size(),
    131                                         del.size()),
    132                                     null,
    133                                     JOptionPane.WARNING_MESSAGE
    134                             ).showDialog();
     61                            Main.main.getCurrentDataSet().setSelected(downloaded);
    13562                        }
    13663                    });
    13764                }
    13865            }
    139         };
    140         Main.worker.submit(showErrorsAndWarnings);
    141     }
    142 
    143     private static ExtendedDialog reportProblemDialog(Set<PrimitiveId> errs,
    144             String TITLE, String TEXT, String LIST_LABEL, int msgType) {
    145         JPanel p = new JPanel(new GridBagLayout());
    146         p.add(new HtmlPanel(TEXT), GBC.eop());
    147         if (LIST_LABEL != null) {
    148             JLabel missing = new JLabel(LIST_LABEL);
    149             missing.setFont(missing.getFont().deriveFont(Font.PLAIN));
    150             p.add(missing, GBC.eol());
    151         }
    152         JosmTextArea txt = new JosmTextArea();
    153         txt.setFont(new Font("Monospaced", txt.getFont().getStyle(), txt.getFont().getSize()));
    154         txt.setEditable(false);
    155         txt.setBackground(p.getBackground());
    156         txt.setColumns(40);
    157         txt.setRows(1);
    158         txt.setText(Utils.join(", ", errs));
    159         JScrollPane scroll = new JScrollPane(txt);
    160         p.add(scroll, GBC.eop().weight(1.0, 0.0).fill(GBC.HORIZONTAL));
    161 
    162         return new ExtendedDialog(
    163                 Main.parent,
    164                 TITLE,
    165                 new String[] { tr("Ok") })
    166             .setButtonIcons(new String[] { "ok" })
    167             .setIcon(msgType)
    168             .setContent(p, false);
     66        });
    16967    }
    17068}
Note: See TracChangeset for help on using the changeset viewer.