// }
//}).start();
}
private boolean saveDatabase(File file, boolean selectedOnly, String encoding) throws SaveException {
SaveSession session;
frame.block();
try {
if (!selectedOnly)
session = FileActions.saveDatabase(database, metaData, file,
Globals.prefs, false, false, encoding, false);
else
session = FileActions.savePartOfDatabase(database, metaData, file,
Globals.prefs, mainTable.getSelectedEntries(), encoding);
} catch (UnsupportedCharsetException ex2) {
JOptionPane.showMessageDialog(frame, Globals.lang("Could not save file. "
+"Character encoding '%0' is not supported.", encoding),
Globals.lang("Save database"), JOptionPane.ERROR_MESSAGE);
throw new SaveException("rt");
} catch (SaveException ex) {
if (ex.specificEntry()) {
// Error occured during processing of
// be. Highlight it:
int row = mainTable.findEntry(ex.getEntry()),
topShow = Math.max(0, row-3);
mainTable.setRowSelectionInterval(row, row);
mainTable.scrollTo(topShow);
showEntry(ex.getEntry());
}
else ex.printStackTrace();
JOptionPane.showMessageDialog
(frame, Globals.lang("Could not save file")
+".\n"+ex.getMessage(),
Globals.lang("Save database"),
JOptionPane.ERROR_MESSAGE);
throw new SaveException("rt");
} finally {
frame.unblock();
}
boolean commit = true;
if (!session.getWriter().couldEncodeAll()) {
DefaultFormBuilder builder = new DefaultFormBuilder(new FormLayout("left:pref, 4dlu, fill:pref", ""));
JTextArea ta = new JTextArea(session.getWriter().getProblemCharacters());
ta.setEditable(false);
builder.append(Globals.lang("The chosen encoding '%0' could not encode the following characters: ",
session.getEncoding()));
builder.append(ta);
builder.append(Globals.lang("What do you want to do?"));
String tryDiff = Globals.lang("Try different encoding");
int answer = JOptionPane.showOptionDialog(frame, builder.getPanel(), Globals.lang("Save database"),
JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null,
new String[] {Globals.lang("Save"), tryDiff, Globals.lang("Cancel")}, tryDiff);
if (answer == JOptionPane.NO_OPTION) {
// The user wants to use another encoding.
Object choice = JOptionPane.showInputDialog(frame, Globals.lang("Select encoding"), Globals.lang("Save database"),
JOptionPane.QUESTION_MESSAGE, null, Globals.ENCODINGS, encoding);
if (choice != null) {
String newEncoding = (String)choice;
return saveDatabase(file, selectedOnly, newEncoding);
} else
commit = false;
} else if (answer == JOptionPane.CANCEL_OPTION)
commit = false;
}
try {
if (commit) {
session.commit();
this.encoding = encoding; // Make sure to remember which encoding we used.
}
else
session.cancel();
} catch (IOException e) {
e.printStackTrace();
}
return commit;