use of com.intellij.ide.projectView.ProjectViewNode in project intellij-community by JetBrains.
the class FormMergerTreeStructureProvider method modify.
@NotNull
public Collection<AbstractTreeNode> modify(@NotNull AbstractTreeNode parent, @NotNull Collection<AbstractTreeNode> children, ViewSettings settings) {
if (parent.getValue() instanceof Form)
return children;
// Optimization. Check if there are any forms at all.
boolean formsFound = false;
for (AbstractTreeNode node : children) {
if (node.getValue() instanceof PsiFile) {
PsiFile file = (PsiFile) node.getValue();
if (file.getFileType() == StdFileTypes.GUI_DESIGNER_FORM) {
formsFound = true;
break;
}
}
}
if (!formsFound)
return children;
Collection<AbstractTreeNode> result = new LinkedHashSet<>(children);
ProjectViewNode[] copy = children.toArray(new ProjectViewNode[children.size()]);
for (ProjectViewNode element : copy) {
PsiClass psiClass = null;
if (element.getValue() instanceof PsiClass) {
psiClass = (PsiClass) element.getValue();
} else if (element.getValue() instanceof PsiClassOwner) {
final PsiClass[] psiClasses = ((PsiClassOwner) element.getValue()).getClasses();
if (psiClasses.length == 1) {
psiClass = psiClasses[0];
}
}
if (psiClass == null)
continue;
String qName = psiClass.getQualifiedName();
if (qName == null)
continue;
List<PsiFile> forms;
try {
forms = FormClassIndex.findFormsBoundToClass(myProject, qName);
} catch (ProcessCanceledException e) {
continue;
}
Collection<BasePsiNode<? extends PsiElement>> formNodes = findFormsIn(children, forms);
if (!formNodes.isEmpty()) {
Collection<PsiFile> formFiles = convertToFiles(formNodes);
Collection<BasePsiNode<? extends PsiElement>> subNodes = new ArrayList<>();
//noinspection unchecked
subNodes.add((BasePsiNode<? extends PsiElement>) element);
subNodes.addAll(formNodes);
result.add(new FormNode(myProject, new Form(psiClass, formFiles), settings, subNodes));
result.remove(element);
result.removeAll(formNodes);
}
}
return result;
}
use of com.intellij.ide.projectView.ProjectViewNode in project intellij-community by JetBrains.
the class XsltTreeStructureProvider method modify.
@NotNull
@SuppressWarnings({ "RawUseOfParameterizedType", "unchecked" })
public Collection<AbstractTreeNode> modify(@NotNull AbstractTreeNode parent, @NotNull Collection<AbstractTreeNode> children, ViewSettings settings) {
Collection<AbstractTreeNode> l = children;
int i = 0;
for (AbstractTreeNode o : children) {
if (o instanceof ProjectViewNode) {
final ProjectViewNode node = (ProjectViewNode) o;
final Object element = node.getValue();
if (element instanceof PsiFile) {
if (XsltSupport.isXsltFile((PsiFile) element)) {
if (l == children && l.getClass() != ArrayList.class) {
l = new ArrayList<>(children);
}
final XsltFileNode fileNode = new XsltFileNode(myProject, (PsiFile) element, settings);
((List<AbstractTreeNode>) l).set(i, fileNode);
}
}
}
i++;
}
return l;
}
use of com.intellij.ide.projectView.ProjectViewNode in project intellij-community by JetBrains.
the class AssociationsEditor method getObject.
@Nullable
private static Object getObject(Object component) {
if (!(component instanceof DefaultMutableTreeNode))
return null;
final DefaultMutableTreeNode node = ((DefaultMutableTreeNode) component);
final Object userObject = node.getUserObject();
if (!(userObject instanceof ProjectViewNode))
return null;
return ((ProjectViewNode<?>) userObject).getValue();
}
use of com.intellij.ide.projectView.ProjectViewNode in project intellij-community by JetBrains.
the class TreeFileChooserDialog method filterFiles.
private Object[] filterFiles(final Object[] list) {
Condition<PsiFile> condition = psiFile -> {
if (myFilter != null && !myFilter.accept(psiFile)) {
return false;
}
boolean accepted = myFileType == null || psiFile.getFileType() == myFileType;
VirtualFile virtualFile = psiFile.getVirtualFile();
if (virtualFile != null && !accepted) {
accepted = virtualFile.getFileType() == myFileType;
}
return accepted;
};
final List<Object> result = new ArrayList<>(list.length);
for (Object o : list) {
final PsiFile psiFile;
if (o instanceof PsiFile) {
psiFile = (PsiFile) o;
} else if (o instanceof PsiFileNode) {
psiFile = ((PsiFileNode) o).getValue();
} else {
psiFile = null;
}
if (psiFile != null && !condition.value(psiFile)) {
continue;
} else {
if (o instanceof ProjectViewNode) {
final ProjectViewNode projectViewNode = (ProjectViewNode) o;
if (!projectViewNode.canHaveChildrenMatching(condition)) {
continue;
}
}
}
result.add(o);
}
return ArrayUtil.toObjectArray(result);
}
use of com.intellij.ide.projectView.ProjectViewNode in project intellij-community by JetBrains.
the class ProjectViewImpl method getParentOfCurrentSelection.
@Override
public PsiElement getParentOfCurrentSelection() {
final AbstractProjectViewPane viewPane = getCurrentProjectViewPane();
if (viewPane == null) {
return null;
}
TreePath path = viewPane.getSelectedPath();
if (path == null) {
return null;
}
path = path.getParentPath();
if (path == null) {
return null;
}
DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
Object userObject = node.getUserObject();
if (userObject instanceof ProjectViewNode) {
ProjectViewNode descriptor = (ProjectViewNode) userObject;
Object element = descriptor.getValue();
if (element instanceof PsiElement) {
PsiElement psiElement = (PsiElement) element;
if (!psiElement.isValid())
return null;
return psiElement;
} else {
return null;
}
}
return null;
}
Aggregations