コード例 #1
0
  private void btnEliminar_actionPerformed(ActionEvent e) {

    GeopistaMap selectMap = (GeopistaMap) lstListaMapas.getSelectedValue();

    if (selectMap != null) {

      int deleteMapConfirm =
          JOptionPane.showConfirmDialog(
              aplicacion.getMainFrame(),
              aplicacion.getI18nString("GeopistaListaMapasPanel.ConfimarBorradoMapa")
                  + " "
                  + selectMap.getName()
                  + "?",
              aplicacion.getI18nString("GeopistaListaMapasPanel.BorrarMapa"),
              JOptionPane.YES_NO_OPTION);
      if (deleteMapConfirm != 0) return;

      String mapDeleteSelected = selectMap.getBasePath();

      if (!selectMap.isSystemMap()) {
        File dirBaseMake = new File(mapDeleteSelected);

        File[] deleteFiles = dirBaseMake.listFiles();
        if (deleteFiles != null) {
          for (int n = 0; n < deleteFiles.length; n++) {
            try {
              File actualDeleteFile = deleteFiles[n];
              boolean borrado = actualDeleteFile.delete();
              if (!borrado)
                throw new IOException(
                    aplicacion.getI18nString("GeopistaListaMapasPanel.ElMapaInicioErrorBorrado")
                        + " "
                        + selectMap.getName()
                        + " "
                        + aplicacion.getI18nString("GeopistaListaMapasPanel.NoBorrado"));

              if (dirBaseMake != null) {
                borrado = dirBaseMake.delete();
              }

            } catch (Exception e1) {
              JOptionPane.showMessageDialog(aplicacion.getMainFrame(), e1.getMessage());
            }
          }
        }

      } else {
        if (selectMap.getIdEntidad() == 0) {
          deleteMapConfirm =
              JOptionPane.showConfirmDialog(
                  aplicacion.getMainFrame(),
                  aplicacion.getI18nString("GeopistaListaMapasPanel.ConfimarBorradoMapaEntidad0")
                      + " "
                      + selectMap.getName()
                      + "?",
                  aplicacion.getI18nString("GeopistaListaMapasPanel.BorrarMapa"),
                  JOptionPane.YES_NO_OPTION);
          if (deleteMapConfirm != 0) return;
        }

        String sUrlPrefix;
        // ------NUEVO------>
        if (SSOAuthManager.isSSOActive())
          sUrlPrefix = aplicacion.getString(SSOConstants.SSO_SERVER_URL);
        else sUrlPrefix = aplicacion.getString("geopista.conexion.servidor");
        // ----FIN NUEVO---->
        AdministradorCartografiaClient administradorCartografiaClient =
            new AdministradorCartografiaClient(sUrlPrefix + "/AdministradorCartografiaServlet");
        try {
          if (!aplicacion.isLogged()) {
            aplicacion.setProfile("Geopista");
            aplicacion.login();
          }

          if (aplicacion.isLogged()) {
            administradorCartografiaClient.deleteMap(selectMap, Locale.getDefault().toString());

          } else {
            return;
          }
        } catch (Exception e1) {

          Throwable deleteError = e1.getCause();
          if (deleteError instanceof PermissionException) {
            JOptionPane.showMessageDialog(
                aplicacion.getMainFrame(),
                aplicacion.getI18nString("GeopistaListaMapasPanel.NoPermisosBorrarMapa"));
          }
          if (deleteError instanceof SystemMapException) {
            JOptionPane.showMessageDialog(
                aplicacion.getMainFrame(),
                aplicacion.getI18nString("GeopistaListaMapasPanel.MapaDeSistemaNoBorrar"));
          }
          if (deleteError instanceof SQLException) {
            JOptionPane.showMessageDialog(
                aplicacion.getMainFrame(),
                aplicacion.getI18nString("GeopistaListaMapasPanel.MapaNoSePuedeBorrarPublicado"));
          }
          if (deleteError instanceof PublishedMapException) {
            JOptionPane.showMessageDialog(
                aplicacion.getMainFrame(),
                aplicacion.getI18nString("GeopistaListaMapasPanel.MapaNoSePuedeBorrarPublicado"));
          }
          return;
        }
      }
      listModel.removeElement(selectMap);
    }
  }
コード例 #2
0
  public void getMapFiles(PlugInContext pluginContext, boolean searchlocal, boolean searchremote) {
    final ArrayList localMapIds = new ArrayList();

    if (searchlocal) {
      final String rutaBase =
          aplicacion.getUserPreference(
              AppContext.PREFERENCES_DATA_PATH_KEY, AppContext.DEFAULT_DATA_PATH, true);
      ;

      // Comprobamos si existe la ruta base y en caso de que no exista la
      // creamos
      File rutaBaseFile = new File(rutaBase);
      if (!rutaBaseFile.exists()) {
        rutaBaseFile.mkdirs();
      }

      final TaskMonitorDialog progressDialog =
          new TaskMonitorDialog(aplicacion.getMainFrame(), pluginContext.getErrorHandler());
      progressDialog.allowCancellationRequests();
      progressDialog.setTitle(aplicacion.getI18nString("BuscandoMapas"));
      progressDialog.report(aplicacion.getI18nString("BuscandoMapasLocales"));
      progressDialog.addComponentListener(
          new ComponentAdapter() {
            public void componentShown(ComponentEvent e) {
              // Wait for the dialog to appear before starting the
              // task. Otherwise
              // the task might possibly finish before the dialog
              // appeared and the
              // dialog would never close. [Jon Aquino]
              new Thread(
                      new Runnable() {
                        public void run() {
                          try {

                            ArrayList listaMap =
                                GeopistaFunctionUtils.searchDirectory(rutaBase, progressDialog);

                            Iterator Iter = listaMap.iterator();

                            while (Iter.hasNext()) {
                              GeopistaMap currentMap = (GeopistaMap) Iter.next();

                              if (!(currentMap.isExtracted()
                                  && currentMap.getIdEntidad() != AppContext.getIdEntidad())) {
                                listModel.addElement(currentMap);
                                String systemId = currentMap.getSystemId();
                                if (systemId.startsWith("e")) systemId = systemId.substring(1);
                                localMapIds.add(systemId);
                              }
                            }
                          } catch (Exception e) {

                          } finally {
                            progressDialog.setVisible(false);
                          }
                        }
                      })
                  .start();
            }
          });
      if (aplicacion.getMainFrame() == null) // sin ventana de referencia
      GUIUtil.centreOnScreen(progressDialog);
      else GUIUtil.centreOnWindow(progressDialog);
      progressDialog.setVisible(true);
    }
    if (searchremote) {
      // final String sUrlPrefix = aplicacion.getString("geopista.conexion.servidor");
      final String sUrlPrefix;
      // ------NUEVO------>
      //            if(SSOAuthManager.isSSOActive())
      //            	sUrlPrefix = aplicacion.getString(SSOConstants.SSO_SERVER_URL);
      //            else
      sUrlPrefix = aplicacion.getString("geopista.conexion.servidor");
      // ----FIN NUEVO---->
      if (aplicacion.isOnline()) {
        try {

          if (!aplicacion.isLogged()) {
            aplicacion.setProfile("Geopista");
            aplicacion.login();
          }

          if (aplicacion.isLogged()) {
            final TaskMonitorDialog progressDialog2 =
                new TaskMonitorDialog(aplicacion.getMainFrame(), pluginContext.getErrorHandler());
            progressDialog2.setTitle(aplicacion.getI18nString("BuscandoMapas"));
            progressDialog2.report(aplicacion.getI18nString("BuscandoMapasBaseDatos"));
            progressDialog2.addComponentListener(
                new ComponentAdapter() {
                  public void componentShown(ComponentEvent e) {
                    // Wait for the dialog to appear before
                    // starting the task. Otherwise
                    // the task might possibly finish before the
                    // dialog appeared and the
                    // dialog would never close. [Jon Aquino]
                    new Thread(
                            new Runnable() {
                              public void run() {
                                try {
                                  Object[] mapSystemIds = localMapIds.toArray();
                                  Arrays.sort(mapSystemIds);
                                  AdministradorCartografiaClient administradorCartografiaClient =
                                      new AdministradorCartografiaClient(
                                          sUrlPrefix + "/AdministradorCartografiaServlet");
                                  Collection lMaps =
                                      administradorCartografiaClient.getMaps(
                                          Locale.getDefault().toString());
                                  Iterator lMapsIter = lMaps.iterator();
                                  while (lMapsIter.hasNext()) {
                                    try {

                                      GeopistaMap currentMap = (GeopistaMap) lMapsIter.next();
                                      int codeIndex =
                                          Arrays.binarySearch(
                                              mapSystemIds, currentMap.getSystemId());
                                      if (codeIndex >= 0) continue;
                                      listModel.addElement(currentMap);
                                    } catch (Exception e) {
                                      e.printStackTrace();
                                    }
                                  }
                                } catch (Exception e) {

                                } finally {
                                  progressDialog2.setVisible(false);
                                }
                              }
                            })
                        .start();
                  }
                });
            if (aplicacion.getMainFrame() == null) GUIUtil.centreOnScreen(progressDialog2);
            else GUIUtil.centreOnWindow(progressDialog2);
            progressDialog2.setVisible(true);
          }
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }
  }