/** Displays a graph based on stored information. */
private void graphButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_graphButtonActionPerformed
JOptionPane errorDialog;
DataSetsLoadTask task;
ProgressBar progressBar;
DataSetsDAO dataSetsDAO;
int sessionID;
TimeSeriesContext.Aggregation aggregation;
TimeSeriesContext.Interpolation interpolation;
SimpleDateFormat dateFormat;
SimpleDateFormat timeFormat;
long sessionStartTime;
long sessionFinishTime;
long fromDate;
long toDate;
String graphTitle;
sessionID = getSessionID();
if ( sessionID == -1 )
return;
if ( ((JTable)(sessionsPane.getViewport().getView())).getSelectedRowCount() > 1 ) {
errorDialog = new JOptionPane();
errorDialog.showMessageDialog(this, "Please select a single session for graph display", "Multiple sessions selected", JOptionPane.ERROR_MESSAGE);
return;
}
try {
dataSetsDAO = DAOFactory.getDataSetsDAO();
aggregation = TimeSeriesContext.Aggregation.values()[aggregationCombo.getSelectedIndex()];
interpolation = TimeSeriesContext.Interpolation.values()[interpolationCombo.getSelectedIndex()];
//dataTypeID = dba.getDataTypeID(sessionID);
dateFormat = new SimpleDateFormat("dd/MM/yyyy H:mm:ss");
fromDate = dateFormat.parse(fromDateField.getText() + " " + fromTimeField.getText()).getTime();
toDate = dateFormat.parse(toDateField.getText() + " " + toTimeField.getText()).getTime();
sessionStartTime = dataSetsDAO.retrieveSessionStartTime(sessionID);
sessionFinishTime = dataSetsDAO.retrieveSessionFinishTime(sessionID);
logger.debug("Creating session from " + fromDate + " to " + toDate);
if ( fromDate < sessionStartTime - 1000 ) {
errorDialog = new JOptionPane();
errorDialog.showMessageDialog(this, "The \'From\' date/time must be within the session interval", "Can't display graph", JOptionPane.ERROR_MESSAGE);
return;
}
if ( toDate > sessionFinishTime ) {
errorDialog = new JOptionPane();
errorDialog.showMessageDialog(this, "The \'To\' date/time must be within the session interval", "Can't display graph", JOptionPane.ERROR_MESSAGE);
return;
}
if ( fromDate >= toDate ) {
errorDialog = new JOptionPane();
errorDialog.showMessageDialog(this, "The \'From\' date/time must be less than the \'To\' date/time", "Can't display graph", JOptionPane.ERROR_MESSAGE);
return;
}
// Old - large blocking call to fetch data that freezes GUI
//dataSets = new DataSets(sessionID, fromDate, toDate, aggregation);
// Instead create an asynchronous thread to fetch data while freeing up GUI
task = new DataSetsLoadTask(this, sessionID, fromDate, toDate, aggregation, interpolation);
graphTitle = ((String)(((JTable)(sessionsPane.getViewport().getView())).getModel().getValueAt(getSelectedRow(), 0)));
progressBar = new ProgressBar("Retrieving data", "Graph title: " + graphTitle, task);
} catch (ParseException e) {
ErrorHandler.modalError(this, "Unable to interpret given dates and times", "Can't display graph", e);
} catch (DBException e) {
ErrorHandler.modalError(this, "Cannot retrieve data from database", "Please check database connectivity", e);