コード例 #1
0
    protected void uploadLayers(List<SaveLayerInfo> toUpload) {
      for (final SaveLayerInfo layerInfo : toUpload) {
        AbstractModifiableLayer layer = layerInfo.getLayer();
        if (canceled) {
          model.setUploadState(layer, UploadOrSaveState.CANCELED);
          continue;
        }
        monitor.subTask(tr("Preparing layer ''{0}'' for upload ...", layerInfo.getName()));

        if (!UploadAction.checkPreUploadConditions(layer)) {
          model.setUploadState(layer, UploadOrSaveState.FAILED);
          continue;
        }

        AbstractUploadDialog dialog = layer.getUploadDialog();
        if (dialog != null) {
          dialog.setVisible(true);
          if (dialog.isCanceled()) {
            model.setUploadState(layer, UploadOrSaveState.CANCELED);
            continue;
          }
          dialog.rememberUserInput();
        }

        currentTask = layer.createUploadTask(monitor);
        if (currentTask == null) {
          model.setUploadState(layer, UploadOrSaveState.FAILED);
          continue;
        }
        currentFuture = worker.submit(currentTask);
        try {
          // wait for the asynchronous task to complete
          //
          currentFuture.get();
        } catch (CancellationException e) {
          Main.trace(e);
          model.setUploadState(layer, UploadOrSaveState.CANCELED);
        } catch (InterruptedException | ExecutionException e) {
          Main.error(e);
          model.setUploadState(layer, UploadOrSaveState.FAILED);
          ExceptionDialogUtil.explainException(e);
        }
        if (currentTask.isCanceled()) {
          model.setUploadState(layer, UploadOrSaveState.CANCELED);
        } else if (currentTask.isFailed()) {
          Main.error(currentTask.getLastException());
          ExceptionDialogUtil.explainException(currentTask.getLastException());
          model.setUploadState(layer, UploadOrSaveState.FAILED);
        } else {
          model.setUploadState(layer, UploadOrSaveState.OK);
        }
        currentTask = null;
        currentFuture = null;
      }
    }
コード例 #2
0
  /**
   * Asks user to perform "save layer" operations (save on disk and/or upload data to server) before
   * data layers deletion.
   *
   * @param selectedLayers The layers to check. Only instances of {@link AbstractModifiableLayer}
   *     are considered.
   * @param reason the cause for requesting an action on unsaved modifications
   * @return {@code true} if there was nothing to save, or if the user wants to proceed to save
   *     operations. {@code false} if the user cancels.
   * @since 11093
   */
  public static boolean saveUnsavedModifications(
      Iterable<? extends Layer> selectedLayers, Reason reason) {
    if (!GraphicsEnvironment.isHeadless()) {
      SaveLayersDialog dialog = new SaveLayersDialog(Main.parent);
      List<AbstractModifiableLayer> layersWithUnmodifiedChanges = new ArrayList<>();
      for (Layer l : selectedLayers) {
        if (!(l instanceof AbstractModifiableLayer)) {
          continue;
        }
        AbstractModifiableLayer odl = (AbstractModifiableLayer) l;
        if (odl.isModified()
            && ((!odl.isSavable() && !odl.isUploadable())
                || odl.requiresSaveToFile()
                || (odl.requiresUploadToServer() && !odl.isUploadDiscouraged()))) {
          layersWithUnmodifiedChanges.add(odl);
        }
      }
      dialog.prepareForSavingAndUpdatingLayers(reason);
      if (!layersWithUnmodifiedChanges.isEmpty()) {
        dialog.getModel().populate(layersWithUnmodifiedChanges);
        dialog.setVisible(true);
        switch (dialog.getUserAction()) {
          case PROCEED:
            return true;
          case CANCEL:
          default:
            return false;
        }
      }
    }

    return true;
  }