use of org.jcryptool.crypto.flexiprovider.algorithms.ui.views.nodes.AlgorithmNode in project core by jcryptool.
the class FlexiProviderAlgorithmsView method hookActions.
/**
* Adds an listener, which will provide the context help for a selected algorithm. If for a child is no context help
* available, it will use the parents context help
*/
@SuppressWarnings("unchecked")
private void hookActions(String xmlfile) {
doubleClickHandler = new AbstractHandler() {
public Object execute(ExecutionEvent event) {
ISelection selection = viewer.getSelection();
Object obj = ((IStructuredSelection) selection).getFirstElement();
if (obj instanceof CategoryNode || obj instanceof FolderNode) {
if (viewer.getTree().getSelection()[0].getExpanded()) {
viewer.collapseToLevel(obj, 1);
} else {
viewer.expandToLevel(obj, 1);
}
} else if (obj instanceof AlgorithmNode) {
AlgorithmsManager.getInstance().algorithmCalled(((AlgorithmNode) obj).getAlgorithm());
}
return (null);
}
};
URL xmlFile = FlexiProviderAlgorithmsPlugin.getDefault().getBundle().getEntry(xmlfile);
SAXBuilder builder = new SAXBuilder();
// Build a lookup table for the names defined in xml/help_algorithmis.xml
// to the according context id (in $nl$/contexts_algorithms.xml)
final Hashtable<String, String> contextIdLookup = new Hashtable<String, String>();
try {
Document doc = builder.build(xmlFile);
Element root = doc.getRootElement();
List<Element> helpEntries = root.getChildren("helpentry");
for (Element helpEntry : helpEntries) {
String mainname = helpEntry.getAttributeValue("mainname");
String contextid = helpEntry.getAttributeValue("contextid");
contextIdLookup.put(mainname, contextid);
Element aliasesRoot = helpEntry.getChild("aliases");
if (aliasesRoot != null) {
List<Element> aliases = aliasesRoot.getChildren("alias");
for (Element alias : aliases) {
contextIdLookup.put(alias.getValue(), contextid);
}
}
}
viewer.getControl().addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(final MouseEvent e) {
if (e.button == 1) {
// only left button double clicks
try {
// run assigned action
doubleClickHandler.execute(null);
} catch (ExecutionException ex) {
LogUtil.logError(FlexiProviderAlgorithmsPlugin.PLUGIN_ID, ex);
}
}
}
@Override
public void mouseDown(final MouseEvent event) {
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
Object obj = ((IStructuredSelection) selection).getFirstElement();
if (obj instanceof ITreeNode) {
ITreeNode node = (ITreeNode) obj;
// display help of parent entry if no context help is available
do {
String name = node.toString();
if (contextIdLookup.containsKey(name)) {
String contextId = FlexiProviderAlgorithmsPlugin.PLUGIN_ID + "." + contextIdLookup.get(name);
PlatformUI.getWorkbench().getHelpSystem().displayHelp(contextId);
break;
}
node = node.getParent();
} while (node != null);
viewer.getControl().setFocus();
viewer.setSelection(selection);
}
}
});
} catch (JDOMException e) {
LogUtil.logError(FlexiProviderAlgorithmsPlugin.PLUGIN_ID, e);
} catch (IOException e) {
LogUtil.logError(FlexiProviderAlgorithmsPlugin.PLUGIN_ID, e);
}
}
use of org.jcryptool.crypto.flexiprovider.algorithms.ui.views.nodes.AlgorithmNode in project core by jcryptool.
the class FlexiProviderAlgorithmsViewContentProvider method init.
private static CategoryNode init(String label, List<IMetaAlgorithm> algorithms) {
CategoryNode category = new CategoryNode(label);
// should be sorted already. just to be on the save side.
Collections.sort(algorithms);
// top level entries
for (IMetaAlgorithm meta : algorithms) {
if (!meta.getClassName().contains("$")) {
// $NON-NLS-1$
category.addChild(new AlgorithmNode(meta));
}
}
// sub level entries
for (IMetaAlgorithm meta : algorithms) {
if (meta.getClassName().contains("$")) {
// $NON-NLS-1$
// $NON-NLS-1$
String primaryPrefix = meta.getClassName().substring(0, meta.getClassName().indexOf("$"));
if (containsClassName(primaryPrefix, algorithms)) {
// recursive entries
buildAlgorithmHierarchy(category, meta);
} else {
// folder entries
// $NON-NLS-1$ //$NON-NLS-2$
String prefix = meta.getClassName().substring(meta.getClassName().lastIndexOf(".") + 1, meta.getClassName().indexOf("$"));
ITreeNode folder = new FolderNode(prefix);
for (IMetaAlgorithm meta2 : algorithms) {
if (meta2.getClassName().contains("$")) {
// $NON-NLS-1$
if (meta2.getClassName().contains("." + prefix)) {
// $NON-NLS-1$
folder.addChild(new AlgorithmNode(meta2));
}
}
}
category.addChild(folder);
}
}
}
return category;
}
Aggregations