public void actionPerformed(ActionEvent e) {
SaveSpecialDialog ssd = new SaveSpecialDialog(parent);
ssd.show();
if (!ssd.okPressed())
return; // Cancelled.
JFileChooser fs = new JFileChooser();
String[] fileType = ssd.getFileType();
ExampleFileFilter filter = new ExampleFileFilter
(fileType[0], fileType[1]);
fs.setFileFilter(filter); //addChoosableFileFilter(filter);
int returnVal = fs.showSaveDialog(parent);
if(returnVal != JFileChooser.APPROVE_OPTION) {
return; // Cancelled.
}
String name = fs.getSelectedFile().getPath();
if (!name.endsWith("."+fileType[0]))
name = name+"."+fileType[0];
File saveTo = new File(name);
if (ssd.getChoice() == SaveSpecialDialog.SAVE_SEARCH) {
try {
FileActions.saveDatabase(database, metaData, saveTo,
prefs, showingSearchResults,
showingGroup);
} catch (SaveException ex) {
if (ex.specificEntry()) {
// Error occured during processing of
// be. Highlight it:
int row = tableModel.getNumberFromName
(ex.getEntry().getId()),
topShow = Math.max(0, row-3);
//Util.pr(""+row);
entryTable.setRowSelectionInterval(row, row);
entryTable.setColumnSelectionInterval
(0, entryTable.getColumnCount()-1);
entryTable.scrollTo(topShow);
}
JOptionPane.showMessageDialog
(parent, "Could not save file.\n"+ex.getMessage(),
"Save database", JOptionPane.ERROR_MESSAGE);
}
} else if (ssd.getChoice() ==
SaveSpecialDialog.OPENOFFICE_EXPORT) {
// Show a warning message.
JOptionPane.showMessageDialog
(parent, "Warning: this feature is rather experimental "
+"so far.\nCrossreferences will be resolved where "
+"possible, but\nLaTeX commands will not be removed.",
"Export to OpenOffice.org format",
JOptionPane.WARNING_MESSAGE);
// The openoffice exporter.
OpenofficeTextExport expo =
new OpenofficeTextExport(prefs);
try {
expo.export(database, saveTo);
output("Exported in OpenOffice CSV format to '"
+saveTo.getPath()+"'.");
} catch (SaveException ex) {
JOptionPane.showMessageDialog
(null, "Error exporting database:\n"+ex.getMessage(),
"Error exporting database",
JOptionPane.ERROR_MESSAGE);
}
}
}
|