Search in sources :

Example 1 with ActionCascadeService

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();
}
Also used : InvalidParameterException(java.security.InvalidParameterException) File(java.io.File) ActionCascadeService(org.jcryptool.actions.core.registry.ActionCascadeService) URL(java.net.URL) WorkbenchException(org.eclipse.ui.WorkbenchException) ExecutionException(org.eclipse.core.commands.ExecutionException) InvalidParameterException(java.security.InvalidParameterException)

Example 2 with ActionCascadeService

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;
}
Also used : Command(org.eclipse.core.commands.Command) State(org.eclipse.core.commands.State) ActionCascadeService(org.jcryptool.actions.core.registry.ActionCascadeService) ActionCascade(org.jcryptool.actions.core.types.ActionCascade) ICommandService(org.eclipse.ui.commands.ICommandService)

Example 3 with ActionCascadeService

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;
}
Also used : FileWriter(java.io.FileWriter) IOException(java.io.IOException) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) ActionCascadeService(org.jcryptool.actions.core.registry.ActionCascadeService) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Example 4 with ActionCascadeService

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;
}
Also used : ImportUtils(org.jcryptool.actions.core.utils.ImportUtils) ISelection(org.eclipse.jface.viewers.ISelection) IFileStore(org.eclipse.core.filesystem.IFileStore) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) PartInitException(org.eclipse.ui.PartInitException) ActionCascadeService(org.jcryptool.actions.core.registry.ActionCascadeService)

Example 5 with ActionCascadeService

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;
}
Also used : ImportUtils(org.jcryptool.actions.core.utils.ImportUtils) ActionView(org.jcryptool.actions.ui.views.ActionView) ActionCascadeService(org.jcryptool.actions.core.registry.ActionCascadeService) FileDialog(org.eclipse.swt.widgets.FileDialog)

Aggregations

ActionCascadeService (org.jcryptool.actions.core.registry.ActionCascadeService)5 File (java.io.File)2 FileDialog (org.eclipse.swt.widgets.FileDialog)2 ImportUtils (org.jcryptool.actions.core.utils.ImportUtils)2 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 Writer (java.io.Writer)1 URL (java.net.URL)1 InvalidParameterException (java.security.InvalidParameterException)1 Command (org.eclipse.core.commands.Command)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 State (org.eclipse.core.commands.State)1 IFileStore (org.eclipse.core.filesystem.IFileStore)1 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 PartInitException (org.eclipse.ui.PartInitException)1 WorkbenchException (org.eclipse.ui.WorkbenchException)1 ICommandService (org.eclipse.ui.commands.ICommandService)1 ActionCascade (org.jcryptool.actions.core.types.ActionCascade)1