Search in sources :

Example 1 with KeyPairNode

use of org.jcryptool.crypto.keystore.ui.views.nodes.keys.KeyPairNode in project core by jcryptool.

the class KeystoreViewer method hookActions.

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

        @Override
        public Object execute(ExecutionEvent event) {
            ISelection selection = getSelection();
            Object obj = ((IStructuredSelection) selection).getFirstElement();
            if (obj instanceof org.jcryptool.crypto.keystore.ui.views.nodes.TreeNode) {
                if (getTree().getSelection()[0].getExpanded()) {
                    collapseToLevel(obj, 1);
                } else {
                    expandToLevel(obj, 1);
                }
            } else if (obj instanceof KeyPairNode) {
            // OperationsManager.getInstance().algorithmCalled(((AlgorithmNode) obj).getAlgorithm());
            }
            return (null);
        }
    };
    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(KeyStorePlugin.PLUGIN_ID, ex);
                }
            }
        }
    });
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) MouseAdapter(org.eclipse.swt.events.MouseAdapter) AbstractHandler(org.eclipse.core.commands.AbstractHandler) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) ISelection(org.eclipse.jface.viewers.ISelection) ExecutionException(org.eclipse.core.commands.ExecutionException) KeyPairNode(org.jcryptool.crypto.keystore.ui.views.nodes.keys.KeyPairNode)

Example 2 with KeyPairNode

use of org.jcryptool.crypto.keystore.ui.views.nodes.keys.KeyPairNode in project core by jcryptool.

the class KeystoreView method hookContextMenu.

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) {
                fillAddContactMenu(manager);
                return;
            }
            Object selection = viewer.getTree().getSelection()[0].getData();
            if (selection instanceof ContactDescriptorNode) {
                selectedNodeType = NodeType.CONTACT_NODE;
                selectedNodeInfo = ((ContactDescriptorNode) selection).getName();
                fillContactContextMenu(manager);
            } else if (selection instanceof SecretKeyNode) {
                LogUtil.logInfo(((SecretKeyNode) selection).getAlias().getAliasString());
                selectedNodeType = NodeType.SECRETKEY_NODE;
                selectedNodeAlias = ((SecretKeyNode) selection).getAlias();
                selectedSecretKeyNode = ((SecretKeyNode) selection);
                fillSecretKeyContextMenu(manager);
            } else if (selection instanceof KeyPairNode) {
                if (((KeyPairNode) selection).getPrivateKeyAlias() != null)
                    LogUtil.logInfo(((KeyPairNode) selection).getPrivateKeyAlias().getAliasString());
                selectedNodeType = NodeType.KEYPAIR_NODE;
                selectedNodeAlias = ((KeyPairNode) selection).getPrivateKeyAlias();
                selectedKeyPairNode = ((KeyPairNode) selection);
                fillKeyPairContextMenu(manager);
            } else if (selection instanceof CertificateNode) {
                IKeyStoreAlias alias = ((CertificateNode) selection).getAlias();
                if (alias.getKeyStoreEntryType().equals(KeyType.PUBLICKEY)) {
                    selectedNodeType = NodeType.PUBLICKEY_NODE;
                    selectedNodeAlias = ((CertificateNode) selection).getAlias();
                    selectedPublicKeyNode = ((CertificateNode) selection);
                    fillCertificateContextMenu(manager);
                } else if (alias.getKeyStoreEntryType().equals(KeyType.KEYPAIR_PUBLIC_KEY)) {
                    selectedNodeType = NodeType.PUBLICKEY_NODE;
                    selectedNodeAlias = ((CertificateNode) selection).getAlias();
                    selectedPublicKeyNode = ((CertificateNode) selection);
                    fillKeyPairPublicContextMenu(manager);
                }
            }
        }
    });
    Menu menu = menuMgr.createContextMenu(viewer.getControl());
    viewer.getControl().setMenu(menu);
    getSite().registerContextMenu("org.jcryptool.crypto.keystore.popup", menuMgr, viewer);
}
Also used : ContactDescriptorNode(org.jcryptool.crypto.keystore.ui.views.nodes.ContactDescriptorNode) CertificateNode(org.jcryptool.crypto.keystore.ui.views.nodes.keys.CertificateNode) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) SecretKeyNode(org.jcryptool.crypto.keystore.ui.views.nodes.keys.SecretKeyNode) Menu(org.eclipse.swt.widgets.Menu) IMenuListener(org.eclipse.jface.action.IMenuListener) KeyPairNode(org.jcryptool.crypto.keystore.ui.views.nodes.keys.KeyPairNode) IKeyStoreAlias(org.jcryptool.crypto.keystore.keys.IKeyStoreAlias)

Example 3 with KeyPairNode

use of org.jcryptool.crypto.keystore.ui.views.nodes.keys.KeyPairNode in project core by jcryptool.

the class KeyPairContainerNode method remove.

public void remove(IKeyStoreAlias alias) {
    KeyPairNode child = nodes.get(alias.getHashValue());
    nodes.remove(alias.getHashValue());
    removeChild(child);
    Iterator<IKeyStoreListener> it = ContactManager.getInstance().getKeyStoreListeners();
    while (it.hasNext()) {
        it.next().fireKeyStoreModified(this);
    }
}
Also used : KeyPairNode(org.jcryptool.crypto.keystore.ui.views.nodes.keys.KeyPairNode) IKeyStoreListener(org.jcryptool.crypto.keystore.ui.views.interfaces.IKeyStoreListener)

Example 4 with KeyPairNode

use of org.jcryptool.crypto.keystore.ui.views.nodes.keys.KeyPairNode in project core by jcryptool.

the class KeyPairContainerNode method addKeyPair.

public void addKeyPair(IKeyStoreAlias privateKey, IKeyStoreAlias publicKey) {
    if (privateKey != null && publicKey != null) {
        KeyPairNode child = new KeyPairNode(privateKey, publicKey);
        setAppropriateNameForNode(child);
        nodes.put(privateKey.getHashValue(), child);
        addChild(child);
    } else if (privateKey != null) {
        if (nodes.containsKey(privateKey.getHashValue())) {
            nodes.get(privateKey.getHashValue()).addPrivateKey(privateKey);
        } else {
            KeyPairNode child = new KeyPairNode(privateKey, null);
            setAppropriateNameForNode(child);
            nodes.put(privateKey.getHashValue(), child);
            addChild(child);
        }
    } else if (publicKey != null) {
        if (nodes.containsKey(publicKey.getHashValue())) {
            nodes.get(publicKey.getHashValue()).addPublicKey(publicKey);
        } else {
            KeyPairNode child = new KeyPairNode(null, publicKey);
            setAppropriateNameForNode(child);
            nodes.put(publicKey.getHashValue(), child);
            addChild(child);
        }
    }
    Iterator<IKeyStoreListener> it = ContactManager.getInstance().getKeyStoreListeners();
    while (it.hasNext()) {
        it.next().fireKeyStoreModified(this);
    }
}
Also used : KeyPairNode(org.jcryptool.crypto.keystore.ui.views.nodes.keys.KeyPairNode) IKeyStoreListener(org.jcryptool.crypto.keystore.ui.views.interfaces.IKeyStoreListener)

Aggregations

KeyPairNode (org.jcryptool.crypto.keystore.ui.views.nodes.keys.KeyPairNode)4 IKeyStoreListener (org.jcryptool.crypto.keystore.ui.views.interfaces.IKeyStoreListener)2 AbstractHandler (org.eclipse.core.commands.AbstractHandler)1 ExecutionEvent (org.eclipse.core.commands.ExecutionEvent)1 ExecutionException (org.eclipse.core.commands.ExecutionException)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 IKeyStoreAlias (org.jcryptool.crypto.keystore.keys.IKeyStoreAlias)1 ContactDescriptorNode (org.jcryptool.crypto.keystore.ui.views.nodes.ContactDescriptorNode)1 CertificateNode (org.jcryptool.crypto.keystore.ui.views.nodes.keys.CertificateNode)1 SecretKeyNode (org.jcryptool.crypto.keystore.ui.views.nodes.keys.SecretKeyNode)1