コード例 #1
0
 protected void openNewChangeset() {
   // make sure the current changeset is removed from the upload dialog.
   //
   ChangesetCache.getInstance().update(changeset);
   Changeset newChangeSet = new Changeset();
   newChangeSet.setKeys(this.changeset.getKeys());
   this.changeset = newChangeSet;
 }
コード例 #2
0
  /**
   * Builds a download task from for a collection of changesets.
   *
   * <p>Ignores null values and changesets with {@link Changeset#isNew()} == true.
   *
   * @param parent the parent component relative to which the {@link PleaseWaitDialog} is displayed.
   *     Must not be null.
   * @param changesets the collection of changesets. Assumes an empty collection if null.
   * @return the download task
   * @throws IllegalArgumentException thrown if parent is null
   */
  public static ChangesetHeaderDownloadTask buildTaskForChangesets(
      Component parent, Collection<Changeset> changesets) {
    CheckParameterUtil.ensureParameterNotNull(parent, "parent");
    if (changesets == null) {
      changesets = Collections.emptyList();
    }

    HashSet<Integer> ids = new HashSet<Integer>();
    for (Changeset cs : changesets) {
      if (cs == null || cs.isNew()) {
        continue;
      }
      ids.add(cs.getId());
    }
    if (parent == null) return new ChangesetHeaderDownloadTask(ids);
    else return new ChangesetHeaderDownloadTask(parent, ids);
  }
コード例 #3
0
  @Override
  protected void finish() {

    // depending on the success of the upload operation and on the policy for
    // multi changeset uploads this will sent the user back to the appropriate
    // place in JOSM, either
    // - to an error dialog
    // - to the Upload Dialog
    // - to map editing
    GuiHelper.runInEDT(
        () -> {
          // if the changeset is still open after this upload we want it to be selected on the next
          // upload
          ChangesetCache.getInstance().update(changeset);
          if (changeset != null && changeset.isOpen()) {
            UploadDialog.getUploadDialog().setSelectedChangesetForNextUpload(changeset);
          }
          if (uploadCanceled) return;
          if (lastException == null) {
            new Notification("<h3>" + tr("Upload successful!") + "</h3>")
                .setIcon(ImageProvider.get("misc", "check_large"))
                .show();
            return;
          }
          if (lastException instanceof ChangesetClosedException) {
            ChangesetClosedException e = (ChangesetClosedException) lastException;
            if (e.getSource().equals(ChangesetClosedException.Source.UPDATE_CHANGESET)) {
              handleFailedUpload(lastException);
              return;
            }
            if (strategy.getPolicy() == null)
              /* do nothing if unknown policy */
              return;
            if (e.getSource().equals(ChangesetClosedException.Source.UPLOAD_DATA)) {
              switch (strategy.getPolicy()) {
                case ABORT:
                  break; /* do nothing - we return to map editing */
                case AUTOMATICALLY_OPEN_NEW_CHANGESETS:
                  break; /* do nothing - we return to map editing */
                case FILL_ONE_CHANGESET_AND_RETURN_TO_UPLOAD_DIALOG:
                  // return to the upload dialog
                  //
                  toUpload.removeProcessed(processedPrimitives);
                  UploadDialog.getUploadDialog().setUploadedPrimitives(toUpload);
                  UploadDialog.getUploadDialog().setVisible(true);
                  break;
              }
            } else {
              handleFailedUpload(lastException);
            }
          } else {
            handleFailedUpload(lastException);
          }
        });
  }
コード例 #4
0
 protected String buildChangesetSummary() {
   StringBuffer msg = new StringBuffer();
   if (selectedChangeset == null || selectedChangeset.isNew()) {
     msg.append(tr("Objects are uploaded to a <strong>new changeset</strong>."));
   } else {
     String uploadComment =
         selectedChangeset.get("comment") == null ? "" : selectedChangeset.get("comment");
     msg.append(
         tr(
             "Objects are uploaded to the <strong>open changeset</strong> {0} with upload comment ''{1}''.",
             selectedChangeset.getId(), uploadComment));
   }
   msg.append(" ");
   if (closeChangesetAfterNextUpload) {
     msg.append(tr("The changeset is going to be <strong>closed</strong> after this upload"));
   } else {
     msg.append(tr("The changeset is <strong>left open</strong> after this upload"));
   }
   msg.append(" (<a href=\"urn:changeset-configuration\">" + tr("configure changeset") + "</a>)");
   return msg.toString();
 }
コード例 #5
0
  @Override
  protected void realRun() throws SAXException, IOException {
    try {
      uploadloop:
      while (true) {
        try {
          getProgressMonitor()
              .subTask(
                  trn(
                      "Uploading {0} object...",
                      "Uploading {0} objects...", toUpload.getSize(), toUpload.getSize()));
          synchronized (this) {
            writer = new OsmServerWriter();
          }
          writer.uploadOsm(
              strategy,
              toUpload.getPrimitives(),
              changeset,
              getProgressMonitor().createSubTaskMonitor(1, false));

          // if we get here we've successfully uploaded the data. Exit the loop.
          //
          break;
        } catch (OsmTransferCancelledException e) {
          e.printStackTrace();
          uploadCancelled = true;
          break uploadloop;
        } catch (OsmApiPrimitiveGoneException e) {
          // try to recover from  410 Gone
          //
          recoverFromGoneOnServer(e, getProgressMonitor());
        } catch (ChangesetClosedException e) {
          processedPrimitives.addAll(writer.getProcessedPrimitives());
          changeset.setOpen(false);
          switch (e.getSource()) {
            case UNSPECIFIED:
              throw e;
            case UPDATE_CHANGESET:
              // The changeset was closed when we tried to update it. Probably, our
              // local list of open changesets got out of sync with the server state.
              // The user will have to select another open changeset.
              // Rethrow exception - this will be handled later.
              //
              throw e;
            case UPLOAD_DATA:
              // Most likely the changeset is full. Try to recover and continue
              // with a new changeset, but let the user decide first (see
              // recoverFromChangesetFullException)
              //
              if (recoverFromChangesetFullException()) {
                continue;
              }
              lastException = e;
              break uploadloop;
          }
        } finally {
          if (writer != null) {
            processedPrimitives.addAll(writer.getProcessedPrimitives());
          }
          synchronized (this) {
            writer = null;
          }
        }
      }
      // if required close the changeset
      //
      if (strategy.isCloseChangesetAfterUpload()
          && changeset != null
          && !changeset.isNew()
          && changeset.isOpen()) {
        OsmApi.getOsmApi()
            .closeChangeset(changeset, progressMonitor.createSubTaskMonitor(0, false));
      }
    } catch (Exception e) {
      if (uploadCancelled) {
        System.out.println(
            tr(
                "Ignoring caught exception because upload is canceled. Exception is: {0}",
                e.toString()));
      } else {
        lastException = e;
      }
    }
    if (uploadCancelled && processedPrimitives.isEmpty()) return;
    cleanupAfterUpload();
  }
コード例 #6
0
ファイル: DefaultNameFormatter.java プロジェクト: kuny/josm
 /**
  * Formats a name for a changeset
  *
  * @param changeset the changeset
  * @return the name
  */
 @Override
 public String format(Changeset changeset) {
   return tr("Changeset {0}", changeset.getId());
 }