Exemplo n.º 1
0
  private void getNewCrs(int code) {
    if (code != -1) {
      //		Eliminar filas en cada nueva bsqueda
      int numRow = dtm.getRowCount();
      while (numRow != 0) {
        numRow = numRow - 1;
        dtm.removeRow(numRow);
      }
      String sentence =
          "SELECT usr_code, usr_wkt, usr_proj, usr_geog, usr_datum "
              + "FROM USR "
              + "WHERE usr_code = "
              + code;
      connect = new EpsgConnection();
      connect.setConnectionUsr();
      ResultSet result = Query.select(sentence, connect.getConnection());
      try {
        connect.shutdown();
      } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

      Object[] data = new Object[4];
      try {
        while (result.next()) {
          data[0] = result.getString("usr_code");
          data[1] = result.getString("usr_wkt");
          String proj = result.getString("usr_proj");
          if (!proj.equals("")) {
            data[1] = proj;
            data[2] = PluginServices.getText(this, "si");
          } else {
            data[1] = result.getString("usr_geog");
            data[2] = PluginServices.getText(this, "no");
          }

          data[3] = result.getString("usr_datum");
          dtm.addRow(data);
        }
      } catch (SQLException e1) {
        e1.printStackTrace();
      }
      int numr = dtm.getRowCount();
      if (numr == 0) {
        searchButton();
      } else {
        this.getJTable().setRowSelectionInterval(0, 0);
      }
    }
  }
Exemplo n.º 2
0
  public void initializeTable() {
    // Eliminar filas en cada nueva bsqueda
    int numRow = dtm.getRowCount();
    while (numRow != 0) {
      numRow = numRow - 1;
      dtm.removeRow(numRow);
    }

    String sentence =
        "SELECT usr_code, usr_wkt, usr_proj, usr_geog, usr_datum "
            + "FROM USR ORDER BY usr_code ASC";

    connect = new EpsgConnection();
    connect.setConnectionUsr();
    ResultSet result = Query.select(sentence, connect.getConnection());
    try {
      connect.shutdown();
    } catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    Object[] data = new Object[4];
    try {
      while (result.next()) {
        data[0] = result.getString("usr_code");
        data[1] = result.getString("usr_wkt");
        String proj = result.getString("usr_proj");
        if (!proj.equals("")) {
          data[1] = proj;
          data[2] = PluginServices.getText(this, "si");
        } else {
          data[1] = result.getString("usr_geog");
          data[2] = PluginServices.getText(this, "no");
        }

        data[3] = result.getString("usr_datum");
        dtm.addRow(data);
      }
    } catch (SQLException e1) {
      e1.printStackTrace();
    }

    int numr = dtm.getRowCount();
    if (numr > 0) {
      this.getJTable().setRowSelectionInterval(0, 0);
      // getBtnEditar().setEnabled(true);
      // getBtnEliminar().setEnabled(true);
    }
  }
Exemplo n.º 3
0
  public boolean isInBD(int code) {
    String sentence = "SELECT usr_code " + "FROM USR " + "WHERE usr_code =" + code;

    connect = new EpsgConnection();
    connect.setConnectionUsr();
    ResultSet result = Query.select(sentence, connect.getConnection());
    try {
      connect.shutdown();
    } catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    try {
      if (result.next()) {
        return true;
      }
    } catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    return false;
  }
Exemplo n.º 4
0
  /**
   * Consigue la cadena wkt del CRS seleccionado, y genera la cadena que ms tarde volver a ser
   * tratada para la consecucin de una cadena wkt legible por la proj4.
   */
  public void setWKT() {
    int code = getCodeCRS();
    String sentence = "SELECT usr_wkt " + "FROM USR " + "WHERE usr_code = " + code;

    connect = new EpsgConnection();
    connect.setConnectionUsr();
    ResultSet result = Query.select(sentence, connect.getConnection());
    try {
      connect.shutdown();
    } catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    try {
      result.next();
      cadWkt = result.getString("usr_wkt");
    } catch (SQLException e1) {
      e1.printStackTrace();
    }
    cadWkt =
        cadWkt.substring(0, cadWkt.length() - 1) + ", AUTHORITY[\"USR\"," + getCodeCRS() + "]]";
  }
Exemplo n.º 5
0
  /**
   * Mtodo que controla la bsqueda de los CRS siguiendo los criterios de bsqueda que le hemos
   * definido. Tambin gestiona los casos en que no encuentre CRS, o que los parmetros de bsqueda
   * sean errneos. Si encuentra algn CRS pero no es soportado por la aplicacin aparecer el mensaje
   * de informacin correspondiente.
   */
  private void searchButton() {
    searchTextField.setBackground(Color.white);

    if (codeRadioButton.isSelected()
        && (searchTextField.getText().length()
            != searchTextField.getText().replaceAll("[^0-9]", "").length())) {
      JOptionPane.showMessageDialog(
          NewCRSPanel.this,
          PluginServices.getText(this, "numeric_format"),
          "Warning...",
          JOptionPane.WARNING_MESSAGE);
      searchTextField.setText("");
      return;
    }

    // Eliminar filas en cada nueva bsqueda
    int numRow = dtm.getRowCount();
    while (numRow != 0) {
      numRow = numRow - 1;
      dtm.removeRow(numRow);
    }
    //			Dependiendo de la opcion se realizada una busqueda
    ResultSet result = null;

    if (searchTextField.getText().equals("")) {
      String sentence =
          "SELECT usr_code, usr_wkt, usr_proj, usr_geog, usr_datum "
              + "FROM USR ORDER BY usr_code ASC";
      connect = new EpsgConnection();
      connect.setConnectionUsr();
      result = Query.select(sentence, connect.getConnection());
      try {
        connect.shutdown();
      } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      Object[] data = new Object[4];
      try {
        while (result.next()) {
          data[0] = result.getString("usr_code");
          data[1] = result.getString("usr_wkt");
          String proj = result.getString("usr_proj");
          if (!proj.equals("")) {
            data[1] = proj;
            data[2] = PluginServices.getText(this, "si");
          } else {
            data[1] = result.getString("usr_geog");
            data[2] = PluginServices.getText(this, "no");
          }

          data[3] = result.getString("usr_datum");
          dtm.addRow(data);
        }
      } catch (SQLException e1) {
        e1.printStackTrace();
      }
    } else if (codeRadioButton.isSelected()) {

      key = searchTextField.getText();
      int code = Integer.parseInt(key);
      String sentence =
          "SELECT usr_code, usr_wkt, usr_proj, usr_geog, usr_datum "
              + "FROM USR "
              + "WHERE usr_code = "
              + code;
      connect = new EpsgConnection();
      connect.setConnectionUsr();
      result = Query.select(sentence, connect.getConnection());
      try {
        connect.shutdown();
      } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

      Object[] data = new Object[4];
      try {
        while (result.next()) {
          data[0] = result.getString("usr_code");
          data[1] = result.getString("usr_wkt");
          String proj = result.getString("usr_proj");
          if (!proj.equals("")) {
            data[1] = proj;
            data[2] = PluginServices.getText(this, "si");
          } else {
            data[1] = result.getString("usr_geog");
            data[2] = PluginServices.getText(this, "no");
          }

          data[3] = result.getString("usr_datum");
          dtm.addRow(data);
        }
      } catch (SQLException e1) {
        e1.printStackTrace();
      }
    } else if (nameRadioButton.isSelected()) {
      key = searchTextField.getText();
      String key2 = key.substring(0, 1);
      String key3 = key.substring(1, key.length());
      key2 = key2.toUpperCase();

      String sentence =
          "SELECT usr_code, usr_wkt, usr_proj, usr_geog, usr_datum "
              + "FROM USR "
              + "WHERE (usr_proj LIKE '%"
              + key
              + "%') OR (usr_proj LIKE '%"
              + key.toUpperCase()
              + "%') "
              + "OR (usr_proj LIKE '%"
              + key2
              + key3
              + "%') OR "
              + "(usr_geog LIKE '%"
              + key
              + "%') OR (usr_geog LIKE '%"
              + key.toUpperCase()
              + "%') "
              + "OR (usr_geog LIKE '%"
              + key2
              + key3
              + "%')";

      connect = new EpsgConnection();
      connect.setConnectionUsr();
      result = Query.select(sentence, connect.getConnection());
      try {
        connect.shutdown();
      } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

      Object[] data = new Object[4];
      try {
        while (result.next()) {
          data[0] = result.getString("usr_code");
          data[1] = result.getString("usr_wkt");
          String proj = result.getString("usr_proj");
          if (!proj.equals("")) {
            data[1] = proj;
            data[2] = PluginServices.getText(this, "si");
          } else {
            data[1] = result.getString("usr_geog");
            data[2] = PluginServices.getText(this, "no");
          }

          data[3] = result.getString("usr_datum");
          dtm.addRow(data);
        }
      } catch (SQLException e1) {
        e1.printStackTrace();
      }
    }

    int numr = dtm.getRowCount();
    if (numr == 0) {
      JOptionPane.showMessageDialog(
          this,
          PluginServices.getText(this, "no_results"),
          "Warning...",
          JOptionPane.WARNING_MESSAGE);
    } else {
      this.getJTable().setRowSelectionInterval(0, 0);
    }
  }
Exemplo n.º 6
0
  /** Manejador de eventos */
  public void actionPerformed(ActionEvent e) {
    if (e.getSource().equals(getCodeRadioButton())) {
      getSearchTextField().setText("");
    } else if (e.getSource().equals(getNameRadioButton())) {
      getSearchTextField().setText("");
    } else if (e.getSource().equals(getBtnEditar())) {
      // editar la fila seleccionada de la tabla (si hay)
      ICrs crs = null;
      try {
        crs = new CrsFactory().getCRS("USR:"******"USR";
      String name = "";
      if (wizard.getPSistCoord().getTxtNombreProy().getText().equals("")) {
        name = wizard.getPDatum().getTxtNombreCrs().getText();
      } else {
        name = wizard.getPSistCoord().getTxtNombreProy().getText();
      }
      int code = getCodeCRS();
      CrsData crsData = new CrsData(authority, code, name);
      RecentCRSsPersistence persistence = new RecentCRSsPersistence();
      persistence.addCrsData(crsData);

    } else if (e.getSource().equals(getBtnEliminar())) {
      // eliminar la fila seleccionada de la tabla
      int i =
          JOptionPane.showConfirmDialog(
              NewCRSPanel.this, PluginServices.getText(this, "deleteUsr"));
      if (i == 0) {
        connect = new EpsgConnection();
        connect.setConnectionUsr();
        String sentence = "DELETE FROM USR WHERE usr_code =" + getCodeCRS();
        ResultSet result = Query.select(sentence, connect.getConnection());
        try {
          connect.shutdown();
        } catch (SQLException arg0) {
          // TODO Auto-generated catch block
          arg0.printStackTrace();
        }
        dtm.removeRow(getJTable().getSelectedRow());
      }
      // searchButton();
    } else if (e.getSource().equals(getBtnNuevo())) {
      // mostrar el asistente de nuevo crs

      MainPanel wizard = new MainPanel(currentCrs);
      if ((wizard.getPCard().getSelectedIndex() == 0)
          && wizard.getPCrsUsr().getRbCrsExistente().isSelected()) {
        ICrs crs = wizard.getPCrsUsr().getCrs();
        if (crs != null) {
          wizard.fillData(crs);
        } else wizard.fillData(wizard.getCrs());
      } else if ((wizard.getPCard().getSelectedIndex() == 0)
          && wizard.getPCrsUsr().getRbNuevoCrs().isSelected()) {
        wizard.cleanData();
      }
      PluginServices.getMDIManager().addWindow(wizard);
      getNewCrs(wizard.getNewCrsCode());

    } else if (e.getSource().equals(getSearchButton())) {
      searchButton();
    }
    /*Si el objeto que genera el evento es el JButton 'InfoCrs'
    se muestra la informacin ralicionada con el Crs seleccionado en la tabla*/
    else if (e.getSource().equals(getInfoCrs())) {
      InfoCRSPanel info = new InfoCRSPanel("USR", getCodeCRS());
      PluginServices.getMDIManager().addWindow(info);
    }
  }
Exemplo n.º 7
0
 public void connection() {
   connect = new EpsgConnection();
   connect.setConnectionUsr();
 }