Ejemplo n.º 1
0
  /**
   * Clean out the data behind the layer. This means clearing the redo/undo lists, really deleting
   * all deleted objects and reset the modified flags. This is done after a successfull upload.
   *
   * @param processed A list of all objects that were actually uploaded. May be <code>null</code>,
   *     which means nothing has been uploaded but saved to disk instead. Note that an empty
   *     collection for "processed" means that an upload has been attempted but failed.
   */
  public void cleanData(final Collection<OsmPrimitive> processed, boolean dataAdded) {

    // return immediately if an upload attempt failed
    if (processed != null && processed.isEmpty() && !dataAdded) return;

    Main.main.undoRedo.clean();

    // if uploaded, clean the modified flags as well
    if (processed != null) {
      final Set<OsmPrimitive> processedSet = new HashSet<OsmPrimitive>(processed);
      for (final Iterator<Node> it = data.nodes.iterator(); it.hasNext(); )
        cleanIterator(it, processedSet);
      for (final Iterator<Way> it = data.ways.iterator(); it.hasNext(); )
        cleanIterator(it, processedSet);
      for (final Iterator<Relation> it = data.relations.iterator(); it.hasNext(); )
        cleanIterator(it, processedSet);
    }

    // update the modified flag
    boolean b = (getAssociatedFile() != null && processed != null);
    if (b && !dataAdded) return; // do nothing when uploading non-harmful changes.

    // modified if server changed the data (esp. the id).
    uploadedModified = b && dataAdded;
    setModified(uploadedModified);
  }