use of com.android.tools.idea.navigator.nodes.FileGroupNode 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);
}
Aggregations