Example usage for com.intellij.openapi.actionSystem.ex ActionUtil performActionDumbAware

List of usage examples for com.intellij.openapi.actionSystem.ex ActionUtil performActionDumbAware

Introduction

In this page you can find the example usage for com.intellij.openapi.actionSystem.ex ActionUtil performActionDumbAware.

Prototype

public static void performActionDumbAware(AnAction action, AnActionEvent e) 

Source Link

Usage

From source file:com.android.tools.idea.rendering.errors.ui.RenderErrorPanel.java

License:Apache License

public RenderErrorPanel() {
    super(new BorderLayout());

    myModel = new RenderErrorModel(Collections.emptyList());

    myHtmlDetailPane = new JEditorPane(UIUtil.HTML_MIME, EMPTY_HTML_BODY);
    myHtmlDetailPane.setEditable(false);
    myHtmlDetailPane.addHyperlinkListener(e -> {
        // TODO: Currently all issues share a common hyperlink listener for now so just get any of them. Different issues
        //       should be able to have different handlers
        HyperlinkListener listener = myModel.getElementAt(0).getHyperlinkListener();
        if (listener != null) {
            listener.hyperlinkUpdate(e);
        }// w w w.  ja v a 2s.  c  o  m
    });
    myHtmlDetailPane.setContentType(UIUtil.HTML_MIME);
    myHtmlDetailPane.setMargin(JBUI.insets(10));

    myList = new JBList();
    // Set a prototype to allow us do measurements of the list
    //noinspection unchecked
    myList.setPrototypeCellValue(RenderErrorModel.Issue.builder().setSummary("Prototype").build());
    myList.setCellRenderer(new ColoredListCellRenderer<RenderErrorModel.Issue>() {
        @Override
        protected void customizeCellRenderer(JList list, @NotNull RenderErrorModel.Issue value, int index,
                boolean selected, boolean hasFocus) {
            Icon icon = getSeverityIcon(value.getSeverity());
            if (icon != null) {
                setIcon(icon);
            }
            append(value.getSummary());
        }
    });

    myList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    myList.addListSelectionListener(e -> {
        int selectedIndex = myList.getSelectedIndex();

        if (selectedIndex != -1) {
            HtmlBuilder htmlBuilder = new HtmlBuilder();

            RenderErrorModel.Issue selectedIssue = (RenderErrorModel.Issue) myList.getModel()
                    .getElementAt(selectedIndex);
            htmlBuilder.addHtml(selectedIssue.getHtmlContent()).newline();

            try {
                myHtmlDetailPane.read(new StringReader(htmlBuilder.getHtml()), null);
                HtmlBuilderHelper.fixFontStyles(myHtmlDetailPane);
                myHtmlDetailPane.setCaretPosition(0);
            } catch (IOException e1) {
                setEmptyHtmlDetail();
            }
        } else {
            setEmptyHtmlDetail();
        }

        revalidate();
        repaint();
    });

    ActionToolbarImpl toolbar = new ActionToolbarImpl(ActionPlaces.UNKNOWN, getActionGroup(), true, false,
            DataManager.getInstance(), ActionManagerEx.getInstanceEx(), KeymapManagerEx.getInstanceEx());
    toolbar.setLayoutPolicy(NOWRAP_LAYOUT_POLICY);
    toolbar.setBorder(JBUI.Borders.empty());
    Box titlePanel = Box.createHorizontalBox();
    myTitleLabel = new JBLabel(TITLE, SwingConstants.LEFT);

    myTitleLabel.setBorder(JBUI.Borders.empty(0, 5, 0, 20));
    myTitleLabel
            .setPreferredSize(new Dimension(Short.MAX_VALUE, ActionToolbar.DEFAULT_MINIMUM_BUTTON_SIZE.height));
    myTitleLabel.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
                // Double clicking the title bar is the same as clicking the minimize action
                MinimizeAction minimizeAction = new MinimizeAction();
                AnActionEvent event = AnActionEvent.createFromAnAction(minimizeAction, e, "unknown",
                        DataManager.getInstance().getDataContext(myTitleLabel));
                ActionUtil.performActionDumbAware(minimizeAction, event);
            }
        }
    });

    titlePanel.add(myTitleLabel);
    titlePanel.add(toolbar.getComponent());
    titlePanel.setMaximumSize(new Dimension(Short.MAX_VALUE, ActionToolbar.DEFAULT_MINIMUM_BUTTON_SIZE.height));

    myListScrollPane = createScrollPane(myList);
    // We display a minimum of 3 issues and a maximum of 5. When there are more than 5 issues, a scrollbar is displayed
    myListScrollPane.setMinimumSize(JBUI.size(0, myList.getFixedCellHeight() * 3));
    myListScrollPane.setPreferredSize(JBUI.size(Short.MAX_VALUE, myList.getFixedCellHeight() * 3));
    myListScrollPane.setMaximumSize(JBUI.size(Short.MAX_VALUE, myList.getFixedCellHeight() * 5));
    myListScrollPane.setBorder(JBUI.Borders.empty());

    myHtmlScrollPane = createScrollPane(myHtmlDetailPane);
    myHtmlScrollPane.setBorder(JBUI.Borders.customLine(UIUtil.getPanelBackground(), 5, 0, 0, 0));

    Box rootPanel = Box.createVerticalBox();
    titlePanel.setAlignmentX(CENTER_ALIGNMENT);
    myListScrollPane.setAlignmentX(CENTER_ALIGNMENT);
    myHtmlScrollPane.setAlignmentX(CENTER_ALIGNMENT);
    rootPanel.add(titlePanel);
    rootPanel.add(myListScrollPane);
    rootPanel.add(myHtmlScrollPane);

    add(rootPanel);

    isMinimized = PropertiesComponent.getInstance().getBoolean(PROPERTY_MINIMIZED, false);
    myListScrollPane.setVisible(!isMinimized);
    myHtmlScrollPane.setVisible(!isMinimized);

    updateTitlebarStyle();
}

From source file:com.intellij.ide.actions.GotoActionAction.java

License:Apache License

public static void performAction(Object element, @Nullable final Component component,
        @Nullable final AnActionEvent e) {
    // element could be AnAction (SearchEverywhere)
    final AnAction action = element instanceof AnAction ? (AnAction) element
            : ((GotoActionModel.ActionWrapper) element).getAction();
    if (action != null) {
        ApplicationManager.getApplication().invokeLater(new Runnable() {
            @Override/*w  ww.j  a  va 2 s .  c o m*/
            public void run() {
                if (component == null)
                    return;
                Presentation presentation = action.getTemplatePresentation().clone();
                DataContext context = DataManager.getInstance().getDataContext(component);
                AnActionEvent event = new AnActionEvent(e == null ? null : e.getInputEvent(), context,
                        ActionPlaces.ACTION_SEARCH, presentation, ActionManager.getInstance(),
                        e == null ? 0 : e.getModifiers());

                if (ActionUtil.lastUpdateAndCheckDumb(action, event, false)) {
                    if (action instanceof ActionGroup && ((ActionGroup) action).getChildren(event).length > 0) {
                        ListPopup popup = JBPopupFactory.getInstance().createActionGroupPopup(
                                presentation.getText(), (ActionGroup) action, context,
                                JBPopupFactory.ActionSelectionAid.SPEEDSEARCH, false);
                        if (component.isShowing()) {
                            popup.showInBestPositionFor(context);
                        } else {
                            popup.showInFocusCenter();
                        }
                    } else {
                        ActionUtil.performActionDumbAware(action, event);
                    }
                }
            }
        }, ModalityState.NON_MODAL);
    }
}

From source file:com.intellij.ui.tabs.impl.ActionButton.java

License:Apache License

public void actionPerformed(final ActionEvent e) {
    AnActionEvent event = createAnEvent(null, e.getModifiers());
    if (event != null && ActionUtil.lastUpdateAndCheckDumb(myAction, event, true)) {
        ActionUtil.performActionDumbAware(myAction, event);
    }/*from   w w w.j av  a 2s .c o  m*/
}

From source file:com.vladsch.MissingInActions.manager.ActionSelectionAdjuster.java

License:Apache License

@SuppressWarnings("WeakerAccess")
public void runAction(AnAction action, boolean autoTriggered) {
    AnActionEvent event = createAnEvent(action, autoTriggered);
    Editor editor = EDITOR.getData(event.getDataContext());
    if (editor == myEditor) {
        beforeActionPerformed(action, event.getDataContext(), event);
        ActionUtil.performActionDumbAware(action, event);
        afterActionPerformed(action, event.getDataContext(), event);
    }/* w  ww .  j av a 2 s.co m*/
}