use of com.intellij.ide.util.TreeClassChooser 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.TreeClassChooser in project intellij-community by JetBrains.
the class UiUtils method createTreeClassChooserList.
public static JPanel createTreeClassChooserList(final Collection<String> collection, String borderTitle, final String chooserTitle, String... ancestorClasses) {
final ClassFilter filter;
if (ancestorClasses.length == 0) {
filter = ClassFilter.ALL;
} else {
filter = new SubclassFilter(ancestorClasses);
}
final JPanel optionsPanel = new JPanel(new BorderLayout());
final JBList list = new JBList(collection);
final JPanel panel = ToolbarDecorator.createDecorator(list).disableUpDownActions().setAddAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton anActionButton) {
final DataContext dataContext = DataManager.getInstance().getDataContext(list);
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
if (project == null) {
return;
}
final TreeClassChooser chooser = TreeClassChooserFactory.getInstance(project).createNoInnerClassesScopeChooser(chooserTitle, GlobalSearchScope.allScope(project), filter, null);
chooser.showDialog();
final PsiClass selected = chooser.getSelected();
if (selected == null) {
return;
}
final String qualifiedName = selected.getQualifiedName();
final DefaultListModel model = (DefaultListModel) list.getModel();
final int index = model.indexOf(qualifiedName);
if (index < 0) {
model.addElement(qualifiedName);
collection.add(qualifiedName);
} else {
list.setSelectedIndex(index);
}
}
}).setRemoveAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton anActionButton) {
collection.remove(list.getSelectedValue());
ListUtil.removeSelectedItems(list);
}
}).createPanel();
panel.setPreferredSize(JBUI.size(150, 100));
optionsPanel.setBorder(IdeBorderFactory.createTitledBorder(borderTitle, false, JBUI.insetsTop(10)));
optionsPanel.add(panel);
return optionsPanel;
}
use of com.intellij.ide.util.TreeClassChooser in project intellij-community by JetBrains.
the class UiUtils method createAddRemoveTreeClassChooserPanel.
public static JPanel createAddRemoveTreeClassChooserPanel(final ListTable table, final String chooserTitle, @NonNls String... ancestorClasses) {
final ClassFilter filter;
if (ancestorClasses.length == 0) {
filter = ClassFilter.ALL;
} else {
filter = new SubclassFilter(ancestorClasses);
}
final JPanel panel = ToolbarDecorator.createDecorator(table).setAddAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
final DataContext dataContext = DataManager.getInstance().getDataContext(table);
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
final int rowIndex;
final ListWrappingTableModel tableModel = table.getModel();
if (project == null) {
tableModel.addRow();
rowIndex = tableModel.getRowCount() - 1;
} else {
final TreeClassChooserFactory chooserFactory = TreeClassChooserFactory.getInstance(project);
final TreeClassChooser classChooser = chooserFactory.createWithInnerClassesScopeChooser(chooserTitle, GlobalSearchScope.allScope(project), filter, null);
classChooser.showDialog();
final PsiClass selectedClass = classChooser.getSelected();
if (selectedClass == null) {
return;
}
final String qualifiedName = selectedClass.getQualifiedName();
final int index = tableModel.indexOf(qualifiedName, 0);
if (index < 0) {
tableModel.addRow(qualifiedName);
rowIndex = tableModel.getRowCount() - 1;
} else {
rowIndex = index;
}
}
editTableCell(table, rowIndex, table.getColumnCount() > 1 && project != null ? 1 : 0);
}
}).setRemoveAction(button -> TableUtil.removeSelectedItems(table)).disableUpDownActions().createPanel();
panel.setPreferredSize(JBUI.size(150, 100));
return panel;
}
use of com.intellij.ide.util.TreeClassChooser in project intellij-community by JetBrains.
the class ClassHierarchyScopeDescriptor method getScope.
@Nullable
public SearchScope getScope() {
if (myCachedScope == null) {
TreeClassChooser chooser = TreeClassChooserFactory.getInstance(myProject).createAllProjectScopeChooser(IdeBundle.message("prompt.choose.base.class.of.the.hierarchy"));
if (myRootClass != null) {
chooser.select(myRootClass);
}
chooser.showDialog();
PsiClass aClass = chooser.getSelected();
if (aClass == null) {
myCachedScope = GlobalSearchScope.EMPTY_SCOPE;
} else {
final List<PsiElement> classesToSearch = new LinkedList<>();
classesToSearch.add(aClass);
classesToSearch.addAll(ClassInheritorsSearch.search(aClass).findAll());
FunctionalExpressionSearch.search(aClass).forEach(expression -> {
classesToSearch.add(expression);
return true;
});
myCachedScope = new LocalSearchScope(PsiUtilCore.toPsiElementArray(classesToSearch), IdeBundle.message("scope.hierarchy", ClassPresentationUtil.getNameForClass(aClass, true)));
}
}
return myCachedScope;
}
use of com.intellij.ide.util.TreeClassChooser 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