Example #1
0
  private boolean bajarInformeFiles(String name) {
    String path = "";
    String url = "";
    String pathDestino = "";
    String plantillasURL = getUrlServer();

    try {

      String localPath =
          aplicacion.getUserPreference(
              AppContext.PREFERENCES_DATA_PATH_KEY, AppContext.DEFAULT_DATA_PATH, true);

      path = "plantillas" + File.separator + "routes" + File.separator;
      pathDestino = localPath + aplicacion.REPORT_DIR_NAME + File.separator + path;
      plantillasURL += "/plantillas/routes/";

      // Comprobamos que el path de las plantillas exista
      if (!new File(pathDestino).exists()) {
        new File(pathDestino).mkdirs();
      }

      // bajamos la plantilla
      url = plantillasURL + name;
      pathDestino = pathDestino + name;
      reportFile = pathDestino;
      // Devolvemos verdadero si todo ha sido correcto:
      return CUtilidadesComponentes.GetURLFile(url, pathDestino, "", 0);
    } catch (Exception ex) {
      StringWriter sw = new StringWriter();
      PrintWriter pw = new PrintWriter(sw);
      ex.printStackTrace(pw);
      logger.error("Exception: " + sw.toString());
      return false;
    }
  }
  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();
        }
      }
    }
  }
  /** InicializaciĆ³n de los componentes */
  private void initComponents() {

    this.setBounds(new Rectangle(10, 10, 1000, 830));
    this.setBorder(BorderFactory.createLineBorder(Color.black, 1));
    this.setLayout(null);

    // Operaciones para aƱadir el panel de dominios
    try {

      // aplicacion.login();
      com.geopista.app.administrador.init.Constantes.url =
          aplicacion.getString("geopista.conexion.servidorurl")
              + WebAppConstants.ADMINISTRACION_WEBAPP_NAME;
      //
      // com.geopista.app.administrador.init.Constantes.idMunicipio=Integer.parseInt(AppContext.getApplicationContext().getString("geopista.DefaultCityId"));
      com.geopista.app.administrador.init.Constantes.idEntidad = aplicacion.getIdEntidad();
      // com.geopista.security.SecurityManager.setHeartBeatTime(100000);
      com.geopista.security.SecurityManager.setHeartBeatTime(10000);
      com.geopista.security.SecurityManager.setsUrl(
          com.geopista.app.administrador.init.Constantes.url);
      com.geopista.app.administrador.init.Constantes.Locale =
          aplicacion.getUserPreference(
              AppContext.GEOPISTA_LOCALE_KEY, GestorCapas.DEFAULT_LOCALE, false);

      /*Municipio municipio =
          (new OperacionesAdministrador(com.geopista.app.administrador.init.Constantes.url))
          .getMunicipio(new Integer(com.geopista.app.administrador.init.Constantes.idMunicipio).toString());
      if (municipio!=null)
      {
          com.geopista.app.administrador.init.Constantes.Municipio = municipio.getNombre();
          com.geopista.app.administrador.init.Constantes.Provincia= municipio.getProvincia();
      }*/
      Entidad entidad =
          (new OperacionesAdministrador(com.geopista.app.administrador.init.Constantes.url))
              .getEntidad(
                  new Integer(com.geopista.app.administrador.init.Constantes.idEntidad).toString());
      if (entidad != null) {
        com.geopista.app.administrador.init.Constantes.Entidad = entidad.getNombre();
        // com.geopista.app.administrador.init.Constantes.Provincia= municipio.getProvincia();
      }

      try {
        messages =
            ResourceBundle.getBundle(
                "config.administrador",
                new Locale(
                    aplicacion.getUserPreference(
                        AppContext.GEOPISTA_LOCALE_KEY, GestorCapas.DEFAULT_LOCALE, false)));
      } catch (Exception e) {
        messages =
            ResourceBundle.getBundle(
                "config.administrador", new Locale(GestorCapas.DEFAULT_LOCALE));
      }

      jPanelDominios = new JPanelDominios(messages, aplicacion.getMainFrame());
      jPanelDominios.hideLeyenda();

    } catch (Exception e) {

      e.printStackTrace();
    }

    templateJScrollPane = new JScrollPane();
    templateJPanel = new JPanel();
    templateJPanel.setLayout(new BorderLayout());

    // jButtonSalir.setBounds(new Rectangle(350, 555, 100, 25));
    jButtonSalir.setBounds(new Rectangle(875, 555, 100, 25));

    jButtonSalir.setMaximumSize(new java.awt.Dimension(100, 25));
    jButtonSalir.setPreferredSize(new java.awt.Dimension(75, 25));
    jButtonSalir.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButtonSalirActionPerformed();
          }
        });

    // aplicacion.loadI18NResource("GestorCapasi18n");
    jButtonSalir.setText(I18N.get("GestorCapas", "general.boton.salir"));

    templateJScrollPane.setViewportView(templateJPanel);

    jPanelDominios.setBounds(new Rectangle(260, 5, 740, 550));

    jPanelLevel.setBounds(new java.awt.Rectangle(15, 490, 200, 25));
    lblLevel.setText(I18N.get("GestorCapas", "tablas.level.dominio"));
    txtLevel.setText("0 ");
    txtLevel.setBounds(new Rectangle(50, 5, 40, 15));
    txtLevel.setEnabled(false);
    lblLevel.setBackground(Color.GRAY);
    jPanelLevel.add(lblLevel, null);
    jPanelLevel.add(txtLevel, null);

    jButtonAsociar.setBounds(new java.awt.Rectangle(35, 525, 180, 25));
    jButtonAsociar.setEnabled(false);
    jButtonAsociar.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButtonAsociarActionPerformed();
          }
        });
    jButtonAsociar.setText(I18N.get("GestorCapas", "tablas.boton.asociar"));

    jButtonDesasociar.setBounds(new java.awt.Rectangle(35, 555, 180, 25));
    jButtonDesasociar.setEnabled(false);
    jButtonDesasociar.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButtonDesasociarActionPerformed();
          }
        });
    jButtonDesasociar.setText(I18N.get("GestorCapas", "tablas.boton.desasociar"));

    jPanelTablas = new JPanelTables(TreeSelectionModel.SINGLE_TREE_SELECTION);
    jPanelTablas.setBorder(
        BorderFactory.createTitledBorder(I18N.get("GestorCapas", "tablas.arbol.titulo")));
    jPanelTablas.setBounds(new java.awt.Rectangle(5, 5, 250, 481));

    jPanelDominios.changeScreenLang(messages);

    treeDominios = jPanelDominios.getJTreeArbol();
    treeDominios.addTreeSelectionListener(this);

    treeDominiosParticular = jPanelDominios.getJTreeArbolParticular();
    treeDominiosParticular.addTreeSelectionListener(this);

    treeTablas = jPanelTablas.getTree();
    treeTablas.addTreeSelectionListener(this);

    this.add(jPanelDominios, null);
    this.add(jButtonSalir, null);
    this.add(jPanelTablas, null);
    this.add(jButtonAsociar, null);
    this.add(jButtonDesasociar, null);
    this.add(jPanelLevel, null);
  }