use of org.jcryptool.crypto.keystore.ui.views.nodes.ContactDescriptorNode 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);
}
Aggregations