Search in sources :

Example 1 with UsageViewPresentation

use of com.intellij.usages.UsageViewPresentation in project intellij-community by JetBrains.

the class SlicePanel method layoutPanel.

private void layoutPanel() {
    if (myUsagePreviewPanel != null) {
        Disposer.dispose(myUsagePreviewPanel);
    }
    removeAll();
    JScrollPane pane = ScrollPaneFactory.createScrollPane(myTree);
    if (isPreview()) {
        pane.setBorder(IdeBorderFactory.createBorder(SideBorder.LEFT | SideBorder.RIGHT));
        boolean vertical = myToolWindow.getAnchor() == ToolWindowAnchor.LEFT || myToolWindow.getAnchor() == ToolWindowAnchor.RIGHT;
        Splitter splitter = new Splitter(vertical, UsageViewSettings.getInstance().PREVIEW_USAGES_SPLITTER_PROPORTIONS);
        splitter.setFirstComponent(pane);
        myUsagePreviewPanel = new UsagePreviewPanel(myProject, new UsageViewPresentation());
        myUsagePreviewPanel.setBorder(IdeBorderFactory.createBorder(SideBorder.LEFT));
        Disposer.register(this, myUsagePreviewPanel);
        splitter.setSecondComponent(myUsagePreviewPanel);
        add(splitter, BorderLayout.CENTER);
    } else {
        pane.setBorder(IdeBorderFactory.createBorder(SideBorder.LEFT));
        add(pane, BorderLayout.CENTER);
    }
    add(createToolbar().getComponent(), BorderLayout.WEST);
    myTree.getParent().setBackground(UIManager.getColor("Tree.background"));
    revalidate();
}
Also used : UsageViewPresentation(com.intellij.usages.UsageViewPresentation) Splitter(com.intellij.openapi.ui.Splitter) UsagePreviewPanel(com.intellij.usages.impl.UsagePreviewPanel)

Example 2 with UsageViewPresentation

use of com.intellij.usages.UsageViewPresentation in project intellij-community by JetBrains.

the class FindPopupPanel method findSettingsChanged.

private void findSettingsChanged() {
    if (isShowing()) {
        ScrollingUtil.ensureSelectionExists(myResultsPreviewTable);
    }
    final ModalityState state = ModalityState.current();
    finishPreviousPreviewSearch();
    mySearchRescheduleOnCancellationsAlarm.cancelAllRequests();
    applyTo(myHelper.getModel(), false);
    myHelper.updateFindSettings();
    FindModel findInProjectModel = FindManager.getInstance(myProject).getFindInProjectModel();
    FindModel copy = new FindModel();
    copy.copyFrom(findInProjectModel);
    findInProjectModel.copyFrom(myHelper.getModel());
    //todo check if we really need to do it now
    ((FindManagerImpl) FindManager.getInstance(myProject)).changeGlobalSettings(myHelper.getModel());
    FindSettings findSettings = FindSettings.getInstance();
    myScopeUI.applyTo(findSettings, mySelectedScope);
    findSettings.setFileMask(myHelper.getModel().getFileFilter());
    ValidationInfo result = getValidationInfo(myHelper.getModel());
    final ProgressIndicatorBase progressIndicatorWhenSearchStarted = new ProgressIndicatorBase();
    myResultsPreviewSearchProgress = progressIndicatorWhenSearchStarted;
    final DefaultTableModel model = new DefaultTableModel() {

        @Override
        public boolean isCellEditable(int row, int column) {
            return false;
        }
    };
    model.addColumn("Usages");
    // Use previously shown usage files as hint for faster search and better usage preview performance if pattern length increased
    final LinkedHashSet<VirtualFile> filesToScanInitially = new LinkedHashSet<>();
    if (myHelper.myPreviousModel != null && myHelper.myPreviousModel.getStringToFind().length() < myHelper.getModel().getStringToFind().length()) {
        final DefaultTableModel previousModel = (DefaultTableModel) myResultsPreviewTable.getModel();
        for (int i = 0, len = previousModel.getRowCount(); i < len; ++i) {
            final UsageInfo2UsageAdapter usage = (UsageInfo2UsageAdapter) previousModel.getValueAt(i, 0);
            final VirtualFile file = usage.getFile();
            if (file != null)
                filesToScanInitially.add(file);
        }
    }
    myHelper.myPreviousModel = myHelper.getModel().clone();
    myCodePreviewComponent.setVisible(false);
    mySearchTextArea.setInfoText(null);
    myResultsPreviewTable.setModel(model);
    if (result != null) {
        myResultsPreviewTable.getEmptyText().setText(UIBundle.message("message.nothingToShow") + " (" + result.message + ")");
        return;
    }
    myResultsPreviewTable.getColumnModel().getColumn(0).setCellRenderer(new FindDialog.UsageTableCellRenderer(myCbFileFilter.isSelected(), false));
    myResultsPreviewTable.getEmptyText().setText("Searching...");
    final AtomicInteger resultsCount = new AtomicInteger();
    final AtomicInteger resultsFilesCount = new AtomicInteger();
    ProgressIndicatorUtils.scheduleWithWriteActionPriority(myResultsPreviewSearchProgress, new ReadTask() {

        @Override
        public void computeInReadAction(@NotNull ProgressIndicator indicator) {
            final UsageViewPresentation presentation = FindInProjectUtil.setupViewPresentation(findSettings.isShowResultsInSeparateView(), /*findModel*/
            myHelper.getModel().clone());
            final boolean showPanelIfOnlyOneUsage = !findSettings.isSkipResultsWithOneUsage();
            final FindUsagesProcessPresentation processPresentation = FindInProjectUtil.setupProcessPresentation(myProject, showPanelIfOnlyOneUsage, presentation);
            Ref<VirtualFile> lastUsageFileRef = new Ref<>();
            FindInProjectUtil.findUsages(myHelper.getModel().clone(), myProject, info -> {
                final Usage usage = UsageInfo2UsageAdapter.CONVERTER.fun(info);
                usage.getPresentation().getIcon();
                VirtualFile file = lastUsageFileRef.get();
                VirtualFile usageFile = info.getVirtualFile();
                if (file == null || !file.equals(usageFile)) {
                    resultsFilesCount.incrementAndGet();
                    lastUsageFileRef.set(usageFile);
                }
                ApplicationManager.getApplication().invokeLater(() -> {
                    model.addRow(new Object[] { usage });
                    myCodePreviewComponent.setVisible(true);
                    if (model.getRowCount() == 1 && myResultsPreviewTable.getModel() == model) {
                        myResultsPreviewTable.setRowSelectionInterval(0, 0);
                    }
                }, state);
                return resultsCount.incrementAndGet() < ShowUsagesAction.USAGES_PAGE_SIZE;
            }, processPresentation, filesToScanInitially);
            boolean succeeded = !progressIndicatorWhenSearchStarted.isCanceled();
            if (succeeded) {
                ApplicationManager.getApplication().invokeLater(() -> {
                    if (progressIndicatorWhenSearchStarted == myResultsPreviewSearchProgress && !myResultsPreviewSearchProgress.isCanceled()) {
                        int occurrences = resultsCount.get();
                        int filesWithOccurrences = resultsFilesCount.get();
                        if (occurrences == 0)
                            myResultsPreviewTable.getEmptyText().setText(UIBundle.message("message.nothingToShow"));
                        myCodePreviewComponent.setVisible(occurrences > 0);
                        StringBuilder info = new StringBuilder();
                        if (occurrences > 0) {
                            info.append(Math.min(ShowUsagesAction.USAGES_PAGE_SIZE, occurrences));
                            boolean foundAllUsages = occurrences < ShowUsagesAction.USAGES_PAGE_SIZE;
                            if (!foundAllUsages) {
                                info.append("+");
                            }
                            info.append(UIBundle.message("message.matches", occurrences));
                            info.append(" in ");
                            info.append(filesWithOccurrences);
                            if (!foundAllUsages) {
                                info.append("+");
                            }
                            info.append(UIBundle.message("message.files", filesWithOccurrences));
                        }
                        mySearchTextArea.setInfoText(info.toString());
                    }
                }, state);
            }
        }

        @Override
        public void onCanceled(@NotNull ProgressIndicator indicator) {
            if (isShowing() && progressIndicatorWhenSearchStarted == myResultsPreviewSearchProgress) {
                scheduleResultsUpdate();
            }
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) UsageViewPresentation(com.intellij.usages.UsageViewPresentation) com.intellij.openapi.util(com.intellij.openapi.util) JBInsets(com.intellij.util.ui.JBInsets) UIUtil(com.intellij.util.ui.UIUtil) AllIcons(com.intellij.icons.AllIcons) ReadTask(com.intellij.openapi.progress.util.ReadTask) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModalityState(com.intellij.openapi.application.ModalityState) JBLabel(com.intellij.ui.components.JBLabel) SmartList(com.intellij.util.SmartList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JBUI(com.intellij.util.ui.JBUI) Messages(com.intellij.openapi.ui.Messages) Logger(com.intellij.openapi.diagnostic.Logger) ListSelectionEvent(javax.swing.event.ListSelectionEvent) JBFont(com.intellij.util.ui.JBFont) ValidationInfo(com.intellij.openapi.ui.ValidationInfo) CustomComponentAction(com.intellij.openapi.actionSystem.ex.CustomComponentAction) ComponentPopupBuilder(com.intellij.openapi.ui.popup.ComponentPopupBuilder) PatternSyntaxException(java.util.regex.PatternSyntaxException) DefaultTableModel(javax.swing.table.DefaultTableModel) ActionButton(com.intellij.openapi.actionSystem.impl.ActionButton) WindowManager(com.intellij.openapi.wm.WindowManager) UsageViewPresentation(com.intellij.usages.UsageViewPresentation) KeymapUtil(com.intellij.openapi.keymap.KeymapUtil) com.intellij.ui(com.intellij.ui) JBScrollPane(com.intellij.ui.components.JBScrollPane) HelpManager(com.intellij.openapi.help.HelpManager) ListPopup(com.intellij.openapi.ui.popup.ListPopup) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) IdeFocusManager(com.intellij.openapi.wm.IdeFocusManager) JBPanel(com.intellij.ui.components.JBPanel) java.awt.event(java.awt.event) ApplicationManager(com.intellij.openapi.application.ApplicationManager) Registry(com.intellij.openapi.util.registry.Registry) Pattern(java.util.regex.Pattern) NotNull(org.jetbrains.annotations.NotNull) RelativePoint(com.intellij.ui.awt.RelativePoint) ProgressIndicatorBase(com.intellij.openapi.progress.util.ProgressIndicatorBase) java.util(java.util) ArrayUtil(com.intellij.util.ArrayUtil) ActionToolbarImpl(com.intellij.openapi.actionSystem.impl.ActionToolbarImpl) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) UsageInfo(com.intellij.usageView.UsageInfo) ProgressIndicatorUtils(com.intellij.openapi.progress.util.ProgressIndicatorUtils) ContainerUtil(com.intellij.util.containers.ContainerUtil) UsageInfo2UsageAdapter(com.intellij.usages.UsageInfo2UsageAdapter) ActionButtonWithText(com.intellij.openapi.actionSystem.impl.ActionButtonWithText) CommonBundle(com.intellij.CommonBundle) IdeFrameImpl(com.intellij.openapi.wm.impl.IdeFrameImpl) FindUsagesProcessPresentation(com.intellij.usages.FindUsagesProcessPresentation) UsagePreviewPanel(com.intellij.usages.impl.UsagePreviewPanel) Project(com.intellij.openapi.project.Project) DocumentEvent(javax.swing.event.DocumentEvent) VfsUtilCore(com.intellij.openapi.vfs.VfsUtilCore) Usage(com.intellij.usages.Usage) StringUtil(com.intellij.openapi.util.text.StringUtil) MigLayout(net.miginfocom.swing.MigLayout) com.intellij.find(com.intellij.find) UISettings(com.intellij.ide.ui.UISettings) OnePixelDivider(com.intellij.openapi.ui.OnePixelDivider) Disposable(com.intellij.openapi.Disposable) JBPopup(com.intellij.openapi.ui.popup.JBPopup) java.awt(java.awt) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) JBTable(com.intellij.ui.table.JBTable) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) ShowUsagesAction(com.intellij.find.actions.ShowUsagesAction) MnemonicHelper(com.intellij.openapi.MnemonicHelper) ListSelectionListener(javax.swing.event.ListSelectionListener) Alarm(com.intellij.util.Alarm) javax.swing(javax.swing) DefaultTableModel(javax.swing.table.DefaultTableModel) ProgressIndicatorBase(com.intellij.openapi.progress.util.ProgressIndicatorBase) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) Usage(com.intellij.usages.Usage) FindUsagesProcessPresentation(com.intellij.usages.FindUsagesProcessPresentation) RelativePoint(com.intellij.ui.awt.RelativePoint) ValidationInfo(com.intellij.openapi.ui.ValidationInfo) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) UsageInfo2UsageAdapter(com.intellij.usages.UsageInfo2UsageAdapter) ModalityState(com.intellij.openapi.application.ModalityState) ReadTask(com.intellij.openapi.progress.util.ReadTask)

Example 3 with UsageViewPresentation

use of com.intellij.usages.UsageViewPresentation in project intellij-community by JetBrains.

the class FindInProjectUtil method setupViewPresentation.

@NotNull
public static UsageViewPresentation setupViewPresentation(final boolean toOpenInNewTab, @NotNull FindModel findModel) {
    final UsageViewPresentation presentation = new UsageViewPresentation();
    final String scope = getTitleForScope(findModel);
    final String stringToFind = findModel.getStringToFind();
    presentation.setScopeText(scope);
    if (stringToFind.isEmpty()) {
        presentation.setTabText("Files");
        presentation.setToolwindowTitle(BundleBase.format("Files in {0}", scope));
        presentation.setUsagesString("files");
    } else {
        FindModel.SearchContext searchContext = findModel.getSearchContext();
        String contextText = "";
        if (searchContext != FindModel.SearchContext.ANY) {
            contextText = FindBundle.message("find.context.presentation.scope.label", FindDialog.getPresentableName(searchContext));
        }
        presentation.setTabText(FindBundle.message("find.usage.view.tab.text", stringToFind, contextText));
        presentation.setToolwindowTitle(FindBundle.message("find.usage.view.toolwindow.title", stringToFind, scope, contextText));
        presentation.setUsagesString(FindBundle.message("find.usage.view.usages.text", stringToFind));
        presentation.setUsagesWord(FindBundle.message("occurrence"));
        presentation.setCodeUsagesString(FindBundle.message("found.occurrences"));
        presentation.setContextText(contextText);
    }
    presentation.setOpenInNewTab(toOpenInNewTab);
    presentation.setCodeUsages(false);
    presentation.setUsageTypeFilteringAvailable(true);
    return presentation;
}
Also used : UsageViewPresentation(com.intellij.usages.UsageViewPresentation) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with UsageViewPresentation

use of com.intellij.usages.UsageViewPresentation in project intellij-community by JetBrains.

the class FindPopupPanel method initComponents.

private void initComponents() {
    myTitleLabel = new JBLabel(FindBundle.message("find.in.path.dialog.title"), UIUtil.ComponentStyle.REGULAR);
    myTitleLabel.setFont(myTitleLabel.getFont().deriveFont(Font.BOLD));
    myTitleLabel.setBorder(JBUI.Borders.empty(0, 4, 0, 16));
    myCbCaseSensitive = new StateRestoringCheckBox(FindBundle.message("find.popup.case.sensitive"));
    ItemListener liveResultsPreviewUpdateListener = new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            scheduleResultsUpdate();
        }
    };
    myCbCaseSensitive.addItemListener(liveResultsPreviewUpdateListener);
    myCbPreserveCase = new StateRestoringCheckBox(FindBundle.message("find.options.replace.preserve.case"));
    myCbPreserveCase.addItemListener(liveResultsPreviewUpdateListener);
    myCbPreserveCase.setVisible(myHelper.getModel().isReplaceState());
    myCbWholeWordsOnly = new StateRestoringCheckBox(FindBundle.message("find.popup.whole.words"));
    myCbWholeWordsOnly.addItemListener(liveResultsPreviewUpdateListener);
    myCbRegularExpressions = new StateRestoringCheckBox(FindBundle.message("find.popup.regex"));
    myCbRegularExpressions.addItemListener(liveResultsPreviewUpdateListener);
    myCbFileFilter = new StateRestoringCheckBox(FindBundle.message("find.popup.filemask"));
    myCbFileFilter.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            if (myCbFileFilter.isSelected()) {
                myFileMaskField.setEnabled(true);
                if (myCbFileFilter.getClientProperty("dontRequestFocus") == null) {
                    myFileMaskField.selectAll();
                    IdeFocusManager.getInstance(myProject).requestFocus(myFileMaskField, true);
                }
            } else {
                myFileMaskField.setEnabled(false);
                if (myCbFileFilter.getClientProperty("dontRequestFocus") == null) {
                    IdeFocusManager.getInstance(myProject).requestFocus(mySearchComponent, true);
                }
            }
        }
    });
    myCbFileFilter.addItemListener(liveResultsPreviewUpdateListener);
    myFileMaskField = new TextFieldWithAutoCompletion<String>(myProject, new TextFieldWithAutoCompletion.StringsCompletionProvider(myFileMasks, null), false, null) {

        @Override
        public void setEnabled(boolean enabled) {
            super.setEnabled(enabled);
            setBackground(enabled ? JBColor.background() : UIUtil.getComboBoxDisabledBackground());
        }
    };
    myFileMaskField.setPreferredWidth(JBUI.scale(100));
    myFileMaskField.addDocumentListener(new com.intellij.openapi.editor.event.DocumentAdapter() {

        @Override
        public void documentChanged(com.intellij.openapi.editor.event.DocumentEvent e) {
            scheduleResultsUpdate();
        }
    });
    DefaultActionGroup switchContextGroup = new DefaultActionGroup();
    switchContextGroup.add(new MySwitchContextToggleAction(FindModel.SearchContext.ANY));
    switchContextGroup.add(new MySwitchContextToggleAction(FindModel.SearchContext.IN_COMMENTS));
    switchContextGroup.add(new MySwitchContextToggleAction(FindModel.SearchContext.IN_STRING_LITERALS));
    switchContextGroup.add(new MySwitchContextToggleAction(FindModel.SearchContext.EXCEPT_COMMENTS));
    switchContextGroup.add(new MySwitchContextToggleAction(FindModel.SearchContext.EXCEPT_STRING_LITERALS));
    switchContextGroup.add(new MySwitchContextToggleAction(FindModel.SearchContext.EXCEPT_COMMENTS_AND_STRING_LITERALS));
    switchContextGroup.setPopup(true);
    Presentation filterPresentation = new Presentation();
    filterPresentation.setIcon(AllIcons.General.Filter);
    AnAction myShowFilterPopupAction = new AnAction() {

        @Override
        public void actionPerformed(AnActionEvent e) {
            if (PlatformDataKeys.CONTEXT_COMPONENT.getData(e.getDataContext()) == null)
                return;
            ListPopup listPopup = JBPopupFactory.getInstance().createActionGroupPopup(null, switchContextGroup, e.getDataContext(), false, null, 10);
            listPopup.showUnderneathOf(myFilterContextButton);
        }
    };
    myFilterContextButton = new ActionButton(myShowFilterPopupAction, filterPresentation, ActionPlaces.UNKNOWN, ActionToolbar.DEFAULT_MINIMUM_BUTTON_SIZE) {

        @Override
        public int getPopState() {
            int state = super.getPopState();
            if (state != ActionButtonComponent.NORMAL)
                return state;
            return mySelectedContextName.equals(FindDialog.getPresentableName(FindModel.SearchContext.ANY)) ? ActionButtonComponent.NORMAL : ActionButtonComponent.PUSHED;
        }
    };
    myFilterContextButton.setFocusable(true);
    DefaultActionGroup tabResultsContextGroup = new DefaultActionGroup();
    tabResultsContextGroup.add(new ToggleAction(FindBundle.message("find.options.skip.results.tab.with.one.usage.checkbox")) {

        @Override
        public boolean isSelected(AnActionEvent e) {
            return FindSettings.getInstance().isSkipResultsWithOneUsage();
        }

        @Override
        public void setSelected(AnActionEvent e, boolean state) {
            myHelper.setSkipResultsWithOneUsage(state);
        }

        @Override
        public void update(@NotNull AnActionEvent e) {
            super.update(e);
            e.getPresentation().setVisible(!myHelper.isReplaceState());
        }
    });
    tabResultsContextGroup.add(new ToggleAction(FindBundle.message("find.open.in.new.tab.checkbox")) {

        @Override
        public boolean isSelected(AnActionEvent e) {
            return FindSettings.getInstance().isShowResultsInSeparateView();
        }

        @Override
        public void setSelected(AnActionEvent e, boolean state) {
            myHelper.setUseSeparateView(state);
        }
    });
    tabResultsContextGroup.setPopup(true);
    Presentation tabSettingsPresentation = new Presentation();
    tabSettingsPresentation.setIcon(AllIcons.General.SecondaryGroup);
    myTabResultsButton = new ActionButton(tabResultsContextGroup, tabSettingsPresentation, ActionPlaces.UNKNOWN, ActionToolbar.DEFAULT_MINIMUM_BUTTON_SIZE);
    myOKButton = new JButton(FindBundle.message("find.popup.find.button"));
    myOkActionListener = new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            FindModel validateModel = myHelper.getModel().clone();
            applyTo(validateModel, false);
            ValidationInfo validationInfo = getValidationInfo(validateModel);
            if (validationInfo == null) {
                myHelper.getModel().copyFrom(validateModel);
                myHelper.updateFindSettings();
                myHelper.doOKAction();
            } else {
                String message = validationInfo.message;
                Messages.showMessageDialog(FindPopupPanel.this, message, CommonBundle.getErrorTitle(), Messages.getErrorIcon());
                return;
            }
            Disposer.dispose(myBalloon);
        }
    };
    myOKButton.addActionListener(myOkActionListener);
    registerKeyboardAction(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (!myHelper.isReplaceState()) {
                navigateToSelectedUsage();
                return;
            }
            myOkActionListener.actionPerformed(e);
        }
    }, NEW_LINE, WHEN_IN_FOCUSED_WINDOW);
    registerKeyboardAction(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (myHelper.isReplaceState())
                return;
            myOkActionListener.actionPerformed(e);
        }
    }, OK_FIND, WHEN_IN_FOCUSED_WINDOW);
    mySearchComponent = new JTextArea();
    mySearchComponent.setColumns(25);
    mySearchComponent.setRows(1);
    myReplaceComponent = new JTextArea();
    myReplaceComponent.setColumns(25);
    myReplaceComponent.setRows(1);
    mySearchTextArea = new SearchTextArea(mySearchComponent, true, true);
    myReplaceTextArea = new SearchTextArea(myReplaceComponent, false, false);
    DocumentAdapter documentAdapter = new DocumentAdapter() {

        @Override
        protected void textChanged(DocumentEvent e) {
            mySearchComponent.setRows(Math.max(1, Math.min(3, StringUtil.countChars(mySearchComponent.getText(), '\n') + 1)));
            myReplaceComponent.setRows(Math.max(1, Math.min(3, StringUtil.countChars(myReplaceComponent.getText(), '\n') + 1)));
            if (myBalloon == null)
                return;
            if (e.getDocument() == mySearchComponent.getDocument()) {
                scheduleResultsUpdate();
            }
        }
    };
    mySearchComponent.getDocument().addDocumentListener(documentAdapter);
    myReplaceComponent.getDocument().addDocumentListener(documentAdapter);
    mySearchTextArea.setMultilineEnabled(false);
    myReplaceTextArea.setMultilineEnabled(false);
    Pair<FindPopupScopeUI.ScopeType, JComponent>[] scopeComponents = myScopeUI.getComponents();
    List<AnAction> scopeActions = new LinkedList<>();
    myScopeDetailsPanel = new JPanel(new CardLayout());
    for (Pair<FindPopupScopeUI.ScopeType, JComponent> scopeComponent : scopeComponents) {
        FindPopupScopeUI.ScopeType scopeType = scopeComponent.first;
        scopeActions.add(new MySelectScopeToggleAction(scopeType));
        myScopeDetailsPanel.add(scopeType.name, scopeComponent.second);
    }
    myScopeSelectionToolbar = createToolbar(scopeActions.toArray(AnAction.EMPTY_ARRAY));
    mySelectedScope = scopeComponents[0].first;
    myResultsPreviewTable = new JBTable() {

        @Override
        public Dimension getPreferredScrollableViewportSize() {
            return new Dimension(getWidth(), 1 + getRowHeight() * 4);
        }
    };
    myResultsPreviewTable.setFocusable(false);
    myResultsPreviewTable.getEmptyText().setShowAboveCenter(false);
    myResultsPreviewTable.setShowColumns(false);
    myResultsPreviewTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    myResultsPreviewTable.setShowGrid(false);
    myResultsPreviewTable.setIntercellSpacing(JBUI.emptySize());
    new DoubleClickListener() {

        @Override
        protected boolean onDoubleClick(MouseEvent event) {
            if (event.getSource() != myResultsPreviewTable)
                return false;
            navigateToSelectedUsage();
            return true;
        }
    }.installOn(myResultsPreviewTable);
    myResultsPreviewTable.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            myResultsPreviewTable.transferFocus();
        }
    });
    applyFont(JBUI.Fonts.label(), myCbCaseSensitive, myCbPreserveCase, myCbWholeWordsOnly, myCbRegularExpressions, myResultsPreviewTable);
    ScrollingUtil.installActions(myResultsPreviewTable, false, mySearchComponent);
    ScrollingUtil.installActions(myResultsPreviewTable, false, myReplaceComponent);
    UIUtil.redirectKeystrokes(myDisposable, mySearchComponent, myResultsPreviewTable, NEW_LINE);
    UIUtil.redirectKeystrokes(myDisposable, myReplaceComponent, myResultsPreviewTable, NEW_LINE);
    ActionListener helpAction = new ActionListener() {

        public void actionPerformed(final ActionEvent e) {
            HelpManager.getInstance().invokeHelp("reference.dialogs.findinpath");
        }
    };
    registerKeyboardAction(helpAction, KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0), JComponent.WHEN_IN_FOCUSED_WINDOW);
    registerKeyboardAction(helpAction, KeyStroke.getKeyStroke(KeyEvent.VK_HELP, 0), JComponent.WHEN_IN_FOCUSED_WINDOW);
    myUsagePreviewPanel = new UsagePreviewPanel(myProject, new UsageViewPresentation(), Registry.is("ide.find.as.popup.editable.code")) {

        @Override
        public Dimension getPreferredSize() {
            return new Dimension(myResultsPreviewTable.getWidth(), Math.max(getHeight(), getLineHeight() * 15));
        }
    };
    Disposer.register(myDisposable, myUsagePreviewPanel);
    myResultsPreviewTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting())
                return;
            int index = myResultsPreviewTable.getSelectedRow();
            if (index != -1) {
                UsageInfo usageInfo = ((UsageInfo2UsageAdapter) myResultsPreviewTable.getModel().getValueAt(index, 0)).getUsageInfo();
                myUsagePreviewPanel.updateLayout(usageInfo.isValid() ? Collections.singletonList(usageInfo) : null);
                VirtualFile file = usageInfo.getVirtualFile();
                String path = "";
                if (file != null) {
                    String relativePath = VfsUtilCore.getRelativePath(file, myProject.getBaseDir());
                    if (relativePath == null)
                        relativePath = file.getPath();
                    path = "<html><body>&nbsp;&nbsp;&nbsp;" + relativePath.replace(file.getName(), "<b>" + file.getName() + "</b>") + "</body></html>";
                }
                myUsagePreviewPanel.setBorder(IdeBorderFactory.createTitledBorder(path, false, new JBInsets(8, 0, -14, 0)));
            } else {
                myUsagePreviewPanel.updateLayout(null);
                myUsagePreviewPanel.setBorder(IdeBorderFactory.createBorder());
            }
        }
    });
    mySearchRescheduleOnCancellationsAlarm = new Alarm();
    JBSplitter splitter = new JBSplitter(true, .33f);
    splitter.setSplitterProportionKey(SPLITTER_SERVICE_KEY);
    splitter.setDividerWidth(JBUI.scale(2));
    splitter.getDivider().setBackground(OnePixelDivider.BACKGROUND);
    JBScrollPane scrollPane = new JBScrollPane(myResultsPreviewTable) {

        @Override
        public Dimension getMinimumSize() {
            Dimension size = super.getMinimumSize();
            size.height = myResultsPreviewTable.getPreferredScrollableViewportSize().height;
            return size;
        }
    };
    scrollPane.setBorder(IdeBorderFactory.createEmptyBorder());
    splitter.setFirstComponent(scrollPane);
    JPanel bottomPanel = new JPanel(new MigLayout("flowx, ins 4 4 0 4, fillx, hidemode 2, gap 0"));
    bottomPanel.add(myTabResultsButton);
    bottomPanel.add(Box.createHorizontalGlue(), "growx, pushx");
    myOKHintLabel = new JBLabel(KeymapUtil.getShortcutsText(new Shortcut[] { new KeyboardShortcut(OK_FIND, null) }));
    myOKHintLabel.setEnabled(false);
    bottomPanel.add(myOKHintLabel, "gapright 10");
    bottomPanel.add(myOKButton);
    myCodePreviewComponent = myUsagePreviewPanel.createComponent();
    splitter.setSecondComponent(myCodePreviewComponent);
    JPanel scopesPanel = new JPanel(new MigLayout("flowx, gap 26, ins 0"));
    scopesPanel.add(myScopeSelectionToolbar.getComponent());
    scopesPanel.add(myScopeDetailsPanel, "growx, pushx");
    setLayout(new MigLayout("flowx, ins 4, gap 0, fillx, hidemode 3"));
    int cbGapLeft = myCbCaseSensitive.getInsets().left;
    int cbGapRight = myCbCaseSensitive.getInsets().right;
    String cbGap = cbGapLeft + cbGapRight < 16 ? "gapright " + (16 - cbGapLeft - cbGapRight) : "";
    add(myTitleLabel, "sx 2, growx, pushx, growy");
    add(myCbCaseSensitive, cbGap);
    add(myCbPreserveCase, cbGap);
    add(myCbWholeWordsOnly, cbGap);
    add(myCbRegularExpressions, "gapright 0");
    add(RegExHelpPopup.createRegExLink("<html><body><b>?</b></body></html>", myCbRegularExpressions, LOG), "gapright " + (16 - cbGapLeft));
    add(myCbFileFilter);
    add(myFileMaskField, "gapright 16");
    add(myFilterContextButton, "wrap");
    add(mySearchTextArea, "pushx, growx, sx 10, gaptop 4, wrap");
    add(myReplaceTextArea, "pushx, growx, sx 10, gaptop 4, wrap");
    add(scopesPanel, "sx 10, pushx, growx, ax left, wrap, gaptop 4, gapbottom 4");
    add(splitter, "pushx, growx, growy, pushy, sx 10, wrap, pad -4 -4 4 4");
    add(bottomPanel, "pushx, growx, dock south, sx 10");
    MnemonicHelper.init(this);
    setFocusCycleRoot(true);
    setFocusTraversalPolicy(new ContainerOrderFocusTraversalPolicy() {

        @Override
        public Component getComponentAfter(Container container, Component c) {
            return (c == myResultsPreviewTable) ? mySearchComponent : super.getComponentAfter(container, c);
        }
    });
}
Also used : UsageViewPresentation(com.intellij.usages.UsageViewPresentation) UsagePreviewPanel(com.intellij.usages.impl.UsagePreviewPanel) JBInsets(com.intellij.util.ui.JBInsets) JBTable(com.intellij.ui.table.JBTable) ActionButton(com.intellij.openapi.actionSystem.impl.ActionButton) JBLabel(com.intellij.ui.components.JBLabel) ListPopup(com.intellij.openapi.ui.popup.ListPopup) DocumentEvent(javax.swing.event.DocumentEvent) ListSelectionListener(javax.swing.event.ListSelectionListener) JBScrollPane(com.intellij.ui.components.JBScrollPane) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ListSelectionEvent(javax.swing.event.ListSelectionEvent) java.awt.event(java.awt.event) UsageInfo(com.intellij.usageView.UsageInfo) MigLayout(net.miginfocom.swing.MigLayout) UsageViewPresentation(com.intellij.usages.UsageViewPresentation) FindUsagesProcessPresentation(com.intellij.usages.FindUsagesProcessPresentation) RelativePoint(com.intellij.ui.awt.RelativePoint) ValidationInfo(com.intellij.openapi.ui.ValidationInfo) Alarm(com.intellij.util.Alarm)

Example 5 with UsageViewPresentation

use of com.intellij.usages.UsageViewPresentation in project intellij-community by JetBrains.

the class InheritanceToDelegationProcessor method showObjectUpcastedUsageView.

private void showObjectUpcastedUsageView(final ObjectUpcastedUsageInfo[] usages) {
    UsageViewPresentation presentation = new UsageViewPresentation();
    presentation.setTargetsNodeText(RefactoringBundle.message("replacing.inheritance.with.delegation"));
    presentation.setCodeUsagesString(RefactoringBundle.message("instances.casted.to.java.lang.object"));
    final String upcastedString = RefactoringBundle.message("instances.upcasted.to.object");
    presentation.setUsagesString(upcastedString);
    presentation.setTabText(upcastedString);
    UsageViewManager manager = UsageViewManager.getInstance(myProject);
    manager.showUsages(new UsageTarget[] { new PsiElement2UsageTargetAdapter(myClass) }, UsageInfoToUsageConverter.convert(new PsiElement[] { myClass }, usages), presentation);
    WindowManager.getInstance().getStatusBar(myProject).setInfo(RefactoringBundle.message("instances.upcasted.to.java.lang.object.found"));
}
Also used : UsageViewPresentation(com.intellij.usages.UsageViewPresentation) UsageViewManager(com.intellij.usages.UsageViewManager) PsiElement2UsageTargetAdapter(com.intellij.find.findUsages.PsiElement2UsageTargetAdapter)

Aggregations

UsageViewPresentation (com.intellij.usages.UsageViewPresentation)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 UsagePreviewPanel (com.intellij.usages.impl.UsagePreviewPanel)3 ActionButton (com.intellij.openapi.actionSystem.impl.ActionButton)2 Project (com.intellij.openapi.project.Project)2 ValidationInfo (com.intellij.openapi.ui.ValidationInfo)2 ListPopup (com.intellij.openapi.ui.popup.ListPopup)2 FindUsagesProcessPresentation (com.intellij.usages.FindUsagesProcessPresentation)2 NotNull (org.jetbrains.annotations.NotNull)2 CommonBundle (com.intellij.CommonBundle)1 com.intellij.find (com.intellij.find)1 FindModel (com.intellij.find.FindModel)1 ShowUsagesAction (com.intellij.find.actions.ShowUsagesAction)1 PsiElement2UsageTargetAdapter (com.intellij.find.findUsages.PsiElement2UsageTargetAdapter)1 AllIcons (com.intellij.icons.AllIcons)1 UISettings (com.intellij.ide.ui.UISettings)1 Disposable (com.intellij.openapi.Disposable)1 MnemonicHelper (com.intellij.openapi.MnemonicHelper)1 com.intellij.openapi.actionSystem (com.intellij.openapi.actionSystem)1 CustomComponentAction (com.intellij.openapi.actionSystem.ex.CustomComponentAction)1