use of org.jcryptool.core.operations.CommandInfo in project core by jcryptool.
the class CryptoContributionItem method fill.
public void fill(Menu menu, int index) {
algorithmsMenu = new Menu(menu);
Comparator<String> menuStringsComparator = new Comparator<String>() {
public int compare(String o1, String o2) {
return o1.toLowerCase().compareTo(o2.toLowerCase());
}
};
SortedMap<String, Menu> typeMap = new TreeMap<String, Menu>(menuStringsComparator);
SortedMap<String, HashMap<String, CommandInfo>> commandMap = new TreeMap<String, HashMap<String, CommandInfo>>(menuStringsComparator);
CommandInfo[] algorithmCommands = OperationsPlugin.getDefault().getAlgorithmsManager().getShadowAlgorithmCommands();
for (final CommandInfo commandInfo : algorithmCommands) {
String translatedType = ApplicationActionBarAdvisor.getTypeTranslation(OperationsPlugin.getDefault().getAlgorithmsManager().getAlgorithmType(commandInfo));
if (!typeMap.containsKey(translatedType)) {
typeMap.put(translatedType, new Menu(algorithmsMenu));
}
HashMap<String, CommandInfo> map = new HashMap<String, CommandInfo>(1);
map.put(translatedType, commandInfo);
String text = null;
text = commandInfo.getText();
commandMap.put(text, map);
}
for (String subMenuKey : typeMap.keySet()) {
MenuItem item = new MenuItem(algorithmsMenu, SWT.CASCADE);
item.setText(subMenuKey);
item.setMenu(typeMap.get(subMenuKey));
}
for (HashMap<String, CommandInfo> algorithmItems : commandMap.values()) {
String translatedType = algorithmItems.keySet().iterator().next();
final CommandInfo commandInfo = algorithmItems.get(translatedType);
// get the menu
Menu typeMenu = typeMap.get(translatedType);
// create an item for the algorithm
MenuItem item = new MenuItem(typeMenu, SWT.CASCADE);
final String commandId = commandInfo.getCommandId();
item.setText(commandInfo.getText());
item.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
run(commandId);
}
});
// update the menu
typeMap.put(translatedType, typeMenu);
}
MenuItem item = new MenuItem(menu, SWT.CASCADE, index);
item.setText(Messages.CryptoContributionItem_0);
item.setMenu(algorithmsMenu);
}
use of org.jcryptool.core.operations.CommandInfo 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.CommandInfo 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.CommandInfo 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.CommandInfo in project core by jcryptool.
the class ApplicationActionBarAdvisor method createAlgorithmMenu.
/**
* Creates the algorithm menu.
*
* @return the menu manager
*/
public static IMenuManager createAlgorithmMenu() {
ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
MenuManager menu = new MenuManager(Messages.applicationActionBarAdvisor_Menu_Algorithms, // $NON-NLS-1$
CorePlugin.PLUGIN_ID + ".algorithms");
// id->compare-relevant-name map
final Map<String, String> idNameMap = new HashMap<String, String>();
// id-comparator (compares the names derived from the ids over the map (above)
Comparator<String> idComparator = new Comparator<String>() {
public int compare(String id1, String id2) {
return menuStringsComparator.compare(idNameMap.get(id1), idNameMap.get(id2));
}
};
// put existing id->name pairs
// $NON-NLS-1$
idNameMap.put("classic", Messages.applicationActionBarAdvisor_Menu_Algorithms_Classic);
// $NON-NLS-1$
idNameMap.put("symmetric", Messages.applicationActionBarAdvisor_Menu_Algorithms_Symmetric);
// $NON-NLS-1$
idNameMap.put("asymmetric", Messages.applicationActionBarAdvisor_Menu_Algorithms_Asymmetric);
// $NON-NLS-1$
idNameMap.put("hybrid", Messages.applicationActionBarAdvisor_Menu_Algorithms_Hybrid);
// $NON-NLS-1$
idNameMap.put("hash", Messages.applicationActionBarAdvisor_Menu_Algorithms_Hash);
// $NON-NLS-1$
idNameMap.put("misc", Messages.applicationActionBarAdvisor_Menu_Algorithms_Misc);
// $NON-NLS-1$
idNameMap.put("mac", Messages.applicationActionBarAdvisor_Menu_Algorithms_Mac);
// $NON-NLS-1$
idNameMap.put("prng", Messages.applicationActionBarAdvisor_Menu_Algorithms_PRNG);
// $NON-NLS-1$
idNameMap.put("signature", Messages.applicationActionBarAdvisor_Menu_Algorithms_Signature);
// $NON-NLS-1$
idNameMap.put("xml", Messages.applicationActionBarAdvisor_Menu_Algorithms_XML_Security);
// Sorted submenus map
SortedMap<String, SortedMap<String, CommandInfo>> sortedSubMenus = new TreeMap<String, SortedMap<String, CommandInfo>>(idComparator);
// fill sub menu sorting map
for (CommandInfo algorithmCommand : algorithmCommands) {
String type = OperationsPlugin.getDefault().getAlgorithmsManager().getAlgorithmType(algorithmCommand);
if (!sortedSubMenus.containsKey(type)) {
// algorithm type) when id has no textual mapping
if (!idNameMap.containsKey(type)) {
idNameMap.put(type, type);
}
// make a new submenu
sortedSubMenus.put(type, new TreeMap<String, CommandInfo>(menuStringsComparator));
}
sortedSubMenus.get(type).put(algorithmCommand.getText(), algorithmCommand);
}
for (String subMenuKey : sortedSubMenus.keySet()) {
MenuManager subMenu = new MenuManager(idNameMap.get(subMenuKey), subMenuKey);
menu.add(subMenu);
Map<String, CommandInfo> subMenuActions = sortedSubMenus.get(subMenuKey);
for (String subMenuActionKey : subMenuActions.keySet()) {
CommandInfo commandInfo = subMenuActions.get(subMenuActionKey);
Command cmd = commandService.getCommand(commandInfo.getCommandId());
cmd.define(commandInfo.getText(), null, commandService.getCategory(CommandManager.AUTOGENERATED_CATEGORY_ID));
cmd.setHandler(commandInfo.getHandler());
subMenu.add(createContributionItem(PlatformUI.getWorkbench(), null, commandInfo.getCommandId()));
}
}
menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
return menu;
}
Aggregations