Search in sources :

Example 1 with AbstractClassicAlgorithm

use of org.jcryptool.core.operations.algorithm.classic.AbstractClassicAlgorithm 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)

Aggregations

ICommandService (org.eclipse.ui.commands.ICommandService)1 ActionItem (org.jcryptool.actions.core.types.ActionItem)1 AbstractClassicAlgorithm (org.jcryptool.core.operations.algorithm.classic.AbstractClassicAlgorithm)1 AbstractModernAlgorithm (org.jcryptool.core.operations.algorithm.modern.AbstractModernAlgorithm)1 ClassicDataObject (org.jcryptool.core.operations.dataobject.classic.ClassicDataObject)1 IClassicDataObject (org.jcryptool.core.operations.dataobject.classic.IClassicDataObject)1 IModernDataObject (org.jcryptool.core.operations.dataobject.modern.IModernDataObject)1 ModernDataObject (org.jcryptool.core.operations.dataobject.modern.ModernDataObject)1