use of org.jcryptool.core.views.content.structure.TreeObject in project core by jcryptool.
the class ViewProviderTreeViewer method makeAndAssignActions.
/**
* creates the actions and assigns them to the viewers double click listener
*/
private void makeAndAssignActions() {
doubleClickHandler = new AbstractHandler() {
public Object execute(ExecutionEvent event) {
final ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
TreeObject treeObject = (TreeObject) ((IStructuredSelection) viewer.getSelection()).getFirstElement();
IConfigurationElement[] elements = Platform.getExtensionRegistry().getExtensionPoint(extensionPointId).getConfigurationElements();
for (IConfigurationElement element : elements) {
if (element.getAttribute("name").equals(treeObject.getName())) {
// $NON-NLS-1$
// $NON-NLS-1$
Command command = commandService.getCommand(element.getAttribute("viewId"));
try {
return command.executeWithChecks(event);
} catch (Exception ex) {
LogUtil.logError(ViewsPlugin.PLUGIN_ID, ex);
}
}
}
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.views.content.structure.TreeObject in project core by jcryptool.
the class AlgorithmTreeViewer method setupDragAndDrop.
/**
* enables the drag'n'drop functionality
*/
private void setupDragAndDrop() {
viewer.addDragSupport(DND.DROP_MOVE, new Transfer[] { TextTransfer.getInstance() }, new DragSourceAdapter() {
public void dragStart(DragSourceEvent event) {
Object obj = ((IStructuredSelection) viewer.getSelection()).getFirstElement();
if (obj instanceof TreeParent) {
// only allow drag&drop for algorithm and not for categories
event.doit = false;
} else if (obj instanceof TreeObject) {
// random number generators have no drag&drop
if (((TreeObject) obj).getParent().getName().equals(org.jcryptool.core.Messages.applicationActionBarAdvisor_Menu_Algorithms_PRNG))
event.doit = false;
}
}
public void dragSetData(DragSourceEvent event) {
event.data = viewer.getTree().getSelection()[0].getText();
}
});
viewer.addDropSupport(DND.DROP_MOVE, new Transfer[] { FileTransfer.getInstance() }, new DropTargetAdapter() {
public void dragOver(DropTargetEvent event) {
if (event.item.getData() instanceof TreeParent) {
event.feedback = DND.DROP_NONE;
return;
} else if (event.item.getData() instanceof TreeObject) {
if (((TreeItem) event.item).getParentItem().getText().equalsIgnoreCase(org.jcryptool.core.Messages.applicationActionBarAdvisor_Menu_Algorithms_PRNG)) {
event.feedback = DND.DROP_NONE;
}
return;
}
}
public void drop(DropTargetEvent event) {
if (event.item instanceof TreeItem) {
String url = ((String[]) event.data)[0];
if (openFile(url))
AlgorithmView.doAction(((TreeItem) event.item).getText());
}
}
});
}
use of org.jcryptool.core.views.content.structure.TreeObject 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.views.content.structure.TreeObject in project core by jcryptool.
the class ViewProviderTreeViewer method createTree.
/**
* creates a tree from the extension point structure
*
* @param needles the search string to filter the elements
*/
private void createTree(String[] needles) {
// $NON-NLS-1$
invisibleRoot = new TreeParent("");
IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(extensionPointId);
// $NON-NLS-1$
String label = "";
if (extensionPoint.getLabel().equals("analysis")) {
// $NON-NLS-1$
label = AlgorithmView.MENU_TEXT_ANALYSIS;
} else if (extensionPoint.getLabel().equals("games")) {
// $NON-NLS-1$
label = AlgorithmView.MENU_TEXT_GAMES;
} else if (extensionPoint.getLabel().equals("visuals")) {
// $NON-NLS-1$
label = AlgorithmView.MENU_TEXT_VISUALS;
}
TreeParent category = new TreeParent(label);
invisibleRoot.addChild(category);
for (IConfigurationElement element : extensionPoint.getConfigurationElements()) {
// $NON-NLS-1$
String name = element.getAttribute("name");
// filter
boolean show = true;
for (String needle : needles) {
if (// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
!needle.equals("") && !name.toLowerCase().matches(".*" + needle.toLowerCase() + ".*"))
show = false;
}
if (// add element
show)
// $NON-NLS-1$
category.addChild(new TreeObject(element.getAttribute("name")));
}
}
use of org.jcryptool.core.views.content.structure.TreeObject 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