use of com.intellij.ide.util.TreeClassChooser in project android by JetBrains.
the class AndroidClassBrowserBase method showDialog.
@Override
protected String showDialog() {
Project project = getProject();
final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
Module module = myModuleSelector.getModule();
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 intellij-community by JetBrains.
the class ReplaceConstructorWithBuilderDialog method createUIComponents.
private void createUIComponents() {
final com.intellij.openapi.editor.event.DocumentAdapter adapter = new com.intellij.openapi.editor.event.DocumentAdapter() {
public void documentChanged(com.intellij.openapi.editor.event.DocumentEvent e) {
validateButtons();
}
};
myPackageTextField = new PackageNameReferenceEditorCombo(((PsiJavaFile) myConstructors[0].getContainingFile()).getPackageName(), myProject, RECENT_KEYS, RefactoringBundle.message("choose.destination.package"));
myPackageTextField.getChildComponent().getDocument().addDocumentListener(adapter);
myDestinationCb = new DestinationFolderComboBox() {
@Override
public String getTargetPackage() {
return myPackageTextField.getText().trim();
}
};
((DestinationFolderComboBox) myDestinationCb).setData(myProject, myConstructors[0].getContainingFile().getContainingDirectory(), myPackageTextField.getChildComponent());
myExistentClassTF = new ReferenceEditorComboWithBrowseButton(new ActionListener() {
public void actionPerformed(ActionEvent e) {
final TreeClassChooser chooser = TreeClassChooserFactory.getInstance(getProject()).createWithInnerClassesScopeChooser("Select Builder Class", GlobalSearchScope.projectScope(myProject), null, null);
final String classText = myExistentClassTF.getText();
final PsiClass currentClass = JavaPsiFacade.getInstance(myProject).findClass(classText, GlobalSearchScope.allScope(myProject));
if (currentClass != null) {
chooser.select(currentClass);
}
chooser.showDialog();
final PsiClass selectedClass = chooser.getSelected();
if (selectedClass != null) {
myExistentClassTF.setText(selectedClass.getQualifiedName());
}
}
}, "", myProject, true, RECENT_KEYS);
myExistentClassTF.getChildComponent().getDocument().addDocumentListener(adapter);
}
use of com.intellij.ide.util.TreeClassChooser in project intellij-community by JetBrains.
the class PsiClassControl method initReferenceEditorWithBrowseButton.
protected static <T extends JPanel> T initReferenceEditorWithBrowseButton(final T boundedComponent, final ReferenceEditorWithBrowseButton editor, final EditorTextFieldControl control) {
boundedComponent.removeAll();
boundedComponent.add(editor);
final GlobalSearchScope resolveScope = control.getDomWrapper().getResolveScope();
editor.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
final DomElement domElement = control.getDomElement();
ExtendClass extend = domElement.getAnnotation(ExtendClass.class);
PsiClass baseClass = null;
ClassFilter filter = null;
if (extend != null) {
baseClass = JavaPsiFacade.getInstance(control.getProject()).findClass(extend.value(), resolveScope);
if (extend.instantiatable()) {
filter = ClassFilter.INSTANTIABLE;
}
}
PsiClass initialClass = null;
if (domElement instanceof GenericDomValue) {
final Object value = ((GenericDomValue) domElement).getValue();
if (value instanceof PsiClass)
initialClass = (PsiClass) value;
}
TreeClassChooser chooser = TreeClassChooserFactory.getInstance(control.getProject()).createInheritanceClassChooser(UIBundle.message("choose.class"), resolveScope, baseClass, initialClass, filter);
chooser.showDialog();
final PsiClass psiClass = chooser.getSelected();
if (psiClass != null) {
control.setValue(psiClass.getQualifiedName());
}
}
});
return boundedComponent;
}
use of com.intellij.ide.util.TreeClassChooser in project intellij-community by JetBrains.
the class CreateClassMappingAction method createElement.
@Override
protected DomElement createElement(final T context, final Editor editor, PsiFile file, final Project project) {
PsiClass selectedClass;
if (!ApplicationManager.getApplication().isUnitTestMode()) {
PsiClass baseClass = getBaseClass(context, project, myBaseClass);
TreeClassChooser chooser = TreeClassChooserFactory.getInstance(project).createInheritanceClassChooser(getChooserTitle(), GlobalSearchScope.allScope(project), baseClass, null, new ClassFilter() {
@Override
public boolean isAccepted(PsiClass aClass) {
return !aClass.isInterface() && !aClass.hasModifierProperty(PsiModifier.ABSTRACT);
}
});
chooser.showDialog();
selectedClass = chooser.getSelected();
} else {
selectedClass = getBaseClass(context, project, myBaseClass == null ? CommonClassNames.JAVA_LANG_OBJECT : myBaseClass);
}
if (selectedClass == null)
return null;
return createElement(context, editor, file, project, selectedClass);
}
use of com.intellij.ide.util.TreeClassChooser in project intellij-community by JetBrains.
the class ManifestFileUtil method selectMainClass.
@Nullable
public static PsiClass selectMainClass(Project project, @Nullable final String initialClassName) {
final TreeClassChooserFactory chooserFactory = TreeClassChooserFactory.getInstance(project);
final GlobalSearchScope searchScope = GlobalSearchScope.allScope(project);
final PsiClass aClass = initialClassName != null ? JavaPsiFacade.getInstance(project).findClass(initialClassName, searchScope) : null;
final TreeClassChooser chooser = chooserFactory.createWithInnerClassesScopeChooser("Select Main Class", searchScope, new MainClassFilter(), aClass);
chooser.showDialog();
return chooser.getSelected();
}
Aggregations