Ejemplo n.º 1
0
  void populateStartDate() throws SQLException, Exception {
    startDateS.removeActionListener(this);
    startDateS.removeAllItems();
    dateRange.clear();
    if (sourceTable.sourceListModel.isSelectionEmpty() == false
        && sourceTable.getValueAt(sourceTable.getSelectedRow(), 0).toString() != null) {
      Statement MySQL_Statement = dbConn.createStatement();
      String getMinMaxSQL =
          "SELECT UNIX_TIMESTAMP(DATE_ADD(DATE(MIN(date_time)),INTERVAL 1 DAY)) AS min_date,UNIX_TIMESTAMP(DATE(MAX(date_time))) AS max_date FROM data_sa WHERE site_id = "
              + siteTable.getValueAt(siteTable.getSelectedRow(), 0)
              + " AND source_id = "
              + sourceTable.getValueAt(sourceTable.getSelectedRow(), 0);
      ResultSet minMaxResults = MySQL_Statement.executeQuery(getMinMaxSQL);
      if (minMaxResults.next()) {
        Calendar minCal = Calendar.getInstance();
        minCal.setTimeZone(TimeZone.getTimeZone("GMT+10"));
        minCal.setTimeInMillis(minMaxResults.getLong("min_date") * 1000);
        long maxCal = minMaxResults.getLong("max_date") * 1000;

        while (minCal.getTimeInMillis() <= maxCal) {
          dateRange.add(minCal.getTimeInMillis());
          startDateS.addItem(dateFormatter.format(minCal.getTimeInMillis()));
          minCal.add(Calendar.DATE, 1);
        }
        startDateS.setEnabled(true);
        populateEndDate();
      } else {
        throw new Exception("ERR:NoData");
      }
    } else { // This should never be able to happen
      throw new Exception("NoSource");
    }
    startDateS.addActionListener(this);
  }
Ejemplo n.º 2
0
  @Override
  public void valueChanged(ListSelectionEvent lSE) {
    if (lSE.getSource().equals(siteTable.siteListModel) && lSE.getValueIsAdjusting() == false) {
      sourceTable.updateList(dbConn, siteTable.siteList.get(siteTable.getSelectedRow()));

      if (sourceTable.sourceListModel.isSelectionEmpty()) {
        plotButton.setEnabled(false);
        startDateS.removeAllItems();
        endDateS.removeAllItems();
      }
    } else if (lSE.getSource().equals(sourceTable.sourceListModel)
        && lSE.getValueIsAdjusting() == false) {

      if (sourceTable.sourceListModel.isSelectionEmpty() == false) {
        try {
          populateStartDate();
          if (startDateS.getItemCount() > 0 && endDateS.getItemCount() > 0) {
            plotButton.setEnabled(true);
          }
        } catch (SQLException e) {
          plotButton.setEnabled(false);
          startDateS.removeAllItems();
          endDateS.removeAllItems();
          startDateS.addItem("ERR:NoData");
          endDateS.addItem("ERR:NoData");
          e.printStackTrace();
        } catch (Exception e) {
          plotButton.setEnabled(false);
          startDateS.removeAllItems();
          endDateS.removeAllItems();
          startDateS.addItem(e.getMessage());
          endDateS.addItem(e.getMessage());
        }
      } else {
        plotButton.setEnabled(false);
        startDateS.removeAllItems();
        endDateS.removeAllItems();
      }
    }
  }