Search in sources :

Example 16 with AnActionEvent

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

the class GrTypeComboBox method registerUpDownHint.

public static void registerUpDownHint(JComponent component, final GrTypeComboBox combo) {
    final AnAction arrow = new AnAction() {

        @Override
        public void actionPerformed(AnActionEvent e) {
            if (e.getInputEvent() instanceof KeyEvent) {
                final int code = ((KeyEvent) e.getInputEvent()).getKeyCode();
                scrollBy(code == KeyEvent.VK_DOWN ? 1 : code == KeyEvent.VK_UP ? -1 : 0, combo);
            }
        }
    };
    final KeyboardShortcut up = new KeyboardShortcut(KeyStroke.getKeyStroke(KeyEvent.VK_UP, InputEvent.ALT_DOWN_MASK), null);
    final KeyboardShortcut down = new KeyboardShortcut(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, InputEvent.ALT_DOWN_MASK), null);
    arrow.registerCustomShortcutSet(new CustomShortcutSet(up, down), component);
}
Also used : KeyEvent(java.awt.event.KeyEvent) CustomShortcutSet(com.intellij.openapi.actionSystem.CustomShortcutSet) KeyboardShortcut(com.intellij.openapi.actionSystem.KeyboardShortcut) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction)

Example 17 with AnActionEvent

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

the class OverriddenDefineRenderer method getClickAction.

@Override
@Nullable
public AnAction getClickAction() {
    return new AnAction() {

        @Override
        public void actionPerformed(AnActionEvent e) {
            final PsiElement element = myDefine.getPsiElement();
            if (element == null || !element.isValid())
                return;
            final PsiElementProcessor.CollectElements<XmlFile> collector = new PsiElementProcessor.CollectElements<>();
            final XmlFile localFile = (XmlFile) element.getContainingFile();
            RelaxIncludeIndex.processBackwardDependencies(localFile, collector);
            final Collection<XmlFile> files = collector.getCollection();
            final List<Define> result = new SmartList<>();
            final OverriddenDefineSearcher searcher = new OverriddenDefineSearcher(myDefine, localFile, result);
            for (XmlFile file : files) {
                final Grammar grammar = GrammarFactory.getGrammar(file);
                if (grammar == null)
                    continue;
                grammar.acceptChildren(searcher);
            }
            if (result.size() > 0) {
                OverridingDefineRenderer.doClickAction(e, result, "Go to overriding define(s)");
            }
        }
    };
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) Grammar(org.intellij.plugins.relaxNG.model.Grammar) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) PsiElementProcessor(com.intellij.psi.search.PsiElementProcessor) Define(org.intellij.plugins.relaxNG.model.Define) SmartList(com.intellij.util.SmartList) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 18 with AnActionEvent

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

the class CaptureConfigurable method createComponent.

@Nullable
@Override
public JComponent createComponent() {
    myTableModel = new MyTableModel();
    JBTable table = new JBTable(myTableModel);
    table.setColumnSelectionAllowed(false);
    TableColumnModel columnModel = table.getColumnModel();
    TableUtil.setupCheckboxColumn(columnModel.getColumn(MyTableModel.ENABLED_COLUMN));
    ToolbarDecorator decorator = ToolbarDecorator.createDecorator(table);
    decorator.setAddAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            myTableModel.addRow();
        }
    });
    decorator.setRemoveAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            TableUtil.removeSelectedItems(table);
        }
    });
    decorator.setMoveUpAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            TableUtil.moveSelectedItemsUp(table);
        }
    });
    decorator.setMoveDownAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            TableUtil.moveSelectedItemsDown(table);
        }
    });
    decorator.addExtraAction(new DumbAwareActionButton("Duplicate", "Duplicate", PlatformIcons.COPY_ICON) {

        @Override
        public boolean isEnabled() {
            return table.getSelectedRowCount() == 1;
        }

        @Override
        public void actionPerformed(@NotNull AnActionEvent e) {
            selectedCapturePoints(table).forEach(c -> {
                try {
                    int idx = myTableModel.add(c.clone());
                    table.getSelectionModel().setSelectionInterval(idx, idx);
                } catch (CloneNotSupportedException ex) {
                    LOG.error(ex);
                }
            });
        }
    });
    decorator.addExtraAction(new DumbAwareActionButton("Enable Selected", "Enable Selected", PlatformIcons.SELECT_ALL_ICON) {

        @Override
        public boolean isEnabled() {
            return table.getSelectedRowCount() > 0;
        }

        @Override
        public void actionPerformed(@NotNull AnActionEvent e) {
            selectedCapturePoints(table).forEach(c -> c.myEnabled = true);
            table.repaint();
        }
    });
    decorator.addExtraAction(new DumbAwareActionButton("Disable Selected", "Disable Selected", PlatformIcons.UNSELECT_ALL_ICON) {

        @Override
        public boolean isEnabled() {
            return table.getSelectedRowCount() > 0;
        }

        @Override
        public void actionPerformed(@NotNull AnActionEvent e) {
            selectedCapturePoints(table).forEach(c -> c.myEnabled = false);
            table.repaint();
        }
    });
    new DumbAwareAction("Toggle") {

        @Override
        public void update(@NotNull AnActionEvent e) {
            e.getPresentation().setEnabled(table.getSelectedRowCount() == 1);
        }

        @Override
        public void actionPerformed(@NotNull final AnActionEvent e) {
            selectedCapturePoints(table).forEach(c -> c.myEnabled = !c.myEnabled);
            table.repaint();
        }
    }.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0)), table);
    decorator.addExtraAction(new DumbAwareActionButton("Import", "Import", AllIcons.Actions.Install) {

        @Override
        public void actionPerformed(@NotNull final AnActionEvent e) {
            FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, true, false, true, true) {

                @Override
                public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
                    return super.isFileVisible(file, showHiddenFiles) && (file.isDirectory() || "xml".equals(file.getExtension()) || file.getFileType() == FileTypes.ARCHIVE);
                }

                @Override
                public boolean isFileSelectable(VirtualFile file) {
                    return file.getFileType() == StdFileTypes.XML;
                }
            };
            descriptor.setDescription("Please select a file to import.");
            descriptor.setTitle("Import Capture Points");
            VirtualFile[] files = FileChooser.chooseFiles(descriptor, e.getProject(), null);
            if (ArrayUtil.isEmpty(files))
                return;
            table.getSelectionModel().clearSelection();
            for (VirtualFile file : files) {
                try {
                    Document document = JDOMUtil.loadDocument(file.getInputStream());
                    List<Element> children = document.getRootElement().getChildren();
                    children.forEach(element -> {
                        int idx = myTableModel.addIfNeeded(XmlSerializer.deserialize(element, CapturePoint.class));
                        table.getSelectionModel().addSelectionInterval(idx, idx);
                    });
                } catch (Exception ex) {
                    final String msg = ex.getLocalizedMessage();
                    Messages.showErrorDialog(e.getProject(), msg != null && msg.length() > 0 ? msg : ex.toString(), "Export Failed");
                }
            }
        }
    });
    decorator.addExtraAction(new DumbAwareActionButton("Export", "Export", AllIcons.Actions.Export) {

        @Override
        public void actionPerformed(@NotNull final AnActionEvent e) {
            VirtualFileWrapper wrapper = FileChooserFactory.getInstance().createSaveFileDialog(new FileSaverDescriptor("Export Selected Capture Points to File...", "", "xml"), e.getProject()).save(null, null);
            if (wrapper == null)
                return;
            Element rootElement = new Element("capture-points");
            selectedCapturePoints(table).forEach(c -> {
                try {
                    CapturePoint clone = c.clone();
                    clone.myEnabled = false;
                    rootElement.addContent(XmlSerializer.serialize(clone));
                } catch (CloneNotSupportedException ex) {
                    LOG.error(ex);
                }
            });
            try {
                JDOMUtil.write(rootElement, wrapper.getFile());
            } catch (Exception ex) {
                final String msg = ex.getLocalizedMessage();
                Messages.showErrorDialog(e.getProject(), msg != null && msg.length() > 0 ? msg : ex.toString(), "Export Failed");
            }
        }

        @Override
        public boolean isEnabled() {
            return table.getSelectedRowCount() > 0;
        }
    });
    BorderLayoutPanel panel = JBUI.Panels.simplePanel();
    panel.addToCenter(decorator.createPanel());
    myCaptureVariables = new JCheckBox(DebuggerBundle.message("label.capture.configurable.capture.variables"));
    panel.addToBottom(myCaptureVariables);
    return panel;
}
Also used : JVMNameUtil(com.intellij.debugger.engine.JVMNameUtil) JavaDebuggerSupport(com.intellij.debugger.ui.JavaDebuggerSupport) AllIcons(com.intellij.icons.AllIcons) VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileSaverDescriptor(com.intellij.openapi.fileChooser.FileSaverDescriptor) Document(org.jdom.Document) Nls(org.jetbrains.annotations.Nls) BorderLayoutPanel(com.intellij.util.ui.components.BorderLayoutPanel) JBUI(com.intellij.util.ui.JBUI) VirtualFileWrapper(com.intellij.openapi.vfs.VirtualFileWrapper) FileTypes(com.intellij.openapi.fileTypes.FileTypes) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) Messages(com.intellij.openapi.ui.Messages) Logger(com.intellij.openapi.diagnostic.Logger) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) FileChooserFactory(com.intellij.openapi.fileChooser.FileChooserFactory) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) KeyEvent(java.awt.event.KeyEvent) com.intellij.ui(com.intellij.ui) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Debugger(org.jetbrains.annotations.Debugger) AnnotatedElementsSearch(com.intellij.psi.search.searches.AnnotatedElementsSearch) StreamEx(one.util.streamex.StreamEx) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) Registry(com.intellij.openapi.util.registry.Registry) IntStreamEx(one.util.streamex.IntStreamEx) com.intellij.psi(com.intellij.psi) ConfigurationException(com.intellij.openapi.options.ConfigurationException) NotNull(org.jetbrains.annotations.NotNull) XmlSerializer(com.intellij.util.xmlb.XmlSerializer) ArrayUtil(com.intellij.util.ArrayUtil) CustomShortcutSet(com.intellij.openapi.actionSystem.CustomShortcutSet) TableColumnModel(javax.swing.table.TableColumnModel) ArrayList(java.util.ArrayList) JDOMUtil(com.intellij.openapi.util.JDOMUtil) AbstractTableModel(javax.swing.table.AbstractTableModel) Project(com.intellij.openapi.project.Project) DebuggerBundle(com.intellij.debugger.DebuggerBundle) PlatformIcons(com.intellij.util.PlatformIcons) DecompiledLocalVariable(com.intellij.debugger.jdi.DecompiledLocalVariable) StdFileTypes(com.intellij.openapi.fileTypes.StdFileTypes) StringUtil(com.intellij.openapi.util.text.StringUtil) ItemRemovable(com.intellij.util.ui.ItemRemovable) JBTable(com.intellij.ui.table.JBTable) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) Element(org.jdom.Element) FileChooser(com.intellij.openapi.fileChooser.FileChooser) SearchableConfigurable(com.intellij.openapi.options.SearchableConfigurable) javax.swing(javax.swing) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Element(org.jdom.Element) TableColumnModel(javax.swing.table.TableColumnModel) JBTable(com.intellij.ui.table.JBTable) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) Document(org.jdom.Document) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) CustomShortcutSet(com.intellij.openapi.actionSystem.CustomShortcutSet) List(java.util.List) ArrayList(java.util.ArrayList) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) BorderLayoutPanel(com.intellij.util.ui.components.BorderLayoutPanel) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) ConfigurationException(com.intellij.openapi.options.ConfigurationException) FileSaverDescriptor(com.intellij.openapi.fileChooser.FileSaverDescriptor) VirtualFileWrapper(com.intellij.openapi.vfs.VirtualFileWrapper) Nullable(org.jetbrains.annotations.Nullable)

Example 19 with AnActionEvent

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

the class ShowInstancesFromClassesViewAction method perform.

@Override
protected void perform(AnActionEvent e) {
    final Project project = e.getProject();
    final ReferenceType selectedClass = getSelectedClass(e);
    if (project != null && selectedClass != null) {
        final XDebugSession debugSession = XDebuggerManager.getInstance(project).getCurrentSession();
        if (debugSession != null) {
            new InstancesWindow(debugSession, limit -> selectedClass.instances(limit), selectedClass.name()).show();
        }
    }
}
Also used : ClassesTable(com.intellij.debugger.memory.ui.ClassesTable) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) ReferenceType(com.sun.jdi.ReferenceType) Project(com.intellij.openapi.project.Project) XDebuggerManager(com.intellij.xdebugger.XDebuggerManager) InstancesWindow(com.intellij.debugger.memory.ui.InstancesWindow) XDebugSession(com.intellij.xdebugger.XDebugSession) Project(com.intellij.openapi.project.Project) XDebugSession(com.intellij.xdebugger.XDebugSession) InstancesWindow(com.intellij.debugger.memory.ui.InstancesWindow) ReferenceType(com.sun.jdi.ReferenceType)

Example 20 with AnActionEvent

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

the class BuildArtifactAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final Project project = getEventProject(e);
    if (project == null)
        return;
    final List<Artifact> artifacts = ArtifactUtil.getArtifactWithOutputPaths(project);
    if (artifacts.isEmpty())
        return;
    List<ArtifactPopupItem> items = new ArrayList<>();
    if (artifacts.size() > 1) {
        items.add(0, new ArtifactPopupItem(null, "All Artifacts", EmptyIcon.ICON_16));
    }
    Set<Artifact> selectedArtifacts = new HashSet<>(ArtifactsWorkspaceSettings.getInstance(project).getArtifactsToBuild());
    TIntArrayList selectedIndices = new TIntArrayList();
    if (Comparing.haveEqualElements(artifacts, selectedArtifacts) && selectedArtifacts.size() > 1) {
        selectedIndices.add(0);
        selectedArtifacts.clear();
    }
    for (Artifact artifact : artifacts) {
        final ArtifactPopupItem item = new ArtifactPopupItem(artifact, artifact.getName(), artifact.getArtifactType().getIcon());
        if (selectedArtifacts.contains(artifact)) {
            selectedIndices.add(items.size());
        }
        items.add(item);
    }
    final ProjectSettingsService projectSettingsService = ProjectSettingsService.getInstance(project);
    final ArtifactAwareProjectSettingsService settingsService = projectSettingsService instanceof ArtifactAwareProjectSettingsService ? (ArtifactAwareProjectSettingsService) projectSettingsService : null;
    final ChooseArtifactStep step = new ChooseArtifactStep(items, artifacts.get(0), project, settingsService);
    step.setDefaultOptionIndices(selectedIndices.toNativeArray());
    final ListPopupImpl popup = (ListPopupImpl) JBPopupFactory.getInstance().createListPopup(step);
    final KeyStroke editKeyStroke = KeymapUtil.getKeyStroke(CommonShortcuts.getEditSource());
    if (settingsService != null && editKeyStroke != null) {
        popup.registerAction("editArtifact", editKeyStroke, new AbstractAction() {

            @Override
            public void actionPerformed(ActionEvent e) {
                Object[] values = popup.getSelectedValues();
                popup.cancel();
                settingsService.openArtifactSettings(values.length > 0 ? ((ArtifactPopupItem) values[0]).getArtifact() : null);
            }
        });
    }
    popup.showCenteredInCurrentWindow(project);
}
Also used : ActionEvent(java.awt.event.ActionEvent) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) TIntArrayList(gnu.trove.TIntArrayList) Artifact(com.intellij.packaging.artifacts.Artifact) TIntArrayList(gnu.trove.TIntArrayList) Project(com.intellij.openapi.project.Project) ListPopupImpl(com.intellij.ui.popup.list.ListPopupImpl) ProjectSettingsService(com.intellij.openapi.roots.ui.configuration.ProjectSettingsService)

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