use of org.jcryptool.core.operations.algorithm.ShadowAlgorithmHandler in project core by jcryptool.
the class AlgorithmView method doAction.
/**
* used to trigger actions when an algorithm is drag&dropped to an editor
*
* @param algorithmName the name of the algorithm whose action is to be done
*/
public static void doAction(String algorithmName) {
Iterator<ShadowAlgorithmHandler> it9 = algorithmTypes.iterator();
ShadowAlgorithmHandler handler = null;
while (it9.hasNext()) {
handler = it9.next();
// TODO the text property doesn't belong in the Handler but in the CommandInfo
if (algorithmName.equals(handler.getText())) {
// TODO maybe Command.executeWithChecks() should be called here, which also requires an ExecutionEvent
handler.execute(null);
}
}
}
use of org.jcryptool.core.operations.algorithm.ShadowAlgorithmHandler in project core by jcryptool.
the class AlgorithmPaletteViewer method createTree.
/**
* creates a tree representation of the algorithm structure
*
* @param needles
* a search string to filter the algorithms
*/
private void createTree(String[] needles) {
invisibleRoot = new PaletteRoot();
TreeMap<String, PaletteDrawer> types = new TreeMap<String, PaletteDrawer>();
TreeMap<String, SelectionToolEntry> sortList = new TreeMap<String, SelectionToolEntry>();
Iterator<CommandInfo> it = algorithmList.iterator();
CommandInfo info = null;
while (it.hasNext()) {
info = it.next();
String text = "";
String type = "";
String toolTipText = "";
boolean isFlexiProviderAlgorithm = false;
ShadowAlgorithmHandler handler = (ShadowAlgorithmHandler) info.getHandler();
text = handler.getText();
type = handler.getType();
toolTipText = handler.getToolTipText();
isFlexiProviderAlgorithm = handler.isFlexiProviderAlgorithm();
// filter
boolean show = true;
for (String needle : needles) {
if (!text.toLowerCase().matches(// $NON-NLS-1$ //$NON-NLS-2$
".*" + needle.toLowerCase() + ".*"))
show = false;
}
if (show) {
// Create Category
if (types.get(type) == null) {
// translate
type = ApplicationActionBarAdvisor.getTypeTranslation(type);
PaletteDrawer paletteDrawer = new PaletteDrawer(type);
paletteDrawer.setSmallIcon(ViewsPlugin.getImageDescriptor(TreeView.ICON_FOLDER));
paletteDrawer.setLargeIcon(ViewsPlugin.getImageDescriptor(TreeView.ICON_FOLDER));
types.put(type, paletteDrawer);
}
// Add element
SelectionToolEntry paletteEntry = new SelectionToolEntry(text, toolTipText);
if (isFlexiProviderAlgorithm) {
// FlexiProvider item
paletteEntry.setSmallIcon(ViewsPlugin.getImageDescriptor(TreeView.ICON_ITEM_FLEXI));
paletteEntry.setLargeIcon(ViewsPlugin.getImageDescriptor(TreeView.ICON_ITEM_FLEXI));
} else {
// JCrypTool item
paletteEntry.setSmallIcon(ViewsPlugin.getImageDescriptor(TreeView.ICON_ITEM_JCT));
paletteEntry.setLargeIcon(ViewsPlugin.getImageDescriptor(TreeView.ICON_ITEM_JCT));
}
paletteEntry.setUserModificationPermission(PaletteEntry.PERMISSION_NO_MODIFICATION);
paletteEntry.setType(type);
// temporary save in list
sortList.put(paletteEntry.getLabel(), paletteEntry);
}
}
ArrayList<PaletteDrawer> parents = new ArrayList<PaletteDrawer>(types.values());
for (SelectionToolEntry paletteEntry : sortList.values()) {
// read from sorted list
// put sorted into palette
types.get(paletteEntry.getType()).add(paletteEntry);
}
// attach tree to the root element
Iterator<PaletteDrawer> parentIterator2 = parents.iterator();
while (parentIterator2.hasNext()) {
invisibleRoot.add(parentIterator2.next());
}
}
use of org.jcryptool.core.operations.algorithm.ShadowAlgorithmHandler in project core by jcryptool.
the class AlgorithmPaletteViewer method makeAndAssignActions.
/**
* Constructs the actions according to the algorithm extension point and
* assigns the actions to the doubleclick listener of the viewer
*/
private void makeAndAssignActions() {
doubleClickHandler = new AbstractHandler() {
public Object execute(ExecutionEvent event) {
Object selection = ((IStructuredSelection) viewer.getSelection()).getFirstElement();
if (selection instanceof PaletteEditPart) {
PaletteEditPart paletteEditPart = (PaletteEditPart) selection;
Object model = paletteEditPart.getModel();
IEditorReference[] editorReferences = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
if (editorReferences.length == 0 && (!((PaletteEntry) model).getParent().getLabel().equals(org.jcryptool.core.Messages.applicationActionBarAdvisor_Menu_Algorithms_PRNG))) {
AlgorithmView.showMessage(Messages.AlgorithmPaletteViewer_0);
} 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 && model.toString().equals("Palette Entry (" + handler.getText() + ")")) {
// $NON-NLS-1$ //$NON-NLS-2$
Command command = commandService.getCommand(commandId);
try {
return command.executeWithChecks(event);
} catch (Exception ex) {
LogUtil.logError(ViewsPlugin.PLUGIN_ID, ex);
return (null);
}
}
}
}
}
return (null);
}
};
viewer.getControl().addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(final MouseEvent e) {
if (e.button == 1) {
// only left button double clicks
final IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class);
IEvaluationContext evaluationContext = handlerService.createContextSnapshot(true);
ExecutionEvent event = new ExecutionEvent(null, Collections.EMPTY_MAP, null, evaluationContext);
try {
// run assigned action
doubleClickHandler.execute(event);
} catch (ExecutionException ex) {
LogUtil.logError(ViewsPlugin.PLUGIN_ID, ex);
}
}
}
@Override
public void mouseDown(final MouseEvent e) {
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
Object obj = selection.getFirstElement();
if (obj instanceof PaletteEditPart) {
AlgorithmView.showContextHelp(extensionPointId, ((PaletteEntry) ((PaletteEditPart) obj).getModel()).getLabel());
viewer.getControl().setFocus();
viewer.setSelection(selection);
}
}
});
}
use of org.jcryptool.core.operations.algorithm.ShadowAlgorithmHandler in project core by jcryptool.
the class AlgorithmTreeViewer method createTree.
/**
* creates a tree for the algorithm structure
*
* @param needles the search string to filter the algorithms
*/
private void createTree(String[] needles) {
HashMap<String, TreeParent> types = new HashMap<String, TreeParent>();
Iterator<CommandInfo> it = algorithmList.iterator();
CommandInfo info = null;
while (it.hasNext()) {
info = it.next();
String text = "";
String type = "";
boolean isFlexiProviderAlgorithm = false;
ShadowAlgorithmHandler handler = (ShadowAlgorithmHandler) info.getHandler();
text = handler.getText();
type = handler.getType();
isFlexiProviderAlgorithm = handler.isFlexiProviderAlgorithm();
// filter
boolean show = true;
for (String needle : needles) {
if (// $NON-NLS-1$ //$NON-NLS-2$
!text.toLowerCase().matches(".*" + needle.toLowerCase() + ".*"))
show = false;
}
if (show) {
// Create Category
if (types.get(type) == null) {
// translate
String translatedType = ApplicationActionBarAdvisor.getTypeTranslation(type);
types.put(type, new TreeParent(translatedType));
}
// Add element
TreeObject object = new TreeObject(text);
if (isFlexiProviderAlgorithm)
object.setIsFlexiProviderAlgorithm();
types.get(type).addChild(object);
}
}
ArrayList<TreeParent> parents = new ArrayList<TreeParent>(types.values());
// attach categories to root element
// $NON-NLS-1$
invisibleRoot = new TreeParent("");
Iterator<TreeParent> parentIterator2 = parents.iterator();
while (parentIterator2.hasNext()) {
invisibleRoot.addChild(parentIterator2.next());
}
}
use of org.jcryptool.core.operations.algorithm.ShadowAlgorithmHandler 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();
}
}
});
}
Aggregations