use of com.intellij.ide.util.treeView.NodeDescriptor in project android by JetBrains.
the class AndroidProjectViewPane method getSelectedDirectories.
@Override
@NotNull
public PsiDirectory[] getSelectedDirectories() {
Object selectedElement = getSelectedElement();
if (selectedElement instanceof PackageElement) {
PackageElement packageElement = (PackageElement) selectedElement;
Module m = packageElement.getModule();
if (m != null) {
return packageElement.getPackage().getDirectories(GlobalSearchScope.moduleScope(m));
}
}
NodeDescriptor descriptor = getSelectedDescriptor();
if (descriptor instanceof DirectoryGroupNode) {
return ((DirectoryGroupNode) descriptor).getDirectories();
}
PsiDirectory[] selectedDirectories = super.getSelectedDirectories();
// to treat these as selectable (for target output directories etc)
if (selectedElement instanceof Module && selectedDirectories.length > 0) {
List<PsiDirectory> dirs = Lists.newArrayListWithExpectedSize(selectedDirectories.length);
for (PsiDirectory dir : selectedDirectories) {
VirtualFile file = dir.getVirtualFile();
if (!GeneratedSourcesFilter.isGeneratedSourceByAnyFilter(file, myProject)) {
if (file.getParent() != null && file.getPath().contains("/generated/")) {
/// build/generated/res/rs/debug, build/generated/res/rs/test/debug, etc.
continue;
}
dirs.add(dir);
}
}
selectedDirectories = dirs.toArray(new PsiDirectory[dirs.size()]);
}
return selectedDirectories;
}
use of com.intellij.ide.util.treeView.NodeDescriptor in project intellij-community by JetBrains.
the class ExcludeFromCompileAction method getSelectedFile.
@Nullable
private VirtualFile getSelectedFile() {
final ErrorTreeNodeDescriptor descriptor = myErrorTreeView.getSelectedNodeDescriptor();
ErrorTreeElement element = descriptor != null ? descriptor.getElement() : null;
if (element != null && !(element instanceof GroupingElement)) {
NodeDescriptor parent = descriptor.getParentDescriptor();
if (parent instanceof ErrorTreeNodeDescriptor) {
element = ((ErrorTreeNodeDescriptor) parent).getElement();
}
}
return element instanceof GroupingElement ? ((GroupingElement) element).getFile() : null;
}
use of com.intellij.ide.util.treeView.NodeDescriptor in project android by JetBrains.
the class AndroidProjectViewPane method getData.
@Override
public Object getData(String dataId) {
if (CommonDataKeys.PROJECT.is(dataId)) {
return myProject;
}
if (PlatformDataKeys.DELETE_ELEMENT_PROVIDER.is(dataId)) {
Object o = getSelectedElement();
if (o instanceof PsiDirectory) {
VirtualFile directory = ((PsiDirectory) o).getVirtualFile();
// See https://code.google.com/p/android/issues/detail?id=212522
if (isTopModuleDirectoryOrParent(directory)) {
return new NoOpDeleteProvider();
}
}
}
if (LangDataKeys.MODULE.is(dataId)) {
Object o = getSelectedElement();
if (o instanceof PackageElement) {
PackageElement packageElement = (PackageElement) o;
return packageElement.getModule();
} else if (o instanceof AndroidFacet) {
return ((AndroidFacet) o).getModule();
}
}
if (CommonDataKeys.VIRTUAL_FILE.is(dataId)) {
Object o = getSelectedElement();
if (o instanceof PackageElement) {
PackageElement packageElement = (PackageElement) o;
Module m = packageElement.getModule();
if (m != null) {
PsiDirectory[] folders = packageElement.getPackage().getDirectories(GlobalSearchScope.moduleScope(m));
if (folders.length > 0) {
return folders[0].getVirtualFile();
} else {
return null;
}
}
}
}
if (CommonDataKeys.VIRTUAL_FILE_ARRAY.is(dataId)) {
NodeDescriptor selectedDescriptor = getSelectedDescriptor();
if (selectedDescriptor instanceof FileGroupNode) {
PsiFile[] files = ((FileGroupNode) selectedDescriptor).getFiles();
if (files.length > 0) {
List<VirtualFile> virtualFiles = Lists.newArrayListWithExpectedSize(files.length);
for (PsiFile file : files) {
if (file.isValid()) {
virtualFiles.add(file.getVirtualFile());
}
}
return virtualFiles.toArray(new VirtualFile[virtualFiles.size()]);
}
}
if (selectedDescriptor instanceof DirectoryGroupNode) {
PsiDirectory[] directories = ((DirectoryGroupNode) selectedDescriptor).getDirectories();
if (directories.length > 0) {
List<VirtualFile> virtualFiles = Lists.newArrayListWithExpectedSize(directories.length);
for (PsiDirectory directory : directories) {
if (directory.isValid()) {
virtualFiles.add(directory.getVirtualFile());
}
}
return virtualFiles.toArray(new VirtualFile[virtualFiles.size()]);
}
}
}
if (CommonDataKeys.PSI_ELEMENT.is(dataId)) {
Object o = getSelectedElement();
if (o instanceof PsiElement) {
return o;
} else if (o instanceof List<?>) {
List<?> l = (List<?>) o;
if (!l.isEmpty() && l.get(0) instanceof PsiElement) {
return l.get(0);
}
}
NodeDescriptor selectedDescriptor = getSelectedDescriptor();
if (selectedDescriptor instanceof FileGroupNode) {
PsiFile[] files = ((FileGroupNode) selectedDescriptor).getFiles();
if (files.length > 0) {
return files[0];
}
}
if (selectedDescriptor instanceof DirectoryGroupNode) {
PsiDirectory[] directories = ((DirectoryGroupNode) selectedDescriptor).getDirectories();
if (directories.length > 0) {
return directories[0];
}
}
}
return super.getData(dataId);
}
use of com.intellij.ide.util.treeView.NodeDescriptor in project android by JetBrains.
the class AndroidResComparator method compare.
@Override
public int compare(Object o1, Object o2) {
if (!(o1 instanceof NodeDescriptor) || !(o2 instanceof NodeDescriptor)) {
return 0;
}
// we only support comparing res file nodes and res group nodes
if (!(o1 instanceof AndroidResFileNode) && !(o1 instanceof AndroidResGroupNode)) {
return 0;
}
if (!(o2 instanceof AndroidResFileNode) && !(o2 instanceof AndroidResGroupNode)) {
return 0;
}
// if one of them is a group node, then we just have to compare them alphabetically
if (o1 instanceof AndroidResGroupNode || o2 instanceof AndroidResGroupNode) {
String n1 = getName(o1);
String n2 = getName(o2);
return StringUtil.compare(n1, n2, false);
}
AndroidResFileNode r1 = (AndroidResFileNode) o1;
AndroidResFileNode r2 = (AndroidResFileNode) o2;
// first check file names
PsiFile file1 = r1.getValue();
PsiFile file2 = r2.getValue();
if (file1 != null && file2 != null) {
int c = StringUtil.compare(file1.getName(), file2.getName(), false);
if (c != 0) {
return c;
}
}
// check folder configurations
FolderConfiguration config1 = r1.getFolderConfiguration();
FolderConfiguration config2 = r2.getFolderConfiguration();
if (config1 != null && config2 != null) {
int c = config1.compareTo(config2);
if (c != 0) {
return c;
}
}
// then check qualifiers
return StringUtil.compare(r1.getQualifier(), r2.getQualifier(), false);
}
use of com.intellij.ide.util.treeView.NodeDescriptor in project intellij-community by JetBrains.
the class ServersToolWindowContent method setupBuilder.
private void setupBuilder(@NotNull final Project project) {
ServersTreeStructure structure = myContribution.createTreeStructure(project, this);
myBuilder = new TreeBuilderBase(myTree, structure, myTreeModel) {
@Override
protected boolean isAutoExpandNode(NodeDescriptor nodeDescriptor) {
return (nodeDescriptor instanceof ServersTreeStructure.RemoteServerNode || nodeDescriptor instanceof ServersTreeStructure.DeploymentNodeImpl) && (!myCollapsedTreeNodeValues.contains(((AbstractTreeNode) nodeDescriptor).getValue()));
}
};
Disposer.register(this, myBuilder);
project.getMessageBus().connect().subscribe(ServerConnectionListener.TOPIC, new ServerConnectionListener() {
@Override
public void onConnectionCreated(@NotNull ServerConnection<?> connection) {
getBuilder().queueUpdate();
}
@Override
public void onConnectionStatusChanged(@NotNull ServerConnection<?> connection) {
getBuilder().queueUpdate();
updateSelectedServerDetails();
if (connection.getStatus() == ConnectionStatus.CONNECTED) {
pollDeployments(connection);
}
}
@Override
public void onDeploymentsChanged(@NotNull ServerConnection<?> connection) {
getBuilder().queueUpdate();
updateSelectedServerDetails();
}
});
}
Aggregations