Search in sources :

Example 1 with ClassCellRenderer

use of com.intellij.refactoring.ui.ClassCellRenderer in project intellij-community by JetBrains.

the class TurnRefsToSuperDialog method createCenterPanel.

@Override
protected JComponent createCenterPanel() {
    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout(UIUtil.DEFAULT_HGAP, UIUtil.DEFAULT_VGAP));
    final JLabel classListLabel = new JLabel();
    panel.add(classListLabel, BorderLayout.NORTH);
    mySuperClassesList = new JBList<>(mySuperClasses.toArray());
    mySuperClassesList.setCellRenderer(new ClassCellRenderer(mySuperClassesList.getCellRenderer()));
    mySuperClassesList.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    classListLabel.setText(RefactoringBundle.message("turnRefsToSuper.change.usages.to", mySubClass.getQualifiedName()));
    PsiClass nearestBase = RefactoringHierarchyUtil.getNearestBaseClass(mySubClass, true);
    int indexToSelect = 0;
    if (nearestBase != null) {
        indexToSelect = mySuperClasses.indexOf(nearestBase);
    }
    mySuperClassesList.setSelectedIndex(indexToSelect);
    panel.add(ScrollPaneFactory.createScrollPane(mySuperClassesList), BorderLayout.CENTER);
    myCbReplaceInstanceOf.setText(RefactoringBundle.message("turnRefsToSuper.use.superclass.in.instanceof"));
    myCbReplaceInstanceOf.setSelected(false);
    myCbReplaceInstanceOf.setFocusable(false);
    panel.add(myCbReplaceInstanceOf, BorderLayout.SOUTH);
    return panel;
}
Also used : ClassCellRenderer(com.intellij.refactoring.ui.ClassCellRenderer) PsiClass(com.intellij.psi.PsiClass)

Example 2 with ClassCellRenderer

use of com.intellij.refactoring.ui.ClassCellRenderer in project intellij-community by JetBrains.

the class InheritanceToDelegationDialog method createNorthPanel.

protected JComponent createNorthPanel() {
    JPanel panel = new JPanel(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.BOTH;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.gridy = 0;
    gbc.gridx = 0;
    gbc.insets = JBUI.insets(4, 0, 0, 8);
    myClassCombo = new JComboBox(mySuperClasses);
    myClassCombo.setRenderer(new ClassCellRenderer(myClassCombo.getRenderer()));
    gbc.gridwidth = 2;
    final JLabel classComboLabel = new JLabel();
    panel.add(classComboLabel, gbc);
    gbc.gridy++;
    panel.add(myClassCombo, gbc);
    classComboLabel.setText(RefactoringBundle.message("replace.inheritance.from"));
    myClassComboItemListener = new MyClassComboItemListener();
    myClassCombo.addItemListener(myClassComboItemListener);
    gbc.gridy++;
    gbc.gridwidth = 1;
    gbc.insets = JBUI.insets(4, 0);
    final JLabel fieldNameLabel = new JLabel();
    panel.add(fieldNameLabel, gbc);
    myFieldNameField = new NameSuggestionsField(myProject);
    gbc.gridx++;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.insets = JBUI.insets(4, 0, 4, 8);
    gbc.weightx = 1.0;
    panel.add(myFieldNameField.getComponent(), gbc);
    fieldNameLabel.setText(RefactoringBundle.message("field.name"));
    //    if(InheritanceToDelegationUtil.isInnerClassNeeded(myClass, mySuperClass)) {
    gbc.gridx = 0;
    gbc.gridy++;
    gbc.gridwidth = 1;
    gbc.insets = JBUI.insets(4, 0);
    gbc.weightx = 0.0;
    final JLabel innerClassNameLabel = new JLabel();
    panel.add(innerClassNameLabel, gbc);
    /*String[] suggestions = new String[mySuperClasses.length];
    for (int i = 0; i < suggestions.length; i++) {
      suggestions[i] = "My" + mySuperClasses[i].getName();
    }*/
    myInnerClassNameField = new NameSuggestionsField(myProject);
    gbc.gridx++;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.insets = JBUI.insets(4, 4, 4, 8);
    gbc.weightx = 1.0;
    panel.add(myInnerClassNameField.getComponent(), gbc);
    innerClassNameLabel.setText(RefactoringBundle.message("inner.class.name"));
    boolean innerClassNeeded = false;
    for (PsiClass superClass : mySuperClasses) {
        innerClassNeeded |= InheritanceToDelegationUtil.isInnerClassNeeded(myClass, superClass);
    }
    myInnerClassNameField.setVisible(innerClassNeeded);
    innerClassNameLabel.setVisible(innerClassNeeded);
    return panel;
}
Also used : ClassCellRenderer(com.intellij.refactoring.ui.ClassCellRenderer) NameSuggestionsField(com.intellij.refactoring.ui.NameSuggestionsField)

Example 3 with ClassCellRenderer

use of com.intellij.refactoring.ui.ClassCellRenderer in project intellij-community by JetBrains.

the class PullUpDialog method initClassCombo.

@Override
protected void initClassCombo(JComboBox classCombo) {
    classCombo.setRenderer(new ClassCellRenderer(classCombo.getRenderer()));
    classCombo.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                if (myMemberSelectionPanel != null) {
                    ((MyMemberInfoModel) myMemberInfoModel).setSuperClass(getSuperClass());
                    myMemberSelectionPanel.getTable().setMemberInfos(myMemberInfos);
                    myMemberSelectionPanel.getTable().fireExternalDataChange();
                }
            }
        }
    });
}
Also used : ItemEvent(java.awt.event.ItemEvent) ClassCellRenderer(com.intellij.refactoring.ui.ClassCellRenderer) ItemListener(java.awt.event.ItemListener)

Aggregations

ClassCellRenderer (com.intellij.refactoring.ui.ClassCellRenderer)3 PsiClass (com.intellij.psi.PsiClass)1 NameSuggestionsField (com.intellij.refactoring.ui.NameSuggestionsField)1 ItemEvent (java.awt.event.ItemEvent)1 ItemListener (java.awt.event.ItemListener)1