Search in sources :

Example 1 with RadioUpDownListener

use of com.intellij.refactoring.util.RadioUpDownListener in project intellij-community by JetBrains.

the class BaseAnalysisActionDialog method createCenterPanel.

@Override
protected JComponent createCenterPanel() {
    myTitledSeparator.setText(myAnalysisNoon);
    //include test option
    myInspectTestSource.setSelected(myAnalysisOptions.ANALYZE_TEST_SOURCES);
    myInspectTestSource.setVisible(ModuleUtil.isSupportedRootType(myProject, JavaSourceRootType.TEST_SOURCE));
    //module scope if applicable
    myModuleButton.setText(AnalysisScopeBundle.message("scope.option.module.with.mnemonic", myModuleName));
    boolean useModuleScope = false;
    if (myModuleName != null) {
        useModuleScope = myAnalysisOptions.SCOPE_TYPE == AnalysisScope.MODULE;
        myModuleButton.setSelected(myRememberScope && useModuleScope);
    }
    myModuleButton.setVisible(myModuleName != null && ModuleManager.getInstance(myProject).getModules().length > 1);
    boolean useUncommitedFiles = false;
    final ChangeListManager changeListManager = ChangeListManager.getInstance(myProject);
    final boolean hasVCS = !changeListManager.getAffectedFiles().isEmpty();
    if (hasVCS) {
        useUncommitedFiles = myAnalysisOptions.SCOPE_TYPE == AnalysisScope.UNCOMMITTED_FILES;
        myUncommitedFilesButton.setSelected(myRememberScope && useUncommitedFiles);
    }
    myUncommitedFilesButton.setVisible(hasVCS);
    DefaultComboBoxModel<String> model = new DefaultComboBoxModel<>();
    model.addElement(ALL);
    final List<? extends ChangeList> changeLists = changeListManager.getChangeListsCopy();
    for (ChangeList changeList : changeLists) {
        model.addElement(changeList.getName());
    }
    myChangeLists.setRenderer(new ListCellRendererWrapper<String>() {

        @Override
        public void customize(JList list, String value, int index, boolean selected, boolean hasFocus) {
            int availableWidth = myPanel.getWidth() - myUncommitedFilesButton.getWidth() - JBUI.scale(10);
            if (availableWidth <= 0) {
                availableWidth = JBUI.scale(200);
            }
            if (list.getFontMetrics(list.getFont()).stringWidth(value) < availableWidth) {
                setText(value);
            } else {
                setText(StringUtil.trimLog(value, 50));
            }
        }
    });
    myChangeLists.setModel(model);
    myChangeLists.setEnabled(myUncommitedFilesButton.isSelected());
    myChangeLists.setVisible(hasVCS);
    //file/package/directory/module scope
    if (myFileName != null) {
        myFileButton.setText(myFileName);
        myFileButton.setMnemonic(myFileName.charAt(getSelectedScopeMnemonic()));
    } else {
        myFileButton.setVisible(false);
    }
    VirtualFile file = PsiUtilBase.getVirtualFile(myContext);
    ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
    boolean searchInLib = file != null && (fileIndex.isInLibraryClasses(file) || fileIndex.isInLibrarySource(file));
    String preselect = StringUtil.isEmptyOrSpaces(myAnalysisOptions.CUSTOM_SCOPE_NAME) ? FindSettings.getInstance().getDefaultScopeName() : myAnalysisOptions.CUSTOM_SCOPE_NAME;
    if (searchInLib && GlobalSearchScope.projectScope(myProject).getDisplayName().equals(preselect)) {
        preselect = GlobalSearchScope.allScope(myProject).getDisplayName();
    }
    if (GlobalSearchScope.allScope(myProject).getDisplayName().equals(preselect) && myAnalysisOptions.SCOPE_TYPE == AnalysisScope.CUSTOM) {
        myAnalysisOptions.CUSTOM_SCOPE_NAME = preselect;
        searchInLib = true;
    }
    //custom scope
    myCustomScopeButton.setSelected(myRememberScope && myAnalysisOptions.SCOPE_TYPE == AnalysisScope.CUSTOM);
    myScopeCombo.init(myProject, searchInLib, true, preselect);
    myScopeCombo.setCurrentSelection(false);
    //correct selection
    myProjectButton.setSelected(myRememberScope && myAnalysisOptions.SCOPE_TYPE == AnalysisScope.PROJECT || myFileName == null);
    myFileButton.setSelected(myFileName != null && (!myRememberScope || myAnalysisOptions.SCOPE_TYPE != AnalysisScope.PROJECT && !useModuleScope && myAnalysisOptions.SCOPE_TYPE != AnalysisScope.CUSTOM && !useUncommitedFiles));
    myScopeCombo.setEnabled(myCustomScopeButton.isSelected());
    final ActionListener radioButtonPressed = new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            onScopeRadioButtonPressed();
        }
    };
    final Enumeration<AbstractButton> enumeration = myGroup.getElements();
    while (enumeration.hasMoreElements()) {
        enumeration.nextElement().addActionListener(radioButtonPressed);
    }
    //additional panel - inspection profile chooser
    JPanel wholePanel = new JPanel(new BorderLayout());
    wholePanel.add(myPanel, BorderLayout.NORTH);
    final JComponent additionalPanel = getAdditionalActionSettings(myProject);
    if (additionalPanel != null) {
        wholePanel.add(additionalPanel, BorderLayout.CENTER);
    }
    new RadioUpDownListener(myProjectButton, myModuleButton, myUncommitedFilesButton, myFileButton, myCustomScopeButton);
    return wholePanel;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ActionEvent(java.awt.event.ActionEvent) RadioUpDownListener(com.intellij.refactoring.util.RadioUpDownListener) ActionListener(java.awt.event.ActionListener) ChangeList(com.intellij.openapi.vcs.changes.ChangeList) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) ChangeListManager(com.intellij.openapi.vcs.changes.ChangeListManager)

Example 2 with RadioUpDownListener

use of com.intellij.refactoring.util.RadioUpDownListener in project intellij-community by JetBrains.

the class InlineOptionsDialog method createCenterPanel.

@NotNull
@Override
protected JComponent createCenterPanel() {
    JPanel optionsPanel = new JPanel();
    optionsPanel.setBorder(new EmptyBorder(JBUI.scale(10), 0, 0, 0));
    optionsPanel.setLayout(new BoxLayout(optionsPanel, BoxLayout.Y_AXIS));
    myRbInlineAll = new JRadioButton();
    myRbInlineAll.setText(getInlineAllText());
    myRbInlineAll.setSelected(true);
    myRbInlineThisOnly = new JRadioButton();
    myRbInlineThisOnly.setText(getInlineThisText());
    final boolean writable = allowInlineAll();
    optionsPanel.add(myRbInlineAll);
    String keepDeclarationText = getKeepTheDeclarationText();
    if (keepDeclarationText != null && writable) {
        myKeepTheDeclaration = new JRadioButton();
        myKeepTheDeclaration.setText(keepDeclarationText);
        optionsPanel.add(myKeepTheDeclaration);
    }
    optionsPanel.add(myRbInlineThisOnly);
    ButtonGroup bg = new ButtonGroup();
    final JRadioButton[] buttons = myKeepTheDeclaration != null ? new JRadioButton[] { myRbInlineAll, myKeepTheDeclaration, myRbInlineThisOnly } : new JRadioButton[] { myRbInlineAll, myRbInlineThisOnly };
    for (JRadioButton button : buttons) {
        bg.add(button);
    }
    new RadioUpDownListener(buttons);
    myRbInlineThisOnly.setEnabled(myInvokedOnReference);
    myRbInlineAll.setEnabled(writable);
    if (myInvokedOnReference) {
        if (canInlineThisOnly()) {
            myRbInlineAll.setSelected(false);
            myRbInlineAll.setEnabled(false);
            if (myKeepTheDeclaration != null) {
                myKeepTheDeclaration.setSelected(false);
                myKeepTheDeclaration.setEnabled(false);
            }
            myRbInlineThisOnly.setSelected(true);
        } else {
            if (writable) {
                final boolean inlineThis = isInlineThis();
                myRbInlineThisOnly.setSelected(inlineThis);
                if (myKeepTheDeclaration != null)
                    myKeepTheDeclaration.setSelected(false);
                myRbInlineAll.setSelected(!inlineThis);
            } else {
                myRbInlineAll.setSelected(false);
                myRbInlineThisOnly.setSelected(true);
            }
        }
    } else {
        myRbInlineAll.setSelected(true);
        if (myKeepTheDeclaration != null)
            myKeepTheDeclaration.setSelected(false);
        myRbInlineThisOnly.setSelected(false);
    }
    getPreviewAction().setEnabled(myRbInlineAll.isSelected() || myKeepTheDeclaration != null && myKeepTheDeclaration.isSelected());
    final ActionListener previewListener = new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            boolean enabled = myRbInlineAll.isSelected() || myKeepTheDeclaration != null && myKeepTheDeclaration.isSelected();
            getPreviewAction().setEnabled(enabled);
        }
    };
    for (JRadioButton button : buttons) {
        button.addActionListener(previewListener);
    }
    return optionsPanel;
}
Also used : RadioUpDownListener(com.intellij.refactoring.util.RadioUpDownListener) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) EmptyBorder(javax.swing.border.EmptyBorder) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

RadioUpDownListener (com.intellij.refactoring.util.RadioUpDownListener)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)1 ChangeList (com.intellij.openapi.vcs.changes.ChangeList)1 ChangeListManager (com.intellij.openapi.vcs.changes.ChangeListManager)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 EmptyBorder (javax.swing.border.EmptyBorder)1 NotNull (org.jetbrains.annotations.NotNull)1