Ignore:
Timestamp:
15.06.2009 20:22:46 (3 years ago)
Author:
Gubaer
Message:

fixed: bug in OsmApi.getOsmApi()
cleanup: exception handling in interfacing with OSM API
new: new action for updating individual elements with the their current state on the server (including new menu item in the file menu)
new: improved user feedback in case of conflicts
new: handles 410 Gone conflicts when uploading a changeset
new: undoable command for "purging" a primitive from the current dataset (necessary if the primitive is already deleted on the server and the user wants to remove it from its local dataset)
new: undoable command for "undeleting" an already deleted primitive on the server (kind of "cloning")
new: after a full upload, checks whether there are primitives in the local dataset which might be deleted on the server.
new: data structures for history data
new: history download support in io package

File:
1 edited

Legend:

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

    r1465 r1670  
    44import static org.openstreetmap.josm.tools.I18n.tr; 
    55 
     6import java.awt.EventQueue; 
     7import java.awt.event.ActionEvent; 
    68import java.awt.geom.Area; 
    79import java.awt.geom.Rectangle2D; 
     10import java.util.ArrayList; 
    811import java.util.Collection; 
     12import java.util.HashSet; 
    913import java.util.LinkedList; 
    1014import java.util.List; 
     15import java.util.Set; 
    1116 
    1217import javax.swing.JOptionPane; 
    1318 
    1419import org.openstreetmap.josm.Main; 
     20import org.openstreetmap.josm.actions.UpdateSelectionAction; 
    1521import org.openstreetmap.josm.data.osm.DataSet; 
     22import org.openstreetmap.josm.data.osm.OsmPrimitive; 
     23import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 
    1624import org.openstreetmap.josm.gui.download.DownloadDialog.DownloadTask; 
    1725import org.openstreetmap.josm.gui.layer.Layer; 
     
    6270    public void download(boolean newLayer, Collection<Area> areas) { 
    6371        List<Rectangle2D> rects = new LinkedList<Rectangle2D>(); 
    64         for(Area a : areas) 
     72        for(Area a : areas) { 
    6573            rects.add(a.getBounds2D()); 
     74        } 
    6675 
    6776        download(newLayer, rects); 
     
    7685        for(DownloadTask dt : osmTasks) { 
    7786            String err = dt.getErrorMessage(); 
    78             if(err.equals("")) 
     87            if(err.equals("")) { 
    7988                continue; 
     89            } 
    8090            errors += "* " + err + "\r\n"; 
    8191        } 
    8292 
    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); 
    8598            return; 
     99        } 
    86100 
    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; 
    91188    } 
    92189} 
Note: See TracChangeset for help on using the changeset viewer.