Shell shell = HandlerUtil.getActiveWorkbenchWindow(event).getShell();
// Get the view
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
IWorkbenchPage page = window.getActivePage();
View view = (View) page.findView(View.ID);
// File standard dialog
FileDialog fileDialog = new FileDialog(shell, SWT.SAVE);
// Set the text
fileDialog.setText("Save as...");
// Open Dialog and save result of selection
String selected = fileDialog.open();
File file = new File(selected);
// if the file exists, check for writeability
if (!file.exists() || (file.exists() && file.canWrite())) {
// enter password for the 1st time
PasswordInputDialog passwordDialog = new PasswordInputDialog(shell,
"Password for " + file.getName(), "Enter password ", "",
new DummyInputValidator());
passwordDialog.open();
String password1 = passwordDialog.getValue();
// Re-enter password. Reusing the same dialog here is quicker to
// implement than using a dialog with two password fields.
passwordDialog = new PasswordInputDialog(shell, "Password for "
+ file.getName(), "Re-Enter password ", "",
new DummyInputValidator());
passwordDialog.open();
String password2 = passwordDialog.getValue();
if (password1.equals(password2)) {
String password = password1;
PWListContentProvider contentProvider = (PWListContentProvider) view
.getContentProvider();
try {
contentProvider.saveEncryptedFile(password, file);
} catch (ParserConfigurationException e) {
MessageDialog.openError(shell, "Cannot save file",