private void createNameAndReturnTypeEditors() {
    myNameCodeFragment = new GroovyCodeFragment(myProject, "");
    myNameField =
        new EditorTextField(
            PsiDocumentManager.getInstance(myProject).getDocument(myNameCodeFragment),
            myProject,
            myNameCodeFragment.getFileType());

    final JavaCodeFragmentFactory factory = JavaCodeFragmentFactory.getInstance(myProject);
    myReturnTypeCodeFragment =
        factory.createTypeCodeFragment("", myMethod, true, JavaCodeFragmentFactory.ALLOW_VOID);
    final Document document =
        PsiDocumentManager.getInstance(myProject).getDocument(myReturnTypeCodeFragment);
    myReturnTypeField =
        new EditorTextField(document, myProject, myReturnTypeCodeFragment.getFileType());

    myNameField.setText(myMethod.getName());
    final GrTypeElement element = myMethod.getReturnTypeElementGroovy();
    if (element != null) {
      myReturnTypeField.setText(element.getText());
    }

    myReturnTypeLabel = new JLabel();
    myReturnTypeLabel.setLabelFor(myReturnTypeField);

    myNameLabel = new JLabel();
    myNameLabel.setLabelFor(myNameField);
  }
 protected JComponent createCenterPanel() {
   final VirtualFile[] sourceRoots = getSourceRoots();
   boolean isDestinationVisible = sourceRoots.length > 1;
   myDestinationFolderCB.setVisible(isDestinationVisible);
   myTargetDestinationLabel.setVisible(isDestinationVisible);
   return null;
 }
  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());
  }
    @Override
    public Pair<Image, Point> createDraggedImage(DnDAction action, Point dragOrigin) {
      final TreePath[] paths = getSelectionPaths();
      if (paths == null) return null;

      final int count = paths.length;

      final JLabel label = new JLabel(String.format("%s item%s", count, count == 1 ? "" : "s"));
      label.setOpaque(true);
      label.setForeground(myTree.getForeground());
      label.setBackground(myTree.getBackground());
      label.setFont(myTree.getFont());
      label.setSize(label.getPreferredSize());
      final BufferedImage image =
          UIUtil.createImage(label.getWidth(), label.getHeight(), BufferedImage.TYPE_INT_ARGB);

      Graphics2D g2 = (Graphics2D) image.getGraphics();
      g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f));
      label.paint(g2);
      g2.dispose();

      return new Pair<Image, Point>(
          image, new Point(-image.getWidth(null), -image.getHeight(null)));
    }
  public void setData(
      PsiElement[] psiElements,
      String targetPackageName,
      final PsiDirectory initialTargetDirectory,
      boolean isTargetDirectoryFixed,
      boolean searchInComments,
      boolean searchForTextOccurences,
      String helpID) {
    myInitialTargetDirectory = initialTargetDirectory;
    myTargetDirectoryFixed = isTargetDirectoryFixed;
    if (targetPackageName.length() != 0) {
      myWithBrowseButtonReference.prependItem(targetPackageName);
      myClassPackageChooser.prependItem(targetPackageName);
    }

    String nameFromCallback =
        myMoveCallback instanceof MoveClassesOrPackagesCallback
            ? ((MoveClassesOrPackagesCallback) myMoveCallback).getElementsToMoveName()
            : null;
    if (nameFromCallback != null) {
      myNameLabel.setText(nameFromCallback);
    } else if (psiElements.length == 1) {
      PsiElement firstElement = psiElements[0];
      if (firstElement instanceof PsiClass) {
        LOG.assertTrue(!MoveClassesOrPackagesImpl.isClassInnerOrLocal((PsiClass) firstElement));
      } else {
        PsiElement parent = firstElement.getParent();
        LOG.assertTrue(parent != null);
      }
      myNameLabel.setText(
          RefactoringBundle.message(
              "move.single.class.or.package.name.label",
              UsageViewUtil.getType(firstElement),
              UsageViewUtil.getLongName(firstElement)));
    } else if (psiElements.length > 1) {
      myNameLabel.setText(
          psiElements[0] instanceof PsiClass
              ? RefactoringBundle.message("move.specified.classes")
              : RefactoringBundle.message("move.specified.packages"));
    }
    selectInitialCard();

    myCbSearchInComments.setSelected(searchInComments);
    myCbSearchTextOccurences.setSelected(searchForTextOccurences);

    ((DestinationFolderComboBox) myDestinationFolderCB)
        .setData(
            myProject,
            myInitialTargetDirectory,
            new Pass<String>() {
              @Override
              public void pass(String s) {
                setErrorText(s);
              }
            },
            myClassPackageChooser.getChildComponent());
    UIUtil.setEnabled(
        myTargetPanel,
        getSourceRoots().length > 0 && isMoveToPackage() && !isTargetDirectoryFixed,
        true);
    validateButtons();
    myHelpID = helpID;
  }
 private void updateLabels() {
   // TODO: Move from JavaDoc to somewhere more appropriate place.
   ElementLocationUtil.customizeElementLabel(myElements[myIndex], myLocationLabel);
   //noinspection AutoBoxing
   myCountLabel.setText(CodeInsightBundle.message("n.of.m", myIndex + 1, myElements.length));
 }
  public void setData(
      PsiElement[] psiElements,
      String targetPackageName,
      PsiDirectory initialTargetDirectory,
      boolean isTargetDirectoryFixed,
      boolean suggestToMoveToAnotherRoot,
      boolean searchInComments,
      boolean searchForTextOccurences,
      String helpID) {
    myTargetDirectoryFixed = isTargetDirectoryFixed;
    mySuggestToMoveToAnotherRoot = suggestToMoveToAnotherRoot;
    if (targetPackageName.length() != 0) {
      myWithBrowseButtonReference.prependItem(targetPackageName);
      myClassPackageChooser.prependItem(targetPackageName);
    }

    String nameFromCallback =
        myMoveCallback instanceof MoveClassesOrPackagesCallback
            ? ((MoveClassesOrPackagesCallback) myMoveCallback).getElementsToMoveName()
            : null;
    if (nameFromCallback != null) {
      myNameLabel.setText(nameFromCallback);
    } else if (psiElements.length == 1) {
      PsiElement firstElement = psiElements[0];
      if (firstElement instanceof PsiClass) {
        LOG.assertTrue(!MoveClassesOrPackagesImpl.isClassInnerOrLocal((PsiClass) firstElement));
      } else {
        PsiElement parent = firstElement.getParent();
        LOG.assertTrue(parent != null);
      }
      myNameLabel.setText(
          RefactoringBundle.message(
              "move.single.class.or.package.name.label",
              UsageViewUtil.getType(firstElement),
              UsageViewUtil.getLongName(firstElement)));
    } else if (psiElements.length > 1) {
      myNameLabel.setText(
          psiElements[0] instanceof PsiClass
              ? RefactoringBundle.message("move.specified.classes")
              : RefactoringBundle.message("move.specified.packages"));
    }
    selectInitialCard();

    myCbSearchInComments.setSelected(searchInComments);
    myCbSearchTextOccurences.setSelected(searchForTextOccurences);

    if (initialTargetDirectory != null
        && JavaMoveClassesOrPackagesHandler.packageHasMultipleDirectoriesInModule(
            myProject, initialTargetDirectory)) {
      final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
      final Set<VirtualFile> initialRoots = new HashSet<VirtualFile>();
      collectSourceRoots(psiElements, fileIndex, initialRoots);
      if (initialRoots.size() > 1) {
        initialTargetDirectory = null;
      }
    }
    ((DestinationFolderComboBox) myDestinationFolderCB)
        .setData(
            myProject,
            initialTargetDirectory,
            new Pass<String>() {
              @Override
              public void pass(String s) {
                setErrorText(s);
              }
            },
            myHavePackages
                ? myWithBrowseButtonReference.getChildComponent()
                : myClassPackageChooser.getChildComponent());
    UIUtil.setEnabled(
        myTargetPanel,
        !getSourceRoots().isEmpty() && isMoveToPackage() && !isTargetDirectoryFixed,
        true);
    validateButtons();
    myHelpID = helpID;
  }
 protected JComponent createCenterPanel() {
   boolean isDestinationVisible = getSourceRoots().size() > 1;
   myDestinationFolderCB.setVisible(isDestinationVisible);
   myTargetDestinationLabel.setVisible(isDestinationVisible);
   return null;
 }
예제 #9
0
  protected JComponent createNorthPanel() {
    GridBagConstraints gbConstraints = new GridBagConstraints();

    JPanel panel = new JPanel(new GridBagLayout());

    gbConstraints.anchor = GridBagConstraints.WEST;
    gbConstraints.fill = GridBagConstraints.NONE;
    gbConstraints.gridx = 0;

    gbConstraints.insets = new Insets(4, 4, 4, 0);
    gbConstraints.gridwidth = 1;
    gbConstraints.weightx = 0;
    gbConstraints.weighty = 0;
    gbConstraints.gridy = 0;
    JLabel type = new JLabel(RefactoringBundle.message("parameter.of.type"));
    panel.add(type, gbConstraints);

    gbConstraints.insets = new Insets(4, 4, 4, 8);
    gbConstraints.gridx++;
    gbConstraints.weightx = 1;
    gbConstraints.fill = GridBagConstraints.BOTH;
    myTypeSelector = myTypeSelectorManager.getTypeSelector();
    panel.add(myTypeSelector.getComponent(), gbConstraints);

    gbConstraints.insets = new Insets(4, 4, 4, 8);
    gbConstraints.gridwidth = 1;
    gbConstraints.weightx = 0;
    gbConstraints.gridx = 0;
    gbConstraints.gridy = 1;
    gbConstraints.fill = GridBagConstraints.NONE;

    myParameterNameField = new NameSuggestionsField(myProject);
    final JLabel nameLabel = new JLabel(RefactoringBundle.message("name.prompt"));
    nameLabel.setLabelFor(myParameterNameField.getComponent());
    panel.add(nameLabel, gbConstraints);

    /*
        if (myNameSuggestions.length > 1) {
          myParameterNameField = createComboBoxForName();
        }
        else {
          myParameterNameField = createTextFieldForName();
        }
    */
    gbConstraints.gridx++;
    gbConstraints.insets = new Insets(4, 4, 4, 8);
    gbConstraints.weightx = 1;
    gbConstraints.fill = GridBagConstraints.BOTH;
    panel.add(myParameterNameField.getComponent(), gbConstraints);
    myParameterNameChangedListener =
        new NameSuggestionsField.DataChanged() {
          public void dataChanged() {
            validateButtons();
          }
        };
    myParameterNameField.addDataChangedListener(myParameterNameChangedListener);

    myNameSuggestionsManager =
        new NameSuggestionsManager(
            myTypeSelector, myParameterNameField, myNameSuggestionsGenerator);
    myNameSuggestionsManager.setLabelsFor(type, nameLabel);

    gbConstraints.gridx = 0;
    gbConstraints.insets = new Insets(4, 0, 4, 8);
    gbConstraints.gridwidth = 2;
    if (myOccurenceNumber > 1 && !myPanel.myIsInvokedOnDeclaration) {
      gbConstraints.gridy++;
      myPanel.createOccurrencesCb(gbConstraints, panel, myOccurenceNumber);
    }
    if (myPanel.myCbReplaceAllOccurences != null) {
      gbConstraints.insets = new Insets(0, 16, 4, 8);
    }
    JavaRefactoringSettings settings = JavaRefactoringSettings.getInstance();
    myPanel.createLocalVariablePanel(gbConstraints, panel, settings);

    myPanel.createRemoveParamsPanel(gbConstraints, panel);
    gbConstraints.insets = new Insets(4, 0, 4, 8);

    gbConstraints.gridy++;
    myCbDeclareFinal = new NonFocusableCheckBox(RefactoringBundle.message("declare.final"));

    final Boolean settingsFinals = settings.INTRODUCE_PARAMETER_CREATE_FINALS;
    myCbDeclareFinal.setSelected(
        settingsFinals == null
            ? CodeStyleSettingsManager.getSettings(myProject).GENERATE_FINAL_PARAMETERS
            : settingsFinals.booleanValue());
    panel.add(myCbDeclareFinal, gbConstraints);
    if (myMustBeFinal) {
      myCbDeclareFinal.setSelected(true);
      myCbDeclareFinal.setEnabled(false);
    } else if (myHasWriteAccess && myPanel.isReplaceAllOccurences()) {
      myCbDeclareFinal.setSelected(false);
      myCbDeclareFinal.setEnabled(false);
    }

    gbConstraints.gridy++;
    myPanel.createDelegateCb(gbConstraints, panel);

    return panel;
  }