Ejemplo n.º 1
0
  /** Unit test of method {@link ChangesetDataSet#getPrimitivesByModificationType}. */
  @Test
  public void testGetPrimitivesByModificationType() {
    final ChangesetDataSet cds = new ChangesetDataSet();
    // empty object, null parameter => IllegalArgumentException
    try {
      cds.getPrimitivesByModificationType(null);
      Assert.fail("Should have thrown an IllegalArgumentException as we gave a null argument.");
    } catch (IllegalArgumentException e) {
      Main.trace(e);
      // Was expected
    }

    // empty object, a modification type => empty list
    Assert.assertTrue(
        "Empty data set should produce an empty list.",
        cds.getPrimitivesByModificationType(ChangesetModificationType.CREATED).isEmpty());

    // object with various items and modification types, fetch for CREATED
    // => list containing only the CREATED item
    HistoryOsmPrimitive prim1 =
        new HistoryNode(1, 1, true, User.getAnonymous(), 1, new Date(), LatLon.ZERO);
    HistoryOsmPrimitive prim2 =
        new HistoryNode(2, 1, true, User.createLocalUser("test"), 1, new Date(), LatLon.NORTH_POLE);
    HistoryOsmPrimitive prim3 =
        new HistoryNode(3, 1, true, User.getAnonymous(), 1, new Date(), LatLon.SOUTH_POLE);
    cds.put(prim1, ChangesetModificationType.CREATED);
    cds.put(prim2, ChangesetModificationType.DELETED);
    cds.put(prim3, ChangesetModificationType.UPDATED);
    Set<HistoryOsmPrimitive> result =
        cds.getPrimitivesByModificationType(ChangesetModificationType.CREATED);
    Assert.assertEquals("We should have found only one item.", 1, result.size());
    Assert.assertTrue("The item found is prim1.", result.contains(prim1));
  }
 @Override
 public void actionPerformed(ActionEvent e) {
   try {
     memberTableModel.addMembersAtBeginning(
         filterConfirmedPrimitives(selectionTableModel.getSelection()));
   } catch (AddAbortException ex) {
     Main.trace(ex);
   }
 }
Ejemplo n.º 3
0
 @Override
 public void actionPerformed(ActionEvent e) {
   try {
     saveSession();
     setUserAction(UserAction.PROCEED);
     closeDialog();
   } catch (UserCancelException ignore) {
     Main.trace(ignore);
   }
 }
Ejemplo n.º 4
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;
      }
    }
Ejemplo n.º 5
0
  protected void cleanupAfterUpload() {
    // we always clean up the data, even in case of errors. It's possible the data was
    // partially uploaded. Better run on EDT.
    Runnable r =
        () -> {
          layer.cleanupAfterUpload(processedPrimitives);
          layer.onPostUploadToServer();
          ChangesetCache.getInstance().update(changeset);
        };

    try {
      SwingUtilities.invokeAndWait(r);
    } catch (InterruptedException e) {
      Main.trace(e);
      lastException = e;
    } catch (InvocationTargetException e) {
      Main.trace(e);
      lastException = new OsmTransferException(e.getCause());
    }
  }
Ejemplo n.º 6
0
 private static Class<?> loadRendererClass(String className) {
   for (ClassLoader cl : PluginHandler.getResourceClassLoaders()) {
     try {
       return Class.forName(className, true, cl);
     } catch (final NoClassDefFoundError | ClassNotFoundException e) {
       Main.trace(e.getMessage());
     }
   }
   Main.error(
       tr("Failed to load map renderer class ''{0}''. The class wasn''t found.", className));
   return null;
 }
Ejemplo n.º 7
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;
      }
    }
Ejemplo n.º 8
0
  public void cancel() {
    cancel = true;
    synchronized (this) {
      if (activeConnection != null) {
        activeConnection.setConnectTimeout(100);
        activeConnection.setReadTimeout(100);
      }
    }
    try {
      Thread.sleep(100);
    } catch (InterruptedException ex) {
      Main.trace(ex);
    }

    synchronized (this) {
      if (activeConnection != null) {
        activeConnection.disconnect();
      }
    }
  }
Ejemplo n.º 9
0
 private static boolean confirmEulaAcceptance(PreferenceTabbedPane gui, String eulaUrl) {
   URL url = null;
   try {
     url = new URL(eulaUrl.replaceAll("\\{lang\\}", LanguageInfo.getWikiLanguagePrefix()));
     JosmEditorPane htmlPane = null;
     try {
       htmlPane = new JosmEditorPane(url);
     } catch (IOException e1) {
       Main.trace(e1);
       // give a second chance with a default Locale 'en'
       try {
         url = new URL(eulaUrl.replaceAll("\\{lang\\}", ""));
         htmlPane = new JosmEditorPane(url);
       } catch (IOException e2) {
         Main.debug(e2);
         JOptionPane.showMessageDialog(gui, tr("EULA license URL not available: {0}", eulaUrl));
         return false;
       }
     }
     Box box = Box.createVerticalBox();
     htmlPane.setEditable(false);
     JScrollPane scrollPane = new JScrollPane(htmlPane);
     scrollPane.setPreferredSize(new Dimension(400, 400));
     box.add(scrollPane);
     int option =
         JOptionPane.showConfirmDialog(
             Main.parent,
             box,
             tr("Please abort if you are not sure"),
             JOptionPane.YES_NO_OPTION,
             JOptionPane.WARNING_MESSAGE);
     if (option == JOptionPane.YES_OPTION) return true;
   } catch (MalformedURLException e2) {
     JOptionPane.showMessageDialog(gui, tr("Malformed URL for the EULA licence: {0}", eulaUrl));
   }
   return false;
 }