Search in sources :

Example 1 with NodeAction

use of com.microsoft.tooling.msservices.serviceexplorer.NodeAction in project azure-tools-for-java by Microsoft.

the class ServerExplorerToolWindowFactory method createPopupMenuForNode.

private JPopupMenu createPopupMenuForNode(Node node) {
    JPopupMenu menu = new JPopupMenu();
    for (final NodeAction nodeAction : node.getNodeActions()) {
        JMenuItem menuItem = new JMenuItem(nodeAction.getName());
        //            menuItem.setIconTextGap(16);
        menuItem.setEnabled(nodeAction.isEnabled());
        if (nodeAction.getIconPath() != null) {
            menuItem.setIcon(UIHelperImpl.loadIcon(nodeAction.getIconPath()));
        }
        // delegate the menu item click to the node action's listeners
        menuItem.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                nodeAction.fireNodeActionEvent();
            }
        });
        menu.add(menuItem);
    }
    return menu;
}
Also used : NodeAction(com.microsoft.tooling.msservices.serviceexplorer.NodeAction) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent)

Example 2 with NodeAction

use of com.microsoft.tooling.msservices.serviceexplorer.NodeAction in project azure-tools-for-java by Microsoft.

the class FileEditorVirtualNode method createJMenuItem.

public JMenuItem createJMenuItem(final String actionName) {
    final JMenuItem menuItem = new JMenuItem(actionName);
    final NodeAction nodeAction = getNodeActionByName(actionName);
    if (nodeAction != null) {
        menuItem.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                nodeAction.fireNodeActionEvent();
            }
        });
    }
    return menuItem;
}
Also used : NodeAction(com.microsoft.tooling.msservices.serviceexplorer.NodeAction) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent)

Example 3 with NodeAction

use of com.microsoft.tooling.msservices.serviceexplorer.NodeAction in project azure-tools-for-java by Microsoft.

the class ExternalStorageNode method refreshItems.

@Override
protected void refreshItems() throws AzureCmdException {
    if (storageAccount.getPrimaryKey().isEmpty()) {
        try {
            NodeActionListener listener = node2Actions.get(this.getClass()).get(0).getConstructor().newInstance();
            listener.actionPerformedAsync(new NodeActionEvent(new NodeAction(this, this.getName()))).get();
        } catch (Throwable t) {
            throw new AzureCmdException("Error opening external storage", t);
        }
    } else {
        fillChildren();
    }
}
Also used : NodeAction(com.microsoft.tooling.msservices.serviceexplorer.NodeAction) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) NodeActionListener(com.microsoft.tooling.msservices.serviceexplorer.NodeActionListener) NodeActionEvent(com.microsoft.tooling.msservices.serviceexplorer.NodeActionEvent)

Example 4 with NodeAction

use of com.microsoft.tooling.msservices.serviceexplorer.NodeAction in project azure-tools-for-java by Microsoft.

the class ServiceExplorerView method hookContextMenu.

private void hookContextMenu() {
    MenuManager menuMgr = new MenuManager("#PopupMenu");
    menuMgr.setRemoveAllWhenShown(true);
    menuMgr.addMenuListener(new IMenuListener() {

        @Override
        public void menuAboutToShow(IMenuManager manager) {
            if (viewer.getSelection().isEmpty()) {
                return;
            }
            if (viewer.getSelection() instanceof IStructuredSelection) {
                IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
                Node node = ((TreeNode) selection.getFirstElement()).node;
                if (node.hasNodeActions()) {
                    for (final NodeAction nodeAction : node.getNodeActions()) {
                        ImageDescriptor imageDescriptor = nodeAction.getIconPath() != null ? Activator.getImageDescriptor("icons/" + nodeAction.getIconPath()) : null;
                        Action action = new Action(nodeAction.getName(), imageDescriptor) {

                            @Override
                            public void run() {
                                nodeAction.fireNodeActionEvent();
                            }
                        };
                        action.setEnabled(nodeAction.isEnabled());
                        manager.add(action);
                    }
                }
            }
        }
    });
    Menu menu = menuMgr.createContextMenu(viewer.getControl());
    viewer.getControl().setMenu(menu);
}
Also used : NodeAction(com.microsoft.tooling.msservices.serviceexplorer.NodeAction) Action(org.eclipse.jface.action.Action) NodeAction(com.microsoft.tooling.msservices.serviceexplorer.NodeAction) Node(com.microsoft.tooling.msservices.serviceexplorer.Node) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) IMenuManager(org.eclipse.jface.action.IMenuManager) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Menu(org.eclipse.swt.widgets.Menu) IMenuListener(org.eclipse.jface.action.IMenuListener)

Aggregations

NodeAction (com.microsoft.tooling.msservices.serviceexplorer.NodeAction)4 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 AzureCmdException (com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)1 Node (com.microsoft.tooling.msservices.serviceexplorer.Node)1 NodeActionEvent (com.microsoft.tooling.msservices.serviceexplorer.NodeActionEvent)1 NodeActionListener (com.microsoft.tooling.msservices.serviceexplorer.NodeActionListener)1 Action (org.eclipse.jface.action.Action)1 IMenuListener (org.eclipse.jface.action.IMenuListener)1 IMenuManager (org.eclipse.jface.action.IMenuManager)1 MenuManager (org.eclipse.jface.action.MenuManager)1 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 Menu (org.eclipse.swt.widgets.Menu)1