- Timestamp:
- 2014-04-12T20:15:09+02:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/DownloadPrimitiveAction.java
r6448 r6973 4 4 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 5 5 import static org.openstreetmap.josm.tools.I18n.tr; 6 import static org.openstreetmap.josm.tools.I18n.trn;7 6 8 import java.awt.Font;9 import java.awt.GridBagLayout;10 7 import java.awt.event.ActionEvent; 11 8 import java.awt.event.KeyEvent; 12 import java.lang.reflect.InvocationTargetException;13 9 import 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;22 10 23 11 import 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;27 12 import org.openstreetmap.josm.data.osm.PrimitiveId; 28 import org.openstreetmap.josm.gui.ExtendedDialog;29 13 import 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; 14 import org.openstreetmap.josm.gui.io.DownloadPrimitivesWithReferrersTask; 15 import org.openstreetmap.josm.gui.util.GuiHelper; 35 16 import org.openstreetmap.josm.tools.Shortcut; 36 import org.openstreetmap.josm.tools.Utils;37 17 38 18 /** … … 63 43 /** 64 44 * @param newLayer if the data should be downloaded into a new layer 65 * @param ids 45 * @param ids List of primitive id to download 66 46 * @param downloadReferrers if the referrers of the object should be downloaded as well, i.e., parent relations, and for nodes, additionally, parent ways 67 47 * @param full if the members of a relation should be downloaded as well 68 48 */ 69 49 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); 76 52 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() { 85 54 @Override 86 55 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() { 123 59 @Override 124 60 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); 135 62 } 136 63 }); 137 64 } 138 65 } 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 }); 169 67 } 170 68 } -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadReferrersTask.java
r6830 r6973 131 131 */ 132 132 public DownloadReferrersTask(OsmDataLayer targetLayer, PrimitiveId primitiveId) throws IllegalArgumentException { 133 super("Download referrers", false /* don't ignore exception*/); 133 this(targetLayer, primitiveId, null); 134 } 135 136 /** 137 * constructor 138 * 139 * @param targetLayer the target layer. Must not be null. 140 * @param primitiveId a PrimitiveId object. 141 * @param progressMonitor ProgressMonitor to use or null to create a new one. 142 * @exception IllegalArgumentException thrown if id <= 0 143 * @exception IllegalArgumentException thrown if targetLayer == null 144 * 145 */ 146 public DownloadReferrersTask(OsmDataLayer targetLayer, PrimitiveId primitiveId, 147 ProgressMonitor progressMonitor) throws IllegalArgumentException { 148 super("Download referrers", progressMonitor, false /* don't ignore exception*/); 134 149 CheckParameterUtil.ensureParameterNotNull(targetLayer, "targetLayer"); 135 150 if (primitiveId.isNew()) … … 168 183 public void run() { 169 184 targetLayer.onPostDownloadFromServer(); 170 Main.map.mapView.repaint(); 185 if(Main.map != null) 186 Main.map.mapView.repaint(); 171 187 } 172 188 } -
trunk/src/org/openstreetmap/josm/gui/io/DownloadPrimitivesTask.java
r6084 r6973 9 9 import java.util.Set; 10 10 11 import org.openstreetmap.josm.Main; 11 12 import org.openstreetmap.josm.actions.AutoScaleAction; 12 13 import org.openstreetmap.josm.data.osm.DataSet; … … 52 53 */ 53 54 public DownloadPrimitivesTask(OsmDataLayer layer, List<PrimitiveId> ids, boolean fullRelation) throws IllegalArgumentException { 54 super(tr("Download objects"), false /* don't ignore exception */); 55 this(layer, ids, fullRelation, null); 56 } 57 58 /** 59 * Creates the task 60 * 61 * @param layer the layer in which primitives are updated. Must not be null. 62 * @param ids a collection of primitives to update from the server. Set to 63 * the empty collection if null. 64 * @param fullRelation true if a full download is required, i.e., 65 * a download including the immediate children of a relation. 66 * @param progressMonitor ProgressMonitor to use or null to create a new one. 67 * @throws IllegalArgumentException thrown if layer is null. 68 */ 69 public DownloadPrimitivesTask(OsmDataLayer layer, List<PrimitiveId> ids, boolean fullRelation, 70 ProgressMonitor progessMonitor) throws IllegalArgumentException { 71 super(tr("Download objects"), progessMonitor, false /* don't ignore exception */); 55 72 ensureParameterNotNull(layer, "layer"); 56 73 this.ids = ids; … … 84 101 public void run() { 85 102 layer.mergeFrom(ds); 86 AutoScaleAction.zoomTo(ds.allPrimitives()); 103 if(Main.map != null) 104 AutoScaleAction.zoomTo(ds.allPrimitives()); 87 105 layer.onPostDownloadFromServer(); 88 106 } -
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/LoadObjectHandler.java
r6782 r6973 8 8 9 9 import org.openstreetmap.josm.Main; 10 import org.openstreetmap.josm.actions.DownloadPrimitiveAction;11 10 import org.openstreetmap.josm.data.osm.PrimitiveId; 12 11 import org.openstreetmap.josm.data.osm.SimplePrimitiveId; 12 import org.openstreetmap.josm.gui.io.DownloadPrimitivesWithReferrersTask; 13 13 import org.openstreetmap.josm.gui.util.GuiHelper; 14 14 import org.openstreetmap.josm.io.remotecontrol.AddTagsDialog; … … 33 33 return new String[]{"objects"}; 34 34 } 35 35 36 36 @Override 37 37 public String[] getOptionalParams() { … … 61 61 final boolean relationMembers = Boolean.parseBoolean(args.get("relation_members")); 62 62 final boolean referrers = args.containsKey("referrers") ? Boolean.parseBoolean(args.get("referrers")) : true; 63 GuiHelper.runInEDTAndWait(new Runnable() { 64 @Override public void run() { 65 DownloadPrimitiveAction.processItems(newLayer, ps, referrers, relationMembers); 66 } 67 }); 68 GuiHelper.executeByMainWorkerInEDT(new Runnable() { 63 final DownloadPrimitivesWithReferrersTask task = new DownloadPrimitivesWithReferrersTask( 64 newLayer, ps, referrers, relationMembers, null); 65 Main.worker.submit(task); 66 Main.worker.submit(new Runnable() { 69 67 @Override 70 68 public void run() { 71 Main.main.getCurrentDataSet().setSelected(ps); 69 final List<PrimitiveId> downloaded = task.getDownloadedId(); 70 if(downloaded != null) { 71 GuiHelper.runInEDT(new Runnable() { 72 @Override 73 public void run() { 74 Main.main.getCurrentDataSet().setSelected(downloaded); 75 } 76 }); 77 } 72 78 AddTagsDialog.addTags(args, sender); 73 79 ps.clear();
Note:
See TracChangeset
for help on using the changeset viewer.