use of com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode in project android by JetBrains.
the class ResourceMergerTreeStructureProvider method modify.
@NotNull
@Override
public Collection<AbstractTreeNode> modify(@NotNull AbstractTreeNode parent, @NotNull Collection<AbstractTreeNode> children, ViewSettings settings) {
if (!ApplicationManager.getApplication().isInternal()) {
return children;
}
if (parent instanceof PsiDirectoryNode) {
PsiDirectory directory = ((PsiDirectoryNode) parent).getValue();
if (!directory.getName().equals("res")) {
return children;
}
Module module = ModuleUtil.findModuleForPsiElement(directory);
AndroidFacet facet = AndroidFacet.getInstance(module);
if (facet == null) {
return children;
}
return mergeResourceDirectories(children, settings);
}
return children;
}
use of com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode in project android by JetBrains.
the class AndroidTreeStructureProvider method modify.
@Override
@NotNull
public Collection<AbstractTreeNode> modify(@NotNull AbstractTreeNode parent, @NotNull Collection<AbstractTreeNode> children, ViewSettings settings) {
Project project = parent.getProject();
if (project != null && AndroidProjectInfo.getInstance(project).requiresAndroidModel()) {
if (parent instanceof NamedLibraryElementNode) {
NamedLibraryElement value = ((NamedLibraryElementNode) parent).getValue();
LibraryOrSdkOrderEntry orderEntry = value.getOrderEntry();
if (orderEntry instanceof JdkOrderEntry) {
Sdk sdk = ((JdkOrderEntry) orderEntry).getJdk();
if (sdk.getSdkType() instanceof JavaSdk) {
List<AbstractTreeNode> newChildren = Lists.newArrayList();
for (AbstractTreeNode child : children) {
if (isRtJar(child)) {
newChildren.add(child);
}
}
if (!newChildren.isEmpty()) {
myEventDispatcher.getMulticaster().nodeChanged(parent, newChildren);
return newChildren;
}
}
}
} else if (isRtJar(parent)) {
List<AbstractTreeNode> newChildren = Lists.newArrayList();
for (AbstractTreeNode child : children) {
if (child instanceof PsiDirectoryNode) {
VirtualFile file = ((PsiDirectoryNode) child).getVirtualFile();
if (file != null && ("java".equals(file.getName()) || "javax".equals(file.getName()))) {
newChildren.add(child);
}
}
}
if (!newChildren.isEmpty()) {
myEventDispatcher.getMulticaster().nodeChanged(parent, newChildren);
return newChildren;
}
}
}
return children;
}
use of com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode in project android by JetBrains.
the class BuildNodeDecorator method decorate.
@Override
public void decorate(ProjectViewNode node, PresentationData data) {
if (!(node instanceof PsiDirectoryNode)) {
return;
}
final PsiDirectoryNode psiDirectoryNode = (PsiDirectoryNode) node;
PsiDirectory directory = psiDirectoryNode.getValue();
if (directory == null || !directory.isValid()) {
return;
}
final Project project = directory.getProject();
if (!ProjectFacetManager.getInstance(project).hasFacets(AndroidFacet.ID)) {
return;
}
// If the build dir is inside the module's content root, ProjectRootsUtil.isModuleContentRoot will return false. The reason is that when
// we set up the project during a sync, we don't create additional content roots if the build dir is inside the module.
final VirtualFile folder = directory.getVirtualFile();
if (!ProjectRootsUtil.isModuleContentRoot(folder, project)) {
return;
}
Object parentValue = psiDirectoryNode.getParent().getValue();
if (!(parentValue instanceof Module)) {
return;
}
Module module = ProjectRootManager.getInstance(project).getFileIndex().getModuleForFile(folder);
if (module == null) {
return;
}
AndroidProject androidProject = GradleUtil.getAndroidProject(module);
if (androidProject == null) {
return;
}
File buildFolderPath = androidProject.getBuildFolder();
File folderPath = VfsUtilCore.virtualToIoFile(folder);
if (FileUtil.filesEqual(buildFolderPath, folderPath)) {
data.clearText();
data.addText(folder.getName(), SimpleTextAttributes.REGULAR_ATTRIBUTES);
}
}
use of com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode in project android by JetBrains.
the class ResourceMergerTreeStructureProvider method mergeResourceDirectories.
private static Collection<AbstractTreeNode> mergeResourceDirectories(Collection<AbstractTreeNode> children, ViewSettings settings) {
List<AbstractTreeNode> result = new ArrayList<AbstractTreeNode>();
Map<ResourceFolderType, ResourceDirectoryNode> resourceDirectories = new HashMap<ResourceFolderType, ResourceDirectoryNode>();
for (AbstractTreeNode child : children) {
if (!(child instanceof PsiDirectoryNode)) {
result.add(child);
continue;
}
PsiDirectoryNode directoryNode = (PsiDirectoryNode) child;
PsiDirectory directory = directoryNode.getValue();
ResourceFolderType type = ResourceFolderType.getFolderType(directory.getName());
if (type == null) {
result.add(child);
continue;
}
ResourceDirectoryNode node = resourceDirectories.get(type);
if (node == null || !directory.getName().contains("-")) {
node = new ResourceDirectoryNode(directoryNode.getProject(), directoryNode, settings);
resourceDirectories.put(type, node);
}
}
for (ResourceDirectoryNode node : resourceDirectories.values()) {
node.collectChildren();
result.add(node);
}
return result;
}
use of com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode in project android by JetBrains.
the class AndroidViewProjectNode method getChildren.
@NotNull
@Override
public Collection<? extends AbstractTreeNode> getChildren() {
Project project = getProject();
assert project != null;
ViewSettings settings = getSettings();
// add a node for every module
// TODO: make this conditional on getSettings().isShowModules(), otherwise collapse them all at the root
List<Module> modules = Arrays.asList(ModuleManager.getInstance(project).getModules());
List<AbstractTreeNode> children = Lists.newArrayListWithExpectedSize(modules.size());
for (Module module : modules) {
if (isRootModuleWithNoSources(module)) {
// If we detect such a module, then we don't show it..
continue;
}
AndroidFacet androidFacet = AndroidFacet.getInstance(module);
NdkFacet ndkFacet = NdkFacet.getInstance(module);
if (androidFacet != null && androidFacet.getAndroidModel() != null) {
children.add(new AndroidModuleNode(project, module, settings, myProjectViewPane));
} else if (ndkFacet != null && ndkFacet.getNdkModuleModel() != null) {
children.add(new NdkModuleNode(project, module, settings));
} else {
children.add(new NonAndroidModuleNode(project, module, settings));
}
}
// are still visible. See https://code.google.com/p/android/issues/detail?id=76564
if (children.isEmpty() && isBuildWithGradle(project) && GradleSyncState.getInstance(project).lastSyncFailed()) {
PsiDirectory dir = PsiManager.getInstance(project).findDirectory(project.getBaseDir());
if (dir != null) {
children.add(new PsiDirectoryNode(project, dir, settings));
}
}
if (isBuildWithGradle(project)) {
children.add(new AndroidBuildScriptsGroupNode(project, settings));
}
ExternalBuildFilesGroupNode externalBuildFilesNode = new ExternalBuildFilesGroupNode(project, settings);
if (!externalBuildFilesNode.getChildren().isEmpty()) {
children.add(externalBuildFilesNode);
}
return children;
}
Aggregations