Example usage for com.intellij.openapi.project DumbAwareAction DumbAwareAction

List of usage examples for com.intellij.openapi.project DumbAwareAction DumbAwareAction

Introduction

In this page you can find the example usage for com.intellij.openapi.project DumbAwareAction DumbAwareAction.

Prototype

protected DumbAwareAction(@Nullable @Nls(capitalization = Nls.Capitalization.Title) String text,
            @Nullable @Nls(capitalization = Nls.Capitalization.Sentence) String description, @Nullable Icon icon) 

Source Link

Usage

From source file:com.android.tools.idea.gradle.invoker.messages.GradleBuildTreeViewPanel.java

License:Apache License

@Override
protected void fillRightToolbarGroup(DefaultActionGroup group) {
    super.fillRightToolbarGroup(group);
    group.add(new DumbAwareAction("Show Console Output", null, AndroidIcons.GradleConsole) {
        @Override/*from  www . j  a  v  a 2 s. co m*/
        public void actionPerformed(AnActionEvent e) {
            ToolWindow window = ToolWindowManager.getInstance(myProject)
                    .getToolWindow(GradleConsoleToolWindowFactory.ID);
            if (window != null) {
                window.activate(null, false);
            }
        }

        @Override
        public void update(AnActionEvent e) {
            e.getPresentation().setEnabledAndVisible(true);
        }
    });

    DefaultActionGroup filterGroup = new DefaultActionGroup("GradleBuildMessagesFilter", true) {
        @Override
        public void update(AnActionEvent e) {
            Presentation presentation = e.getPresentation();
            presentation.setDescription("Filter messages to display");
            presentation.setIcon(AllIcons.General.Filter);
        }

        @Override
        public boolean isDumbAware() {
            return true;
        }
    };

    // We could have iterated through ErrorTreeElementKind.values() and have less code, but we want to keep this order:
    filterGroup.add(new FilterMessagesByKindAction(ErrorTreeElementKind.ERROR));
    filterGroup.add(new FilterMessagesByKindAction(ErrorTreeElementKind.WARNING));
    filterGroup.add(new FilterMessagesByKindAction(ErrorTreeElementKind.INFO));
    filterGroup.add(new FilterMessagesByKindAction(ErrorTreeElementKind.NOTE));
    filterGroup.add(new FilterMessagesByKindAction(ErrorTreeElementKind.GENERIC));
    group.add(filterGroup);
}

From source file:com.android.tools.idea.gradle.structure.configurables.ui.AbstractMainPanel.java

License:Apache License

private void createAndAddModulesAction(@NotNull List<PsModule> extraTopModules) {
    DefaultActionGroup actions = new DefaultActionGroup();
    actions.add(new ModulesComboBoxAction(myContext, extraTopModules));

    AnAction restoreModuleListAction = new DumbAwareAction("Restore 'Modules' List", "",
            AllIcons.Actions.MoveTo2) {/*from  w w w  .jav  a 2s  . c  om*/
        @Override
        public void actionPerformed(AnActionEvent e) {
            PsUISettings settings = PsUISettings.getInstance();
            settings.MODULES_LIST_MINIMIZE = myShowModulesDropDown = false;
            settings.fireUISettingsChanged();
            removeModulesAction();
        }
    };
    actions.add(restoreModuleListAction);

    ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar("TOP", actions, true);
    myModulesToolbar = toolbar.getComponent();
    myModulesToolbar.setBorder(IdeBorderFactory.createBorder(SideBorder.BOTTOM));

    add(myModulesToolbar, BorderLayout.NORTH);
}

From source file:com.android.tools.idea.gradle.structure.configurables.ui.dependencies.AbstractDependenciesPanel.java

License:Apache License

@NotNull
protected final JPanel createActionsPanel() {
    JPanel actionsPanel = new JPanel(new BorderLayout());

    DefaultActionGroup actions = new DefaultActionGroup();

    AnAction addDependencyAction = new DumbAwareAction("Add Dependency", "", IconUtil.getAddIcon()) {
        @Override//  ww  w . j  a  v a  2 s .c  o m
        public void actionPerformed(AnActionEvent e) {
            JBPopup popup = JBPopupFactory.getInstance()
                    .createListPopup(new BaseListPopupStep<AbstractPopupAction>(null, getPopupActions()) {
                        @Override
                        public Icon getIconFor(AbstractPopupAction action) {
                            return action.icon;
                        }

                        @Override
                        public boolean isMnemonicsNavigationEnabled() {
                            return true;
                        }

                        @Override
                        public PopupStep onChosen(AbstractPopupAction action, boolean finalChoice) {
                            return doFinalStep(action::execute);
                        }

                        @Override
                        @NotNull
                        public String getTextFor(AbstractPopupAction action) {
                            return "&" + action.index + "  " + action.text;
                        }
                    });
            popup.show(new RelativePoint(actionsPanel, new Point(0, actionsPanel.getHeight() - 1)));
        }
    };

    actions.add(addDependencyAction);
    List<AnAction> extraToolbarActions = getExtraToolbarActions();
    if (!extraToolbarActions.isEmpty()) {
        actions.addSeparator();
        actions.addAll(extraToolbarActions);
    }

    ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar("TOP", actions, true);
    JComponent toolbarComponent = toolbar.getComponent();
    toolbarComponent.setBorder(IdeBorderFactory.createBorder(SideBorder.BOTTOM));
    actionsPanel.add(toolbarComponent, BorderLayout.CENTER);

    return actionsPanel;
}

From source file:com.android.tools.idea.gradle.structure.configurables.ui.ToolWindowHeader.java

License:Apache License

private ToolWindowHeader(@NotNull String title, @NotNull Icon icon, @Nullable ToolWindowAnchor anchor) {
    super(title);
    myIcon = icon;/*from   w  ww.j a v  a  2 s. com*/
    myAnchor = anchor;
    if (myAnchor != null) {
        Icon minimizeIcon = myAnchor == LEFT ? HideLeft : HideRight; // We don't support TOP or BOTTOM
        myMinimizeAction = new DumbAwareAction("Hide", "", minimizeIcon) {
            @Override
            public void actionPerformed(AnActionEvent e) {
                myEventDispatcher.getMulticaster().minimized();
            }
        };
        setAdditionalActions(Lists.newArrayList(myMinimizeAction));
    }
    addActivationListener(() -> {
        if (myPreferredFocusedComponent != null) {
            myPreferredFocusedComponent.requestFocusInWindow();
        }
    }, this);
}

From source file:com.ansorgit.plugins.bash.runner.repl.AbstractConsoleRunnerWithHistory.java

License:Apache License

protected AnAction[] fillToolBarActions(final DefaultActionGroup toolbarActions, final Executor defaultExecutor,
        final RunContentDescriptor myDescriptor) {
    //stop//  w w w.j a  va 2 s . com
    final AnAction stopAction = createStopAction();
    toolbarActions.add(stopAction);

    //close
    final AnAction closeAction = createCloseAction(defaultExecutor, myDescriptor);
    toolbarActions.add(closeAction);

    // run action
    myRunAction = new DumbAwareAction("Execute current input",
            "Executes the current input of the editor with the Bash executable",
            IconLoader.getIcon("/actions/execute.png")) {
        public void actionPerformed(final AnActionEvent e) {
            runExecuteActionInner();
        }

        public void update(final AnActionEvent e) {
            final EditorEx editor = getLanguageConsole().getConsoleEditor();
            final Lookup lookup = LookupManager.getActiveLookup(editor);
            e.getPresentation().setEnabled(
                    !myProcessHandler.isProcessTerminated() && (lookup == null || !lookup.isCompletion()));
        }
    };
    myRunAction.registerCustomShortcutSet(KeyEvent.VK_ENTER, KeyEvent.CTRL_DOWN_MASK, null);

    //EmptyAction.setupAction(myRunAction, "Console.Execute", null);
    toolbarActions.add(myRunAction);

    // Help
    toolbarActions.add(CommonActionsManager.getInstance().createHelpAction("interactive_console"));

    // history actions
    final PairProcessor<AnActionEvent, String> historyProcessor = new PairProcessor<AnActionEvent, String>() {
        public boolean process(final AnActionEvent e, final String s) {
            new WriteCommandAction(myProject, getLanguageConsole().getFile()) {
                protected void run(final Result result) throws Throwable {
                    getLanguageConsole().getEditorDocument().setText(s == null ? "" : s);
                }
            }.execute();
            return true;
        }
    };

    final AnAction historyNextAction = ConsoleHistoryModel.createHistoryAction(myHistory, true,
            historyProcessor);
    final AnAction historyPrevAction = ConsoleHistoryModel.createHistoryAction(myHistory, false,
            historyProcessor);
    historyNextAction.getTemplatePresentation().setVisible(false);
    historyPrevAction.getTemplatePresentation().setVisible(false);
    toolbarActions.add(historyNextAction);
    toolbarActions.add(historyPrevAction);

    return new AnAction[] { stopAction, closeAction, myRunAction, historyNextAction, historyPrevAction };
}

From source file:com.chrisrm.idea.MTBundledThemesManager.java

License:Open Source License

/**
 * Adds a bundled theme to the list, and mark it if it's the current theme
 *
 * @param group               switch scheme group
 * @param theme               theme/*ww w.ja  va  2s . c om*/
 * @param current             current theme
 * @param ourCurrentAction    default current icon (check mark)
 * @param ourNotCurrentAction default not current icon (empty)
 */
@SuppressWarnings("FeatureEnvy")
private static void addBundledTheme(final DefaultActionGroup group, final MTThemeable theme,
        final MTThemeable current, final Icon ourCurrentAction, final Icon ourNotCurrentAction) {
    final Icon themeIcon = theme.getIcon() != null ? theme.getIcon() : ourNotCurrentAction;

    group.add(new DumbAwareAction(theme.getName(), theme.getEditorColorsScheme(),
            theme == current ? ourCurrentAction : themeIcon) {
        @Override
        public void actionPerformed(@NotNull final AnActionEvent e) {
            //         Install theme if not installed
            final MTThemeFacade externalTheme = MTThemes.installTheme(theme);

            MTTreeUI.resetIcons();
            MTThemeManager.activate(externalTheme, true);
            MTAnalytics.getInstance().trackValue(MTAnalytics.SELECT_THEME, externalTheme);
        }
    });
}

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

License:Apache License

private static void addScheme(final DefaultActionGroup group, final EditorColorsScheme current,
        final EditorColorsScheme scheme, final boolean addScheme) {
    group.add(new DumbAwareAction(scheme.getName(), "",
            scheme == current ? ourCurrentAction : ourNotCurrentAction) {
        @Override/*w  w  w. j a va  2  s  . c  om*/
        public void actionPerformed(@Nullable AnActionEvent e) {
            if (addScheme) {
                EditorColorsManager.getInstance().addColorsScheme(scheme);
            }
            EditorColorsManager.getInstance().setGlobalScheme(scheme);
        }
    });
}

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

License:Apache License

@Override
protected void fillActions(Project project, @NotNull DefaultActionGroup group,
        @NotNull DataContext dataContext) {
    final LafManager manager = LafManager.getInstance();
    final UIManager.LookAndFeelInfo[] lfs = manager.getInstalledLookAndFeels();
    final UIManager.LookAndFeelInfo current = manager.getCurrentLookAndFeel();
    for (final UIManager.LookAndFeelInfo lf : lfs) {
        group.add(/*from   w w w .ja  v a 2 s.  c  om*/
                new DumbAwareAction(lf.getName(), "", lf == current ? ourCurrentAction : ourNotCurrentAction) {
                    @Override
                    public void actionPerformed(AnActionEvent e) {
                        final UIManager.LookAndFeelInfo cur = manager.getCurrentLookAndFeel();
                        if (cur == lf)
                            return;
                        manager.setCurrentLookAndFeel(lf);
                        manager.updateUI();
                    }
                });
    }
}

From source file:com.intellij.lang.jsgraphql.ide.project.toolwindow.JSGraphQLErrorTreeViewPanel.java

License:Open Source License

private Component createToolPanel() {
    CloseTabToolbarAction closeMessageViewAction = new CloseTabToolbarAction() {
        public void actionPerformed(AnActionEvent e) {
            close();/*  w ww.j a  va  2 s . c  om*/
        }
    };
    DefaultActionGroup leftActionGroup = new DefaultActionGroup();
    DefaultActionGroup rightActionGroup = new DefaultActionGroup();
    if (myTreeExpander != null) {
        rightActionGroup.add(CommonActionsManager.getInstance().createExpandAllAction(myTreeExpander, this));
        rightActionGroup.add(CommonActionsManager.getInstance().createCollapseAllAction(myTreeExpander, this));
    }

    rightActionGroup.add(new DumbAwareAction("Clear All", null, Actions.GC) {
        public void actionPerformed(AnActionEvent e) {
            if (myCleanAction != null) {
                myCleanAction.run();
            }
            getErrorViewStructure().clear();
            updateTree();
        }
    });
    if (myActions != null) {
        for (AnAction rightToolbar : myActions) {
            leftActionGroup.add(rightToolbar);
        }
    }

    leftActionGroup.add(new ContextHelpAction(myHelpId));
    leftActionGroup.add(closeMessageViewAction);
    final JPanel panel = new JPanel(new BorderLayout());
    final ActionManager actionManager = ActionManager.getInstance();
    final ActionToolbar leftToolbar = actionManager.createActionToolbar(ActionPlaces.COMPILER_MESSAGES_TOOLBAR,
            leftActionGroup, false);
    final ActionToolbar rightToolbar = actionManager.createActionToolbar(ActionPlaces.COMPILER_MESSAGES_TOOLBAR,
            rightActionGroup, false);
    panel.add(leftToolbar.getComponent(), BorderLayout.WEST);
    panel.add(rightToolbar.getComponent(), BorderLayout.CENTER);
    return panel;
}

From source file:com.intellij.profile.codeInspection.ui.SingleInspectionProfilePanel.java

License:Apache License

private ActionToolbar createTreeToolbarPanel() {
    final CommonActionsManager actionManager = CommonActionsManager.getInstance();

    DefaultActionGroup actions = new DefaultActionGroup();

    actions.add(new InspectionFilterAction(mySelectedProfile, myInspectionsFilter,
            myProjectProfileManager.getProject()));
    actions.addSeparator();/* ww  w  .ja  v a 2  s  . c om*/

    actions.add(actionManager.createExpandAllAction(myTreeExpander, myTreeTable));
    actions.add(actionManager.createCollapseAllAction(myTreeExpander, myTreeTable));
    actions.add(new DumbAwareAction("Reset to Empty", "Reset to empty", AllIcons.Actions.Reset_to_empty) {

        @Override
        public void update(@NotNull AnActionEvent e) {
            e.getPresentation().setEnabled(mySelectedProfile != null
                    && mySelectedProfile.isExecutable(myProjectProfileManager.getProject()));
        }

        @Override
        public void actionPerformed(@NotNull AnActionEvent e) {
            mySelectedProfile.resetToEmpty(e.getProject());
            loadDescriptorsConfigs(false);
            postProcessModification();
        }
    });

    actions.add(new AdvancedSettingsAction(myProjectProfileManager.getProject(), myRoot) {
        @Override
        protected InspectionProfileImpl getInspectionProfile() {
            return mySelectedProfile;
        }

        @Override
        protected void postProcessModification() {
            loadDescriptorsConfigs(true);
            SingleInspectionProfilePanel.this.postProcessModification();
        }
    });

    final ActionToolbar actionToolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN,
            actions, true);
    actionToolbar.setTargetComponent(this);
    return actionToolbar;
}