Search in sources :

Example 1 with ActionItem

use of org.jcryptool.actions.core.types.ActionItem in project core by jcryptool.

the class AbstractAlgorithmHandler method addActionItem.

/**
 * Adds the cryptographic action information as a new <code>ActionItem</code> to the <b>Actions view</b>. Adding the
 * new ActionItem must be executed in an async way since a Job may be used to execute the cryptographic operation.
 *
 * @param algorithm The executed AbstractAlgorithm implementation
 */
private void addActionItem(AbstractAlgorithm algorithm) {
    ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
    if ((Boolean) // $NON-NLS-1$
    service.getCommand("org.jcryptool.actions.recordCommand").getState("org.jcryptool.actions.recordCommand.toggleState").getValue()) {
        // $NON-NLS-1$
        final ActionItem item = new ActionItem(output.getName(), algorithm.getAlgorithmName());
        item.setPluginId(this.getId());
        if (algorithm instanceof AbstractClassicAlgorithm) {
            ClassicDataObject dataobject = (ClassicDataObject) dataObject;
            if (dataobject.getOpmode() == 0) {
                // $NON-NLS-1$
                item.setActionType("encrypt");
            } else if (dataobject.getOpmode() == 1) {
                // $NON-NLS-1$
                item.setActionType("decrypt");
            }
            item.setAlphabet(dataobject.getAlphabet().getName());
            dataobject.setFilterNonAlphaChars(((AbstractClassicAlgorithm) algorithm).isFilter());
            item.setParams(DataObjectConverter.propertiesToHashtable(dataobject));
            item.setDataObjectType(dataobject.getClass().getName());
        } else if (algorithm instanceof AbstractModernAlgorithm) {
            ModernDataObject dataobject = (ModernDataObject) dataObject;
            item.setParams(DataObjectConverter.propertiesToHashtable(dataobject));
            item.setDataObjectType(dataobject.getClass().getName());
        }
        Display.getDefault().asyncExec(new Runnable() {

            public void run() {
                ActionCascadeService.getInstance().addItem(item);
            }
        });
    }
}
Also used : AbstractClassicAlgorithm(org.jcryptool.core.operations.algorithm.classic.AbstractClassicAlgorithm) AbstractModernAlgorithm(org.jcryptool.core.operations.algorithm.modern.AbstractModernAlgorithm) ActionItem(org.jcryptool.actions.core.types.ActionItem) ModernDataObject(org.jcryptool.core.operations.dataobject.modern.ModernDataObject) IModernDataObject(org.jcryptool.core.operations.dataobject.modern.IModernDataObject) ClassicDataObject(org.jcryptool.core.operations.dataobject.classic.ClassicDataObject) IClassicDataObject(org.jcryptool.core.operations.dataobject.classic.IClassicDataObject) ICommandService(org.eclipse.ui.commands.ICommandService)

Example 2 with ActionItem

use of org.jcryptool.actions.core.types.ActionItem in project core by jcryptool.

the class MoveDownHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (selection instanceof IStructuredSelection) {
        ActionView view = (ActionView) HandlerUtil.getActivePart(event);
        TableViewer viewer = view.getViewer();
        ActionItem item = (ActionItem) ((IStructuredSelection) selection).getFirstElement();
        ActionCascadeService.getInstance().moveDown(item);
        // Set focus on moved row
        viewer.setSelection(new StructuredSelection(item));
    }
    return null;
}
Also used : ActionItem(org.jcryptool.actions.core.types.ActionItem) ISelection(org.eclipse.jface.viewers.ISelection) ActionView(org.jcryptool.actions.ui.views.ActionView) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 3 with ActionItem

use of org.jcryptool.actions.core.types.ActionItem in project core by jcryptool.

the class MoveUpHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (selection instanceof IStructuredSelection) {
        ActionView view = (ActionView) HandlerUtil.getActivePart(event);
        TableViewer viewer = view.getViewer();
        ActionItem item = (ActionItem) ((IStructuredSelection) selection).getFirstElement();
        ActionCascadeService.getInstance().moveUp(item);
        // Set focus on moved row
        viewer.setSelection(new StructuredSelection(item));
    }
    return null;
}
Also used : ActionItem(org.jcryptool.actions.core.types.ActionItem) ISelection(org.eclipse.jface.viewers.ISelection) ActionView(org.jcryptool.actions.ui.views.ActionView) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 4 with ActionItem

use of org.jcryptool.actions.core.types.ActionItem in project core by jcryptool.

the class PerformOperationListener method addActionItem.

private void addActionItem(IFlexiProviderOperation operation) {
    ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
    if ((Boolean) // $NON-NLS-1$
    service.getCommand("org.jcryptool.actions.recordCommand").getState("org.jcryptool.actions.recordCommand.toggleState").getValue()) {
        // $NON-NLS-1$
        AlgorithmDescriptor descriptor = operation.getAlgorithmDescriptor();
        ActionItem item = // $NON-NLS-1$
        new ActionItem(EditorsManager.getInstance().getActiveEditorTitle(), descriptor.getAlgorithmName());
        item.setPluginId(operation.getRegistryType().getName());
        if (operation.getOperation() == OperationType.DECRYPT) {
            // $NON-NLS-1$
            item.setActionType("decrypt");
        } else if (operation.getOperation() == OperationType.ENCRYPT) {
            // $NON-NLS-1$
            item.setActionType("encrypt");
        } else if (operation.getOperation() == OperationType.SIGN) {
            // $NON-NLS-1$
            item.setActionType("sign");
        } else if (operation.getOperation() == OperationType.VERIFY) {
            // $NON-NLS-1$
            item.setActionType("verify");
        }
        // item.addParam("input", operation.getInput()); //$NON-NLS-1$
        // item.addParam("output", operation.getOutput()); //$NON-NLS-1$
        // $NON-NLS-1$
        item.addParam("signature", operation.getSignature());
        // $NON-NLS-1$
        item.addParam("algorithm type", operation.getAlgorithmDescriptor().getType().getName());
        IKeyStoreAlias alias = operation.getKeyStoreAlias();
        if (alias != null) {
            // $NON-NLS-1$
            item.addParam("contact", alias.getContactName());
            // $NON-NLS-1$
            item.addParam("key alias", alias.getAliasString());
            // $NON-NLS-1$
            item.addParam("key length", String.valueOf(alias.getKeyLength()));
            if (operation.getPassword() != null) {
                // $NON-NLS-1$
                item.addParam("key password", String.valueOf(operation.getPassword()));
            }
        }
        if (descriptor instanceof BlockCipherDescriptor) {
            // $NON-NLS-1$
            item.addParam("mode", ((BlockCipherDescriptor) descriptor).getMode());
            // $NON-NLS-1$
            item.addParam("padding scheme", ((BlockCipherDescriptor) descriptor).getPadding());
        } else if (descriptor instanceof SecureRandomDescriptor) {
            // $NON-NLS-1$ //$NON-NLS-2$
            item.addParam("random size", "" + ((SecureRandomDescriptor) descriptor).getLength());
        // byte[][] alphabets = ((SecureRandomDescriptor) descriptor).getAlphabet();
        // TODO push alphapet to items property "alphabet"
        }
        ActionCascadeService.getInstance().addItem(item);
    }
}
Also used : SecureRandomDescriptor(org.jcryptool.crypto.flexiprovider.descriptors.algorithms.SecureRandomDescriptor) BlockCipherDescriptor(org.jcryptool.crypto.flexiprovider.descriptors.algorithms.BlockCipherDescriptor) ActionItem(org.jcryptool.actions.core.types.ActionItem) AlgorithmDescriptor(org.jcryptool.crypto.flexiprovider.descriptors.algorithms.AlgorithmDescriptor) ICommandService(org.eclipse.ui.commands.ICommandService) IKeyStoreAlias(org.jcryptool.crypto.keystore.keys.IKeyStoreAlias)

Example 5 with ActionItem

use of org.jcryptool.actions.core.types.ActionItem in project core by jcryptool.

the class RemoveSelectedHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (selection instanceof IStructuredSelection) {
        ActionItem item = (ActionItem) ((IStructuredSelection) selection).getFirstElement();
        ActionCascadeService.getInstance().removeItem(item);
    }
    return null;
}
Also used : ActionItem(org.jcryptool.actions.core.types.ActionItem) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Aggregations

ActionItem (org.jcryptool.actions.core.types.ActionItem)10 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)6 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)4 TableViewer (org.eclipse.jface.viewers.TableViewer)4 ISelection (org.eclipse.jface.viewers.ISelection)3 ActionView (org.jcryptool.actions.ui.views.ActionView)3 ICommandService (org.eclipse.ui.commands.ICommandService)2 ActionCascade (org.jcryptool.actions.core.types.ActionCascade)2 AlgorithmDescriptor (org.jcryptool.crypto.flexiprovider.descriptors.algorithms.AlgorithmDescriptor)2 BlockCipherDescriptor (org.jcryptool.crypto.flexiprovider.descriptors.algorithms.BlockCipherDescriptor)2 SecureRandomDescriptor (org.jcryptool.crypto.flexiprovider.descriptors.algorithms.SecureRandomDescriptor)2 File (java.io.File)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 Job (org.eclipse.core.runtime.jobs.Job)1 ObservableListContentProvider (org.eclipse.jface.databinding.viewers.ObservableListContentProvider)1 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)1 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1