use of com.intellij.ide.util.ClassFilter 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.ClassFilter 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);
}
use of com.intellij.ide.util.ClassFilter 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));
}
}
use of com.intellij.ide.util.ClassFilter 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;
}
Aggregations