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) 

Source Link

Usage

From source file:com.intellij.codeInsight.template.impl.TemplateListPanel.java

License:Apache License

private void installPopup() {
    final DumbAwareAction rename = new DumbAwareAction("Rename") {

        @Override/*from  www.ja v  a  2 s.  c  om*/
        public void update(AnActionEvent e) {
            final int selected = getSingleSelectedIndex();
            final TemplateGroup templateGroup = getGroup(selected);
            boolean enabled = templateGroup != null;
            e.getPresentation().setEnabled(enabled);
            e.getPresentation().setVisible(enabled);
            super.update(e);
        }

        @Override
        public void actionPerformed(AnActionEvent e) {
            renameGroup();
        }
    };
    rename.registerCustomShortcutSet(
            ActionManager.getInstance().getAction(IdeActions.ACTION_RENAME).getShortcutSet(), myTree);

    final DefaultActionGroup move = new DefaultActionGroup("Move", true) {
        @Override
        public void update(AnActionEvent e) {
            final Map<TemplateImpl, DefaultMutableTreeNode> templates = getSelectedTemplates();
            boolean enabled = !templates.isEmpty();
            e.getPresentation().setEnabled(enabled);
            e.getPresentation().setVisible(enabled);

            if (enabled) {
                Set<String> oldGroups = getAllGroups(templates);

                removeAll();
                SchemesManager<TemplateGroup, TemplateGroup> schemesManager = TemplateSettings.getInstance()
                        .getSchemesManager();

                for (TemplateGroup group : getTemplateGroups()) {
                    final String newGroupName = group.getName();
                    if (!oldGroups.contains(newGroupName)) {
                        add(new DumbAwareAction(newGroupName) {
                            @Override
                            public void actionPerformed(AnActionEvent e) {
                                moveTemplates(templates, newGroupName);
                            }
                        });
                    }
                }
                addSeparator();
                add(new DumbAwareAction("New group...") {
                    @Override
                    public void actionPerformed(AnActionEvent e) {
                        String newName = Messages.showInputDialog(myTree, "Enter the new group name:",
                                "Move to a New Group", null, "", new TemplateGroupInputValidator(null));
                        if (newName != null) {
                            moveTemplates(templates, newName);
                        }
                    }
                });
            }
        }
    };

    myTree.addMouseListener(new PopupHandler() {
        @Override
        public void invokePopup(Component comp, int x, int y) {
            final DefaultActionGroup group = new DefaultActionGroup();
            group.add(rename);
            group.add(move);
            ActionManager.getInstance().createActionPopupMenu(ActionPlaces.UNKNOWN, group).getComponent()
                    .show(comp, x, y);
        }
    });
}

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

License:Apache License

@NotNull
@Override//from ww  w.  j  ava  2  s.  c  o m
public DefaultActionGroup createPopupActionGroup(final JComponent anchor) {
    final DefaultActionGroup group = new DefaultActionGroup();
    for (final HighlightSeverity severity : getSeverities(mySeverityRegistrar)) {
        final HighlightSeverityAction action = new HighlightSeverityAction(severity);
        if (myChosen == null) {
            setChosen(action.getSeverity());
        }
        group.add(action);
    }
    group.addSeparator();
    group.add(new DumbAwareAction("Edit severities...") {
        @Override
        public void actionPerformed(@NotNull final AnActionEvent e) {
            final SeverityEditorDialog dlg = new SeverityEditorDialog(anchor, myChosen, mySeverityRegistrar);
            if (dlg.showAndGet()) {
                final HighlightInfoType type = dlg.getSelectedType();
                if (type != null) {
                    final HighlightSeverity severity = type.getSeverity(null);
                    setChosen(severity);
                    onChosen(severity);
                }
            }
        }
    });
    return group;
}

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

License:Apache License

@NotNull
@Override//  w  ww  .ja v  a 2  s . c o  m
public DefaultActionGroup createPopupActionGroup(final JComponent component) {
    final DefaultActionGroup group = new DefaultActionGroup();

    final List<NamedScope> predefinedScopes = new ArrayList<NamedScope>();
    final List<NamedScope> customScopes = new ArrayList<NamedScope>();
    for (final NamedScopesHolder holder : NamedScopesHolder.getAllNamedScopeHolders(myProject)) {
        Collections.addAll(customScopes, holder.getEditableScopes());
        predefinedScopes.addAll(holder.getPredefinedScopes());
    }
    predefinedScopes.remove(CustomScopesProviderEx.getAllScope());
    for (NamedScope predefinedScope : predefinedScopes) {
        if (predefinedScope instanceof NonProjectFilesScope) {
            predefinedScopes.remove(predefinedScope);
            break;
        }
    }

    fillActionGroup(group, predefinedScopes, myDefaultDescriptors, myInspectionProfile, myExcludedScopeNames);
    group.addSeparator();
    fillActionGroup(group, customScopes, myDefaultDescriptors, myInspectionProfile, myExcludedScopeNames);

    group.addSeparator();
    group.add(new DumbAwareAction("Edit Scopes Order...") {
        @Override
        public void actionPerformed(final AnActionEvent e) {
            final ScopesOrderDialog dlg = new ScopesOrderDialog(component, myInspectionProfile, myProject);
            if (dlg.showAndGet()) {
                onScopesOrderChanged();
            }
        }
    });

    return group;
}

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

License:Apache License

private void fillActionGroup(final DefaultActionGroup group, final List<NamedScope> scopes,
        final List<Descriptor> defaultDescriptors, final InspectionProfileImpl inspectionProfile,
        final Set<String> excludedScopeNames) {
    for (final NamedScope scope : scopes) {
        final String scopeName = scope.getName();
        if (excludedScopeNames.contains(scopeName)) {
            continue;
        }//from w  ww  .j av a  2s .c  o  m
        group.add(new DumbAwareAction(scopeName) {
            @Override
            public void actionPerformed(final AnActionEvent e) {
                for (final Descriptor defaultDescriptor : defaultDescriptors) {
                    inspectionProfile.addScope(defaultDescriptor.getToolWrapper().createCopy(), scope,
                            defaultDescriptor.getLevel(), true, getEventProject(e));
                }
                onScopeAdded();
            }
        });
    }
}

From source file:com.urswolfer.intellij.plugin.gerrit.ui.changesbrowser.SelectBaseRevisionAction.java

License:Apache License

@Override
protected void createActions(Consumer<AnAction> anActionConsumer) {
    anActionConsumer.consume(new DumbAwareAction("Base") {
        @Override//from   w  w  w  .  j  av  a  2  s  .c  o  m
        public void actionPerformed(AnActionEvent e) {
            removeSelectedValue();
            updateLabel();
        }
    });
    if (selectedChange.isPresent()) {
        ImmutableSortedSet<Map.Entry<String, RevisionInfo>> revisions = ImmutableSortedSet
                .copyOf(RevisionInfos.MAP_ENTRY_COMPARATOR, selectedChange.get().revisions.entrySet());
        for (Map.Entry<String, RevisionInfo> entry : revisions) {
            anActionConsumer.consume(getActionForRevision(entry.getKey(), entry.getValue()));
        }
    }
}

From source file:com.urswolfer.intellij.plugin.gerrit.ui.changesbrowser.SelectBaseRevisionAction.java

License:Apache License

private DumbAwareAction getActionForRevision(final String commitHash, final RevisionInfo revisionInfo) {
    final Pair<String, RevisionInfo> infoPair = Pair.create(commitHash, revisionInfo);
    String actionLabel = REVISION_LABEL_FUNCTION.apply(infoPair);
    return new DumbAwareAction(actionLabel) {
        @Override//from  ww w  .  j  a v a 2 s .  co m
        public void actionPerformed(AnActionEvent e) {
            updateSelectedValue(infoPair);
            updateLabel();
        }

        @Override
        public void update(AnActionEvent e) {
            e.getPresentation().setEnabled(!isSameRevisionAsSelected());
        }

        private boolean isSameRevisionAsSelected() {
            return commitHash.equals(selectedRevisions.get(selectedChange.get()));
        }
    };
}

From source file:org.community.intellij.plugins.communitycase.checkout.branches.BranchesWidget.java

License:Apache License

/**
 * @return get or create remotes group//from   w  ww.  j  a v a2s .c o m
 */
private AnAction[] getRemotes() {
    assert myPopupEnabled : "pop should be enabled";
    if (myRemoveConfigurations == null) {
        ArrayList<AnAction> rc = new ArrayList<AnAction>();
        for (final String c : myConfigurations.getRemotesCandidates()) {
            rc.add(new DumbAwareAction(escapeActionText(c)) {
                @Override
                public void actionPerformed(AnActionEvent e) {
                    myConfigurations.startCheckout(null, c, false);
                }
            });
        }
        rc.add(new RefreshRemotesAction());
        myRemoveConfigurations = rc.toArray(new AnAction[rc.size()]);
    }
    return myRemoveConfigurations;
}

From source file:org.community.intellij.plugins.communitycase.checkout.branches.BranchesWidget.java

License:Apache License

/**
 * Checkout actions//from   w w  w  .  j  a v  a  2 s. c  o m
 *
 * @param name  the excluded name
 * @param quick true, if quick checkout actions
 * @return an array of actions for the configurations
 */
private AnAction[] checkoutActions(String name, final boolean quick) {
    ArrayList<AnAction> rc = new ArrayList<AnAction>();
    for (final String c : myConfigurations.getConfigurationNames()) {
        if (name.equals(c)) {
            // skip current config
            continue;
        }
        rc.add(new DumbAwareAction(escapeActionText(c)) {
            @Override
            public void actionPerformed(AnActionEvent e) {
                try {
                    final BranchConfiguration toCheckout = myConfigurations.getConfiguration(c);
                    if (toCheckout == null) {
                        throw new VcsException("The configuration " + c + " cannot be found.");
                    }
                    myConfigurations.startCheckout(toCheckout, null, quick);
                } catch (VcsException e1) {
                    UiUtil.showOperationError(myProject, e1, "Unable to load: " + c);
                }
            }
        });
    }
    return rc.toArray(new AnAction[rc.size()]);
}

From source file:org.community.intellij.plugins.communitycase.checkout.branches.BranchesWidget.java

License:Apache License

/**
 * @return the action group for popup/*  www.  ja va  2s . c  om*/
 */
ActionGroup getPopupActionGroup() {
    if (myPopupActionGroup == null) {
        myPopupActionGroup = new DefaultActionGroup(null, false);
        myPopupActionGroup.addAction(new DumbAwareAction("Manage Configurations ...") {
            @Override
            public void actionPerformed(AnActionEvent e) {
                ManageConfigurationsDialog.showDialog(myProject, myConfigurations);
            }
        });
        myPopupActionGroup.addAction(new DumbAwareAction("Modify Current Configuration ...") {
            @Override
            public void actionPerformed(AnActionEvent e) {
                try {
                    final BranchConfiguration current = myConfigurations.getCurrentConfiguration();
                    myConfigurations.startCheckout(current, null, false);
                } catch (VcsException e1) {
                    LOG.error("The current configuration must exists at this point", e1);
                }
            }
        });
        myPopupActionGroup.addAction(new DumbAwareAction("New Configuration ...") {
            @Override
            public void actionPerformed(AnActionEvent e) {
                myConfigurations.startCheckout(null, null, false);
            }
        });
        myPopupActionGroup.add(new MyRemotesActionGroup());
        myPopupActionGroup.add(new MySelectableWithChangesActionGroup());
        myPopupActionGroup.addSeparator("Branch Configurations");
        myPopupActionGroup.add(new MySelectableActionGroup());
    }
    return myPopupActionGroup;
}

From source file:org.twodividedbyzero.idea.findbugs.gui.settings.PluginTablePane.java

License:Open Source License

private void doAdd(@NotNull final AnActionButton anActionButton) {
    final Project project = IdeaUtilImpl.getProject(anActionButton.getDataContext());
    if (bundled.isEmpty()) {
        doAddWithFileChooser(project);/*from   w w w  .  ja va2 s  . c o  m*/
    } else {
        // like com.intellij.codeInsight.template.impl.TemplateListPanel#addTemplateOrGroup
        final DefaultActionGroup group = new DefaultActionGroup();
        for (final PluginInfo pluginInfo : bundled) {
            group.add(
                    new DumbAwareAction(ResourcesLoader.getString("plugins.add", pluginInfo.shortDescription)) {
                        @Override
                        public void actionPerformed(@NotNull final AnActionEvent e) {
                            final Set<PluginSettings> settings = New.set();
                            pluginInfo.settings.enabled = true;
                            for (final PluginInfo other : getModel().rows) {
                                settings.add(other.settings);
                                if (other.settings.enabled) {
                                    if (other.settings.id.equals(pluginInfo.settings.id)) {
                                        pluginInfo.settings.enabled = false;
                                        break;
                                    }
                                }
                            }
                            bundled.remove(pluginInfo);
                            settings.add(pluginInfo.settings);
                            load(settings);
                        }
                    });
        }
        group.add(new DumbAwareAction(ResourcesLoader.getString("plugins.addFromDisk")) {
            @Override
            public void actionPerformed(@NotNull AnActionEvent e) {
                doAddWithFileChooser(project);
            }
        });
        final DataContext context = DataManager.getInstance()
                .getDataContext(anActionButton.getContextComponent());
        final ListPopup popup = JBPopupFactory.getInstance().createActionGroupPopup(null, group, context,
                JBPopupFactory.ActionSelectionAid.ALPHA_NUMBERING, true, null);
        popup.show(anActionButton.getPreferredPopupPoint());
    }
}