DataSetsDAO dataSetsDAO;
DataSetDAO dataSetDAO;
int sessionID;
String[] headings;
DataSet dataSet;
DataPoint point;
savedFile = null;
dialog = new JOptionPane();
sessionID = getSessionID();
if ( sessionID == -1 )
return;
if ( ((JTable)(sessionsPane.getViewport().getView())).getSelectedRowCount() > 1 ) {
dialog.showMessageDialog(this, "Please select a single session for data export", "Multiple sessions selected", JOptionPane.ERROR_MESSAGE);
return;
}
try {
//.testConnection();
dataSetsDAO = DAOFactory.getDataSetsDAO();
dataSetDAO = DAOFactory.getDataSetDAO();
chooser = new JFileChooser();
returnStatus = chooser.showSaveDialog(this);
if ( returnStatus == JFileChooser.APPROVE_OPTION ) {
savedFile = chooser.getSelectedFile();
if ( ! savedFile.exists() || ( savedFile.exists() && dialog.showConfirmDialog(null,
"File already exists - are you sure you want to overwrite it?",
"Confirm file overwrite", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION ) ) {
out = new FileWriter(savedFile);
out.write("Title: " + dataSetsDAO.retrieveSessionTitle(sessionID) + "\n");
out.write("Description: " + DataSets.retrieveDescription(sessionID) + "\n\n");
headings = DAOFactory.getDataHeadingsDAO().retrieve(sessionID);
for ( int set = 0 ; set < headings.length ; set++ ) {
out.write("Set " + set + ": " + headings[set] + "\n");
}
out.write("\n");
out.write("Set,Time,Value\n");
for ( int set = 0; set < headings.length ; set++ ) {
dataSet = dataSetDAO.retrieve(sessionID, set);
//out.write("Set " + set + ": " + headings[set] + "\n");
for ( int i = 0 ; i < dataSet.size() ; i++ ) {
point = dataSet.elementAt(i);
out.write(set + "," + point.getTime() + "," + point.getValue() + "\n");
}
//out.write("\n");
}
out.close();