Search in sources :

Example 56 with AnActionEvent

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

the class AbstractGithubTagDownloadedProjectGenerator method createGitHubLink.

public ActionLink createGitHubLink() {
    final ActionLink link = new ActionLink(getName() + " on GitHub", new AnAction() {

        @Override
        public void actionPerformed(AnActionEvent e) {
            BrowserUtil.open("https://github.com/" + getGithubUserName() + "/" + getGithubRepositoryName());
        }
    });
    link.setFont(UIUtil.getLabelFont(UIUtil.FontSize.SMALL));
    return link;
}
Also used : AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) ActionLink(com.intellij.ui.components.labels.ActionLink)

Example 57 with AnActionEvent

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

the class AnnotateStackTraceAction method actionPerformed.

@Override
public void actionPerformed(final AnActionEvent e) {
    myIsLoading = true;
    ProgressManager.getInstance().run(new Task.Backgroundable(myEditor.getProject(), "Getting File History", true) {

        private final Object LOCK = new Object();

        private final MergingUpdateQueue myUpdateQueue = new MergingUpdateQueue("AnnotateStackTraceAction", 200, true, null);

        private MyActiveAnnotationGutter myGutter;

        @Override
        public void onCancel() {
            myEditor.getGutter().closeAllAnnotations();
        }

        @Override
        public void onFinished() {
            myIsLoading = false;
            Disposer.dispose(myUpdateQueue);
        }

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            MultiMap<VirtualFile, Integer> files2lines = new MultiMap<>();
            Map<Integer, LastRevision> revisions = ContainerUtil.newHashMap();
            ApplicationManager.getApplication().runReadAction(() -> {
                for (int line = 0; line < myEditor.getDocument().getLineCount(); line++) {
                    indicator.checkCanceled();
                    VirtualFile file = getHyperlinkVirtualFile(myHyperlinks.findAllHyperlinksOnLine(line));
                    if (file == null)
                        continue;
                    files2lines.putValue(file, line);
                }
            });
            files2lines.entrySet().forEach(entry -> {
                indicator.checkCanceled();
                VirtualFile file = entry.getKey();
                Collection<Integer> lines = entry.getValue();
                LastRevision revision = getLastRevision(file);
                if (revision == null)
                    return;
                synchronized (LOCK) {
                    for (Integer line : lines) {
                        revisions.put(line, revision);
                    }
                }
                myUpdateQueue.queue(new Update("update") {

                    @Override
                    public void run() {
                        updateGutter(indicator, revisions);
                    }
                });
            });
            // myUpdateQueue can be disposed before the last revisions are passed to the gutter
            ApplicationManager.getApplication().invokeLater(() -> updateGutter(indicator, revisions));
        }

        @CalledInAwt
        private void updateGutter(@NotNull ProgressIndicator indicator, @NotNull Map<Integer, LastRevision> revisions) {
            if (indicator.isCanceled())
                return;
            if (myGutter == null) {
                myGutter = new MyActiveAnnotationGutter(getProject(), myHyperlinks, indicator);
                myEditor.getGutter().registerTextAnnotation(myGutter, myGutter);
            }
            Map<Integer, LastRevision> revisionsCopy;
            synchronized (LOCK) {
                revisionsCopy = ContainerUtil.newHashMap(revisions);
            }
            myGutter.updateData(revisionsCopy);
            ((EditorGutterComponentEx) myEditor.getGutter()).revalidateMarkup();
        }

        @Nullable
        private LastRevision getLastRevision(@NotNull VirtualFile file) {
            try {
                AbstractVcs vcs = VcsUtil.getVcsFor(myEditor.getProject(), file);
                if (vcs == null)
                    return null;
                VcsHistoryProvider historyProvider = vcs.getVcsHistoryProvider();
                if (historyProvider == null)
                    return null;
                FilePath filePath = VcsContextFactory.SERVICE.getInstance().createFilePathOn(file);
                if (historyProvider instanceof VcsHistoryProviderEx) {
                    VcsFileRevision revision = ((VcsHistoryProviderEx) historyProvider).getLastRevision(filePath);
                    if (revision == null)
                        return null;
                    return LastRevision.create(revision);
                } else {
                    VcsHistorySession session = historyProvider.createSessionFor(filePath);
                    if (session == null)
                        return null;
                    List<VcsFileRevision> list = session.getRevisionList();
                    if (list == null || list.isEmpty())
                        return null;
                    return LastRevision.create(list.get(0));
                }
            } catch (VcsException ignored) {
                LOG.warn(ignored);
                return null;
            }
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VcsRevisionNumber(com.intellij.openapi.vcs.history.VcsRevisionNumber) DateFormatUtil(com.intellij.util.text.DateFormatUtil) java.util(java.util) AllIcons(com.intellij.icons.AllIcons) VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileHyperlinkInfo(com.intellij.execution.filters.FileHyperlinkInfo) EditorHyperlinkSupport(com.intellij.execution.impl.EditorHyperlinkSupport) EditorFontType(com.intellij.openapi.editor.colors.EditorFontType) ContainerUtil(com.intellij.util.containers.ContainerUtil) ActiveAnnotationGutter(com.intellij.openapi.vcs.actions.ActiveAnnotationGutter) ShowAllAffectedGenericAction(com.intellij.openapi.vcs.annotate.ShowAllAffectedGenericAction) VcsHistorySession(com.intellij.openapi.vcs.history.VcsHistorySession) Task(com.intellij.openapi.progress.Task) ColorKey(com.intellij.openapi.editor.colors.ColorKey) VcsContextFactory(com.intellij.openapi.vcs.actions.VcsContextFactory) AnnotationSource(com.intellij.openapi.vcs.annotate.AnnotationSource) CalledWithReadLock(org.jetbrains.annotations.CalledWithReadLock) Disposer(com.intellij.openapi.util.Disposer) RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) Project(com.intellij.openapi.project.Project) Logger(com.intellij.openapi.diagnostic.Logger) EditorGutterComponentEx(com.intellij.openapi.editor.ex.EditorGutterComponentEx) com.intellij.openapi.vcs(com.intellij.openapi.vcs) MultiMap(com.intellij.util.containers.MultiMap) CalledInAwt(org.jetbrains.annotations.CalledInAwt) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) ProgressManager(com.intellij.openapi.progress.ProgressManager) VcsUtil(com.intellij.vcsUtil.VcsUtil) StringUtil(com.intellij.openapi.util.text.StringUtil) AnAction(com.intellij.openapi.actionSystem.AnAction) VcsHistoryProvider(com.intellij.openapi.vcs.history.VcsHistoryProvider) VcsFileRevision(com.intellij.openapi.vcs.history.VcsFileRevision) Editor(com.intellij.openapi.editor.Editor) VcsHistoryProviderEx(com.intellij.vcs.history.VcsHistoryProviderEx) MergingUpdateQueue(com.intellij.util.ui.update.MergingUpdateQueue) java.awt(java.awt) HyperlinkInfo(com.intellij.execution.filters.HyperlinkInfo) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) Update(com.intellij.util.ui.update.Update) List(java.util.List) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) ApplicationManager(com.intellij.openapi.application.ApplicationManager) XmlStringUtil(com.intellij.xml.util.XmlStringUtil) NotNull(org.jetbrains.annotations.NotNull) Task(com.intellij.openapi.progress.Task) CalledInAwt(org.jetbrains.annotations.CalledInAwt) VcsHistoryProvider(com.intellij.openapi.vcs.history.VcsHistoryProvider) Update(com.intellij.util.ui.update.Update) MultiMap(com.intellij.util.containers.MultiMap) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) VcsHistoryProviderEx(com.intellij.vcs.history.VcsHistoryProviderEx) VcsHistorySession(com.intellij.openapi.vcs.history.VcsHistorySession) List(java.util.List) VcsFileRevision(com.intellij.openapi.vcs.history.VcsFileRevision) MergingUpdateQueue(com.intellij.util.ui.update.MergingUpdateQueue) MultiMap(com.intellij.util.containers.MultiMap) Nullable(org.jetbrains.annotations.Nullable)

Example 58 with AnActionEvent

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

the class JavaChangeSignatureDialog method createAdditionalPanels.

@NotNull
protected List<Pair<String, JPanel>> createAdditionalPanels() {
    // this method is invoked before constructor body
    myExceptionsModel = new ExceptionsTableModel(myMethod.getMethod().getThrowsList());
    myExceptionsModel.setTypeInfos(myMethod.getMethod());
    final JBTable table = new JBTable(myExceptionsModel);
    table.setStriped(true);
    table.setRowHeight(20);
    table.getColumnModel().getColumn(0).setCellRenderer(new CodeFragmentTableCellRenderer(myProject));
    final JavaCodeFragmentTableCellEditor cellEditor = new JavaCodeFragmentTableCellEditor(myProject);
    cellEditor.addDocumentListener(new DocumentAdapter() {

        @Override
        public void documentChanged(DocumentEvent e) {
            final int row = table.getSelectedRow();
            final int col = table.getSelectedColumn();
            myExceptionsModel.setValueAt(cellEditor.getCellEditorValue(), row, col);
            updateSignature();
        }
    });
    table.getColumnModel().getColumn(0).setCellEditor(cellEditor);
    table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.getSelectionModel().setSelectionInterval(0, 0);
    table.setSurrendersFocusOnKeystroke(true);
    myPropExceptionsButton = new AnActionButton(RefactoringBundle.message("changeSignature.propagate.exceptions.title"), null, AllIcons.Hierarchy.Caller) {

        @Override
        public void actionPerformed(AnActionEvent e) {
            final Ref<JavaCallerChooser> chooser = new Ref<>();
            Consumer<Set<PsiMethod>> callback = psiMethods -> {
                myMethodsToPropagateExceptions = psiMethods;
                myExceptionPropagationTree = chooser.get().getTree();
            };
            chooser.set(new JavaCallerChooser(myMethod.getMethod(), myProject, RefactoringBundle.message("changeSignature.exception.caller.chooser"), myExceptionPropagationTree, callback));
            chooser.get().show();
        }
    };
    myPropExceptionsButton.setShortcut(CustomShortcutSet.fromString("alt X"));
    final JPanel panel = ToolbarDecorator.createDecorator(table).addExtraAction(myPropExceptionsButton).createPanel();
    panel.setBorder(IdeBorderFactory.createEmptyBorder());
    myExceptionsModel.addTableModelListener(mySignatureUpdater);
    final ArrayList<Pair<String, JPanel>> result = new ArrayList<>();
    final String message = RefactoringBundle.message("changeSignature.exceptions.panel.border.title");
    result.add(Pair.create(message, panel));
    return result;
}
Also used : JavaCallerChooser(com.intellij.refactoring.changeSignature.inCallers.JavaCallerChooser) ArrayList(java.util.ArrayList) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) JBTable(com.intellij.ui.table.JBTable) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) JavaCodeFragmentTableCellEditor(com.intellij.refactoring.ui.JavaCodeFragmentTableCellEditor) Ref(com.intellij.openapi.util.Ref) CodeFragmentTableCellRenderer(com.intellij.refactoring.ui.CodeFragmentTableCellRenderer) Pair(com.intellij.openapi.util.Pair) NotNull(org.jetbrains.annotations.NotNull)

Example 59 with AnActionEvent

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

the class BaseGenerateTestSupportMethodAction method createEditTemplateAction.

@Nullable
@Override
public AnAction createEditTemplateAction(DataContext dataContext) {
    final Project project = CommonDataKeys.PROJECT.getData(dataContext);
    final Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
    final PsiFile file = CommonDataKeys.PSI_FILE.getData(dataContext);
    final PsiClass targetClass = editor == null || file == null ? null : getTargetClass(editor, file);
    if (targetClass != null) {
        final List<TestFramework> frameworks = TestIntegrationUtils.findSuitableFrameworks(targetClass);
        final TestIntegrationUtils.MethodKind methodKind = ((MyHandler) getHandler()).myMethodKind;
        if (!frameworks.isEmpty()) {
            return new AnAction("Edit Template") {

                @Override
                public void actionPerformed(AnActionEvent e) {
                    chooseAndPerform(editor, frameworks, framework -> {
                        final FileTemplateDescriptor descriptor = methodKind.getFileTemplateDescriptor(framework);
                        if (descriptor != null) {
                            final String fileName = descriptor.getFileName();
                            AllFileTemplatesConfigurable.editCodeTemplate(FileUtil.getNameWithoutExtension(fileName), project);
                        } else {
                            HintManager.getInstance().showErrorHint(editor, "No template found for " + framework.getName() + ":" + BaseGenerateTestSupportMethodAction.this.getTemplatePresentation().getText());
                        }
                    });
                }
            };
        }
    }
    return null;
}
Also used : AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) Project(com.intellij.openapi.project.Project) FileTemplateDescriptor(com.intellij.ide.fileTemplates.FileTemplateDescriptor) Editor(com.intellij.openapi.editor.Editor) Nullable(org.jetbrains.annotations.Nullable)

Example 60 with AnActionEvent

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

the class ScrollingUtil method installActions.

public static void installActions(final JTable table, final boolean cycleScrolling, JComponent focusParent) {
    ActionMap actionMap = table.getActionMap();
    actionMap.put(SCROLLUP_ACTION_ID, new MoveAction(SCROLLUP_ACTION_ID, table, cycleScrolling));
    actionMap.put(SCROLLDOWN_ACTION_ID, new MoveAction(SCROLLDOWN_ACTION_ID, table, cycleScrolling));
    actionMap.put(SELECT_PREVIOUS_ROW_ACTION_ID, new MoveAction(SELECT_PREVIOUS_ROW_ACTION_ID, table, cycleScrolling));
    actionMap.put(SELECT_NEXT_ROW_ACTION_ID, new MoveAction(SELECT_NEXT_ROW_ACTION_ID, table, cycleScrolling));
    actionMap.put(SELECT_LAST_ROW_ACTION_ID, new MoveAction(SELECT_LAST_ROW_ACTION_ID, table, cycleScrolling));
    actionMap.put(SELECT_FIRST_ROW_ACTION_ID, new MoveAction(SELECT_FIRST_ROW_ACTION_ID, table, cycleScrolling));
    maybeInstallDefaultShortcuts(table);
    JComponent target = focusParent == null ? table : focusParent;
    new MyScrollingAction(table) {

        @Override
        public void actionPerformed(AnActionEvent e) {
            moveHome(table);
        }
    }.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0)), table);
    new MyScrollingAction(table) {

        @Override
        public void actionPerformed(AnActionEvent e) {
            moveEnd(table);
        }
    }.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0)), table);
    if (!(focusParent instanceof JTextComponent)) {
        new MyScrollingAction(table) {

            @Override
            public void actionPerformed(AnActionEvent e) {
                moveHome(table);
            }
        }.registerCustomShortcutSet(CommonShortcuts.getMoveHome(), target);
        new MyScrollingAction(table) {

            @Override
            public void actionPerformed(AnActionEvent e) {
                moveEnd(table);
            }
        }.registerCustomShortcutSet(CommonShortcuts.getMoveEnd(), target);
    }
    new MyScrollingAction(table) {

        @Override
        public void actionPerformed(AnActionEvent e) {
            moveDown(table, e.getModifiers(), cycleScrolling);
        }
    }.registerCustomShortcutSet(CommonShortcuts.getMoveDown(), target);
    new MyScrollingAction(table) {

        @Override
        public void actionPerformed(AnActionEvent e) {
            moveUp(table, e.getModifiers(), cycleScrolling);
        }
    }.registerCustomShortcutSet(CommonShortcuts.getMoveUp(), target);
    new MyScrollingAction(table) {

        @Override
        public void actionPerformed(AnActionEvent e) {
            movePageUp(table);
        }
    }.registerCustomShortcutSet(CommonShortcuts.getMovePageUp(), target);
    new MyScrollingAction(table) {

        @Override
        public void actionPerformed(AnActionEvent e) {
            movePageDown(table);
        }
    }.registerCustomShortcutSet(CommonShortcuts.getMovePageDown(), target);
}
Also used : CustomShortcutSet(com.intellij.openapi.actionSystem.CustomShortcutSet) JTextComponent(javax.swing.text.JTextComponent) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent)

Aggregations

AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)130 AnAction (com.intellij.openapi.actionSystem.AnAction)67 Project (com.intellij.openapi.project.Project)27 NotNull (org.jetbrains.annotations.NotNull)25 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)22 VirtualFile (com.intellij.openapi.vfs.VirtualFile)21 Nullable (org.jetbrains.annotations.Nullable)20 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)15 List (java.util.List)14 CustomShortcutSet (com.intellij.openapi.actionSystem.CustomShortcutSet)13 ArrayList (java.util.ArrayList)11 Presentation (com.intellij.openapi.actionSystem.Presentation)10 StringUtil (com.intellij.openapi.util.text.StringUtil)9 CommonDataKeys (com.intellij.openapi.actionSystem.CommonDataKeys)8 JBTable (com.intellij.ui.table.JBTable)8 DataContext (com.intellij.openapi.actionSystem.DataContext)7 Pair (com.intellij.openapi.util.Pair)7 Logger (com.intellij.openapi.diagnostic.Logger)6 Ref (com.intellij.openapi.util.Ref)6 AnActionButton (com.intellij.ui.AnActionButton)6