use of org.jcryptool.core.operations.CommandInfo in project core by jcryptool.
the class AlgorithmTreeViewer method makeAndAssignActions.
/**
* creates the actions according to the algorithm extension point and assigns them to the
* viewers double click listener
*/
private void makeAndAssignActions() {
doubleClickHandler = new AbstractHandler() {
public Object execute(ExecutionEvent event) {
TreeObject treeObject = (TreeObject) ((IStructuredSelection) viewer.getSelection()).getFirstElement();
IEditorReference[] editorReferences = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
if (editorReferences.length == 0 && (!treeObject.getParent().getName().equals(org.jcryptool.core.Messages.applicationActionBarAdvisor_Menu_Algorithms_PRNG))) {
AlgorithmView.showMessage(Messages.AlgorithmView_warning_message_no_active_editor);
} else {
final ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
Iterator<CommandInfo> it9 = algorithmList.iterator();
CommandInfo commandInfo = null;
while (it9.hasNext()) {
commandInfo = it9.next();
ShadowAlgorithmHandler handler = (ShadowAlgorithmHandler) commandInfo.getHandler();
String commandId = commandInfo.getCommandId();
if (commandId != null && treeObject.getName().equals(handler.getText())) {
Command command = commandService.getCommand(commandId);
try {
return command.executeWithChecks(event);
} catch (Exception ex) {
LogUtil.logError(ViewsPlugin.PLUGIN_ID, ex);
return (null);
}
}
}
}
return (null);
}
};
addDoubleClickListener(new IDoubleClickListener() {
public void doubleClick(final DoubleClickEvent event) {
Object obj = ((IStructuredSelection) viewer.getSelection()).getFirstElement();
if (obj instanceof TreeParent) {
if (viewer.getTree().getSelection()[0].getExpanded()) {
viewer.collapseToLevel(obj, 1);
} else {
viewer.expandToLevel(obj, 1);
}
} else if (obj instanceof TreeObject) {
try {
final IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class);
IEvaluationContext evaluationContext = handlerService.createContextSnapshot(true);
ExecutionEvent executionEvent = new ExecutionEvent(null, Collections.EMPTY_MAP, null, evaluationContext);
// run assigned action
doubleClickHandler.execute(executionEvent);
} catch (ExecutionException ex) {
LogUtil.logError(ViewsPlugin.PLUGIN_ID, ex);
}
}
}
});
addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(final SelectionChangedEvent event) {
Object treeObject = ((IStructuredSelection) viewer.getSelection()).getFirstElement();
if (treeObject instanceof TreeParent) {
// $NON-NLS-1$
PlatformUI.getWorkbench().getHelpSystem().displayHelp(ViewsPlugin.PLUGIN_ID + ".algorithmsView");
getControl().setFocus();
} else if (treeObject instanceof TreeObject) {
AlgorithmView.showContextHelp(extensionPointId, ((TreeObject) treeObject).getName());
getControl().setFocus();
}
}
});
}
use of org.jcryptool.core.operations.CommandInfo in project core by jcryptool.
the class StartHandler method execute.
public IStatus execute(final ActionView view, final ActionItem startItem, final Shell shell, IProgressMonitor monitor) {
ActionCascade ac = view.getActionCascade();
final TableViewer viewer = view.getViewer();
// $NON-NLS-1$
LogUtil.logInfo("Running Action Cascade " + ac.getName());
boolean start = false;
for (final ActionItem a : ac.getAllItems()) {
int steps = ac.getSize();
// Start the execution at the first selected element
if (a == startItem) {
start = true;
monitor.beginTask(a.getActionName(), steps);
} else
steps--;
if (start) {
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
try {
boolean executed = false;
// Set focus on moved row. Just look and feel ...
display.asyncExec(new Runnable() {
public void run() {
viewer.setSelection(new StructuredSelection(a), true);
}
});
OperationsPlugin op = OperationsPlugin.getDefault();
CommandInfo[] commands = op.getAlgorithmsManager().getShadowAlgorithmCommands();
// Try to find an CryptoAlgorithm-Plug-in (Classic or Modern)
for (int i = 0, length = commands.length; i < length; i++) {
if (commands[i].getHandler() != null && a.getPluginId().equals(commands[i].getCommandId())) {
((ShadowAlgorithmHandler) commands[i].getHandler()).run(convert(a));
executed = true;
}
}
// Try to find a FlexiProvider algorithm
if (!executed) {
// $NON-NLS-1$
LogUtil.logInfo("Trying to execute FlexiProvider algorithm");
for (RegistryType rt : RegistryType.values()) {
if (rt.getName().equals(a.getPluginId())) {
AlgorithmDescriptor descriptor = new AlgorithmDescriptor(a.getActionName(), rt, null);
if (a.getParam("algorithm type").equals(RegistryType.BLOCK_CIPHER.getName())) {
// $NON-NLS-1$
descriptor = new BlockCipherDescriptor(descriptor.getAlgorithmName(), a.getParam("mode"), a.getParam("padding scheme"), null, // $NON-NLS-1$ //$NON-NLS-2$
null);
} else if (a.getParam("algorithm type").equals(RegistryType.SECURE_RANDOM.getName())) {
// $NON-NLS-1$
// TODO Get property "alphabet" from item
byte[][] alphabet = null;
if (alphabet == null) {
descriptor = new SecureRandomDescriptor(descriptor.getAlgorithmName(), // $NON-NLS-1$
Integer.parseInt(a.getParam("random size")));
}
}
final IFlexiProviderOperation operation = new IntegratorOperation(descriptor);
operation.setInput(Messages.InputType);
operation.setOutput(Messages.StartHandler_6);
// $NON-NLS-1$
operation.setSignature(a.getParam("signature"));
if ("encrypt".equals(a.getActionType())) {
// $NON-NLS-1$
operation.setOperation(OperationType.ENCRYPT);
} else if ("decrypt".equals(a.getActionType())) {
// $NON-NLS-1$
operation.setOperation(OperationType.DECRYPT);
} else if ("sign".equals(a.getActionType())) {
// $NON-NLS-1$
operation.setOperation(OperationType.SIGN);
} else if ("verify".equals(a.getActionType())) {
// $NON-NLS-1$
operation.setOperation(OperationType.VERIFY);
} else {
operation.setOperation(OperationType.UNKNOWN);
}
// $NON-NLS-1$
String alias = a.getParam("key alias");
if (alias != null) {
operation.setKeyStoreAlias(new KeyStoreAlias(alias));
}
// $NON-NLS-1$
String password = a.getParam("key password");
if (password != null) {
operation.setPassword(password.toCharArray());
}
display.asyncExec(new Runnable() {
public void run() {
PerformOperationManager.getInstance().firePerformOperation(operation);
}
});
executed = true;
}
}
}
if (!executed) {
throw new Exception(Messages.StartHandler_2 + a.getPluginId());
}
} catch (final Exception e) {
if (ActionsUIPlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.P_IGNORE_ERRORS)) {
// $NON-NLS-1$
LogUtil.logError(ActionsUIPlugin.PLUGIN_ID, a.getActionName() + ": " + e.getMessage(), e, false);
if (!ActionsUIPlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.P_DONT_SHOW_MESSAGES)) {
display.syncExec(new Runnable() {
public void run() {
MessageDialog.openWarning(shell, Messages.StartHandler_3, e.getMessage());
}
});
}
} else {
display.asyncExec(new Runnable() {
public void run() {
MessageDialog.openError(shell, Messages.StartHandler_3, e.getMessage() + // $NON-NLS-1$
Messages.StartHandler_4);
}
});
return Status.CANCEL_STATUS;
}
} finally {
monitor.worked(ac.getSize() - steps);
}
}
}
monitor.done();
return Status.OK_STATUS;
}
Aggregations