Search in sources :

Example 26 with DumbAwareAction

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

the class FindDialog method createCenterPanel.

@Override
public JComponent createCenterPanel() {
    JPanel optionsPanel = new JPanel();
    optionsPanel.setLayout(new GridBagLayout());
    GridBagConstraints gbConstraints = new GridBagConstraints();
    gbConstraints.weightx = 1;
    gbConstraints.weighty = 1;
    gbConstraints.fill = GridBagConstraints.BOTH;
    gbConstraints.gridwidth = GridBagConstraints.REMAINDER;
    JPanel topOptionsPanel = new JPanel();
    topOptionsPanel.setLayout(new GridLayout(1, 2, UIUtil.DEFAULT_HGAP, 0));
    topOptionsPanel.add(createFindOptionsPanel());
    optionsPanel.add(topOptionsPanel, gbConstraints);
    JPanel resultsOptionPanel = null;
    if (myHelper.getModel().isMultipleFiles()) {
        optionsPanel.add(createGlobalScopePanel(), gbConstraints);
        gbConstraints.weightx = 1;
        gbConstraints.weighty = 1;
        gbConstraints.fill = GridBagConstraints.HORIZONTAL;
        gbConstraints.gridwidth = GridBagConstraints.REMAINDER;
        optionsPanel.add(createFilterPanel(), gbConstraints);
        myCbToSkipResultsWhenOneUsage = createCheckbox(myHelper.isSkipResultsWithOneUsage(), FindBundle.message("find.options.skip.results.tab.with.one.occurrence.checkbox"));
        myCbToSkipResultsWhenOneUsage.addActionListener(e -> myHelper.setSkipResultsWithOneUsage(myCbToSkipResultsWhenOneUsage.isSelected()));
        resultsOptionPanel = createResultsOptionPanel(optionsPanel, gbConstraints);
        resultsOptionPanel.add(myCbToSkipResultsWhenOneUsage);
        myCbToSkipResultsWhenOneUsage.setVisible(!myHelper.isReplaceState());
        if (haveResultsPreview()) {
            final JBTable table = new JBTable() {

                @Override
                public Dimension getPreferredSize() {
                    return new Dimension(myInputComboBox.getWidth(), super.getPreferredSize().height);
                }
            };
            table.setShowColumns(false);
            table.setShowGrid(false);
            table.setIntercellSpacing(JBUI.emptySize());
            new NavigateToSourceListener().installOn(table);
            Splitter previewSplitter = new Splitter(true, 0.5f, 0.1f, 0.9f);
            myUsagePreviewPanel = new UsagePreviewPanel(myProject, new UsageViewPresentation(), true);
            myUsagePreviewPanel.setBorder(IdeBorderFactory.createBorder());
            registerNavigateToSourceShortcutOnComponent(table, myUsagePreviewPanel);
            myResultsPreviewTable = table;
            new TableSpeedSearch(table, new Convertor<Object, String>() {

                @Override
                public String convert(Object o) {
                    return ((UsageInfo2UsageAdapter) o).getFile().getName();
                }
            });
            myResultsPreviewTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

                @Override
                public void valueChanged(ListSelectionEvent e) {
                    if (e.getValueIsAdjusting())
                        return;
                    int index = myResultsPreviewTable.getSelectionModel().getLeadSelectionIndex();
                    if (index != -1) {
                        UsageInfo usageInfo = ((UsageInfo2UsageAdapter) myResultsPreviewTable.getModel().getValueAt(index, 0)).getUsageInfo();
                        myUsagePreviewPanel.updateLayout(usageInfo.isValid() ? Collections.singletonList(usageInfo) : null);
                        VirtualFile file = usageInfo.getVirtualFile();
                        myUsagePreviewPanel.setBorder(IdeBorderFactory.createTitledBorder(file != null ? file.getPath() : "", false));
                    } else {
                        myUsagePreviewPanel.updateLayout(null);
                        myUsagePreviewPanel.setBorder(IdeBorderFactory.createBorder());
                    }
                }
            });
            mySearchRescheduleOnCancellationsAlarm = new Alarm();
            previewSplitter.setFirstComponent(new JBScrollPane(myResultsPreviewTable));
            previewSplitter.setSecondComponent(myUsagePreviewPanel.createComponent());
            myPreviewSplitter = previewSplitter;
        }
    } else {
        JPanel leftOptionsPanel = new JPanel();
        leftOptionsPanel.setLayout(new GridLayout(3, 1, 0, 4));
        leftOptionsPanel.add(createDirectionPanel());
        leftOptionsPanel.add(createOriginPanel());
        leftOptionsPanel.add(createScopePanel());
        topOptionsPanel.add(leftOptionsPanel);
    }
    if (myHelper.getModel().isOpenInNewTabVisible()) {
        myCbToOpenInNewTab = new JCheckBox(FindBundle.message("find.open.in.new.tab.checkbox"));
        myCbToOpenInNewTab.setFocusable(false);
        myCbToOpenInNewTab.setSelected(myHelper.isUseSeparateView());
        myCbToOpenInNewTab.setEnabled(myHelper.getModel().isOpenInNewTabEnabled());
        myCbToOpenInNewTab.addActionListener(e -> myHelper.setUseSeparateView(myCbToOpenInNewTab.isSelected()));
        if (resultsOptionPanel == null)
            resultsOptionPanel = createResultsOptionPanel(optionsPanel, gbConstraints);
        resultsOptionPanel.add(myCbToOpenInNewTab);
    }
    if (myPreviewSplitter != null) {
        TabbedPane pane = new JBTabsPaneImpl(myProject, SwingConstants.TOP, myDisposable);
        pane.insertTab("Options", null, optionsPanel, null, 0);
        pane.insertTab(PREVIEW_TITLE, null, myPreviewSplitter, null, RESULTS_PREVIEW_TAB_INDEX);
        myContent = pane;
        final AnAction anAction = new DumbAwareAction() {

            @Override
            public void actionPerformed(AnActionEvent e) {
                int selectedIndex = myContent.getSelectedIndex();
                myContent.setSelectedIndex(1 - selectedIndex);
            }
        };
        final ShortcutSet shortcutSet = ActionManager.getInstance().getAction(IdeActions.ACTION_SWITCHER).getShortcutSet();
        anAction.registerCustomShortcutSet(shortcutSet, getRootPane(), myDisposable);
        if (myPreviewResultsTabWasSelected)
            myContent.setSelectedIndex(RESULTS_PREVIEW_TAB_INDEX);
        return pane.getComponent();
    }
    return optionsPanel;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ListSelectionEvent(javax.swing.event.ListSelectionEvent) UsagePreviewPanel(com.intellij.usages.impl.UsagePreviewPanel) JBTable(com.intellij.ui.table.JBTable) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) UsageInfo(com.intellij.usageView.UsageInfo) ListSelectionListener(javax.swing.event.ListSelectionListener) Alarm(com.intellij.util.Alarm) JBScrollPane(com.intellij.ui.components.JBScrollPane)

Example 27 with DumbAwareAction

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

the class FindPopupPanel method registerCloseAction.

private void registerCloseAction(JBPopup popup) {
    final AnAction escape = ActionManager.getInstance().getAction("EditorEscape");
    DumbAwareAction closeAction = new DumbAwareAction() {

        @Override
        public void actionPerformed(AnActionEvent e) {
            if (myBalloon != null && myBalloon.isVisible()) {
                myBalloon.cancel();
            }
        }
    };
    closeAction.registerCustomShortcutSet(escape == null ? CommonShortcuts.ESCAPE : escape.getShortcutSet(), popup.getContent(), popup);
}
Also used : DumbAwareAction(com.intellij.openapi.project.DumbAwareAction)

Example 28 with DumbAwareAction

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

the class ProjectStartupConfigurable method createComponent.

@Nullable
@Override
public JComponent createComponent() {
    myModel = new ProjectStartupTasksTableModel(RunManagerEx.getInstanceEx(myProject));
    myTable = new JBTable(myModel);
    myTable.getEmptyText().setText("Add run configurations with the + button");
    new TableSpeedSearch(myTable);
    DefaultCellEditor defaultEditor = (DefaultCellEditor) myTable.getDefaultEditor(Object.class);
    defaultEditor.setClickCountToStart(1);
    myTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    new DumbAwareAction() {

        @Override
        public void actionPerformed(AnActionEvent e) {
            final int row = myTable.getSelectedRow();
            if (row >= 0 && myModel.isCellEditable(row, ProjectStartupTasksTableModel.IS_SHARED_COLUMN)) {
                myModel.setValueAt(!Boolean.TRUE.equals(myTable.getValueAt(row, ProjectStartupTasksTableModel.IS_SHARED_COLUMN)), row, ProjectStartupTasksTableModel.IS_SHARED_COLUMN);
            }
        }
    }.registerCustomShortcutSet(new CustomShortcutSet(KeyEvent.VK_SPACE), myTable);
    myTable.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() >= 2) {
                editRunConfiguration();
            }
        }
    });
    installRenderers();
    myDecorator = ToolbarDecorator.createDecorator(myTable).setAddAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            selectAndAddConfiguration(button);
        }
    }).setEditAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            editRunConfiguration();
        }
    }).setEditActionUpdater(new AnActionButtonUpdater() {

        @Override
        public boolean isEnabled(AnActionEvent e) {
            return myTable.getSelectedRow() >= 0;
        }
    }).disableUpAction().disableDownAction();
    final JPanel tasksPanel = myDecorator.createPanel();
    final JLabel label = new JLabel("Run tasks and tools via run configurations");
    label.setForeground(UIUtil.getInactiveTextColor());
    label.setHorizontalAlignment(SwingConstants.RIGHT);
    final JPanel wrapper = new JPanel(new BorderLayout());
    wrapper.add(new JLabel("To be started on project opening:"), BorderLayout.WEST);
    wrapper.add(label, BorderLayout.EAST);
    wrapper.setBorder(BorderFactory.createEmptyBorder(0, 0, UIUtil.DEFAULT_VGAP, 0));
    final JPanel main = new JPanel(new BorderLayout());
    main.add(wrapper, BorderLayout.NORTH);
    main.add(tasksPanel, BorderLayout.CENTER);
    return main;
}
Also used : MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) JBTable(com.intellij.ui.table.JBTable) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) CustomShortcutSet(com.intellij.openapi.actionSystem.CustomShortcutSet) Nullable(org.jetbrains.annotations.Nullable)

Example 29 with DumbAwareAction

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

the class QuickEditHandler method showBalloon.

public static void showBalloon(Editor editor, PsiFile newFile, JComponent component) {
    final Balloon balloon = JBPopupFactory.getInstance().createBalloonBuilder(component).setShadow(true).setAnimationCycle(0).setHideOnClickOutside(true).setHideOnKeyOutside(true).setHideOnAction(false).setFillColor(UIUtil.getControlColor()).createBalloon();
    new DumbAwareAction() {

        @Override
        public void actionPerformed(AnActionEvent e) {
            balloon.hide();
        }
    }.registerCustomShortcutSet(CommonShortcuts.ESCAPE, component);
    Disposer.register(newFile.getProject(), balloon);
    final Balloon.Position position = QuickEditAction.getBalloonPosition(editor);
    RelativePoint point = JBPopupFactory.getInstance().guessBestPopupLocation(editor);
    if (position == Balloon.Position.above) {
        final Point p = point.getPoint();
        point = new RelativePoint(point.getComponent(), new Point(p.x, p.y - editor.getLineHeight()));
    }
    balloon.show(point, position);
}
Also used : Balloon(com.intellij.openapi.ui.popup.Balloon) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction)

Example 30 with DumbAwareAction

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

the class ChooseFileEncodingAction method createCharsetsActionGroup.

@NotNull
protected DefaultActionGroup createCharsetsActionGroup(@Nullable String clearItemText, @Nullable Charset alreadySelected, @NotNull Function<Charset, String> charsetFilter) {
    DefaultActionGroup group = new DefaultActionGroup();
    List<Charset> favorites = new ArrayList<>(EncodingManager.getInstance().getFavorites());
    Collections.sort(favorites);
    Charset current = myVirtualFile == null ? null : myVirtualFile.getCharset();
    favorites.remove(current);
    favorites.remove(alreadySelected);
    if (clearItemText != null) {
        String description = "Clear " + (myVirtualFile == null ? "default" : "file '" + myVirtualFile.getName() + "'") + " encoding.";
        group.add(new DumbAwareAction(clearItemText, description, null) {

            @Override
            public void actionPerformed(AnActionEvent e) {
                chosen(myVirtualFile, NO_ENCODING);
            }
        });
    }
    if (favorites.isEmpty() && clearItemText == null) {
        fillCharsetActions(group, myVirtualFile, Arrays.asList(CharsetToolkit.getAvailableCharsets()), charsetFilter);
    } else {
        fillCharsetActions(group, myVirtualFile, favorites, charsetFilter);
        DefaultActionGroup more = new DefaultActionGroup("more", true);
        group.add(more);
        fillCharsetActions(more, myVirtualFile, Arrays.asList(CharsetToolkit.getAvailableCharsets()), charsetFilter);
    }
    return group;
}
Also used : ArrayList(java.util.ArrayList) Charset(java.nio.charset.Charset) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)41 NotNull (org.jetbrains.annotations.NotNull)19 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)18 AnAction (com.intellij.openapi.actionSystem.AnAction)8 Nullable (org.jetbrains.annotations.Nullable)8 List (java.util.List)6 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)4 FileChooser (com.intellij.openapi.fileChooser.FileChooser)4 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)4 SearchableConfigurable (com.intellij.openapi.options.SearchableConfigurable)4 Project (com.intellij.openapi.project.Project)4 Messages (com.intellij.openapi.ui.Messages)4 JBPopup (com.intellij.openapi.ui.popup.JBPopup)4 RelativePoint (com.intellij.ui.awt.RelativePoint)4 JBTable (com.intellij.ui.table.JBTable)4 MouseEvent (java.awt.event.MouseEvent)4 StdFileTypes (com.intellij.openapi.fileTypes.StdFileTypes)3 ConfigurationException (com.intellij.openapi.options.ConfigurationException)3 JBPopupFactory (com.intellij.openapi.ui.popup.JBPopupFactory)3 StringUtil (com.intellij.openapi.util.text.StringUtil)3