Changeset 1756 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2009-07-09T18:54:09+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/UpdateSelectionAction.java
r1750 r1756 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.EventQueue; 6 7 import java.awt.event.ActionEvent; 7 8 import java.awt.event.KeyEvent; 9 import java.io.IOException; 8 10 import java.util.Collection; 9 11 import java.util.HashSet; … … 13 15 14 16 import org.openstreetmap.josm.Main; 15 import org.openstreetmap.josm.command.PurgePrimitivesCommand;16 17 import org.openstreetmap.josm.data.osm.DataSet; 17 18 import org.openstreetmap.josm.data.osm.OsmPrimitive; 19 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 18 20 import org.openstreetmap.josm.io.MultiFetchServerObjectReader; 21 import org.openstreetmap.josm.io.OsmApi; 22 import org.openstreetmap.josm.io.OsmTransferException; 19 23 import org.openstreetmap.josm.tools.Shortcut; 24 import org.xml.sax.SAXException; 20 25 21 26 /** … … 25 30 */ 26 31 public class UpdateSelectionAction extends JosmAction { 27 28 static public int DEFAULT_MAX_SIZE_UPDATE_SELECTION = 50;29 32 30 33 /** … … 43 46 return; 44 47 } 45 Main.ma in.createOrGetEditLayer().mergeFrom(ds);48 Main.map.mapView.getEditLayer().mergeFrom(ds); 46 49 } 47 50 … … 63 66 64 67 /** 65 * 66 * @param id 68 * handles an exception case: primitive with id <code>id</code> is not in the current 69 * data set 70 * 71 * @param id the primitive id 67 72 */ 68 73 protected void handleMissingPrimitive(long id) { … … 76 81 77 82 /** 78 * 79 * 80 * 81 */ 82 public void updatePrimitives(Collection<OsmPrimitive> selection) { 83 MultiFetchServerObjectReader reader = new MultiFetchServerObjectReader(); 84 reader.append(selection); 85 DataSet ds = null; 86 try { 87 ds = reader.parseOsm(); 88 } catch(Exception e) { 89 handleUpdateException(e); 90 return; 83 * Updates the data for for the {@see OsmPrimitive}s in <code>selection</code> 84 * with the data currently kept on the server. 85 * 86 * @param selection a collection of {@see OsmPrimitive}s to update 87 * 88 */ 89 public void updatePrimitives(final Collection<OsmPrimitive> selection) { 90 91 /** 92 * The asynchronous task for updating the data using multi fetch. 93 * 94 */ 95 class UpdatePrimitiveTask extends PleaseWaitRunnable { 96 private DataSet ds; 97 private boolean cancelled; 98 Exception lastException; 99 100 protected void setIndeterminateEnabled(final boolean enabled) { 101 EventQueue.invokeLater( 102 new Runnable() { 103 public void run() { 104 Main.pleaseWaitDlg.setIndeterminate(enabled); 105 } 106 } 107 ); 108 } 109 110 public UpdatePrimitiveTask() { 111 super("Update primitives", false /* don't ignore exception*/); 112 cancelled = false; 113 } 114 115 protected void showLastException() { 116 String msg = lastException.getMessage(); 117 if (msg == null) { 118 msg = lastException.toString(); 119 } 120 JOptionPane.showMessageDialog( 121 Main.map, 122 msg, 123 tr("Error"), 124 JOptionPane.ERROR_MESSAGE 125 ); 126 } 127 128 @Override 129 protected void cancel() { 130 cancelled = true; 131 OsmApi.getOsmApi().cancel(); 132 } 133 134 @Override 135 protected void finish() { 136 if (cancelled) 137 return; 138 if (lastException != null) { 139 showLastException(); 140 return; 141 } 142 if (ds != null) { 143 Main.map.mapView.getEditLayer().mergeFrom(ds); 144 } 145 } 146 147 @Override 148 protected void realRun() throws SAXException, IOException, OsmTransferException { 149 setIndeterminateEnabled(true); 150 try { 151 MultiFetchServerObjectReader reader = new MultiFetchServerObjectReader(); 152 reader.append(selection); 153 ds = reader.parseOsm(); 154 } catch(Exception e) { 155 if (cancelled) 156 return; 157 lastException = e; 158 } finally { 159 setIndeterminateEnabled(false); 160 } 161 } 91 162 } 92 Main.main.createOrGetEditLayer().mergeFrom(ds); 93 } 94 163 164 Main.worker.submit(new UpdatePrimitiveTask()); 165 } 166 167 /** 168 * Updates the data for for the {@see OsmPrimitive}s with id <code>id</code> 169 * with the data currently kept on the server. 170 * 171 * @param id the id of a primitive in the {@see DataSet} of the current edit layser 172 * 173 */ 95 174 public void updatePrimitive(long id) { 96 OsmPrimitive primitive = Main.ma in.createOrGetEditLayer().data.getPrimitiveById(id);175 OsmPrimitive primitive = Main.map.mapView.getEditLayer().data.getPrimitiveById(id); 97 176 Set<OsmPrimitive> s = new HashSet<OsmPrimitive>(); 98 177 s.add(primitive); … … 100 179 } 101 180 181 /** 182 * constructor 183 */ 102 184 public UpdateSelectionAction() { 103 185 super(tr("Update Selection"), … … 111 193 } 112 194 113 195 /** 196 * action handler 197 */ 114 198 public void actionPerformed(ActionEvent e) { 115 199 Collection<OsmPrimitive> selection = Main.ds.getSelected(); -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTaskList.java
r1750 r1756 5 5 6 6 import java.awt.EventQueue; 7 import java.awt.event.ActionEvent;8 7 import java.awt.geom.Area; 9 8 import java.awt.geom.Rectangle2D; … … 98 97 } 99 98 100 Set<Long> myPrimitiveIds = Main.ma in.createOrGetEditLayer().data.getPrimitiveIds();99 Set<Long> myPrimitiveIds = Main.map.mapView.getEditLayer().data.getCompletePrimitiveIds(); 101 100 Set<Long> downloadedIds = getDownloadedIds(); 102 101 myPrimitiveIds.removeAll(downloadedIds); 103 myPrimitiveIds.remove(new Long(0)); 102 myPrimitiveIds.remove(new Long(0)); // ignore new primitives 104 103 if (! myPrimitiveIds.isEmpty()) { 105 104 handlePotentiallyDeletedPrimitives(myPrimitiveIds); … … 107 106 } 108 107 109 protected void checkPotentiallyDeletedPrimitives(Set<Long> potentiallyDeleted) { 110 DataSet ds = Main.main.createOrGetEditLayer().data; 111 ArrayList<OsmPrimitive> toSelect = new ArrayList<OsmPrimitive>(); 108 /** 109 * Updates the local state of a set of primitives (given by a set of primitive 110 * ids) with the state currently held on the server. 111 * 112 * @param potentiallyDeleted a set of ids to check update from the server 113 */ 114 protected void updatePotentiallyDeletedPrimitives(Set<Long> potentiallyDeleted) { 115 DataSet ds = Main.map.mapView.getEditLayer().data; 116 final ArrayList<OsmPrimitive> toSelect = new ArrayList<OsmPrimitive>(); 112 117 for (Long id : potentiallyDeleted) { 113 118 OsmPrimitive primitive = ds.getPrimitiveById(id); … … 116 121 } 117 122 } 118 ds.setSelected(toSelect);119 123 EventQueue.invokeLater( 120 124 new Runnable() { 121 125 public void run() { 122 new UpdateSelectionAction(). actionPerformed(new ActionEvent(this, 0, ""));126 new UpdateSelectionAction().updatePrimitives(toSelect); 123 127 } 124 128 } … … 126 130 } 127 131 132 /** 133 * Processes a set of primitives (given by a set of their ids) which might be 134 * deleted on the server. First prompts the user whether he wants to check 135 * the current state on the server. If yes, retrieves the current state on the server 136 * and checks whether the primitives are indeed deleted on the server. 137 * 138 * @param potentiallyDeleted a set of primitives (given by their ids) 139 */ 128 140 protected void handlePotentiallyDeletedPrimitives(Set<Long> potentiallyDeleted) { 129 141 String [] options = { … … 158 170 case JOptionPane.CLOSED_OPTION: return; 159 171 case JOptionPane.NO_OPTION: return; 160 case JOptionPane.YES_OPTION: checkPotentiallyDeletedPrimitives(potentiallyDeleted); break; 161 } 162 } 163 172 case JOptionPane.YES_OPTION: updatePotentiallyDeletedPrimitives(potentiallyDeleted); break; 173 } 174 } 175 176 /** 177 * replies true, if the primitive with id <code>id</code> was downloaded into the 178 * dataset <code>ds</code> 179 * 180 * @param id the id 181 * @param ds the dataset 182 * @return true, if the primitive with id <code>id</code> was downloaded into the 183 * dataset <code>ds</code>; false otherwise 184 */ 164 185 protected boolean wasDownloaded(long id, DataSet ds) { 165 186 OsmPrimitive primitive = ds.getPrimitiveById(id); … … 167 188 } 168 189 190 /** 191 * replies true, if the primitive with id <code>id</code> was downloaded into the 192 * dataset of one of the download tasks 193 * 194 * @param id the id 195 * @return true, if the primitive with id <code>id</code> was downloaded into the 196 * dataset of one of the download tasks 197 * 198 */ 169 199 public boolean wasDownloaded(long id) { 170 200 for (DownloadTask task : osmTasks) { … … 177 207 } 178 208 209 /** 210 * Replies the set of primitive ids which have been downloaded by this task list 211 * 212 * @return the set of primitive ids which have been downloaded by this task list 213 */ 179 214 public Set<Long> getDownloadedIds() { 180 215 HashSet<Long> ret = new HashSet<Long>(); -
trunk/src/org/openstreetmap/josm/data/osm/DataSet.java
r1690 r1756 313 313 } 314 314 315 /** 316 * Replies the set of ids of all complete primitivies (i.e. those with 317 * ! primitive.incomplete) 318 * 319 * @return the set of ids of all complete primitivies 320 */ 321 public Set<Long> getCompletePrimitiveIds() { 322 HashSet<Long> ret = new HashSet<Long>(); 323 for (OsmPrimitive primitive : nodes) { 324 if (!primitive.incomplete) { 325 ret.add(primitive.id); 326 } 327 } 328 for (OsmPrimitive primitive : ways) { 329 if (! primitive.incomplete) { 330 ret.add(primitive.id); 331 } 332 } 333 for (OsmPrimitive primitive : relations) { 334 if (! primitive.incomplete) { 335 ret.add(primitive.id); 336 } 337 } 338 return ret; 339 } 340 315 341 protected void deleteWay(Way way) { 316 342 way.nodes.clear();
Note:
See TracChangeset
for help on using the changeset viewer.