Changeset 2923 in josm for trunk/src/org
- Timestamp:
- 2010-02-02T18:30:24+01:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 5 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/DownloadReferrersAction.java
r2842 r2923 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 7 import java.awt.event.ActionEvent; 9 8 import java.awt.event.KeyEvent; 10 import java.io.IOException;11 9 import java.text.MessageFormat; 12 10 import java.util.Collection; 13 import java.util.HashMap;14 11 import java.util.Map; 15 import java.util.Map.Entry;16 17 import javax.swing.JOptionPane;18 import javax.swing.SwingUtilities;19 12 20 13 import org.openstreetmap.josm.Main; 21 import org.openstreetmap.josm.data.osm.DataSet; 22 import org.openstreetmap.josm.data.osm.DataSetMerger; 14 import org.openstreetmap.josm.actions.downloadtasks.DownloadReferrersTask; 23 15 import org.openstreetmap.josm.data.osm.OsmPrimitive; 24 16 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 25 import org.openstreetmap.josm.gui.PleaseWaitRunnable;26 17 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 27 import org.openstreetmap.josm.gui.progress.ProgressMonitor;28 import org.openstreetmap.josm.io.OsmServerBackreferenceReader;29 import org.openstreetmap.josm.io.OsmTransferException;30 18 import org.openstreetmap.josm.tools.CheckParameterUtil; 31 import org.openstreetmap.josm.tools.ExceptionUtil;32 19 import org.openstreetmap.josm.tools.Shortcut; 33 import org.xml.sax.SAXException;34 20 35 21 /** … … 103 89 } 104 90 105 /**106 * The asynchronous task for downloading referring primitives107 *108 */109 public static class DownloadReferrersTask extends PleaseWaitRunnable {110 private boolean cancelled;111 private Exception lastException;112 private OsmServerBackreferenceReader reader;113 /** the target layer */114 private OsmDataLayer targetLayer;115 /** the collection of child primitives */116 private Map<Long, OsmPrimitiveType> children;117 /** the parents */118 private DataSet parents;119 120 /**121 * constructor122 *123 * @param targetLayer the target layer for the downloaded primitives. Must not be null.124 * @param children the collection of child primitives for which parents are to be downloaded125 *126 */127 public DownloadReferrersTask(OsmDataLayer targetLayer, Collection<OsmPrimitive> children) {128 super("Download referrers", false /* don't ignore exception*/);129 CheckParameterUtil.ensureParameterNotNull(targetLayer, "targetLayer");130 cancelled = false;131 this.children = new HashMap<Long, OsmPrimitiveType>();132 if (children != null) {133 for (OsmPrimitive p: children) {134 if (! p.isNew()) {135 this.children.put(p.getId(), OsmPrimitiveType.from(p));136 }137 }138 }139 this.targetLayer = targetLayer;140 parents = new DataSet();141 }142 143 /**144 * constructor145 *146 * @param targetLayer the target layer for the downloaded primitives. Must not be null.147 * @param primitives the collection of children for which parents are to be downloaded. Children148 * are specified by their id and their type.149 *150 */151 public DownloadReferrersTask(OsmDataLayer targetLayer, Map<Long, OsmPrimitiveType> children) {152 super("Download referrers", false /* don't ignore exception*/);153 CheckParameterUtil.ensureParameterNotNull(targetLayer, "targetLayer");154 cancelled = false;155 this.children = new HashMap<Long, OsmPrimitiveType>();156 if (children != null) {157 for (Entry<Long, OsmPrimitiveType> entry : children.entrySet()) {158 if (entry.getKey() > 0 && entry.getValue() != null) {159 children.put(entry.getKey(), entry.getValue());160 }161 }162 }163 this.targetLayer = targetLayer;164 parents = new DataSet();165 }166 167 /**168 * constructor169 *170 * @param targetLayer the target layer. Must not be null.171 * @param id the primitive id. id > 0 required.172 * @param type the primitive type. type != null required173 * @exception IllegalArgumentException thrown if id <= 0174 * @exception IllegalArgumentException thrown if type == null175 * @exception IllegalArgumentException thrown if targetLayer == null176 *177 */178 public DownloadReferrersTask(OsmDataLayer targetLayer, long id, OsmPrimitiveType type) throws IllegalArgumentException {179 super("Download referrers", false /* don't ignore exception*/);180 CheckParameterUtil.ensureParameterNotNull(targetLayer, "targetLayer");181 if (id <= 0)182 throw new IllegalArgumentException(MessageFormat.format("Id > 0 required, got {0}", id));183 CheckParameterUtil.ensureParameterNotNull(type, "type");184 cancelled = false;185 this.children = new HashMap<Long, OsmPrimitiveType>();186 this.children.put(id, type);187 this.targetLayer = targetLayer;188 parents = new DataSet();189 }190 191 @Override192 protected void cancel() {193 cancelled = true;194 synchronized(this) {195 if (reader != null) {196 reader.cancel();197 }198 }199 }200 201 @Override202 protected void finish() {203 if (cancelled)204 return;205 if (lastException != null) {206 ExceptionUtil.explainException(lastException);207 return;208 }209 210 DataSetMerger visitor = new DataSetMerger(targetLayer.data, parents);211 visitor.merge();212 SwingUtilities.invokeLater(213 new Runnable() {214 public void run() {215 targetLayer.fireDataChange();216 targetLayer.onPostDownloadFromServer();217 Main.map.mapView.repaint();218 }219 }220 );221 if (visitor.getConflicts().isEmpty())222 return;223 targetLayer.getConflicts().add(visitor.getConflicts());224 JOptionPane.showMessageDialog(225 Main.parent,226 trn("There was {0} conflict during import.",227 "There were {0} conflicts during import.",228 visitor.getConflicts().size(),229 visitor.getConflicts().size()230 ),231 trn("Conflict during download", "Conflicts during download", visitor.getConflicts().size()),232 JOptionPane.WARNING_MESSAGE233 );234 }235 236 protected void downloadParents(long id, OsmPrimitiveType type, ProgressMonitor progressMonitor) throws OsmTransferException{237 reader = new OsmServerBackreferenceReader(id, type);238 DataSet ds = reader.parseOsm(progressMonitor);239 synchronized(this) { // avoid race condition in cancel()240 reader = null;241 }242 DataSetMerger visitor = new DataSetMerger(parents, ds);243 visitor.merge();244 }245 246 @Override247 protected void realRun() throws SAXException, IOException, OsmTransferException {248 try {249 progressMonitor.setTicksCount(children.size());250 int i=1;251 for (Entry<Long, OsmPrimitiveType> entry: children.entrySet()) {252 if (cancelled)253 return;254 String msg = "";255 switch(entry.getValue()) {256 case NODE: msg = tr("({0}/{1}) Loading parents of node {2}", i+1,children.size(), entry.getKey()); break;257 case WAY: msg = tr("({0}/{1}) Loading parents of way {2}", i+1,children.size(), entry.getKey()); break;258 case RELATION: msg = tr("({0}/{1}) Loading parents of relation {2}", i+1,children.size(), entry.getKey()); break;259 }260 progressMonitor.subTask(msg);261 downloadParents(entry.getKey(), entry.getValue(), progressMonitor.createSubTaskMonitor(1, false));262 i++;263 }264 } catch(Exception e) {265 if (cancelled)266 return;267 lastException = e;268 }269 }270 }271 272 91 @Override 273 92 protected void updateEnabledState() { -
trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitiveType.java
r2845 r2923 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.data.osm; 3 import static org.openstreetmap.josm.tools.I18n.marktr; 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 4 5 … … 7 8 public enum OsmPrimitiveType { 8 9 9 NODE ( "node", Node.class, NodeData.class),10 WAY ( "way", Way.class, WayData.class),11 RELATION ( "relation", Relation.class, RelationData.class);10 NODE (marktr("node"), Node.class, NodeData.class), 11 WAY (marktr("way"), Way.class, WayData.class), 12 RELATION (marktr("relation"), Relation.class, RelationData.class); 12 13 13 14 private final String apiTypeName; … … 71 72 } 72 73 74 @Override 75 public String toString() { 76 return tr(getAPIName()); 77 } 73 78 } -
trunk/src/org/openstreetmap/josm/gui/MainMenu.java
r2902 r2923 29 29 import org.openstreetmap.josm.actions.DistributeAction; 30 30 import org.openstreetmap.josm.actions.DownloadAction; 31 import org.openstreetmap.josm.actions.DownloadPrimitiveAction; 31 32 import org.openstreetmap.josm.actions.DownloadReferrersAction; 32 33 import org.openstreetmap.josm.actions.DuplicateAction; … … 100 101 public final JosmAction gpxExport = new GpxExportAction(); 101 102 public final DownloadAction download = new DownloadAction(); 103 public final DownloadPrimitiveAction downloadPrimitive = new DownloadPrimitiveAction(); 102 104 public final DownloadReferrersAction downloadReferrers = new DownloadReferrersAction(); 103 105 public final CloseChangesetAction closeChangesetAction = new CloseChangesetAction(); … … 210 212 fileMenu.addSeparator(); 211 213 add(fileMenu, download); 214 add(fileMenu, downloadPrimitive); 212 215 add(fileMenu, downloadReferrers); 213 216 add(fileMenu, update);
Note:
See TracChangeset
for help on using the changeset viewer.