Changeset 1756 in josm for trunk


Ignore:
Timestamp:
2009-07-09T18:54:09+02:00 (15 years ago)
Author:
Gubaer
Message:

fixed #2888: Check for deleted elements should ignore incomplete elements

Location:
trunk/src/org/openstreetmap/josm
Files:
3 edited

Legend:

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

    r1750 r1756  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import java.awt.EventQueue;
    67import java.awt.event.ActionEvent;
    78import java.awt.event.KeyEvent;
     9import java.io.IOException;
    810import java.util.Collection;
    911import java.util.HashSet;
     
    1315
    1416import org.openstreetmap.josm.Main;
    15 import org.openstreetmap.josm.command.PurgePrimitivesCommand;
    1617import org.openstreetmap.josm.data.osm.DataSet;
    1718import org.openstreetmap.josm.data.osm.OsmPrimitive;
     19import org.openstreetmap.josm.gui.PleaseWaitRunnable;
    1820import org.openstreetmap.josm.io.MultiFetchServerObjectReader;
     21import org.openstreetmap.josm.io.OsmApi;
     22import org.openstreetmap.josm.io.OsmTransferException;
    1923import org.openstreetmap.josm.tools.Shortcut;
     24import org.xml.sax.SAXException;
    2025
    2126/**
     
    2530 */
    2631public class UpdateSelectionAction extends JosmAction {
    27 
    28     static public int DEFAULT_MAX_SIZE_UPDATE_SELECTION = 50;
    2932
    3033    /**
     
    4346            return;
    4447        }
    45         Main.main.createOrGetEditLayer().mergeFrom(ds);
     48        Main.map.mapView.getEditLayer().mergeFrom(ds);
    4649    }
    4750
     
    6366
    6467    /**
    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
    6772     */
    6873    protected void handleMissingPrimitive(long id) {
     
    7681
    7782    /**
    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            }
    91162        }
    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     */
    95174    public void updatePrimitive(long id) {
    96         OsmPrimitive primitive = Main.main.createOrGetEditLayer().data.getPrimitiveById(id);
     175        OsmPrimitive primitive = Main.map.mapView.getEditLayer().data.getPrimitiveById(id);
    97176        Set<OsmPrimitive> s = new HashSet<OsmPrimitive>();
    98177        s.add(primitive);
     
    100179    }
    101180
     181    /**
     182     * constructor
     183     */
    102184    public UpdateSelectionAction() {
    103185        super(tr("Update Selection"),
     
    111193    }
    112194
    113 
     195    /**
     196     * action handler
     197     */
    114198    public void actionPerformed(ActionEvent e) {
    115199        Collection<OsmPrimitive> selection = Main.ds.getSelected();
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTaskList.java

    r1750 r1756  
    55
    66import java.awt.EventQueue;
    7 import java.awt.event.ActionEvent;
    87import java.awt.geom.Area;
    98import java.awt.geom.Rectangle2D;
     
    9897        }
    9998
    100         Set<Long> myPrimitiveIds = Main.main.createOrGetEditLayer().data.getPrimitiveIds();
     99        Set<Long> myPrimitiveIds = Main.map.mapView.getEditLayer().data.getCompletePrimitiveIds();
    101100        Set<Long> downloadedIds = getDownloadedIds();
    102101        myPrimitiveIds.removeAll(downloadedIds);
    103         myPrimitiveIds.remove(new Long(0));
     102        myPrimitiveIds.remove(new Long(0)); // ignore new primitives
    104103        if (! myPrimitiveIds.isEmpty()) {
    105104            handlePotentiallyDeletedPrimitives(myPrimitiveIds);
     
    107106    }
    108107
    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>();
    112117        for (Long id : potentiallyDeleted) {
    113118            OsmPrimitive primitive = ds.getPrimitiveById(id);
     
    116121            }
    117122        }
    118         ds.setSelected(toSelect);
    119123        EventQueue.invokeLater(
    120124                new Runnable() {
    121125                    public void run() {
    122                         new UpdateSelectionAction().actionPerformed(new ActionEvent(this, 0, ""));
     126                        new UpdateSelectionAction().updatePrimitives(toSelect);
    123127                    }
    124128                }
     
    126130    }
    127131
     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     */
    128140    protected void handlePotentiallyDeletedPrimitives(Set<Long> potentiallyDeleted) {
    129141        String [] options = {
     
    158170        case JOptionPane.CLOSED_OPTION: return;
    159171        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     */
    164185    protected boolean wasDownloaded(long id, DataSet ds) {
    165186        OsmPrimitive primitive = ds.getPrimitiveById(id);
     
    167188    }
    168189
     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     */
    169199    public boolean wasDownloaded(long id) {
    170200        for (DownloadTask task : osmTasks) {
     
    177207    }
    178208
     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     */
    179214    public Set<Long> getDownloadedIds() {
    180215        HashSet<Long> ret = new HashSet<Long>();
  • trunk/src/org/openstreetmap/josm/data/osm/DataSet.java

    r1690 r1756  
    313313    }
    314314
     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
    315341    protected void deleteWay(Way way) {
    316342        way.nodes.clear();
Note: See TracChangeset for help on using the changeset viewer.