use of com.intellij.ide.util.TreeClassChooser in project intellij-community by JetBrains.
the class PsiClassTableCellEditor method getTableCellEditorComponent.
public final Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
final Document document = JavaReferenceEditorUtil.createDocument(value == null ? "" : (String) value, myProject, true);
myEditor = new EditorTextField(document, myProject, StdFileTypes.JAVA) {
protected boolean shouldHaveBorder() {
return false;
}
public void addNotify() {
super.addNotify();
final JComponent editorComponent = getEditor().getContentComponent();
editorComponent.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "ENTER");
editorComponent.getActionMap().put("ENTER", new AbstractAction() {
public void actionPerformed(ActionEvent e) {
stopCellEditing();
}
});
}
};
final JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.add(myEditor);
final FixedSizeButton button = new FixedSizeButton(myEditor);
panel.add(button, BorderLayout.EAST);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
TreeClassChooser chooser = TreeClassChooserFactory.getInstance(myProject).createInheritanceClassChooser(UIBundle.message("choose.class"), mySearchScope, null, true, true, Conditions.alwaysTrue());
chooser.showDialog();
final PsiClass psiClass = chooser.getSelected();
if (psiClass != null) {
myEditor.setText(psiClass.getQualifiedName());
}
}
});
panel.addFocusListener(new FocusListener() {
public void focusGained(FocusEvent e) {
if (!e.isTemporary() && myEditor != null) {
IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
IdeFocusManager.getGlobalInstance().requestFocus(myEditor, true);
});
}
}
public void focusLost(FocusEvent e) {
}
});
myEditor.addFocusListener(new FocusListener() {
public void focusGained(FocusEvent e) {
}
public void focusLost(FocusEvent e) {
if (!e.isTemporary()) {
stopCellEditing();
}
}
});
return panel;
}
use of com.intellij.ide.util.TreeClassChooser in project intellij-community by JetBrains.
the class ClassFilterEditor method addClassFilter.
protected void addClassFilter() {
TreeClassChooser chooser = TreeClassChooserFactory.getInstance(myProject).createNoInnerClassesScopeChooser(UIBundle.message("class.filter.editor.choose.class.title"), GlobalSearchScope.allScope(myProject), myChooserFilter, null);
chooser.showDialog();
PsiClass selectedClass = chooser.getSelected();
if (selectedClass != null) {
com.intellij.ui.classFilter.ClassFilter filter = createFilter(getJvmClassName(selectedClass));
myTableModel.addRow(filter);
int row = myTableModel.getRowCount() - 1;
myTable.getSelectionModel().setSelectionInterval(row, row);
myTable.scrollRectToVisible(myTable.getCellRect(row, 0, true));
IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
IdeFocusManager.getGlobalInstance().requestFocus(myTable, true);
});
}
}
use of com.intellij.ide.util.TreeClassChooser in project intellij-community by JetBrains.
the class ClassFilterEditorAddDialog method createCenterPanel.
protected JComponent createCenterPanel() {
final JPanel panel = new JPanel(new GridBagLayout());
final JLabel header = new JLabel(UIBundle.message("label.class.filter.editor.add.dialog.filter.pattern"));
myClassName = new TextFieldWithBrowseButton(new JTextField(35));
final JLabel iconLabel = new JLabel(Messages.getQuestionIcon());
panel.add(header, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(5, 10, 0, 0), 0, 0));
panel.add(myClassName, new GridBagConstraints(1, 1, 1, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(5, 10, 0, 0), 0, 0));
panel.add(iconLabel, new GridBagConstraints(0, 0, 1, 2, 0.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(15, 0, 0, 0), 0, 0));
myClassName.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
PsiClass currentClass = getSelectedClass();
TreeClassChooser chooser = TreeClassChooserFactory.getInstance(myProject).createNoInnerClassesScopeChooser(UIBundle.message("class.filter.editor.choose.class.title"), GlobalSearchScope.allScope(myProject), null, null);
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) {
myClassName.setText(selectedClass.getQualifiedName());
}
}
});
myClassName.setEnabled(myProject != null);
return panel;
}
use of com.intellij.ide.util.TreeClassChooser in project moe-ide-integration by multi-os-engine.
the class MOETestClassBrowser method showDialog.
@Override
protected String showDialog() {
Project project = getProject();
final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
if (module == null) {
Messages.showErrorDialog(project, ExecutionBundle.message("module.not.specified.error.text"), CommonBundle.getErrorTitle());
return null;
}
GlobalSearchScope scope = myIncludeLibraryClasses ? module.getModuleWithDependenciesAndLibrariesScope(true) : module.getModuleWithDependenciesScope();
PsiClass initialSelection = facade.findClass(getText(), scope);
TreeClassChooser chooser = createTreeClassChooser(project, scope, initialSelection, new ClassFilter() {
@Override
public boolean isAccepted(PsiClass aClass) {
if (aClass.isInterface())
return false;
final PsiModifierList modifierList = aClass.getModifierList();
return modifierList == null || !modifierList.hasModifierProperty(PsiModifier.ABSTRACT);
}
});
if (chooser == null)
return null;
chooser.showDialog();
PsiClass selClass = chooser.getSelected();
return selClass != null ? selClass.getQualifiedName() : null;
}
use of com.intellij.ide.util.TreeClassChooser in project android by JetBrains.
the class AndroidCreateOnClickHandlerAction method invoke.
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
final AndroidFacet facet = AndroidFacet.getInstance(file);
assert facet != null;
final XmlAttributeValue attrValue = getXmlAttributeValue(file, editor);
assert attrValue != null;
final String methodName = attrValue.getValue();
assert methodName != null;
final GenericAttributeValue domValue = DomManager.getDomManager(project).getDomElement((XmlAttribute) attrValue.getParent());
assert domValue != null;
final OnClickConverter converter = (OnClickConverter) domValue.getConverter();
final PsiClass activityBaseClass = JavaPsiFacade.getInstance(project).findClass(AndroidUtils.ACTIVITY_BASE_CLASS_NAME, facet.getModule().getModuleWithDependenciesAndLibrariesScope(false));
if (activityBaseClass == null) {
return;
}
final GlobalSearchScope scope = facet.getModule().getModuleScope(false);
final PsiClass selectedClass;
if (ApplicationManager.getApplication().isUnitTestMode()) {
final Ref<PsiClass> selClassRef = Ref.create();
ClassInheritorsSearch.search(activityBaseClass, scope, true, true, false).forEach(new Processor<PsiClass>() {
@Override
public boolean process(PsiClass psiClass) {
if (!psiClass.isInterface() && !psiClass.hasModifierProperty(PsiModifier.ABSTRACT)) {
selClassRef.set(psiClass);
return false;
}
return true;
}
});
selectedClass = selClassRef.get();
} else {
final TreeClassChooser chooser = TreeClassChooserFactory.getInstance(project).createInheritanceClassChooser("Choose Activity to Create the Method", scope, activityBaseClass, null, new ClassFilter() {
@Override
public boolean isAccepted(PsiClass aClass) {
return !converter.findHandlerMethod(aClass, methodName);
}
});
chooser.showDialog();
selectedClass = chooser.getSelected();
}
if (selectedClass != null) {
addHandlerMethodAndNavigate(project, selectedClass, methodName, converter.getDefaultMethodParameterType(selectedClass));
}
}
Aggregations