Search in sources :

Example 6 with MemberChooser

use of com.intellij.ide.util.MemberChooser in project intellij-community by JetBrains.

the class AddFieldBreakpointDialog method createCenterPanel.

protected JComponent createCenterPanel() {
    myClassChooser.getTextField().getDocument().addDocumentListener(new DocumentAdapter() {

        public void textChanged(DocumentEvent event) {
            updateUI();
        }
    });
    myClassChooser.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            PsiClass currentClass = getSelectedClass();
            TreeClassChooser chooser = TreeClassChooserFactory.getInstance(myProject).createAllProjectScopeChooser(DebuggerBundle.message("add.field.breakpoint.dialog.classchooser.title"));
            if (currentClass != null) {
                PsiFile containingFile = currentClass.getContainingFile();
                if (containingFile != null) {
                    PsiDirectory containingDirectory = containingFile.getContainingDirectory();
                    if (containingDirectory != null) {
                        chooser.selectDirectory(containingDirectory);
                    }
                }
            }
            chooser.showDialog();
            PsiClass selectedClass = chooser.getSelected();
            if (selectedClass != null) {
                myClassChooser.setText(selectedClass.getQualifiedName());
            }
        }
    });
    myFieldChooser.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            PsiClass selectedClass = getSelectedClass();
            if (selectedClass != null) {
                PsiField[] fields = selectedClass.getFields();
                MemberChooser<PsiFieldMember> chooser = new MemberChooser<>(ContainerUtil.map2Array(fields, PsiFieldMember.class, PsiFieldMember::new), false, false, myProject);
                chooser.setTitle(DebuggerBundle.message("add.field.breakpoint.dialog.field.chooser.title", fields.length));
                chooser.setCopyJavadocVisible(false);
                TransactionGuard.getInstance().submitTransactionAndWait(() -> chooser.show());
                List<PsiFieldMember> selectedElements = chooser.getSelectedElements();
                if (selectedElements != null && selectedElements.size() == 1) {
                    PsiField field = selectedElements.get(0).getElement();
                    myFieldChooser.setText(field.getName());
                }
            }
        }
    });
    myFieldChooser.setEnabled(false);
    return myPanel;
}
Also used : TreeClassChooser(com.intellij.ide.util.TreeClassChooser) ActionEvent(java.awt.event.ActionEvent) DocumentAdapter(com.intellij.ui.DocumentAdapter) PsiFieldMember(com.intellij.codeInsight.generation.PsiFieldMember) DocumentEvent(javax.swing.event.DocumentEvent) MemberChooser(com.intellij.ide.util.MemberChooser) ActionListener(java.awt.event.ActionListener) List(java.util.List)

Example 7 with MemberChooser

use of com.intellij.ide.util.MemberChooser in project intellij-community by JetBrains.

the class GenerateToStringActionHandlerImpl method doExecuteAction.

private static void doExecuteAction(@NotNull final Project project, @NotNull final PsiClass clazz, final Editor editor) {
    if (!FileModificationService.getInstance().preparePsiElementsForWrite(clazz)) {
        return;
    }
    logger.debug("+++ doExecuteAction - START +++");
    if (logger.isDebugEnabled()) {
        logger.debug("Current project " + project.getName());
    }
    final PsiElementClassMember[] dialogMembers = buildMembersToShow(clazz);
    final MemberChooserHeaderPanel header = new MemberChooserHeaderPanel(clazz);
    logger.debug("Displaying member chooser dialog");
    final MemberChooser<PsiElementClassMember> chooser = new MemberChooser<PsiElementClassMember>(dialogMembers, true, true, project, PsiUtil.isLanguageLevel5OrHigher(clazz), header) {

        @Nullable
        @Override
        protected String getHelpId() {
            return "editing.altInsert.tostring";
        }
    };
    //noinspection DialogTitleCapitalization
    chooser.setTitle("Generate toString()");
    chooser.setCopyJavadocVisible(false);
    chooser.selectElements(getPreselection(clazz, dialogMembers));
    header.setChooser(chooser);
    chooser.show();
    if (DialogWrapper.OK_EXIT_CODE == chooser.getExitCode()) {
        Collection<PsiMember> selectedMembers = GenerationUtil.convertClassMembersToPsiMembers(chooser.getSelectedElements());
        final TemplateResource template = header.getSelectedTemplate();
        ToStringTemplatesManager.getInstance().setDefaultTemplate(template);
        if (template.isValidTemplate()) {
            final GenerateToStringWorker worker = new GenerateToStringWorker(clazz, editor, chooser.isInsertOverrideAnnotation());
            // decide what to do if the method already exists
            ConflictResolutionPolicy resolutionPolicy = worker.exitsMethodDialog(template);
            WriteAction.run(() -> {
                try {
                    worker.execute(selectedMembers, template, resolutionPolicy);
                } catch (Exception e) {
                    GenerationUtil.handleException(project, e);
                }
            });
        } else {
            HintManager.getInstance().showErrorHint(editor, "toString() template '" + template.getFileName() + "' is invalid");
        }
    }
    logger.debug("+++ doExecuteAction - END +++");
}
Also used : ConflictResolutionPolicy(org.jetbrains.java.generate.config.ConflictResolutionPolicy) MemberChooser(com.intellij.ide.util.MemberChooser) PsiElementClassMember(com.intellij.codeInsight.generation.PsiElementClassMember) TemplateResource(org.jetbrains.java.generate.template.TemplateResource) ConfigurationException(com.intellij.openapi.options.ConfigurationException)

Example 8 with MemberChooser

use of com.intellij.ide.util.MemberChooser in project kotlin by JetBrains.

the class AddFieldBreakpointDialog method createCenterPanel.

@Override
protected JComponent createCenterPanel() {
    myClassChooser.getTextField().getDocument().addDocumentListener(new DocumentAdapter() {

        @Override
        public void textChanged(DocumentEvent event) {
            updateUI();
        }
    });
    myClassChooser.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            PsiClass currentClass = getSelectedClass();
            TreeClassChooser chooser = TreeClassChooserFactory.getInstance(myProject).createAllProjectScopeChooser(DebuggerBundle.message("add.field.breakpoint.dialog.classchooser.title"));
            if (currentClass != null) {
                PsiFile containingFile = currentClass.getContainingFile();
                if (containingFile != null) {
                    PsiDirectory containingDirectory = containingFile.getContainingDirectory();
                    if (containingDirectory != null) {
                        chooser.selectDirectory(containingDirectory);
                    }
                }
            }
            chooser.showDialog();
            PsiClass selectedClass = chooser.getSelected();
            if (selectedClass != null) {
                myClassChooser.setText(selectedClass.getQualifiedName());
            }
        }
    });
    myFieldChooser.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(@NotNull ActionEvent e) {
            PsiClass selectedClass = getSelectedClass();
            DescriptorMemberChooserObject[] properties = FieldBreakpointDialogUtilKt.collectProperties(selectedClass);
            MemberChooser<DescriptorMemberChooserObject> chooser = new MemberChooser<DescriptorMemberChooserObject>(properties, false, false, myProject);
            chooser.setTitle(DebuggerBundle.message("add.field.breakpoint.dialog.field.chooser.title", properties.length));
            chooser.setCopyJavadocVisible(false);
            chooser.show();
            List<DescriptorMemberChooserObject> selectedElements = chooser.getSelectedElements();
            if (selectedElements != null && selectedElements.size() == 1) {
                KtProperty field = (KtProperty) selectedElements.get(0).getElement();
                myFieldChooser.setText(field.getName());
            }
        }
    });
    myFieldChooser.setEnabled(false);
    return myPanel;
}
Also used : TreeClassChooser(com.intellij.ide.util.TreeClassChooser) ActionEvent(java.awt.event.ActionEvent) DocumentAdapter(com.intellij.ui.DocumentAdapter) DocumentEvent(javax.swing.event.DocumentEvent) MemberChooser(com.intellij.ide.util.MemberChooser) KtProperty(org.jetbrains.kotlin.psi.KtProperty) DescriptorMemberChooserObject(org.jetbrains.kotlin.idea.core.util.DescriptorMemberChooserObject) ActionListener(java.awt.event.ActionListener) List(java.util.List)

Aggregations

MemberChooser (com.intellij.ide.util.MemberChooser)8 PsiElementClassMember (com.intellij.codeInsight.generation.PsiElementClassMember)2 PsiFieldMember (com.intellij.codeInsight.generation.PsiFieldMember)2 TreeClassChooser (com.intellij.ide.util.TreeClassChooser)2 DocumentAdapter (com.intellij.ui.DocumentAdapter)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 List (java.util.List)2 DocumentEvent (javax.swing.event.DocumentEvent)2 PsiMethodMember (com.intellij.codeInsight.generation.PsiMethodMember)1 ParameterClassMember (com.intellij.codeInsight.intention.impl.ParameterClassMember)1 ConfigurationException (com.intellij.openapi.options.ConfigurationException)1 TextRange (com.intellij.openapi.util.TextRange)1 CodeStyleManager (com.intellij.psi.codeStyle.CodeStyleManager)1 JavaCodeStyleManager (com.intellij.psi.codeStyle.JavaCodeStyleManager)1 PsiDocComment (com.intellij.psi.javadoc.PsiDocComment)1 SpeedSearchComparator (com.intellij.ui.SpeedSearchComparator)1 IncorrectOperationException (com.intellij.util.IncorrectOperationException)1 DartNamedElementNode (com.jetbrains.lang.dart.ide.DartNamedElementNode)1 DartClass (com.jetbrains.lang.dart.psi.DartClass)1