Exemplo n.º 1
0
 @Override
 public void tableChanged(TableModelEvent arg0) {
   boolean dis = model.getLayersToSave().isEmpty() && model.getLayersToUpload().isEmpty();
   if (saveAndProceedActionButton != null) {
     saveAndProceedActionButton.setEnabled(!dis);
   }
   saveAndProceedAction.redrawIcon();
 }
Exemplo n.º 2
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;
      }
    }
Exemplo n.º 3
0
 protected void warnBecauseOfUnsavedData() {
   int numProblems = model.getNumCancel() + model.getNumFailed();
   if (numProblems == 0) return;
   Main.warn(numProblems + " problems occured during upload/save");
   String msg =
       trn(
           "<html>An upload and/or save operation of one layer with modifications<br>"
               + "was canceled or has failed.</html>",
           "<html>Upload and/or save operations of {0} layers with modifications<br>"
               + "were canceled or have failed.</html>",
           numProblems,
           numProblems);
   JOptionPane.showMessageDialog(
       Main.parent, msg, tr("Incomplete upload and/or save"), JOptionPane.WARNING_MESSAGE);
 }
Exemplo n.º 4
0
  static boolean confirmSaveLayerInfosOK(SaveLayersModel model) {
    List<SaveLayerInfo> layerInfos = model.getLayersWithConflictsAndUploadRequest();
    if (!layerInfos.isEmpty()) {
      warnLayersWithConflictsAndUploadRequest(layerInfos);
      return false;
    }

    layerInfos = model.getLayersWithoutFilesAndSaveRequest();
    if (!layerInfos.isEmpty()) {
      warnLayersWithoutFilesAndSaveRequest(layerInfos);
      return false;
    }

    layerInfos = model.getLayersWithIllegalFilesAndSaveRequest();
    if (!layerInfos.isEmpty()) {
      warnLayersWithIllegalFilesAndSaveRequest(layerInfos);
      return false;
    }

    return true;
  }
Exemplo n.º 5
0
  /**
   * builds the button row
   *
   * @return the panel with the button row
   */
  protected JPanel buildButtonRow() {
    JPanel pnl = new JPanel(new GridBagLayout());

    model.addPropertyChangeListener(saveAndProceedAction);
    pnl.add(saveAndProceedActionButton, GBC.std(0, 0).insets(5, 5, 0, 0).fill(GBC.HORIZONTAL));

    pnl.add(new JButton(saveSessionAction), GBC.std(1, 0).insets(5, 5, 5, 0).fill(GBC.HORIZONTAL));

    model.addPropertyChangeListener(discardAndProceedAction);
    pnl.add(
        new JButton(discardAndProceedAction),
        GBC.std(0, 1).insets(5, 5, 0, 5).fill(GBC.HORIZONTAL));

    pnl.add(new JButton(cancelAction), GBC.std(1, 1).insets(5, 5, 5, 5).fill(GBC.HORIZONTAL));

    JPanel pnl2 = new JPanel(new BorderLayout());
    pnl2.add(pnlUploadLayers, BorderLayout.CENTER);
    model.addPropertyChangeListener(pnlUploadLayers);
    pnl2.add(pnl, BorderLayout.SOUTH);
    return pnl2;
  }
Exemplo n.º 6
0
 @Override
 public void run() {
   GuiHelper.runInEDTAndWait(
       () -> {
         model.setMode(SaveLayersModel.Mode.UPLOADING_AND_SAVING);
         List<SaveLayerInfo> toUpload = model.getLayersToUpload();
         if (!toUpload.isEmpty()) {
           uploadLayers(toUpload);
         }
         List<SaveLayerInfo> toSave = model.getLayersToSave();
         if (!toSave.isEmpty()) {
           saveLayers(toSave);
         }
         model.setMode(SaveLayersModel.Mode.EDITING_DATA);
         if (model.hasUnsavedData()) {
           warnBecauseOfUnsavedData();
           model.setMode(Mode.EDITING_DATA);
           if (canceled) {
             setUserAction(UserAction.CANCEL);
             closeDialog();
           }
         } else {
           setUserAction(UserAction.PROCEED);
           closeDialog();
         }
       });
   worker.shutdownNow();
 }
Exemplo n.º 7
0
  /** builds the GUI */
  protected void build() {
    WindowGeometry geometry = WindowGeometry.centerOnScreen(new Dimension(650, 300));
    geometry.applySafe(this);
    getContentPane().setLayout(new BorderLayout());

    SaveLayersTable table = new SaveLayersTable(model);
    JScrollPane pane = new JScrollPane(table);
    model.addPropertyChangeListener(table);
    table.getModel().addTableModelListener(this);

    getContentPane().add(pane, BorderLayout.CENTER);
    getContentPane().add(buildButtonRow(), BorderLayout.SOUTH);

    addWindowListener(new WindowClosingAdapter());
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
  }
Exemplo n.º 8
0
    protected void saveLayers(List<SaveLayerInfo> toSave) {
      for (final SaveLayerInfo layerInfo : toSave) {
        if (canceled) {
          model.setSaveState(layerInfo.getLayer(), UploadOrSaveState.CANCELED);
          continue;
        }
        // Check save preconditions earlier to avoid a blocking reentring call to EDT (see #10086)
        if (layerInfo.isDoCheckSaveConditions()) {
          if (!layerInfo.getLayer().checkSaveConditions()) {
            continue;
          }
          layerInfo.setDoCheckSaveConditions(false);
        }
        currentTask = new SaveLayerTask(layerInfo, monitor);
        currentFuture = worker.submit(currentTask);

        try {
          // wait for the asynchronous task to complete
          //
          currentFuture.get();
        } catch (CancellationException e) {
          Main.trace(e);
          model.setSaveState(layerInfo.getLayer(), UploadOrSaveState.CANCELED);
        } catch (InterruptedException | ExecutionException e) {
          Main.error(e);
          model.setSaveState(layerInfo.getLayer(), UploadOrSaveState.FAILED);
          ExceptionDialogUtil.explainException(e);
        }
        if (currentTask.isCanceled()) {
          model.setSaveState(layerInfo.getLayer(), UploadOrSaveState.CANCELED);
        } else if (currentTask.isFailed()) {
          if (currentTask.getLastException() != null) {
            Main.error(currentTask.getLastException());
            ExceptionDialogUtil.explainException(currentTask.getLastException());
          }
          model.setSaveState(layerInfo.getLayer(), UploadOrSaveState.FAILED);
        } else {
          model.setSaveState(layerInfo.getLayer(), UploadOrSaveState.OK);
        }
        this.currentTask = null;
        this.currentFuture = null;
      }
    }
Exemplo n.º 9
0
 protected void cancelSafeAndUploadTask() {
   if (this.saveAndUploadTask != null) {
     this.saveAndUploadTask.cancel();
   }
   model.setMode(Mode.EDITING_DATA);
 }