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;
}
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 +++");
}
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;
}
Aggregations