use of name.abuchen.portfolio.ui.dialogs.PasswordDialog in project portfolio by buchen.
the class PortfolioPart method doSaveAs.
public // NOSONAR
void doSaveAs(// NOSONAR
MPart part, // NOSONAR
Shell shell, // NOSONAR
String extension, // NOSONAR
String encryptionMethod) {
FileDialog dialog = new FileDialog(shell, SWT.SAVE);
dialog.setOverwrite(true);
// if an extension is given, make sure the file name proposal has the
// right extension in the save as dialog
String fileNameProposal = clientFile != null ? clientFile.getName() : part.getLabel();
if (extension != null && !fileNameProposal.endsWith('.' + extension)) {
int p = fileNameProposal.lastIndexOf('.');
fileNameProposal = (p > 0 ? fileNameProposal.substring(0, p + 1) : fileNameProposal + '.') + extension;
}
dialog.setFileName(fileNameProposal);
// $NON-NLS-1$
dialog.setFilterPath(clientFile != null ? clientFile.getAbsolutePath() : System.getProperty("user.home"));
String path = dialog.open();
if (path == null)
return;
// changed it in the save dialog
if (extension != null && !path.endsWith('.' + extension))
path += '.' + extension;
File localFile = new File(path);
char[] password = null;
if (ClientFactory.isEncrypted(localFile)) {
PasswordDialog pwdDialog = new PasswordDialog(shell);
if (pwdDialog.open() != PasswordDialog.OK)
return;
password = pwdDialog.getPassword().toCharArray();
}
try {
clientFile = localFile;
part.getPersistedState().put(UIConstants.File.PERSISTED_STATE_KEY, clientFile.getAbsolutePath());
ClientFactory.save(client, clientFile, encryptionMethod, password);
broker.post(UIConstants.Event.File.SAVED, clientFile.getAbsolutePath());
dirty.setDirty(false);
part.setLabel(clientFile.getName());
part.setTooltip(clientFile.getAbsolutePath());
storePreferences(true);
} catch (IOException e) {
PortfolioPlugin.log(e);
ErrorDialog.openError(shell, Messages.LabelError, e.getMessage(), new Status(Status.ERROR, PortfolioPlugin.PLUGIN_ID, e.getMessage(), e));
}
}
Aggregations