JComponent () { 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(JavaRefactoringBundle.message("replace.inheritance.from")); myClassComboItemListener = new MyClassComboItemListener(); myClassCombo.addItemListener(myClassComboItemListener); gbc.gridy++; gbc.gridwidth = 1; gbc.insets = JBInsets.create(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(JavaRefactoringBundle.message("field.name")); // if(InheritanceToDelegationUtil.isInnerClassNeeded(myClass, mySuperClass)) { gbc.gridx = 0; gbc.gridy++; gbc.gridwidth = 1; gbc.insets = JBInsets.create(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(JavaRefactoringBundle.message("inner.class.name")); boolean innerClassNeeded = false; for (PsiClass superClass : mySuperClasses) { innerClassNeeded |= InheritanceToDelegationUtil.isInnerClassNeeded(myClass, superClass); } myInnerClassNameField.setVisible(innerClassNeeded); innerClassNameLabel.setVisible(innerClassNeeded); return panel; } @Override protected JComponent createCenterPanel() { 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.weightx = 1.0; gbc.weighty = 1.0; gbc.gridwidth = 1; gbc.insets = JBUI.insets(4, 0, 4, 4); String delegatePanelTitle = "replace.inheritance.with.delegation.delegate.members.title"; myMemberSelectionPanel = new MemberSelectionPanel(JavaRefactoringBundle.message(delegatePanelTitle), Collections.emptyList(), null); panel.add(myMemberSelectionPanel, gbc); MyMemberInfoModel memberInfoModel = new InheritanceToDelegationDialog.MyMemberInfoModel(); myMemberSelectionPanel.getTable().setMemberInfoModel(memberInfoModel); myMemberSelectionPanel.getTable().addMemberInfoChangeListener(memberInfoModel); gbc.gridy++; gbc.insets = JBUI.insets(4, 8, 0, 8); gbc.weighty = 0.0; myCbGenerateGetter = new JCheckBox(JavaRefactoringBundle.message("generate.getter.for.delegated.component")); myCbGenerateGetter.setFocusable(false); panel.add(myCbGenerateGetter, gbc); myCbGenerateGetter.setSelected(JavaRefactoringSettings.getInstance().INHERITANCE_TO_DELEGATION_DELEGATE_OTHER); updateTargetClass(); return panel; } private void updateTargetClass() { final PsiClass targetClass = getSelectedTargetClass(); myFieldNameField.setSuggestions(InheritanceToDelegationHandler.suggestFieldNames(myClass, targetClass)); myInnerClassNameField.getComponent().setEnabled(InheritanceToDelegationUtil.isInnerClassNeeded(myClass, targetClass)); myInnerClassNameField.setSuggestions(new String[]{InheritanceToDelegationHandler.suggestTargetClassName(targetClass)}); myDataChangedListener = () -> validateButtons(); myInnerClassNameField.addDataChangedListener(myDataChangedListener); myFieldNameField.addDataChangedListener(myDataChangedListener); myMemberSelectionPanel.getTable().setMemberInfos(myBasesToMemberInfos.get(targetClass)); myMemberSelectionPanel.getTable().fireExternalDataChange(); } private class MyMemberInfoModel implements MemberInfoModel<PsiMember, MemberInfo> { final HashMap<PsiClass,InterfaceMemberDependencyGraph<PsiMember, MemberInfo>> myGraphs; MyMemberInfoModel() { myGraphs = new HashMap<>(); for (PsiClass superClass : mySuperClasses) { myGraphs.put(superClass, new InterfaceMemberDependencyGraph<>(superClass)); } } @Override public boolean isMemberEnabled(MemberInfo memberInfo) { if (getGraph().getDependent().contains(memberInfo.getMember())) { return false; } else { return true; } } @Override public boolean isCheckedWhenDisabled(MemberInfo member) { return true; } @Override public boolean isAbstractEnabled(MemberInfo member) { return false; } @Override public boolean isAbstractWhenDisabled(MemberInfo member) { return false; } @Override public Boolean isFixedAbstract(MemberInfo member) { return null; } @Override public int checkForProblems(@NotNull MemberInfo member) { return OK; } @Override public String getTooltipText(MemberInfo member) { return null; } @Override public void memberInfoChanged(@NotNull MemberInfoChange<PsiMember, MemberInfo> event) { final Collection<MemberInfo> changedMembers = event.getChangedMembers(); for (MemberInfo changedMember : changedMembers) { getGraph().memberChanged(changedMember); } } private InterfaceMemberDependencyGraph<PsiMember, MemberInfo> getGraph() { return myGraphs.get(getSelectedTargetClass()); } } private class MyClassComboItemListener implements ItemListener { @Override public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { updateTargetClass(); } } } }