use of com.intellij.ide.projectView.ProjectViewNode in project intellij-community by JetBrains.
the class GroupByTypeComparator method compare.
@Override
public int compare(NodeDescriptor descriptor1, NodeDescriptor descriptor2) {
if (!isSortByType() && descriptor1 instanceof ProjectViewNode && ((ProjectViewNode) descriptor1).isSortByFirstChild()) {
final Collection<AbstractTreeNode> children = ((ProjectViewNode) descriptor1).getChildren();
if (!children.isEmpty()) {
descriptor1 = children.iterator().next();
descriptor1.update();
}
}
if (!isSortByType() && descriptor2 instanceof ProjectViewNode && ((ProjectViewNode) descriptor2).isSortByFirstChild()) {
final Collection<AbstractTreeNode> children = ((ProjectViewNode) descriptor2).getChildren();
if (!children.isEmpty()) {
descriptor2 = children.iterator().next();
descriptor2.update();
}
}
if (descriptor1 instanceof ProjectViewNode && descriptor2 instanceof ProjectViewNode) {
final Project project = descriptor1.getProject();
final ProjectView projectView = ProjectView.getInstance(project);
ProjectViewNode node1 = (ProjectViewNode) descriptor1;
ProjectViewNode node2 = (ProjectViewNode) descriptor2;
if (isManualOrder()) {
final Comparable key1 = node1.getManualOrderKey();
final Comparable key2 = node2.getManualOrderKey();
int result = compare(key1, key2);
if (result != 0)
return result;
}
boolean isFoldersOnTop = !(projectView instanceof ProjectViewImpl && !((ProjectViewImpl) projectView).isFoldersAlwaysOnTop());
if (isFoldersOnTop) {
int typeWeight1 = node1.getTypeSortWeight(isSortByType());
int typeWeight2 = node2.getTypeSortWeight(isSortByType());
if (typeWeight1 != 0 && typeWeight2 == 0) {
return -1;
}
if (typeWeight1 == 0 && typeWeight2 != 0) {
return 1;
}
if (typeWeight1 != 0 && typeWeight2 != typeWeight1) {
return typeWeight1 - typeWeight2;
}
}
if (isSortByType()) {
final Comparable typeSortKey1 = node1.getTypeSortKey();
final Comparable typeSortKey2 = node2.getTypeSortKey();
int result = compare(typeSortKey1, typeSortKey2);
if (result != 0)
return result;
} else {
final Comparable typeSortKey1 = node1.getSortKey();
final Comparable typeSortKey2 = node2.getSortKey();
if (typeSortKey1 != null && typeSortKey2 != null) {
int result = compare(typeSortKey1, typeSortKey2);
if (result != 0)
return result;
}
}
if (isAbbreviateQualifiedNames()) {
String key1 = node1.getQualifiedNameSortKey();
String key2 = node2.getQualifiedNameSortKey();
if (key1 != null && key2 != null) {
return naturalCompare(key1, key2);
}
}
}
if (descriptor1 == null)
return -1;
if (descriptor2 == null)
return 1;
return AlphaComparator.INSTANCE.compare(descriptor1, descriptor2);
}
use of com.intellij.ide.projectView.ProjectViewNode in project intellij-community by JetBrains.
the class SameNamesJoiner method modify.
@NotNull
@Override
public Collection<AbstractTreeNode> modify(@NotNull AbstractTreeNode parent, @NotNull Collection<AbstractTreeNode> children, ViewSettings settings) {
if (parent instanceof JoinedNode)
return children;
ArrayList<AbstractTreeNode> result = new ArrayList<>();
MultiValuesMap<Object, AbstractTreeNode> executed = new MultiValuesMap<>();
for (Iterator<AbstractTreeNode> iterator = children.iterator(); iterator.hasNext(); ) {
ProjectViewNode treeNode = (ProjectViewNode) iterator.next();
Object o = treeNode.getValue();
if (o instanceof PsiFile) {
String name = ((PsiFile) o).getVirtualFile().getNameWithoutExtension();
executed.put(name, treeNode);
} else {
executed.put(o, treeNode);
}
}
Iterator<Object> keys = executed.keySet().iterator();
while (keys.hasNext()) {
Object each = keys.next();
Collection<AbstractTreeNode> objects = executed.get(each);
if (objects.size() > 1) {
result.add(new JoinedNode(objects, new Joined(findPsiFileIn(objects))));
} else if (objects.size() == 1) {
result.add(objects.iterator().next());
}
}
return result;
}
use of com.intellij.ide.projectView.ProjectViewNode in project intellij-community by JetBrains.
the class Commander method syncViews.
public void syncViews() {
final CommanderPanel activePanel;
final CommanderPanel passivePanel;
if (isLeftPanelActive()) {
activePanel = myLeftPanel;
passivePanel = myRightPanel;
} else {
activePanel = myRightPanel;
passivePanel = myLeftPanel;
}
ProjectViewNode element = (ProjectViewNode) activePanel.getBuilder().getParentNode();
passivePanel.getBuilder().enterElement(element);
}
use of com.intellij.ide.projectView.ProjectViewNode in project intellij-plugins by JetBrains.
the class FlexTreeStructureProvider method modify.
@NotNull
@Override
public Collection<AbstractTreeNode> modify(@NotNull AbstractTreeNode parent, @NotNull Collection<AbstractTreeNode> children, ViewSettings settings) {
List<AbstractTreeNode> result = new ArrayList<>();
if (parent instanceof SwfQualifiedNamedElementNode || parent instanceof FlexFileNode) {
if (((ProjectViewNode) parent).getSettings().isShowMembers()) {
JSQualifiedNamedElement parentElement = getElement(parent);
if (parentElement != null) {
JSStructureViewElement structureViewElement = parentElement instanceof XmlBackedJSClassImpl ? new FlexStructureViewElement(((XmlBackedJSClassImpl) parentElement), (XmlFile) parentElement.getContainingFile(), false) : new JSStructureViewElement(parentElement, false, true);
StructureViewTreeElement[] structureViewChildren = structureViewElement.getChildren();
for (final StructureViewTreeElement structureViewChild : structureViewChildren) {
if (structureViewChild instanceof JSStructureViewElement) {
PsiElement childElement = ((JSStructureViewElement) structureViewChild).getValue();
result.add(new FlexClassMemberNode((JSElement) childElement, ((ProjectViewNode) parent).getSettings()));
} else {
result.add(new UnknownNode(parentElement.getProject(), structureViewChild, ((ProjectViewNode) parent).getSettings()));
}
}
}
}
} else {
for (final AbstractTreeNode child : children) {
Object o = child.getValue();
if (o instanceof JSFileImpl && !(o instanceof PsiCompiledFile) && DialectDetector.isActionScript((PsiFile) o) || o instanceof XmlFile && JavaScriptSupportLoader.isFlexMxmFile((PsiFile) o)) {
result.add(new FlexFileNode((PsiFile) o, ((ProjectViewNode) parent).getSettings()));
continue;
}
result.add(child);
}
}
return result;
}
use of com.intellij.ide.projectView.ProjectViewNode in project intellij-community by JetBrains.
the class ClassesTreeStructureProvider method modify.
@NotNull
@Override
public Collection<AbstractTreeNode> modify(@NotNull AbstractTreeNode parent, @NotNull Collection<AbstractTreeNode> children, ViewSettings settings) {
ArrayList<AbstractTreeNode> result = new ArrayList<>();
for (final AbstractTreeNode child : children) {
Object o = child.getValue();
if (o instanceof PsiClassOwner && !(o instanceof ServerPageFile)) {
final ViewSettings settings1 = ((ProjectViewNode) parent).getSettings();
final PsiClassOwner classOwner = (PsiClassOwner) o;
final VirtualFile file = classOwner.getVirtualFile();
if (!(classOwner instanceof PsiCompiledElement)) {
//do not show duplicated items if jar file contains classes and sources
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
if (file != null && fileIndex.isInLibrarySource(file)) {
final PsiElement originalElement = classOwner.getOriginalElement();
if (originalElement instanceof PsiFile) {
PsiFile classFile = (PsiFile) originalElement;
final VirtualFile virtualClassFile = classFile.getVirtualFile();
if (virtualClassFile != null && fileIndex.isInLibraryClasses(virtualClassFile) && !classOwner.getManager().areElementsEquivalent(classOwner, classFile) && classOwner.getManager().areElementsEquivalent(classOwner.getContainingDirectory(), classFile.getContainingDirectory())) {
continue;
}
}
}
}
if (fileInRoots(file)) {
PsiClass[] classes = ApplicationManager.getApplication().runReadAction(new Computable<PsiClass[]>() {
@Override
public PsiClass[] compute() {
try {
return classOwner.getClasses();
} catch (IndexNotReadyException e) {
return PsiClass.EMPTY_ARRAY;
}
}
});
if (classes.length == 1 && !(classes[0] instanceof SyntheticElement) && (file == null || file.getNameWithoutExtension().equals(classes[0].getName()))) {
result.add(new ClassTreeNode(myProject, classes[0], settings1));
} else {
result.add(new PsiClassOwnerTreeNode(classOwner, settings1));
}
continue;
}
}
result.add(child);
}
return result;
}
Aggregations