Search in sources :

Example 26 with EditorTextField

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

the class CopyClassDialog method createNorthPanel.

protected JComponent createNorthPanel() {
    myNameField = new EditorTextField("");
    String qualifiedName = getQualifiedName();
    myTfPackage = new PackageNameReferenceEditorCombo(qualifiedName, myProject, RECENTS_KEY, RefactoringBundle.message("choose.destination.package"));
    myTfPackage.setTextFieldPreferredWidth(Math.max(qualifiedName.length() + 5, 40));
    myPackageLabel.setText(RefactoringBundle.message("destination.package"));
    myPackageLabel.setLabelFor(myTfPackage);
    if (myDoClone) {
        myTfPackage.setVisible(false);
        myPackageLabel.setVisible(false);
    }
    final JLabel label = new JLabel(RefactoringBundle.message("target.destination.folder"));
    final boolean isMultipleSourceRoots = JavaProjectRootsUtil.getSuitableDestinationSourceRoots(myProject).size() > 1;
    myDestinationCB.setVisible(!myDoClone && isMultipleSourceRoots);
    label.setVisible(!myDoClone && isMultipleSourceRoots);
    label.setLabelFor(myDestinationCB);
    final JPanel panel = new JPanel(new BorderLayout());
    panel.add(myOpenInEditorCb, BorderLayout.EAST);
    return FormBuilder.createFormBuilder().addComponent(myInformationLabel).addLabeledComponent(RefactoringBundle.message("copy.files.new.name.label"), myNameField, UIUtil.LARGE_VGAP).addLabeledComponent(myPackageLabel, myTfPackage).addLabeledComponent(label, myDestinationCB).addComponent(panel).getPanel();
}
Also used : EditorTextField(com.intellij.ui.EditorTextField) PackageNameReferenceEditorCombo(com.intellij.refactoring.ui.PackageNameReferenceEditorCombo)

Example 27 with EditorTextField

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

the class ExternalProjectPathField method createPanel.

@NotNull
public static MyPathAndProjectButtonPanel createPanel(@NotNull final Project project, @NotNull final ProjectSystemId externalSystemId) {
    final EditorTextField textField = createTextField(project, externalSystemId);
    final FixedSizeButton selectRegisteredProjectButton = new FixedSizeButton();
    selectRegisteredProjectButton.setIcon(AllIcons.Actions.Module);
    String tooltipText = ExternalSystemBundle.message("run.configuration.tooltip.choose.registered.project", externalSystemId.getReadableName());
    selectRegisteredProjectButton.setToolTipText(tooltipText);
    selectRegisteredProjectButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            final Ref<JBPopup> popupRef = new Ref<>();
            final Tree tree = buildRegisteredProjectsTree(project, externalSystemId);
            tree.setBorder(IdeBorderFactory.createEmptyBorder(8));
            Runnable treeSelectionCallback = () -> {
                TreePath path = tree.getSelectionPath();
                if (path != null) {
                    Object lastPathComponent = path.getLastPathComponent();
                    if (lastPathComponent instanceof ExternalSystemNode) {
                        Object e1 = ((ExternalSystemNode) lastPathComponent).getDescriptor().getElement();
                        if (e1 instanceof ExternalProjectPojo) {
                            ExternalProjectPojo pojo = (ExternalProjectPojo) e1;
                            textField.setText(pojo.getPath());
                            Editor editor = textField.getEditor();
                            if (editor != null) {
                                collapseIfPossible(editor, externalSystemId, project);
                            }
                        }
                    }
                }
                popupRef.get().closeOk(null);
            };
            JBPopup popup = new PopupChooserBuilder(tree).setTitle(ExternalSystemBundle.message("run.configuration.title.choose.registered.project", externalSystemId.getReadableName())).setResizable(true).setItemChoosenCallback(treeSelectionCallback).setAutoselectOnMouseMove(true).setCloseOnEnter(false).createPopup();
            popupRef.set(popup);
            popup.showUnderneathOf(selectRegisteredProjectButton);
        }
    });
    return new MyPathAndProjectButtonPanel(textField, selectRegisteredProjectButton);
}
Also used : ActionEvent(java.awt.event.ActionEvent) ExternalSystemNode(com.intellij.openapi.externalSystem.service.task.ui.ExternalSystemNode) Ref(com.intellij.openapi.util.Ref) ActionListener(java.awt.event.ActionListener) TreePath(javax.swing.tree.TreePath) EditorTextField(com.intellij.ui.EditorTextField) Tree(com.intellij.ui.treeStructure.Tree) ExternalSystemTasksTree(com.intellij.openapi.externalSystem.service.task.ui.ExternalSystemTasksTree) Editor(com.intellij.openapi.editor.Editor) PopupChooserBuilder(com.intellij.openapi.ui.popup.PopupChooserBuilder) JBPopup(com.intellij.openapi.ui.popup.JBPopup) FixedSizeButton(com.intellij.openapi.ui.FixedSizeButton) ExternalProjectPojo(com.intellij.openapi.externalSystem.model.project.ExternalProjectPojo) NotNull(org.jetbrains.annotations.NotNull)

Example 28 with EditorTextField

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

the class ExternalProjectPathField method createTextField.

@NotNull
private static EditorTextField createTextField(@NotNull final Project project, @NotNull final ProjectSystemId externalSystemId) {
    ExternalSystemManager<?, ?, ?, ?, ?> manager = ExternalSystemApiUtil.getManager(externalSystemId);
    assert manager != null;
    final AbstractExternalSystemLocalSettings settings = manager.getLocalSettingsProvider().fun(project);
    final ExternalSystemUiAware uiAware = ExternalSystemUiUtil.getUiAware(externalSystemId);
    TextFieldCompletionProvider provider = new TextFieldCompletionProviderDumbAware() {

        @Override
        protected void addCompletionVariants(@NotNull String text, int offset, @NotNull String prefix, @NotNull CompletionResultSet result) {
            for (Map.Entry<ExternalProjectPojo, Collection<ExternalProjectPojo>> entry : settings.getAvailableProjects().entrySet()) {
                String rootProjectPath = entry.getKey().getPath();
                String rootProjectName = uiAware.getProjectRepresentationName(rootProjectPath, null);
                ExternalProjectPathLookupElement rootProjectElement = new ExternalProjectPathLookupElement(rootProjectName, rootProjectPath);
                result.addElement(rootProjectElement);
                for (ExternalProjectPojo subProject : entry.getValue()) {
                    String p = subProject.getPath();
                    if (rootProjectPath.equals(p)) {
                        continue;
                    }
                    String subProjectName = uiAware.getProjectRepresentationName(p, rootProjectPath);
                    ExternalProjectPathLookupElement subProjectElement = new ExternalProjectPathLookupElement(subProjectName, p);
                    result.addElement(subProjectElement);
                }
            }
            result.stopHere();
        }
    };
    EditorTextField result = provider.createEditor(project, false, editor -> {
        collapseIfPossible(editor, externalSystemId, project);
        editor.getSettings().setShowIntentionBulb(false);
    });
    result.setBorder(UIUtil.getTextFieldBorder());
    result.setOneLineMode(true);
    result.setOpaque(true);
    result.setBackground(UIUtil.getTextFieldBackground());
    return result;
}
Also used : AbstractExternalSystemLocalSettings(com.intellij.openapi.externalSystem.settings.AbstractExternalSystemLocalSettings) CompletionResultSet(com.intellij.codeInsight.completion.CompletionResultSet) NotNull(org.jetbrains.annotations.NotNull) ExternalSystemUiAware(com.intellij.openapi.externalSystem.ExternalSystemUiAware) TextFieldCompletionProviderDumbAware(com.intellij.util.TextFieldCompletionProviderDumbAware) EditorTextField(com.intellij.ui.EditorTextField) TextFieldCompletionProvider(com.intellij.util.TextFieldCompletionProvider) Collection(java.util.Collection) Map(java.util.Map) ExternalProjectPojo(com.intellij.openapi.externalSystem.model.project.ExternalProjectPojo) NotNull(org.jetbrains.annotations.NotNull)

Example 29 with EditorTextField

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

the class MoveInstanceMethodDialog method doAction.

protected void doAction() {
    Map<PsiClass, String> parameterNames = new LinkedHashMap<>();
    for (final PsiClass aClass : myThisClassesMap.keySet()) {
        EditorTextField field = myOldClassParameterNameFields.get(aClass);
        if (field.isEnabled()) {
            String parameterName = field.getText().trim();
            if (!PsiNameHelper.getInstance(myMethod.getProject()).isIdentifier(parameterName)) {
                Messages.showErrorDialog(getProject(), RefactoringBundle.message("move.method.enter.a.valid.name.for.parameter"), myRefactoringName);
                return;
            }
            parameterNames.put(aClass, parameterName);
        }
    }
    final PsiVariable targetVariable = (PsiVariable) myList.getSelectedValue();
    if (targetVariable == null)
        return;
    final MoveInstanceMethodProcessor processor = new MoveInstanceMethodProcessor(myMethod.getProject(), myMethod, targetVariable, myVisibilityPanel.getVisibility(), isOpenInEditor(), parameterNames);
    if (!verifyTargetClass(processor.getTargetClass()))
        return;
    saveOpenInEditorOption();
    invokeRefactoring(processor);
}
Also used : EditorTextField(com.intellij.ui.EditorTextField) LinkedHashMap(java.util.LinkedHashMap)

Example 30 with EditorTextField

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

the class MoveInstanceMethodDialog method validateTextFields.

private void validateTextFields(final int selectedIndex) {
    for (EditorTextField textField : myOldClassParameterNameFields.values()) {
        textField.setEnabled(true);
    }
    final PsiVariable variable = myVariables[selectedIndex];
    if (variable instanceof PsiField) {
        final PsiField field = (PsiField) variable;
        final PsiClass hisClass = field.getContainingClass();
        final Set<PsiMember> members = myThisClassesMap.get(hisClass);
        if (members != null && members.size() == 1 && members.contains(field)) {
            //Just the field is referenced
            myOldClassParameterNameFields.get(hisClass).setEnabled(false);
        }
    }
}
Also used : EditorTextField(com.intellij.ui.EditorTextField)

Aggregations

EditorTextField (com.intellij.ui.EditorTextField)47 Document (com.intellij.openapi.editor.Document)11 NotNull (org.jetbrains.annotations.NotNull)11 DocumentEvent (com.intellij.openapi.editor.event.DocumentEvent)9 DocumentAdapter (com.intellij.openapi.editor.event.DocumentAdapter)7 EditorEx (com.intellij.openapi.editor.ex.EditorEx)5 EditorComboBoxEditor (com.intellij.ui.EditorComboBoxEditor)5 EditorComboBoxRenderer (com.intellij.ui.EditorComboBoxRenderer)5 StringComboboxEditor (com.intellij.ui.StringComboboxEditor)5 JBLabel (com.intellij.ui.components.JBLabel)4 Editor (com.intellij.openapi.editor.Editor)3 DocumentListener (com.intellij.openapi.editor.event.DocumentListener)3 ExternalSystemUiAware (com.intellij.openapi.externalSystem.ExternalSystemUiAware)3 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)3 Project (com.intellij.openapi.project.Project)3 ComboBox (com.intellij.openapi.ui.ComboBox)3 FixedSizeButton (com.intellij.openapi.ui.FixedSizeButton)3 CompletionResultSet (com.intellij.codeInsight.completion.CompletionResultSet)2 InlayParameterHintsProvider (com.intellij.codeInsight.hints.InlayParameterHintsProvider)2 Language (com.intellij.lang.Language)2