Changeset 1670 in josm for trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTaskList.java
- Timestamp:
- 15.06.2009 20:22:46 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTaskList.java
r1465 r1670 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.EventQueue; 7 import java.awt.event.ActionEvent; 6 8 import java.awt.geom.Area; 7 9 import java.awt.geom.Rectangle2D; 10 import java.util.ArrayList; 8 11 import java.util.Collection; 12 import java.util.HashSet; 9 13 import java.util.LinkedList; 10 14 import java.util.List; 15 import java.util.Set; 11 16 12 17 import javax.swing.JOptionPane; 13 18 14 19 import org.openstreetmap.josm.Main; 20 import org.openstreetmap.josm.actions.UpdateSelectionAction; 15 21 import org.openstreetmap.josm.data.osm.DataSet; 22 import org.openstreetmap.josm.data.osm.OsmPrimitive; 23 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 16 24 import org.openstreetmap.josm.gui.download.DownloadDialog.DownloadTask; 17 25 import org.openstreetmap.josm.gui.layer.Layer; … … 62 70 public void download(boolean newLayer, Collection<Area> areas) { 63 71 List<Rectangle2D> rects = new LinkedList<Rectangle2D>(); 64 for(Area a : areas) 72 for(Area a : areas) { 65 73 rects.add(a.getBounds2D()); 74 } 66 75 67 76 download(newLayer, rects); … … 76 85 for(DownloadTask dt : osmTasks) { 77 86 String err = dt.getErrorMessage(); 78 if(err.equals("")) 87 if(err.equals("")) { 79 88 continue; 89 } 80 90 errors += "* " + err + "\r\n"; 81 91 } 82 92 83 osmTasks.clear(); 84 if(errors.equals("")) 93 if(! errors.equals("")) { 94 JOptionPane.showMessageDialog(Main.parent, 95 tr("The following errors occured during mass download:") + "\r\n" + errors, 96 tr("Errors during Download"), 97 JOptionPane.ERROR_MESSAGE); 85 98 return; 99 } 86 100 87 JOptionPane.showMessageDialog(Main.parent, 88 tr("The following errors occured during mass download:") + "\r\n" + errors, 89 tr("Errors during Download"), 90 JOptionPane.ERROR_MESSAGE); 101 Set<Long> myPrimitiveIds = Main.main.editLayer().data.getPrimitiveIds(); 102 Set<Long> downloadedIds = getDownloadedIds(); 103 myPrimitiveIds.removeAll(downloadedIds); 104 if (! myPrimitiveIds.isEmpty()) { 105 handlePotentiallyDeletedPrimitives(myPrimitiveIds); 106 } 107 } 108 109 protected void checkPotentiallyDeletedPrimitives(Set<Long> potentiallyDeleted) { 110 DataSet ds = Main.main.editLayer().data; 111 ArrayList<OsmPrimitive> toSelect = new ArrayList<OsmPrimitive>(); 112 for (Long id : potentiallyDeleted) { 113 OsmPrimitive primitive = ds.getPrimitiveById(id); 114 if (primitive != null) { 115 toSelect.add(primitive); 116 } 117 } 118 ds.setSelected(toSelect); 119 EventQueue.invokeLater( 120 new Runnable() { 121 public void run() { 122 new UpdateSelectionAction().actionPerformed(new ActionEvent(this, 0, "")); 123 } 124 } 125 ); 126 } 127 128 protected void handlePotentiallyDeletedPrimitives(Set<Long> potentiallyDeleted) { 129 String [] options = { 130 "Check individually", 131 "Ignore" 132 }; 133 134 String message = tr("<html>" 135 + "There are {0} primitives in your local dataset which<br>" 136 + "might be deleted on the server. If you later try to delete or<br>" 137 + "update them on the server the server is likely to report a<br>" 138 + "conflict.<br>" 139 + "<br>" 140 + "Click <strong>{1}</strong> to check these primitives individually.<br>" 141 + "Click <strong>{2}</strong> to ignore.<br>" 142 + "</html>", 143 potentiallyDeleted.size(), options[0], options[1] 144 ); 145 146 int ret = JOptionPane.showOptionDialog( 147 Main.parent, 148 message, 149 tr("Deleted or moved primitives"), 150 JOptionPane.YES_NO_OPTION, 151 JOptionPane.WARNING_MESSAGE, 152 null, 153 options, 154 options[0] 155 ); 156 switch(ret) { 157 case JOptionPane.CLOSED_OPTION: return; 158 case JOptionPane.NO_OPTION: return; 159 case JOptionPane.YES_OPTION: checkPotentiallyDeletedPrimitives(potentiallyDeleted); break; 160 } 161 } 162 163 protected boolean wasDownloaded(long id, DataSet ds) { 164 OsmPrimitive primitive = ds.getPrimitiveById(id); 165 return primitive != null; 166 } 167 168 public boolean wasDownloaded(long id) { 169 for (DownloadTask task : osmTasks) { 170 if(task instanceof DownloadOsmTask) { 171 DataSet ds = ((DownloadOsmTask)task).getDownloadedData(); 172 if(wasDownloaded(id,ds)) return true; 173 } 174 } 175 return false; 176 } 177 178 179 public Set<Long> getDownloadedIds() { 180 HashSet<Long> ret = new HashSet<Long>(); 181 for (DownloadTask task : osmTasks) { 182 if(task instanceof DownloadOsmTask) { 183 DataSet ds = ((DownloadOsmTask)task).getDownloadedData(); 184 ret.addAll(ds.getPrimitiveIds()); 185 } 186 } 187 return ret; 91 188 } 92 189 }
Note: See TracChangeset
for help on using the changeset viewer.
