use of com.intellij.ide.projectView.impl.nodes.PackageElement 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.projectView.impl.nodes.PackageElement 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.projectView.impl.nodes.PackageElement in project intellij-community by JetBrains.
the class TodoPackageNode method update.
@Override
protected void update(PresentationData data) {
super.update(data);
final PackageElement packageElement = getValue();
try {
if (packageElement == null || !packageElement.getPackage().isValid()) {
setValue(null);
return;
}
int fileCount = getFileCount(packageElement);
if (fileCount == 0) {
setValue(null);
return;
}
PsiPackage aPackage = packageElement.getPackage();
String newName;
if (getStructure().areFlattenPackages()) {
newName = aPackage.getQualifiedName();
} else {
newName = myPresentationName != null ? myPresentationName : "";
}
int nameEndOffset = newName.length();
int todoItemCount = getTodoItemCount(packageElement);
newName = IdeBundle.message("node.todo.group", newName, todoItemCount, fileCount);
myHighlightedRegions.clear();
TextAttributes textAttributes = new TextAttributes();
Color newColor = null;
if (CopyPasteManager.getInstance().isCutElement(packageElement)) {
newColor = CopyPasteManager.CUT_COLOR;
}
textAttributes.setForegroundColor(newColor);
myHighlightedRegions.add(new HighlightedRegion(0, nameEndOffset, textAttributes));
EditorColorsScheme colorsScheme = UsageTreeColorsScheme.getInstance().getScheme();
myHighlightedRegions.add(new HighlightedRegion(nameEndOffset, newName.length(), colorsScheme.getAttributes(UsageTreeColors.NUMBER_OF_USAGES)));
data.setPresentableText(newName);
} catch (IndexNotReadyException e) {
LOG.info(e);
data.setPresentableText("N/A");
}
}
use of com.intellij.ide.projectView.impl.nodes.PackageElement in project intellij-community by JetBrains.
the class TodoPackageNode method getChildren.
@Override
@NotNull
public Collection<AbstractTreeNode> getChildren() {
ArrayList<AbstractTreeNode> children = new ArrayList<>();
final Project project = getProject();
final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
final PsiPackage psiPackage = getValue().getPackage();
final Module module = getValue().getModule();
if (!getStructure().getIsFlattenPackages() || psiPackage == null) {
final Iterator<PsiFile> iterator = getFiles(getValue());
while (iterator.hasNext()) {
final PsiFile psiFile = iterator.next();
final Module psiFileModule = projectFileIndex.getModuleForFile(psiFile.getVirtualFile());
//group by module
if (module != null && psiFileModule != null && !module.equals(psiFileModule)) {
continue;
}
// Add files
final PsiDirectory containingDirectory = psiFile.getContainingDirectory();
TodoFileNode todoFileNode = new TodoFileNode(project, psiFile, myBuilder, false);
if (ArrayUtil.find(psiPackage.getDirectories(), containingDirectory) > -1 && !children.contains(todoFileNode)) {
children.add(todoFileNode);
continue;
}
// Add packages
PsiDirectory _dir = psiFile.getContainingDirectory();
while (_dir != null) {
final PsiDirectory parentDirectory = _dir.getParentDirectory();
if (parentDirectory != null) {
PsiPackage _package = JavaDirectoryService.getInstance().getPackage(_dir);
if (_package != null && _package.getParentPackage() != null && psiPackage.equals(_package.getParentPackage())) {
final GlobalSearchScope scope = module != null ? GlobalSearchScope.moduleScope(module) : GlobalSearchScope.projectScope(project);
//compact empty middle packages
_package = TodoJavaTreeHelper.findNonEmptyPackage(_package, module, project, myBuilder, scope);
final String name = _package.getParentPackage().equals(psiPackage) ? //non compacted
null : _package.getQualifiedName().substring(psiPackage.getQualifiedName().length() + 1);
TodoPackageNode todoPackageNode = new TodoPackageNode(project, new PackageElement(module, _package, false), myBuilder, name);
if (!children.contains(todoPackageNode)) {
children.add(todoPackageNode);
break;
}
}
}
_dir = parentDirectory;
}
}
} else {
// flatten packages
final Iterator<PsiFile> iterator = getFiles(getValue());
while (iterator.hasNext()) {
final PsiFile psiFile = iterator.next();
//group by module
final Module psiFileModule = projectFileIndex.getModuleForFile(psiFile.getVirtualFile());
if (module != null && psiFileModule != null && !module.equals(psiFileModule)) {
continue;
}
final PsiDirectory _dir = psiFile.getContainingDirectory();
// Add files
TodoFileNode todoFileNode = new TodoFileNode(getProject(), psiFile, myBuilder, false);
if (ArrayUtil.find(psiPackage.getDirectories(), _dir) > -1 && !children.contains(todoFileNode)) {
children.add(todoFileNode);
continue;
}
}
}
Collections.sort(children, TodoFileDirAndModuleComparator.INSTANCE);
return children;
}
use of com.intellij.ide.projectView.impl.nodes.PackageElement in project intellij-community by JetBrains.
the class PackageViewPane method getSelectedDirectories.
@NotNull
@Override
public PsiDirectory[] getSelectedDirectories() {
List<PsiDirectory> directories = ContainerUtil.newArrayList();
for (PackageElementNode node : getSelectedNodes(PackageElementNode.class)) {
PackageElement packageElement = node.getValue();
PsiPackage aPackage = packageElement != null ? packageElement.getPackage() : null;
final Module module = packageElement != null ? packageElement.getModule() : null;
if (aPackage != null && module != null) {
GlobalSearchScope scope = GlobalSearchScope.moduleScope(module);
Collections.addAll(directories, aPackage.getDirectories(scope));
if (Registry.is("projectView.choose.directory.on.compacted.middle.packages")) {
Object parentValue = node.getParent().getValue();
PsiPackage parentNodePackage = parentValue instanceof PackageElement ? ((PackageElement) parentValue).getPackage() : null;
while (true) {
aPackage = aPackage.getParentPackage();
if (aPackage == null || aPackage.getQualifiedName().isEmpty() || aPackage.equals(parentNodePackage)) {
break;
}
Collections.addAll(directories, aPackage.getDirectories(scope));
}
}
}
}
if (!directories.isEmpty()) {
return directories.toArray(new PsiDirectory[directories.size()]);
}
return super.getSelectedDirectories();
}
Aggregations