use of com.intellij.ide.util.TreeJavaClassChooserDialog in project intellij-community by JetBrains.
the class ClassChooserTest method testSubclassModel.
public void testSubclassModel() throws Exception {
myFixture.addClass("class Foo extends Exception {}");
myFixture.addClass("class Bar {}");
PsiClass aClass = JavaPsiFacade.getInstance(getProject()).findClass(CommonClassNames.JAVA_LANG_EXCEPTION, GlobalSearchScope.allScope(getProject()));
final Ref<ChooseByNameModel> ref = new Ref<>();
TreeJavaClassChooserDialog dialog = new TreeJavaClassChooserDialog("hey", getProject(), GlobalSearchScope.projectScope(getProject()), null, aClass, null, false) {
@Override
protected ChooseByNameModel createChooseByNameModel() {
ChooseByNameModel model = super.createChooseByNameModel();
ref.set(model);
return model;
}
@Override
public JRootPane getRootPane() {
return new JRootPane();
}
};
Disposer.register(myFixture.getTestRootDisposable(), dialog.getDisposable());
ChooseByNameModelEx model = (ChooseByNameModelEx) ref.get();
CommonProcessors.CollectProcessor<String> processor = new CommonProcessors.CollectProcessor<>();
model.processNames(processor, false);
List<String> results = (List<String>) processor.getResults();
assertEquals(1, results.size());
}
use of com.intellij.ide.util.TreeJavaClassChooserDialog in project intellij-plugins by JetBrains.
the class OsmorcFacetManifestGenerationEditorTab method onBundleActivatorSelect.
private void onBundleActivatorSelect() {
Project project = myEditorContext.getProject();
PsiClass activatorClass = OsgiPsiUtil.getActivatorClass(project);
ClassFilter filter = new TreeJavaClassChooserDialog.InheritanceJavaClassFilterImpl(activatorClass, false, true, null);
GlobalSearchScope scope = GlobalSearchScope.moduleWithDependenciesScope(myEditorContext.getModule());
TreeJavaClassChooserDialog dialog = new TreeJavaClassChooserDialog(OsmorcBundle.message("facet.editor.select.bundle.activator"), project, scope, filter, null);
dialog.showDialog();
PsiClass psiClass = dialog.getSelected();
if (psiClass != null) {
myBundleActivator.setText(psiClass.getQualifiedName());
}
}
use of com.intellij.ide.util.TreeJavaClassChooserDialog in project intellij-community by JetBrains.
the class IntroduceParameterObjectDialog method createUIComponents.
private void createUIComponents() {
final PsiFile file = mySourceMethod.getContainingFile();
packageTextField = new PackageNameReferenceEditorCombo(file instanceof PsiJavaFile ? ((PsiJavaFile) file).getPackageName() : "", myProject, RECENTS_KEY, RefactoringBundle.message("choose.destination.package"));
final Document document = packageTextField.getChildComponent().getDocument();
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();
}
};
document.addDocumentListener(adapter);
existingClassField = new ReferenceEditorComboWithBrowseButton(new ActionListener() {
public void actionPerformed(ActionEvent e) {
final Project project = mySourceMethod.getProject();
final GlobalSearchScope scope = GlobalSearchScope.allScope(project);
final TreeJavaClassChooserDialog chooser = new TreeJavaClassChooserDialog(RefactorJBundle.message("select.wrapper.class"), project, scope, null, null);
final String classText = existingClassField.getText();
final PsiClass currentClass = JavaPsiFacade.getInstance(project).findClass(classText, GlobalSearchScope.allScope(project));
if (currentClass != null) {
chooser.select(currentClass);
}
chooser.show();
final PsiClass selectedClass = chooser.getSelected();
if (selectedClass != null) {
final String className = selectedClass.getQualifiedName();
existingClassField.setText(className);
RecentsManager.getInstance(myProject).registerRecentEntry(EXISTING_KEY, className);
}
}
}, "", myProject, true, EXISTING_KEY);
existingClassField.getChildComponent().getDocument().addDocumentListener(new com.intellij.openapi.editor.event.DocumentAdapter() {
@Override
public void documentChanged(com.intellij.openapi.editor.event.DocumentEvent e) {
validateButtons();
enableGenerateAccessors();
}
});
myDestinationCb = new DestinationFolderComboBox() {
@Override
public String getTargetPackage() {
return getPackageName();
}
};
((DestinationFolderComboBox) myDestinationCb).setData(myProject, mySourceMethod.getContainingFile().getContainingDirectory(), packageTextField.getChildComponent());
}
use of com.intellij.ide.util.TreeJavaClassChooserDialog in project kotlin by JetBrains.
the class MoveKotlinNestedClassesDialog method initClassChooser.
private void initClassChooser(@NotNull KtClassOrObject initialTargetClass) {
//noinspection ConstantConditions
originalClassField.setText(originalClass.getFqName().asString());
//noinspection ConstantConditions
targetClassChooser = new ReferenceEditorComboWithBrowseButton(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
TreeClassChooser chooser = new TreeJavaClassChooserDialog(RefactoringBundle.message("choose.destination.class"), myProject, GlobalSearchScope.projectScope(myProject), new ClassFilter() {
@Override
public boolean isAccepted(PsiClass aClass) {
if (!(aClass instanceof KtLightClassForSourceDeclaration))
return false;
KtClassOrObject classOrObject = ((KtLightClassForSourceDeclaration) aClass).getKotlinOrigin();
if (classOrObject instanceof KtObjectDeclaration) {
return !((KtObjectDeclaration) classOrObject).isObjectLiteral();
}
if (classOrObject instanceof KtClass) {
KtClass ktClass = (KtClass) classOrObject;
return !(ktClass.isInner() || ktClass.isAnnotation());
}
return false;
}
}, null, null, true) {
@Nullable
@Override
protected PsiClass getSelectedFromTreeUserObject(DefaultMutableTreeNode node) {
PsiClass psiClass = super.getSelectedFromTreeUserObject(node);
if (psiClass != null)
return psiClass;
Object userObject = node.getUserObject();
if (!(userObject instanceof KtClassOrObjectTreeNode))
return null;
return LightClassUtilsKt.toLightClass(((KtClassOrObjectTreeNode) userObject).getValue());
}
};
chooser.selectDirectory((targetClass != null ? targetClass : originalClass).getContainingFile().getContainingDirectory());
chooser.showDialog();
PsiClass aClass = chooser.getSelected();
if (aClass instanceof KtLightClassForSourceDeclaration) {
targetClass = ((KtLightClassForSourceDeclaration) aClass).getKotlinOrigin();
targetClassChooser.setText(aClass.getQualifiedName());
}
}
}, initialTargetClass.getFqName().asString(), myProject, true, JavaCodeFragment.VisibilityChecker.PROJECT_SCOPE_VISIBLE, RECENTS_KEY);
targetClassChooser.getChildComponent().getDocument().addDocumentListener(new DocumentAdapter() {
@Override
public void documentChanged(DocumentEvent e) {
PsiClass aClass = JavaPsiFacade.getInstance(myProject).findClass(targetClassChooser.getText(), GlobalSearchScope.projectScope(myProject));
targetClass = aClass instanceof KtLightClassForSourceDeclaration ? ((KtLightClassForSourceDeclaration) aClass).getKotlinOrigin() : null;
validateButtons();
}
});
targetClassChooserPanel.add(targetClassChooser);
}
Aggregations