use of org.jcryptool.actions.core.registry.ActionCascadeService in project core by jcryptool.
the class ImportSampleHandler method getCascadeFilename.
private String getCascadeFilename(ExecutionEvent event) {
// $NON-NLS-1$
String cascadeFilename = event.getParameter("cascadeFilename");
if (cascadeFilename == null) {
// $NON-NLS-1$
throw new InvalidParameterException("command parameter cascadeFilename is required");
}
URL bundleUrl = null;
File cascadeFile = null;
try {
bundleUrl = // $NON-NLS-1$
FileLocator.toFileURL((ActionsUIPlugin.getDefault().getBundle().getEntry("/")));
cascadeFile = new File(bundleUrl.getFile() + "templates" + // $NON-NLS-1$
File.separatorChar + // $NON-NLS-1$
cascadeFilename);
} catch (Exception ex) {
// $NON-NLS-1$ //$NON-NLS-2$
LogUtil.logError("Error loading sample file " + cascadeFilename + " from plugin.", ex);
}
ActionCascadeService service = ActionCascadeService.getInstance();
if (service.getCurrentActionCascade() != null && service.getCurrentActionCascade().getSize() > 0) {
boolean confirmImport = MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), Messages.ImportHandler_0, Messages.ImportHandler_1);
if (!confirmImport) {
return null;
}
}
return cascadeFile.getAbsolutePath();
}
use of org.jcryptool.actions.core.registry.ActionCascadeService in project core by jcryptool.
the class NewCascadeHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
ActionCascadeService service = ActionCascadeService.getInstance();
if (service.getCurrentActionCascade() != null && service.getCurrentActionCascade().getSize() > 0) {
boolean confirmNew = MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), Messages.NewCascadeHandler_0, Messages.NewCascadeHandler_1);
if (confirmNew) {
// $NON-NLS-1$
ActionCascade ac = new ActionCascade("actionCascade");
ActionsUIPlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.P_STORE_PASSWORDS);
service.setCurrentActionCascade(ac);
}
}
ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
// $NON-NLS-1$
Command command = commandService.getCommand("org.jcryptool.actions.recordCommand");
// $NON-NLS-1$
State state = command.getState("org.jcryptool.actions.recordCommand.toggleState");
boolean doRecord = (Boolean) state.getValue();
if (doRecord) {
state.setValue(!doRecord);
// $NON-NLS-1$
commandService.refreshElements("org.jcryptool.actions.recordCommand", null);
}
return null;
}
use of org.jcryptool.actions.core.registry.ActionCascadeService in project core by jcryptool.
the class ExportHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
ActionCascadeService service = ActionCascadeService.getInstance();
if (service.getCurrentActionCascade() != null && service.getCurrentActionCascade().getSize() > 0) {
FileDialog dialog = new FileDialog(HandlerUtil.getActiveShell(event), SWT.SAVE);
dialog.setFilterPath(DirectoryService.getUserHomeDir());
// $NON-NLS-1$
dialog.setFileName(service.getCurrentActionCascade().getName() + ".xml");
dialog.setFilterNames(Constants.FILTER_NAMES);
dialog.setFilterExtensions(Constants.FILTER_EXTENSIONS);
dialog.setOverwrite(true);
String filename = dialog.open();
if (filename != null && filename.length() > 0) {
Writer fw = null;
boolean confirmOverwrite = false;
IPreferenceStore store = ActionsUIPlugin.getDefault().getPreferenceStore();
boolean storePasswords = store.getBoolean(PreferenceConstants.P_STORE_PASSWORDS);
try {
File file = new File(filename);
if (file.exists()) {
confirmOverwrite = MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), Messages.ExportHandler_1, NLS.bind(Messages.ExportHandler_2, new Object[] { file.getName() }));
}
if (!file.exists() || confirmOverwrite) {
fw = new FileWriter(file);
service.getCurrentActionCascade().setSavePasswords(storePasswords);
fw.write(service.getCurrentActionCascade().toString());
fw.flush();
}
} catch (IOException ex) {
LogUtil.logError(ActionsUIPlugin.PLUGIN_ID, Messages.ExportHandler_4, ex, true);
} finally {
if (fw != null) {
try {
fw.close();
} catch (IOException ex) {
LogUtil.logError(ActionsUIPlugin.PLUGIN_ID, "Could not close FileOutputStream for action cascade", ex, // $NON-NLS-1$
false);
}
}
}
}
} else {
MessageDialog.openInformation(HandlerUtil.getActiveShell(event), Messages.ExportHandler_3, Messages.ExportHandler_5);
}
return null;
}
use of org.jcryptool.actions.core.registry.ActionCascadeService in project core by jcryptool.
the class ImportActionCascadeHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
ActionCascadeService service = ActionCascadeService.getInstance();
if (service.getCurrentActionCascade() != null && service.getCurrentActionCascade().getSize() > 0) {
boolean confirmImport = MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), Messages.ImportHandler_0, Messages.ImportHandler_1);
if (!confirmImport) {
return null;
}
}
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection) {
IFileStore file = (IFileStore) ((IStructuredSelection) selection).getFirstElement();
if (file != null) {
ImportUtils importUtil = new ImportUtils(file.getParent().toURI().getPath() + File.separatorChar + file.getName());
if (importUtil.validateActionCascade()) {
service.setCurrentActionCascade(importUtil.createActionCascade());
try {
HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().showView(ActionView.ID);
} catch (PartInitException ex) {
LogUtil.logError(ActionsUIPlugin.PLUGIN_ID, Messages.ImportActionCascadeHandler_0, ex, true);
}
} else {
MessageDialog.openInformation(HandlerUtil.getActiveShell(event), Messages.ImportHandler_2, Messages.ImportHandler_3);
}
}
}
return null;
}
use of org.jcryptool.actions.core.registry.ActionCascadeService in project core by jcryptool.
the class ImportHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
ActionCascadeService service = ActionCascadeService.getInstance();
if (service.getCurrentActionCascade() != null && service.getCurrentActionCascade().getSize() > 0) {
boolean confirmImport = MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), Messages.ImportHandler_0, Messages.ImportHandler_1);
if (!confirmImport) {
return null;
}
}
ActionView view = (ActionView) HandlerUtil.getActivePart(event);
FileDialog dialog = new FileDialog(HandlerUtil.getActiveShell(event), SWT.OPEN);
dialog.setFilterPath(DirectoryService.getUserHomeDir());
dialog.setFilterNames(Constants.FILTER_NAMES);
dialog.setFilterExtensions(Constants.FILTER_EXTENSIONS);
String filename = dialog.open();
if (filename != null && filename.length() > 0) {
view.setImportPath(ImportUtils.getPathFromFile(filename));
ImportUtils importUtil = new ImportUtils(filename);
boolean isValid = importUtil.validateActionCascade();
if (isValid) {
service.setCurrentActionCascade(importUtil.createActionCascade());
} else {
MessageDialog.openInformation(HandlerUtil.getActiveShell(event), Messages.ImportHandler_2, Messages.ImportHandler_3);
}
}
return null;
}
Aggregations