Search in sources :

Example 16 with EditorTextField

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

the class MoveInstanceMethodDialog method createParametersPanel.

@Nullable
private JPanel createParametersPanel() {
    myThisClassesMap = MoveInstanceMembersUtil.getThisClassesToMembers(myMethod);
    myOldClassParameterNameFields = new HashMap<>();
    if (myThisClassesMap.size() == 0)
        return null;
    JPanel panel = new JPanel(new VerticalFlowLayout(VerticalFlowLayout.TOP, 0, 0, true, true));
    for (PsiClass aClass : myThisClassesMap.keySet()) {
        final String text = RefactoringBundle.message("move.method.this.parameter.label", ObjectUtils.notNull(aClass.getName(), ""));
        panel.add(new TitledSeparator(text, null));
        String suggestedName = MoveInstanceMethodHandler.suggestParameterNameForThisClass(aClass);
        final EditorTextField field = new EditorTextField(suggestedName, getProject(), StdFileTypes.JAVA);
        field.setMinimumSize(new Dimension(field.getPreferredSize()));
        myOldClassParameterNameFields.put(aClass, field);
        panel.add(field);
    }
    panel.setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 0));
    return panel;
}
Also used : TitledSeparator(com.intellij.ui.TitledSeparator) EditorTextField(com.intellij.ui.EditorTextField) VerticalFlowLayout(com.intellij.openapi.ui.VerticalFlowLayout) Nullable(org.jetbrains.annotations.Nullable)

Example 17 with EditorTextField

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

the class GenerateVisitorByHierarchyAction method actionPerformed.

public void actionPerformed(AnActionEvent e) {
    final Ref<String> visitorNameRef = Ref.create("MyVisitor");
    final Ref<PsiClass> parentClassRef = Ref.create(null);
    final Project project = e.getData(CommonDataKeys.PROJECT);
    assert project != null;
    final PsiNameHelper helper = PsiNameHelper.getInstance(project);
    final PackageChooserDialog dialog = new PackageChooserDialog("Choose Target Package and Hierarchy Root Class", project) {

        @Override
        protected ValidationInfo doValidate() {
            PsiDocumentManager.getInstance(project).commitAllDocuments();
            if (!helper.isQualifiedName(visitorNameRef.get())) {
                return new ValidationInfo("Visitor class name is not valid");
            } else if (parentClassRef.isNull()) {
                return new ValidationInfo("Hierarchy root class should be specified");
            } else if (parentClassRef.get().isAnnotationType() || parentClassRef.get().isEnum()) {
                return new ValidationInfo("Hierarchy root class should be an interface or a class");
            }
            return super.doValidate();
        }

        protected JComponent createCenterPanel() {
            final JPanel panel = new JPanel(new BorderLayout());
            panel.add(super.createCenterPanel(), BorderLayout.CENTER);
            panel.add(createNamePanel(), BorderLayout.NORTH);
            panel.add(createBaseClassPanel(), BorderLayout.SOUTH);
            return panel;
        }

        private JComponent createNamePanel() {
            LabeledComponent<JTextField> labeledComponent = new LabeledComponent<>();
            labeledComponent.setText("Visitor class");
            final JTextField nameField = new JTextField(visitorNameRef.get());
            labeledComponent.setComponent(nameField);
            nameField.getDocument().addDocumentListener(new DocumentAdapter() {

                protected void textChanged(final DocumentEvent e) {
                    visitorNameRef.set(nameField.getText());
                }
            });
            return labeledComponent;
        }

        private JComponent createBaseClassPanel() {
            LabeledComponent<EditorTextField> labeledComponent = new LabeledComponent<>();
            labeledComponent.setText("Hierarchy root class");
            final JavaCodeFragmentFactory factory = JavaCodeFragmentFactory.getInstance(project);
            final PsiTypeCodeFragment codeFragment = factory.createTypeCodeFragment("", null, true, JavaCodeFragmentFactory.ALLOW_VOID);
            final Document document = PsiDocumentManager.getInstance(project).getDocument(codeFragment);
            final EditorTextField editorTextField = new EditorTextField(document, project, StdFileTypes.JAVA);
            labeledComponent.setComponent(editorTextField);
            editorTextField.addDocumentListener(new com.intellij.openapi.editor.event.DocumentAdapter() {

                public void documentChanged(final com.intellij.openapi.editor.event.DocumentEvent e) {
                    parentClassRef.set(null);
                    try {
                        final PsiType psiType = codeFragment.getType();
                        final PsiClass psiClass = psiType instanceof PsiClassType ? ((PsiClassType) psiType).resolve() : null;
                        parentClassRef.set(psiClass);
                    } catch (PsiTypeCodeFragment.IncorrectTypeException e1) {
                    // ok
                    }
                }
            });
            return labeledComponent;
        }
    };
    final PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(e.getDataContext());
    if (element instanceof PsiPackage) {
        dialog.selectPackage(((PsiPackage) element).getQualifiedName());
    } else if (element instanceof PsiDirectory) {
        final PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage((PsiDirectory) element);
        if (aPackage != null) {
            dialog.selectPackage(aPackage.getQualifiedName());
        }
    }
    dialog.show();
    if (dialog.getExitCode() != DialogWrapper.OK_EXIT_CODE || dialog.getSelectedPackage() == null || dialog.getSelectedPackage().getQualifiedName().length() == 0 || parentClassRef.isNull()) {
        return;
    }
    final String visitorQName = generateEverything(dialog.getSelectedPackage(), parentClassRef.get(), visitorNameRef.get());
    final IdeView ideView = LangDataKeys.IDE_VIEW.getData(e.getDataContext());
    final PsiClass visitorClass = JavaPsiFacade.getInstance(project).findClass(visitorQName, GlobalSearchScope.projectScope(project));
    if (ideView != null && visitorClass != null) {
        ideView.selectElement(visitorClass);
    }
}
Also used : Document(com.intellij.openapi.editor.Document) IdeView(com.intellij.ide.IdeView) EditorTextField(com.intellij.ui.EditorTextField) DocumentAdapter(com.intellij.ui.DocumentAdapter) DocumentEvent(javax.swing.event.DocumentEvent) LabeledComponent(com.intellij.openapi.ui.LabeledComponent) Project(com.intellij.openapi.project.Project) ValidationInfo(com.intellij.openapi.ui.ValidationInfo) PackageChooserDialog(com.intellij.ide.util.PackageChooserDialog)

Example 18 with EditorTextField

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

the class PackageChooserDialog method setupPathComponent.

private void setupPathComponent(final JPanel northPanel) {
    northPanel.add(new TextFieldAction() {

        @Override
        public void linkSelected(LinkLabel aSource, Object aLinkData) {
            toggleShowPathComponent(northPanel, this);
        }
    }, BorderLayout.EAST);
    myPathEditor = new EditorTextField(JavaReferenceEditorUtil.createDocument("", myProject, false), myProject, StdFileTypes.JAVA);
    myPathEditor.addDocumentListener(new DocumentAdapter() {

        @Override
        public void documentChanged(DocumentEvent e) {
            myAlarm.cancelAllRequests();
            myAlarm.addRequest(() -> updateTreeFromPath(), 300);
        }
    });
    myPathEditor.setBorder(BorderFactory.createEmptyBorder(0, 0, 2, 0));
    northPanel.add(myPathEditor, BorderLayout.SOUTH);
}
Also used : TextFieldAction(com.intellij.openapi.fileChooser.ex.TextFieldAction) EditorTextField(com.intellij.ui.EditorTextField) LinkLabel(com.intellij.ui.components.labels.LinkLabel) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent)

Example 19 with EditorTextField

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

the class ExternalSystemTaskSettingsControl method fillUi.

@Override
public void fillUi(@NotNull final PaintAwarePanel canvas, int indentLevel) {
    myProjectPathLabel = new JBLabel(ExternalSystemBundle.message("run.configuration.settings.label.project", myExternalSystemId.getReadableName()));
    ExternalSystemManager<?, ?, ?, ?, ?> manager = ExternalSystemApiUtil.getManager(myExternalSystemId);
    FileChooserDescriptor projectPathChooserDescriptor = null;
    if (manager instanceof ExternalSystemUiAware) {
        projectPathChooserDescriptor = ((ExternalSystemUiAware) manager).getExternalProjectConfigDescriptor();
    }
    if (projectPathChooserDescriptor == null) {
        projectPathChooserDescriptor = FileChooserDescriptorFactory.createSingleLocalFileDescriptor();
    }
    String title = ExternalSystemBundle.message("settings.label.select.project", myExternalSystemId.getReadableName());
    myProjectPathField = new ExternalProjectPathField(myProject, myExternalSystemId, projectPathChooserDescriptor, title) {

        @Override
        public Dimension getPreferredSize() {
            return myVmOptionsEditor == null ? super.getPreferredSize() : myVmOptionsEditor.getTextField().getPreferredSize();
        }
    };
    canvas.add(myProjectPathLabel, ExternalSystemUiUtil.getLabelConstraints(0));
    canvas.add(myProjectPathField, ExternalSystemUiUtil.getFillLineConstraints(0));
    myTasksLabel = new JBLabel(ExternalSystemBundle.message("run.configuration.settings.label.tasks"));
    myTasksTextField = new EditorTextField("", myProject, PlainTextFileType.INSTANCE);
    canvas.add(myTasksLabel, ExternalSystemUiUtil.getLabelConstraints(0));
    GridBag c = ExternalSystemUiUtil.getFillLineConstraints(0);
    c.insets.right = myProjectPathField.getButton().getPreferredSize().width + 8;
    canvas.add(myTasksTextField, c);
    new TaskCompletionProvider(myProject, myExternalSystemId, myProjectPathField).apply(myTasksTextField);
    myVmOptionsLabel = new JBLabel(ExternalSystemBundle.message("run.configuration.settings.label.vmoptions"));
    myVmOptionsEditor = new RawCommandLineEditor();
    myVmOptionsEditor.setDialogCaption(ExternalSystemBundle.message("run.configuration.settings.label.vmoptions"));
    canvas.add(myVmOptionsLabel, ExternalSystemUiUtil.getLabelConstraints(0));
    canvas.add(myVmOptionsEditor, ExternalSystemUiUtil.getFillLineConstraints(0));
    myArgumentsLabel = new JBLabel(ExternalSystemBundle.message("run.configuration.settings.label.arguments"));
    myArgumentsEditor = new RawCommandLineEditor();
    myArgumentsEditor.setDialogCaption(ExternalSystemBundle.message("run.configuration.settings.label.arguments"));
    canvas.add(myArgumentsLabel, ExternalSystemUiUtil.getLabelConstraints(0));
    canvas.add(myArgumentsEditor, ExternalSystemUiUtil.getFillLineConstraints(0));
}
Also used : ExternalProjectPathField(com.intellij.openapi.externalSystem.service.ui.ExternalProjectPathField) JBLabel(com.intellij.ui.components.JBLabel) EditorTextField(com.intellij.ui.EditorTextField) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) RawCommandLineEditor(com.intellij.ui.RawCommandLineEditor) GridBag(com.intellij.util.ui.GridBag) ExternalSystemUiAware(com.intellij.openapi.externalSystem.ExternalSystemUiAware)

Example 20 with EditorTextField

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

the class JBListTable method installPaddingAndBordersForEditors.

private static void installPaddingAndBordersForEditors(JBTableRowEditor editor) {
    final List<EditorTextField> editors = UIUtil.findComponentsOfType(editor, EditorTextField.class);
    for (EditorTextField textField : editors) {
        textField.putClientProperty("JComboBox.isTableCellEditor", Boolean.FALSE);
        textField.putClientProperty("JBListTable.isTableCellEditor", Boolean.TRUE);
    }
}
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