Search in sources :

Example 1 with TreeParent

use of org.jcryptool.core.views.content.structure.TreeParent 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();
            }
        }
    });
}
Also used : TreeParent(org.jcryptool.core.views.content.structure.TreeParent) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) AbstractHandler(org.eclipse.core.commands.AbstractHandler) ICommandService(org.eclipse.ui.commands.ICommandService) ExecutionException(org.eclipse.core.commands.ExecutionException) IHandlerService(org.eclipse.ui.handlers.IHandlerService) Command(org.eclipse.core.commands.Command) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) TreeObject(org.jcryptool.core.views.content.structure.TreeObject) TreeObject(org.jcryptool.core.views.content.structure.TreeObject) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 2 with TreeParent

use of org.jcryptool.core.views.content.structure.TreeParent 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());
            }
        }
    });
}
Also used : DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) DragSourceAdapter(org.eclipse.swt.dnd.DragSourceAdapter) DropTargetAdapter(org.eclipse.swt.dnd.DropTargetAdapter) TreeItem(org.eclipse.swt.widgets.TreeItem) TreeParent(org.jcryptool.core.views.content.structure.TreeParent) TreeObject(org.jcryptool.core.views.content.structure.TreeObject) TreeObject(org.jcryptool.core.views.content.structure.TreeObject) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent)

Example 3 with TreeParent

use of org.jcryptool.core.views.content.structure.TreeParent 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());
    }
}
Also used : CommandInfo(org.jcryptool.core.operations.CommandInfo) HashMap(java.util.HashMap) ShadowAlgorithmHandler(org.jcryptool.core.operations.algorithm.ShadowAlgorithmHandler) TreeParent(org.jcryptool.core.views.content.structure.TreeParent) ArrayList(java.util.ArrayList) TreeObject(org.jcryptool.core.views.content.structure.TreeObject)

Example 4 with TreeParent

use of org.jcryptool.core.views.content.structure.TreeParent 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")));
    }
}
Also used : IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) TreeParent(org.jcryptool.core.views.content.structure.TreeParent) TreeObject(org.jcryptool.core.views.content.structure.TreeObject) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement)

Example 5 with TreeParent

use of org.jcryptool.core.views.content.structure.TreeParent 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();
            }
        }
    });
}
Also used : ShadowAlgorithmHandler(org.jcryptool.core.operations.algorithm.ShadowAlgorithmHandler) TreeParent(org.jcryptool.core.views.content.structure.TreeParent) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) AbstractHandler(org.eclipse.core.commands.AbstractHandler) ICommandService(org.eclipse.ui.commands.ICommandService) PartInitException(org.eclipse.ui.PartInitException) ExecutionException(org.eclipse.core.commands.ExecutionException) CommandInfo(org.jcryptool.core.operations.CommandInfo) IHandlerService(org.eclipse.ui.handlers.IHandlerService) Command(org.eclipse.core.commands.Command) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) Iterator(java.util.Iterator) TreeObject(org.jcryptool.core.views.content.structure.TreeObject) TreeObject(org.jcryptool.core.views.content.structure.TreeObject) ExecutionException(org.eclipse.core.commands.ExecutionException)

Aggregations

TreeObject (org.jcryptool.core.views.content.structure.TreeObject)5 TreeParent (org.jcryptool.core.views.content.structure.TreeParent)5 AbstractHandler (org.eclipse.core.commands.AbstractHandler)2 Command (org.eclipse.core.commands.Command)2 ExecutionEvent (org.eclipse.core.commands.ExecutionEvent)2 ExecutionException (org.eclipse.core.commands.ExecutionException)2 IEvaluationContext (org.eclipse.core.expressions.IEvaluationContext)2 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)2 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)2 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)2 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)2 ICommandService (org.eclipse.ui.commands.ICommandService)2 IHandlerService (org.eclipse.ui.handlers.IHandlerService)2 CommandInfo (org.jcryptool.core.operations.CommandInfo)2 ShadowAlgorithmHandler (org.jcryptool.core.operations.algorithm.ShadowAlgorithmHandler)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1