Search in sources :

Example 11 with JBPopupMenu

use of com.intellij.openapi.ui.JBPopupMenu in project android by JetBrains.

the class ManifestPanel method createPopupMenu.

private void createPopupMenu() {
    myPopup = new JBPopupMenu();
    JMenuItem gotoItem = new JBMenuItem("Go to Declaration");
    gotoItem.addActionListener(e -> {
        TreePath treePath = myTree.getSelectionPath();
        final ManifestTreeNode node = (ManifestTreeNode) treePath.getLastPathComponent();
        if (node != null) {
            goToDeclaration(node.getUserObject());
        }
    });
    myPopup.add(gotoItem);
    myRemoveItem = new JBMenuItem("Remove");
    myRemoveItem.addActionListener(e -> {
        TreePath treePath = myTree.getSelectionPath();
        final ManifestTreeNode node = (ManifestTreeNode) treePath.getLastPathComponent();
        new WriteCommandAction.Simple(myFacet.getModule().getProject(), "Removing manifest tag", ManifestUtils.getMainManifest(myFacet)) {

            @Override
            protected void run() throws Throwable {
                ManifestUtils.toolsRemove(ManifestUtils.getMainManifest(myFacet), node.getUserObject());
            }
        }.execute();
    });
    myPopup.add(myRemoveItem);
    MouseListener ml = new MouseAdapter() {

        @Override
        public void mousePressed(@NotNull MouseEvent e) {
            if (e.isPopupTrigger()) {
                handlePopup(e);
            }
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            if (e.isPopupTrigger()) {
                handlePopup(e);
            }
        }

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) {
                TreePath treePath = myTree.getPathForLocation(e.getX(), e.getY());
                if (treePath != null) {
                    ManifestTreeNode node = (ManifestTreeNode) treePath.getLastPathComponent();
                    Node attribute = node.getUserObject();
                    if (attribute instanceof Attr) {
                        goToDeclaration(attribute);
                    }
                }
            }
        }

        private void handlePopup(@NotNull MouseEvent e) {
            TreePath treePath = myTree.getPathForLocation(e.getX(), e.getY());
            if (treePath == null || e.getSource() == myDetails) {
                // Use selection instead
                treePath = myTree.getSelectionPath();
            }
            if (treePath != null) {
                ManifestTreeNode node = (ManifestTreeNode) treePath.getLastPathComponent();
                myRemoveItem.setEnabled(canRemove(node.getUserObject()));
                myPopup.show(e.getComponent(), e.getX(), e.getY());
            }
        }
    };
    myTree.addMouseListener(ml);
    myDetails.addMouseListener(ml);
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) MouseEvent(java.awt.event.MouseEvent) XmlNode(com.android.manifmerger.XmlNode) MouseAdapter(java.awt.event.MouseAdapter) JBPopupMenu(com.intellij.openapi.ui.JBPopupMenu) NotNull(org.jetbrains.annotations.NotNull) MouseListener(java.awt.event.MouseListener) JBMenuItem(com.intellij.openapi.ui.JBMenuItem)

Example 12 with JBPopupMenu

use of com.intellij.openapi.ui.JBPopupMenu in project android by JetBrains.

the class DeviceDefinitionList method possiblyShowPopup.

private void possiblyShowPopup(MouseEvent e) {
    if (!e.isPopupTrigger()) {
        return;
    }
    Point p = e.getPoint();
    int row = myTable.rowAtPoint(p);
    int col = myTable.columnAtPoint(p);
    if (row != -1 && col != -1) {
        JBPopupMenu menu = new JBPopupMenu();
        menu.add(createMenuItem(new CloneDeviceAction(this)));
        menu.add(createMenuItem(new EditDeviceAction(this)));
        menu.add(createMenuItem(new ExportDeviceAction(this)));
        menu.add(createMenuItem(new DeleteDeviceAction(this)));
        menu.show(myTable, p.x, p.y);
    }
}
Also used : JBPopupMenu(com.intellij.openapi.ui.JBPopupMenu)

Example 13 with JBPopupMenu

use of com.intellij.openapi.ui.JBPopupMenu in project android by JetBrains.

the class StateListPicker method createAlphaPopupMenu.

@NotNull
private JBPopupMenu createAlphaPopupMenu(@NotNull final ResourceHelper.StateListState state, @NotNull final StateComponent stateComponent) {
    JBPopupMenu popupMenu = new JBPopupMenu();
    final JMenuItem deleteAlpha = new JMenuItem("Delete alpha");
    popupMenu.add(deleteAlpha);
    deleteAlpha.setVisible(!StringUtil.isEmpty(state.getAlpha()));
    final JMenuItem createAlpha = new JMenuItem("Create alpha");
    popupMenu.add(createAlpha);
    createAlpha.setVisible(StringUtil.isEmpty(state.getAlpha()));
    deleteAlpha.addActionListener(e -> {
        stateComponent.getAlphaComponent().setVisible(false);
        stateComponent.setAlphaValue(null);
        state.setAlpha(null);
        updateIcon(stateComponent);
        deleteAlpha.setVisible(false);
        createAlpha.setVisible(true);
    });
    createAlpha.addActionListener(e -> {
        AlphaActionListener listener = stateComponent.getAlphaActionListener();
        if (listener == null) {
            return;
        }
        listener.actionPerformed(new ActionEvent(stateComponent.getAlphaComponent(), ActionEvent.ACTION_PERFORMED, null));
        if (!StringUtil.isEmpty(state.getAlpha())) {
            stateComponent.getAlphaComponent().setVisible(true);
            createAlpha.setVisible(false);
            deleteAlpha.setVisible(true);
        }
    });
    return popupMenu;
}
Also used : ActionEvent(java.awt.event.ActionEvent) JBPopupMenu(com.intellij.openapi.ui.JBPopupMenu) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

JBPopupMenu (com.intellij.openapi.ui.JBPopupMenu)13 ActionEvent (java.awt.event.ActionEvent)4 JBMenuItem (com.intellij.openapi.ui.JBMenuItem)3 NotNull (org.jetbrains.annotations.NotNull)3 ActionListener (java.awt.event.ActionListener)2 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)1 ResourceResolver (com.android.ide.common.resources.ResourceResolver)1 XmlNode (com.android.manifmerger.XmlNode)1 AttributesTableModel (com.android.tools.idea.editors.theme.attributes.AttributesTableModel)1 ConfiguredThemeEditorStyle (com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle)1 EditedStyleItem (com.android.tools.idea.editors.theme.datamodels.EditedStyleItem)1 DnDManagerImpl (com.intellij.ide.dnd.DnDManagerImpl)1 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)1 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)1 Project (com.intellij.openapi.project.Project)1 JBCheckboxMenuItem (com.intellij.openapi.ui.JBCheckboxMenuItem)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 VirtualFileManager (com.intellij.openapi.vfs.VirtualFileManager)1 PsiFile (com.intellij.psi.PsiFile)1 RelativePoint (com.intellij.ui.awt.RelativePoint)1