private void updateControlsEnabled() {
   myClassPackageChooser.setEnabled(myToPackageRadioButton.isSelected());
   myInnerClassChooser.setEnabled(myMakeInnerClassOfRadioButton.isSelected());
   UIUtil.setEnabled(
       myTargetPanel,
       isMoveToPackage() && getSourceRoots().length > 1 && !myTargetDirectoryFixed,
       true);
   validateButtons();
 }
  private void updateEnabledState() {
    myLabelEditor.setEnabled(myRbExpressionLabel.isSelected());

    final boolean isChildrenExpression = myRbExpressionChildrenRenderer.isSelected();
    myChildrenExpandedEditor.setEnabled(isChildrenExpression);
    myExpandedLabel.setEnabled(isChildrenExpression);
    myChildrenEditor.setEnabled(isChildrenExpression);
    myTable.setEnabled(myRbListChildrenRenderer.isSelected());
  }
  public MoveClassesOrPackagesDialog(
      Project project,
      boolean searchTextOccurences,
      PsiElement[] elementsToMove,
      final PsiElement initialTargetElement,
      MoveCallback moveCallback) {
    super(project, true);
    myElementsToMove = elementsToMove;
    myMoveCallback = moveCallback;
    myManager = PsiManager.getInstance(myProject);
    setTitle(MoveHandler.REFACTORING_NAME);
    mySearchTextOccurencesEnabled = searchTextOccurences;

    selectInitialCard();

    init();

    if (initialTargetElement instanceof PsiClass) {
      myMakeInnerClassOfRadioButton.setSelected(true);

      myInnerClassChooser.setText(((PsiClass) initialTargetElement).getQualifiedName());

      ApplicationManager.getApplication()
          .invokeLater(
              () -> myInnerClassChooser.requestFocus(),
              ModalityState.stateForComponent(myMainPanel));
    } else if (initialTargetElement instanceof PsiPackage) {
      myClassPackageChooser.setText(((PsiPackage) initialTargetElement).getQualifiedName());
    }

    updateControlsEnabled();
    myToPackageRadioButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            updateControlsEnabled();
            myClassPackageChooser.requestFocus();
          }
        });
    myMakeInnerClassOfRadioButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            updateControlsEnabled();
            myInnerClassChooser.requestFocus();
          }
        });

    for (PsiElement element : elementsToMove) {
      if (element.getContainingFile() != null) {
        myOpenInEditorPanel.add(initOpenInEditorCb(), BorderLayout.EAST);
        break;
      }
    }
  }
  private String generateSignatureText() {
    String name = getNewName();
    String type = myReturnTypeField.getText().trim();

    StringBuilder builder = new StringBuilder();
    if (myPublicRadioButton.isSelected() && type.length() == 0) {
      builder.append(GrModifier.DEF);
    }
    if (myPrivateRadioButton.isSelected()) {
      builder.append(GrModifier.PRIVATE).append(' ');
    } else if (myProtectedRadioButton.isSelected()) {
      builder.append(GrModifier.PROTECTED).append(' ');
    }
    builder.append(type).append(' ');
    builder.append(name).append('(');

    final List<GrTableParameterInfo> infos = myParameterModel.getParameterInfos();
    if (infos.size() > 0) {
      final List<String> paramsText =
          ContainerUtil.map(
              infos,
              new Function<GrTableParameterInfo, String>() {
                public String fun(GrTableParameterInfo grParameterInfo) {
                  return generateParameterText(grParameterInfo);
                }
              });
      builder.append("\n").append(INDENT);
      builder.append(StringUtil.join(paramsText, ",\n" + INDENT));
      builder.append('\n');
    }
    builder.append(')');

    final PsiTypeCodeFragment[] exceptions = myExceptionTableModel.getTypeCodeFragments();
    if (exceptions.length > 0) {
      builder.append("\nthrows\n");
      final List<String> exceptionNames =
          ContainerUtil.map(
              exceptions,
              new Function<PsiTypeCodeFragment, String>() {
                public String fun(PsiTypeCodeFragment fragment) {
                  return fragment.getText();
                }
              });

      builder.append(INDENT).append(StringUtil.join(exceptionNames, ",\n" + INDENT));
    }
    return builder.toString();
  }
 public GrChangeSignatureDialog(@NotNull Project project, GrMethod method) {
   super(project, true);
   myMethod = method;
   setTitle(ChangeSignatureHandler.REFACTORING_NAME);
   init();
   updateSignature();
   ActionListener listener =
       new ActionListener() {
         public void actionPerformed(ActionEvent e) {
           updateSignature();
         }
       };
   myPublicRadioButton.addActionListener(listener);
   myPrivateRadioButton.addActionListener(listener);
   myProtectedRadioButton.addActionListener(listener);
 }
  protected void init() {
    super.init();
    final PsiClass psiClass = myMethod.getContainingClass();
    if (psiClass == null) return;
    if (psiClass.isInterface()) {
      myDelegatePanel.setVisible(false);
    }

    if (myMethod.hasModifierProperty(GrModifier.PRIVATE)) {
      myPrivateRadioButton.setSelected(true);
    } else if (myMethod.hasModifierProperty(GrModifier.PROTECTED)) {
      myProtectedRadioButton.setSelected(true);
    } else if (myMethod.hasModifierProperty(GrModifier.PUBLIC)) {
      myPublicRadioButton.setSelected(true);
    }
  }
  public void reset() {
    final TextWithImports emptyExpressionFragment =
        new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, "");
    ((CardLayout) myMainPanel.getLayout())
        .show(myMainPanel, myRenderer == null ? EMPTY_PANEL_ID : DATA_PANEL_ID);
    if (myRenderer == null) {
      return;
    }
    final String className = myRenderer.getClassName();
    myClassNameField.setText(className);
    final ValueLabelRenderer labelRenderer = myRenderer.getLabelRenderer();
    final ChildrenRenderer childrenRenderer = myRenderer.getChildrenRenderer();
    final NodeRendererSettings rendererSettings = NodeRendererSettings.getInstance();

    if (rendererSettings.isBase(labelRenderer)) {
      myRbDefaultLabel.setSelected(true);
      myLabelEditor.setText(emptyExpressionFragment);
    } else {
      myRbExpressionLabel.setSelected(true);
      myLabelEditor.setText(((LabelRenderer) labelRenderer).getLabelExpression());
    }

    if (rendererSettings.isBase(childrenRenderer)) {
      myRbDefaultChildrenRenderer.setSelected(true);
      myChildrenEditor.setText(emptyExpressionFragment);
      myChildrenExpandedEditor.setText(emptyExpressionFragment);
      getTableModel().clear();
    } else if (childrenRenderer instanceof ExpressionChildrenRenderer) {
      myRbExpressionChildrenRenderer.setSelected(true);
      final ExpressionChildrenRenderer exprRenderer = (ExpressionChildrenRenderer) childrenRenderer;
      myChildrenEditor.setText(exprRenderer.getChildrenExpression());
      myChildrenExpandedEditor.setText(exprRenderer.getChildrenExpandable());
      getTableModel().clear();
    } else {
      myRbListChildrenRenderer.setSelected(true);
      myChildrenEditor.setText(emptyExpressionFragment);
      myChildrenExpandedEditor.setText(emptyExpressionFragment);
      if (childrenRenderer instanceof EnumerationChildrenRenderer) {
        getTableModel().init(((EnumerationChildrenRenderer) childrenRenderer).getChildren());
      } else {
        getTableModel().clear();
      }
    }

    updateEnabledState();
    updateContext(className);
  }
  @Override
  protected void doAction() {
    if (!validateInputData()) {
      return;
    }

    stopEditing();
    String modifier = "";
    if (myPublicRadioButton.isSelected()) {
      modifier = GrModifier.PUBLIC;
    } else if (myPrivateRadioButton.isSelected()) {
      modifier = GrModifier.PRIVATE;
    } else if (myProtectedRadioButton.isSelected()) {
      modifier = GrModifier.PROTECTED;
    }

    PsiType returnType = null;
    try {
      returnType = myReturnTypeCodeFragment.getType();
    } catch (PsiTypeCodeFragment.TypeSyntaxException ignored) {
    } catch (PsiTypeCodeFragment.NoTypeException ignored) {
    }

    String newName = getNewName();
    final List<GrTableParameterInfo> tableParameterInfos = myParameterModel.getParameterInfos();
    final List<GrParameterInfo> parameterInfos =
        ContainerUtil.map(
            tableParameterInfos,
            new Function<GrTableParameterInfo, GrParameterInfo>() {
              public GrParameterInfo fun(GrTableParameterInfo info) {
                return info.generateParameterInfo();
              }
            });
    final ThrownExceptionInfo[] exceptionInfos = myExceptionTableModel.getThrownExceptions();
    invokeRefactoring(
        new GrChangeSignatureProcessor(
            myProject,
            new GrChangeInfoImpl(
                myMethod,
                modifier,
                returnType == null ? null : CanonicalTypes.createTypeWrapper(returnType),
                newName,
                parameterInfos,
                exceptionInfos,
                myDelegateRadioButton.isSelected())));
  }
 private void flushDataTo(final CompoundReferenceRenderer renderer) { // label
   LabelRenderer labelRenderer = null;
   if (myRbExpressionLabel.isSelected()) {
     labelRenderer = new LabelRenderer();
     labelRenderer.setLabelExpression(myLabelEditor.getText());
   }
   renderer.setLabelRenderer(labelRenderer);
   // children
   ChildrenRenderer childrenRenderer = null;
   if (myRbExpressionChildrenRenderer.isSelected()) {
     childrenRenderer = new ExpressionChildrenRenderer();
     ((ExpressionChildrenRenderer) childrenRenderer)
         .setChildrenExpression(myChildrenEditor.getText());
     ((ExpressionChildrenRenderer) childrenRenderer)
         .setChildrenExpandable(myChildrenExpandedEditor.getText());
   } else if (myRbListChildrenRenderer.isSelected()) {
     childrenRenderer = new EnumerationChildrenRenderer(getTableModel().getExpressions());
   }
   renderer.setChildrenRenderer(childrenRenderer);
   // classname
   renderer.setClassName(myClassNameField.getText());
 }
 protected boolean isMoveToPackage() {
   return myHavePackages || myToPackageRadioButton.isSelected();
 }
  public JComponent createComponent() {
    if (myProject == null) {
      myProject = JavaDebuggerSupport.getContextProjectForEditorFieldsInDebuggerConfigurables();
    }
    final JPanel panel = new JPanel(new GridBagLayout());

    myRbDefaultLabel =
        new JRadioButton(
            DebuggerBundle.message("label.compound.renderer.configurable.use.default.renderer"));
    myRbExpressionLabel =
        new JRadioButton(
            DebuggerBundle.message("label.compound.renderer.configurable.use.expression"));
    final ButtonGroup labelButtonsGroup = new ButtonGroup();
    labelButtonsGroup.add(myRbDefaultLabel);
    labelButtonsGroup.add(myRbExpressionLabel);

    myRbDefaultChildrenRenderer =
        new JRadioButton(
            DebuggerBundle.message("label.compound.renderer.configurable.use.default.renderer"));
    myRbExpressionChildrenRenderer =
        new JRadioButton(
            DebuggerBundle.message("label.compound.renderer.configurable.use.expression"));
    myRbListChildrenRenderer =
        new JRadioButton(
            DebuggerBundle.message("label.compound.renderer.configurable.use.expression.list"));
    final ButtonGroup childrenButtonGroup = new ButtonGroup();
    childrenButtonGroup.add(myRbDefaultChildrenRenderer);
    childrenButtonGroup.add(myRbExpressionChildrenRenderer);
    childrenButtonGroup.add(myRbListChildrenRenderer);

    myLabelEditor = new DebuggerExpressionTextField(myProject, null, "ClassLabelExpression");
    myChildrenEditor = new DebuggerExpressionTextField(myProject, null, "ClassChildrenExpression");
    myChildrenExpandedEditor =
        new DebuggerExpressionTextField(myProject, null, "ClassChildrenExpression");
    myChildrenListEditor = createChildrenListEditor();

    final ItemListener updateListener =
        new ItemListener() {
          public void itemStateChanged(ItemEvent e) {
            updateEnabledState();
          }
        };
    myRbExpressionLabel.addItemListener(updateListener);
    myRbListChildrenRenderer.addItemListener(updateListener);
    myRbExpressionChildrenRenderer.addItemListener(updateListener);

    myClassNameField =
        new ClassNameEditorWithBrowseButton(
            new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                PsiClass psiClass =
                    DebuggerUtils.getInstance()
                        .chooseClassDialog(
                            DebuggerBundle.message(
                                "title.compound.renderer.configurable.choose.renderer.reference.type"),
                            myProject);
                if (psiClass != null) {
                  String qName = JVMNameUtil.getNonAnonymousClassName(psiClass);
                  myClassNameField.setText(qName);
                  updateContext(qName);
                }
              }
            },
            myProject);
    myClassNameField
        .getEditorTextField()
        .addFocusListener(
            new FocusAdapter() {
              public void focusLost(FocusEvent e) {
                final String qName = myClassNameField.getText();
                updateContext(qName);
              }
            });

    panel.add(
        new JLabel(DebuggerBundle.message("label.compound.renderer.configurable.apply.to")),
        new GridBagConstraints(
            0,
            GridBagConstraints.RELATIVE,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE,
            new Insets(0, 0, 0, 0),
            0,
            0));
    panel.add(
        myClassNameField,
        new GridBagConstraints(
            0,
            GridBagConstraints.RELATIVE,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(4, 0, 0, 0),
            0,
            0));

    panel.add(
        new JLabel(DebuggerBundle.message("label.compound.renderer.configurable.when.rendering")),
        new GridBagConstraints(
            0,
            GridBagConstraints.RELATIVE,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE,
            new Insets(20, 0, 0, 0),
            0,
            0));
    panel.add(
        myRbDefaultLabel,
        new GridBagConstraints(
            0,
            GridBagConstraints.RELATIVE,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE,
            new Insets(0, 10, 0, 0),
            0,
            0));
    panel.add(
        myRbExpressionLabel,
        new GridBagConstraints(
            0,
            GridBagConstraints.RELATIVE,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE,
            new Insets(0, 10, 0, 0),
            0,
            0));
    panel.add(
        myLabelEditor,
        new GridBagConstraints(
            0,
            GridBagConstraints.RELATIVE,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 30, 0, 0),
            0,
            0));

    panel.add(
        new JLabel(DebuggerBundle.message("label.compound.renderer.configurable.when.expanding")),
        new GridBagConstraints(
            0,
            GridBagConstraints.RELATIVE,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE,
            new Insets(20, 0, 0, 0),
            0,
            0));
    panel.add(
        myRbDefaultChildrenRenderer,
        new GridBagConstraints(
            0,
            GridBagConstraints.RELATIVE,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE,
            new Insets(0, 10, 0, 0),
            0,
            0));
    panel.add(
        myRbExpressionChildrenRenderer,
        new GridBagConstraints(
            0,
            GridBagConstraints.RELATIVE,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE,
            new Insets(0, 10, 0, 0),
            0,
            0));
    panel.add(
        myChildrenEditor,
        new GridBagConstraints(
            0,
            GridBagConstraints.RELATIVE,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 30, 0, 0),
            0,
            0));
    myExpandedLabel =
        new JLabel(DebuggerBundle.message("label.compound.renderer.configurable.test.can.expand"));
    panel.add(
        myExpandedLabel,
        new GridBagConstraints(
            0,
            GridBagConstraints.RELATIVE,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE,
            new Insets(4, 30, 0, 0),
            0,
            0));
    panel.add(
        myChildrenExpandedEditor,
        new GridBagConstraints(
            0,
            GridBagConstraints.RELATIVE,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 30, 0, 0),
            0,
            0));
    panel.add(
        myRbListChildrenRenderer,
        new GridBagConstraints(
            0,
            GridBagConstraints.RELATIVE,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 10, 0, 0),
            0,
            0));
    panel.add(
        myChildrenListEditor,
        new GridBagConstraints(
            0,
            GridBagConstraints.RELATIVE,
            1,
            1,
            1.0,
            1.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.BOTH,
            new Insets(4, 30, 0, 0),
            0,
            0));

    myMainPanel = new JPanel(new CardLayout());
    myMainPanel.add(new JPanel(), EMPTY_PANEL_ID);
    myMainPanel.add(panel, DATA_PANEL_ID);
    return myMainPanel;
  }