Search in sources :

Example 36 with AnActionEvent

use of com.intellij.openapi.actionSystem.AnActionEvent in project intellij-community by JetBrains.

the class JavadocEditor method createComponentImpl.

@Override
public JComponent createComponentImpl() {
    final DefaultTableModel tableModel = createModel();
    myTable = new JBTable(tableModel);
    myTable.setIntercellSpacing(new Dimension(0, 0));
    myTable.setDefaultRenderer(TableItem.class, new MyRenderer());
    myTable.setShowGrid(false);
    myTable.setDragEnabled(false);
    myTable.setShowHorizontalLines(false);
    myTable.setShowVerticalLines(false);
    myTable.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    JPanel tablePanel = ToolbarDecorator.createDecorator(myTable).setAddAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            FileChooserDescriptor myDescriptor = FileChooserDescriptorFactory.createMultipleJavaPathDescriptor();
            myDescriptor.setTitle(ProjectBundle.message("module.javadoc.add.path.title"));
            myDescriptor.setDescription(ProjectBundle.message("module.javadoc.add.path.prompt"));
            VirtualFile[] files = FileChooser.chooseFiles(myDescriptor, myTable, myProject, null);
            final MyTableModel tableModel = (MyTableModel) myTable.getModel();
            boolean changes = false;
            for (final VirtualFile file : files) {
                if (file != null) {
                    tableModel.addTableItem(new TableItem(file));
                    changes = true;
                }
            }
            if (changes) {
                saveData();
                TableUtil.selectRows(myTable, new int[] { tableModel.getRowCount() - 1 });
            }
        }
    }).addExtraAction(new DumbAwareActionButton(ProjectBundle.message("module.javadoc.add.url.button"), IconUtil.getAddLinkIcon()) {

        @Override
        public void actionPerformed(AnActionEvent e) {
            VirtualFile[] files = new VirtualFile[] { Util.showSpecifyJavadocUrlDialog(myTable) };
            final MyTableModel tableModel = (MyTableModel) myTable.getModel();
            boolean changes = false;
            for (final VirtualFile file : files) {
                if (file != null) {
                    tableModel.addTableItem(new TableItem(file));
                    changes = true;
                }
            }
            if (changes) {
                saveData();
                TableUtil.selectRows(myTable, new int[] { tableModel.getRowCount() - 1 });
            }
        }
    }).setRemoveAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            final List removedItems = TableUtil.removeSelectedItems(myTable);
            if (removedItems.size() > 0) {
                saveData();
            }
        }
    }).setButtonComparator("Add", ProjectBundle.message("module.javadoc.add.url.button"), "Remove").createPanel();
    final JPanel mainPanel = new JPanel(new BorderLayout());
    mainPanel.add(tablePanel, BorderLayout.CENTER);
    mainPanel.add(new JBLabel(ProjectBundle.message("project.roots.javadoc.tab.description"), UIUtil.ComponentStyle.SMALL, UIUtil.FontColor.BRIGHTER), BorderLayout.NORTH);
    return mainPanel;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) DefaultTableModel(javax.swing.table.DefaultTableModel) JBTable(com.intellij.ui.table.JBTable) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) JBLabel(com.intellij.ui.components.JBLabel) List(java.util.List)

Example 37 with AnActionEvent

use of com.intellij.openapi.actionSystem.AnActionEvent in project intellij-community by JetBrains.

the class ChooseFileEncodingAction method fillCharsetActions.

private void fillCharsetActions(@NotNull DefaultActionGroup group, @Nullable final VirtualFile virtualFile, @NotNull List<Charset> charsets, @NotNull final Function<Charset, String> charsetFilter) {
    for (final Charset charset : charsets) {
        AnAction action = new DumbAwareAction(charset.displayName(), null, EmptyIcon.ICON_16) {

            @Override
            public void actionPerformed(AnActionEvent e) {
                chosen(virtualFile, charset);
            }

            @Override
            public void update(AnActionEvent e) {
                super.update(e);
                String description = charsetFilter.fun(charset);
                e.getPresentation().setIcon(description == null ? AllIcons.General.Warning : null);
                e.getPresentation().setDescription(description);
            }
        };
        group.add(action);
    }
}
Also used : Charset(java.nio.charset.Charset) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction)

Example 38 with AnActionEvent

use of com.intellij.openapi.actionSystem.AnActionEvent in project intellij-community by JetBrains.

the class LineTooltipRenderer method show.

@Override
public LightweightHint show(@NotNull final Editor editor, @NotNull final Point p, final boolean alignToRight, @NotNull final TooltipGroup group, @NotNull final HintHint hintHint) {
    if (myText == null)
        return null;
    //setup text
    myText = myText.replaceAll(String.valueOf(UIUtil.MNEMONIC), "");
    final boolean expanded = myCurrentWidth > 0 && dressDescription(editor);
    final HintManagerImpl hintManager = HintManagerImpl.getInstanceImpl();
    final JComponent contentComponent = editor.getContentComponent();
    final JComponent editorComponent = editor.getComponent();
    if (!editorComponent.isShowing())
        return null;
    final JLayeredPane layeredPane = editorComponent.getRootPane().getLayeredPane();
    final JEditorPane pane = IdeTooltipManager.initPane(new Html(myText).setKeepFont(true), hintHint, layeredPane);
    hintHint.setContentActive(isActiveHtml(myText));
    if (!hintHint.isAwtTooltip()) {
        correctLocation(editor, pane, p, alignToRight, expanded, myCurrentWidth);
    }
    final JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(pane);
    scrollPane.setBorder(null);
    scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
    scrollPane.setOpaque(hintHint.isOpaqueAllowed());
    scrollPane.getViewport().setOpaque(hintHint.isOpaqueAllowed());
    scrollPane.setBackground(hintHint.getTextBackground());
    scrollPane.getViewport().setBackground(hintHint.getTextBackground());
    scrollPane.setViewportBorder(null);
    if (hintHint.isRequestFocus()) {
        pane.setFocusable(true);
    }
    final Ref<AnAction> actionRef = new Ref<>();
    final LightweightHint hint = new LightweightHint(scrollPane) {

        @Override
        public void hide() {
            onHide(pane);
            super.hide();
            final AnAction action = actionRef.get();
            if (action != null) {
                action.unregisterCustomShortcutSet(contentComponent);
            }
        }
    };
    actionRef.set(new AnAction() {

        // an action to expand description when tooltip was shown after mouse move; need to unregister from editor component
        {
            registerCustomShortcutSet(new CustomShortcutSet(KeymapManager.getInstance().getActiveKeymap().getShortcuts(IdeActions.ACTION_SHOW_ERROR_DESCRIPTION)), contentComponent);
        }

        @Override
        public void actionPerformed(final AnActionEvent e) {
            // The tooltip gets the focus if using a screen reader and invocation through a keyboard shortcut.
            hintHint.setRequestFocus(ScreenReader.isActive() && (e.getInputEvent() instanceof KeyEvent));
            expand(hint, editor, p, pane, alignToRight, group, hintHint);
        }
    });
    pane.addHyperlinkListener(new HyperlinkListener() {

        @Override
        public void hyperlinkUpdate(final HyperlinkEvent e) {
            myActiveLink = true;
            if (e.getEventType() == HyperlinkEvent.EventType.EXITED) {
                myActiveLink = false;
                return;
            }
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                final URL url = e.getURL();
                if (url != null) {
                    BrowserUtil.browse(url);
                    hint.hide();
                    return;
                }
                final String description = e.getDescription();
                if (description != null && handle(description, editor)) {
                    hint.hide();
                    return;
                }
                if (!expanded) {
                    expand(hint, editor, p, pane, alignToRight, group, hintHint);
                } else {
                    stripDescription();
                    hint.hide();
                    TooltipController.getInstance().showTooltip(editor, new Point(p.x - 3, p.y - 3), createRenderer(myText, 0), false, group, hintHint);
                }
            }
        }
    });
    // This listener makes hint transparent for mouse events. It means that hint is closed
    // by MousePressed and this MousePressed goes into the underlying editor component.
    pane.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseReleased(final MouseEvent e) {
            if (!myActiveLink) {
                MouseEvent newMouseEvent = SwingUtilities.convertMouseEvent(e.getComponent(), e, contentComponent);
                hint.hide();
                contentComponent.dispatchEvent(newMouseEvent);
            }
        }

        @Override
        public void mouseExited(final MouseEvent e) {
            if (!expanded) {
                hint.hide();
            }
        }
    });
    hintManager.showEditorHint(hint, editor, p, HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_OTHER_HINT | HintManager.HIDE_BY_SCROLLING, 0, false, hintHint);
    return hint;
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) Html(com.intellij.util.ui.Html) LightweightHint(com.intellij.ui.LightweightHint) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) URL(java.net.URL) KeyEvent(java.awt.event.KeyEvent) CustomShortcutSet(com.intellij.openapi.actionSystem.CustomShortcutSet) Ref(com.intellij.openapi.util.Ref) HyperlinkListener(javax.swing.event.HyperlinkListener)

Example 39 with AnActionEvent

use of com.intellij.openapi.actionSystem.AnActionEvent in project intellij-community by JetBrains.

the class MacMessagesTest method actionPerformed.

@Override
public void actionPerformed(final AnActionEvent anActionEvent) {
    JDialog controlDialog = new JDialog();
    controlDialog.setTitle("Messages testing control panel");
    controlDialog.setModalExclusionType(Dialog.ModalExclusionType.APPLICATION_EXCLUDE);
    controlDialog.setModal(false);
    controlDialog.setFocusableWindowState(false);
    controlDialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    Container cp = controlDialog.getContentPane();
    cp.setLayout(new FlowLayout());
    JButton showDialogWrapperButton = new JButton("Show a dialog wrapper");
    showDialogWrapperButton.setFocusable(false);
    FocusManagerImpl fmi = FocusManagerImpl.getInstance();
    final Project p = fmi.getLastFocusedFrame().getProject();
    showDialogWrapperButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            DialogWrapper dw = new SimpleDialogWrapper(p);
            dw.setTitle(dw.getWindow().getName());
            dw.show();
        }
    });
    JButton showMessageButton = new JButton("Show a message");
    showDialogWrapperButton.setFocusable(false);
    showMessageButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            showTestMessage(p);
        }
    });
    JButton showProgressIndicatorButton = new JButton("Show progress indicator");
    showProgressIndicatorButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            final Task task = new Task.Modal(null, "Test task", true) {

                public void run(@NotNull final ProgressIndicator indicator) {
                    ApplicationManager.getApplication().invokeAndWait(() -> {
                        FocusManagerImpl fmi1 = FocusManagerImpl.getInstance();
                        final Project p1 = fmi1.getLastFocusedFrame().getProject();
                        showTestMessage(p1);
                    }, ModalityState.any());
                }

                @Override
                public void onCancel() {
                }
            };
            ProgressManager.getInstance().run(task);
        }
    });
    cp.add(showDialogWrapperButton);
    cp.add(showMessageButton);
    cp.add(showProgressIndicatorButton);
    controlDialog.pack();
    controlDialog.setVisible(true);
}
Also used : FocusManagerImpl(com.intellij.openapi.wm.impl.FocusManagerImpl) Task(com.intellij.openapi.progress.Task) ActionEvent(java.awt.event.ActionEvent) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) Project(com.intellij.openapi.project.Project) ActionListener(java.awt.event.ActionListener) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator)

Example 40 with AnActionEvent

use of com.intellij.openapi.actionSystem.AnActionEvent in project intellij-community by JetBrains.

the class MergeList method addActions.

private void addActions(@NotNull final FragmentSide side) {
    ChangeList changeList = getChanges(side);
    final FragmentSide originalSide = BRANCH_SIDE;
    for (int i = 0; i < changeList.getCount(); i++) {
        final Change change = changeList.getChange(i);
        if (!change.canHasActions(originalSide))
            continue;
        Icon arrowIcon = side == FragmentSide.SIDE1 ? AllIcons.Diff.ArrowRight : AllIcons.Diff.Arrow;
        AnAction applyAction = new DumbAwareAction(DiffBundle.message("merge.dialog.apply.change.action.name"), null, arrowIcon) {

            @Override
            public void actionPerformed(@Nullable AnActionEvent e) {
                apply(change);
            }
        };
        AnAction ignoreAction = new DumbAwareAction(DiffBundle.message("merge.dialog.ignore.change.action.name"), null, AllIcons.Diff.Remove) {

            @Override
            public void actionPerformed(@Nullable AnActionEvent e) {
                change.removeFromList();
            }
        };
        change.getChangeSide(originalSide).getHighlighterHolder().setActions(new AnAction[] { applyAction, ignoreAction });
    }
}
Also used : FragmentSide(com.intellij.openapi.diff.impl.highlighting.FragmentSide) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)167 AnAction (com.intellij.openapi.actionSystem.AnAction)76 Project (com.intellij.openapi.project.Project)33 NotNull (org.jetbrains.annotations.NotNull)29 VirtualFile (com.intellij.openapi.vfs.VirtualFile)28 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)27 Nullable (org.jetbrains.annotations.Nullable)21 List (java.util.List)19 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)18 Test (org.junit.Test)16 CustomShortcutSet (com.intellij.openapi.actionSystem.CustomShortcutSet)13 ArrayList (java.util.ArrayList)13 SonarTest (org.sonarlint.intellij.SonarTest)13 Presentation (com.intellij.openapi.actionSystem.Presentation)12 JBTable (com.intellij.ui.table.JBTable)12 AnActionButton (com.intellij.ui.AnActionButton)11 Notification (com.intellij.notification.Notification)10 CommonDataKeys (com.intellij.openapi.actionSystem.CommonDataKeys)10 StringUtil (com.intellij.openapi.util.text.StringUtil)9 ToolbarDecorator (com.intellij.ui.ToolbarDecorator)9