Search in sources :

Example 1 with SignatureNode

use of org.jcryptool.crypto.flexiprovider.operations.ui.views.nodes.io.SignatureNode in project core by jcryptool.

the class FlexiProviderOperationsView method hookContextMenu.

// private IExtendedOperationDescriptor currentOperation;
private void hookContextMenu() {
    // $NON-NLS-1$
    MenuManager menuMgr = new MenuManager("#PopupMenu");
    menuMgr.setRemoveAllWhenShown(true);
    menuMgr.addMenuListener(new IMenuListener() {

        public void menuAboutToShow(IMenuManager manager) {
            if (viewer.getTree().getSelection().length > 0) {
                Object selection = viewer.getTree().getSelection()[0].getData();
                if (selection instanceof TreeNode) {
                    currentEntryNode = getCurrentEntryNode((TreeNode) selection);
                }
                if (selection instanceof EntryNode) {
                    fillEntryNodeContextMenu(manager);
                } else if (selection instanceof OperationsNode) {
                    if (displayOperationContextMenu(currentEntryNode)) {
                        fillEncryptDecryptNodeContextMenu(manager);
                    }
                } else if (selection instanceof InputNode) {
                    fillInputContextMenu(manager);
                } else if (selection instanceof OutputNode) {
                    fillOutputContextMenu(manager);
                } else if (selection instanceof SignatureNode) {
                    fillSignatureOutputContextMenu(manager);
                } else if (selection instanceof KeyNode) {
                    fillKeyNodeContextMenu(manager);
                }
            }
        }
    });
    Menu menu = menuMgr.createContextMenu(viewer.getControl());
    viewer.getControl().setMenu(menu);
    getSite().registerContextMenu("org.jcryptool.crypto.flexiprovider.operations.popup", menuMgr, viewer);
}
Also used : InputNode(org.jcryptool.crypto.flexiprovider.operations.ui.views.nodes.io.InputNode) OutputNode(org.jcryptool.crypto.flexiprovider.operations.ui.views.nodes.io.OutputNode) TreeNode(org.jcryptool.crypto.flexiprovider.ui.nodes.TreeNode) ITreeNode(org.jcryptool.crypto.flexiprovider.ui.nodes.ITreeNode) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) EntryNode(org.jcryptool.crypto.flexiprovider.operations.ui.views.nodes.EntryNode) KeyNode(org.jcryptool.crypto.flexiprovider.operations.ui.views.nodes.keys.KeyNode) IMenuManager(org.eclipse.jface.action.IMenuManager) OperationsNode(org.jcryptool.crypto.flexiprovider.operations.ui.views.nodes.ops.OperationsNode) Menu(org.eclipse.swt.widgets.Menu) SignatureNode(org.jcryptool.crypto.flexiprovider.operations.ui.views.nodes.io.SignatureNode) IMenuListener(org.eclipse.jface.action.IMenuListener)

Example 2 with SignatureNode

use of org.jcryptool.crypto.flexiprovider.operations.ui.views.nodes.io.SignatureNode in project core by jcryptool.

the class FlexiProviderOperationsView method hookActions.

/**
 * Adds a listener, which will fold or unfold the nodes.
 */
private void hookActions() {
    doubleClickHandler = new AbstractHandler() {

        private ToolTip keyTipViewer;

        @Override
        public Object execute(ExecutionEvent event) {
            ISelection selection = viewer.getSelection();
            Object obj = ((IStructuredSelection) selection).getFirstElement();
            if (obj instanceof TreeNode) {
                if (viewer.getTree().getSelection()[0].getExpanded()) {
                    viewer.collapseToLevel(obj, 1);
                } else {
                    viewer.expandToLevel(obj, 1);
                }
            } else if (obj instanceof OperationsNode) {
            // OperationsManager.getInstance().algorithmCalled(((AlgorithmNode)
            // obj).getAlgorithm());
            }
            if (obj instanceof KeyNode) {
                if (keyTipViewer != null && !keyTipViewer.isDisposed())
                    keyTipViewer.dispose();
                keyTipViewer = new ToolTip(viewer.getControl().getShell(), SWT.BALLOON);
                keyTipViewer.setMessage(Messages.FlexiProviderOperationsView_keystore_hint);
                keyTipViewer.setAutoHide(true);
                keyTipViewer.setLocation(MouseInfo.getPointerInfo().getLocation().x, MouseInfo.getPointerInfo().getLocation().y);
                keyTipViewer.setVisible(true);
            }
            if (obj instanceof IONode || obj instanceof InputNode || obj instanceof SignatureNode) {
                // Event e = new Event();
                // e.widget = viewer.getTree();
                // e.x = viewer.getTree().toControl(MouseInfo.getPointerInfo().getLocation().x,
                // MouseInfo.getPointerInfo().getLocation().y).x;
                // e.y = viewer.getTree().toControl(MouseInfo.getPointerInfo().getLocation().x,
                // MouseInfo.getPointerInfo().getLocation().y).y;
                // e.button = 3;
                // e.stateMask = 0;
                // e.count = 1;
                // MouseEvent mE = new MouseEvent(e);
                // viewer.getTree().notifyListeners(SWT.MouseDown, e);
                viewer.getControl().getMenu().setVisible(true);
                viewer.getControl().getMenu().setEnabled(true);
            }
            if (obj instanceof OperationsNode) {
                if (obj instanceof TreeNode) {
                    currentEntryNode = getCurrentEntryNode((TreeNode) obj);
                    if (displayOperationContextMenu(currentEntryNode)) {
                        viewer.getControl().getMenu().setVisible(true);
                        viewer.getControl().getMenu().setEnabled(true);
                    } else {
                        if (keyTipViewer != null && !keyTipViewer.isDisposed())
                            keyTipViewer.dispose();
                        keyTipViewer = new ToolTip(viewer.getControl().getShell(), SWT.BALLOON);
                        keyTipViewer.setMessage(Messages.FlexiProviderOperationsView_keystore_hint_operations);
                        keyTipViewer.setAutoHide(true);
                        keyTipViewer.setLocation(MouseInfo.getPointerInfo().getLocation().x, MouseInfo.getPointerInfo().getLocation().y);
                        keyTipViewer.setVisible(true);
                    }
                }
            }
            return (null);
        }
    };
    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 (Exception ex) {
                    LogUtil.logError(FlexiProviderOperationsPlugin.PLUGIN_ID, ex);
                }
            }
        }
    });
}
Also used : ToolTip(org.eclipse.swt.widgets.ToolTip) InputNode(org.jcryptool.crypto.flexiprovider.operations.ui.views.nodes.io.InputNode) MouseEvent(org.eclipse.swt.events.MouseEvent) MouseAdapter(org.eclipse.swt.events.MouseAdapter) OperationsNode(org.jcryptool.crypto.flexiprovider.operations.ui.views.nodes.ops.OperationsNode) SignatureNode(org.jcryptool.crypto.flexiprovider.operations.ui.views.nodes.io.SignatureNode) AbstractHandler(org.eclipse.core.commands.AbstractHandler) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) TreeNode(org.jcryptool.crypto.flexiprovider.ui.nodes.TreeNode) ITreeNode(org.jcryptool.crypto.flexiprovider.ui.nodes.ITreeNode) ISelection(org.eclipse.jface.viewers.ISelection) IONode(org.jcryptool.crypto.flexiprovider.operations.ui.views.nodes.io.IONode) KeyNode(org.jcryptool.crypto.flexiprovider.operations.ui.views.nodes.keys.KeyNode)

Aggregations

InputNode (org.jcryptool.crypto.flexiprovider.operations.ui.views.nodes.io.InputNode)2 SignatureNode (org.jcryptool.crypto.flexiprovider.operations.ui.views.nodes.io.SignatureNode)2 KeyNode (org.jcryptool.crypto.flexiprovider.operations.ui.views.nodes.keys.KeyNode)2 OperationsNode (org.jcryptool.crypto.flexiprovider.operations.ui.views.nodes.ops.OperationsNode)2 ITreeNode (org.jcryptool.crypto.flexiprovider.ui.nodes.ITreeNode)2 TreeNode (org.jcryptool.crypto.flexiprovider.ui.nodes.TreeNode)2 AbstractHandler (org.eclipse.core.commands.AbstractHandler)1 ExecutionEvent (org.eclipse.core.commands.ExecutionEvent)1 IMenuListener (org.eclipse.jface.action.IMenuListener)1 IMenuManager (org.eclipse.jface.action.IMenuManager)1 MenuManager (org.eclipse.jface.action.MenuManager)1 ISelection (org.eclipse.jface.viewers.ISelection)1 MouseAdapter (org.eclipse.swt.events.MouseAdapter)1 MouseEvent (org.eclipse.swt.events.MouseEvent)1 Menu (org.eclipse.swt.widgets.Menu)1 ToolTip (org.eclipse.swt.widgets.ToolTip)1 EntryNode (org.jcryptool.crypto.flexiprovider.operations.ui.views.nodes.EntryNode)1 IONode (org.jcryptool.crypto.flexiprovider.operations.ui.views.nodes.io.IONode)1 OutputNode (org.jcryptool.crypto.flexiprovider.operations.ui.views.nodes.io.OutputNode)1