use of com.intellij.ide.util.treeView.AbstractTreeNode in project android by JetBrains.
the class NativeAndroidSourceDirectoryNode method getChildrenImpl.
@Override
public Collection<AbstractTreeNode> getChildrenImpl() {
PsiDirectory psiDirectory = getValue();
if (psiDirectory == null) {
return ImmutableList.of();
}
Collection<AbstractTreeNode> directoryChildren = ProjectViewDirectoryHelper.getInstance(myProject).getDirectoryChildren(psiDirectory, getSettings(), true);
List<AbstractTreeNode> result = Lists.newArrayList();
for (AbstractTreeNode child : directoryChildren) {
Object value = child.getValue();
if (value instanceof PsiFile) {
VirtualFile file = ((PsiFile) value).getVirtualFile();
if ((mySourceFolders.contains(psiDirectory.getVirtualFile()) && myFileExtensions.contains(file.getExtension())) || mySourceFiles.contains(file)) {
result.add(child);
}
} else if (value instanceof PsiDirectory) {
VirtualFile dir = ((PsiDirectory) value).getVirtualFile();
if (mySourceFolders.contains(dir) || mySourceFolders.contains(psiDirectory.getVirtualFile())) {
result.add(new NativeAndroidSourceDirectoryNode(myProject, (PsiDirectory) value, getSettings(), myFileExtensions, ImmutableList.of(dir), ImmutableList.of()));
continue;
}
List<VirtualFile> childDirs = Lists.newArrayList();
for (VirtualFile sourceFolder : mySourceFolders) {
if (VfsUtilCore.isAncestor(dir, sourceFolder, true)) {
childDirs.add(sourceFolder);
}
}
List<VirtualFile> childFiles = Lists.newArrayList();
for (VirtualFile file : mySourceFiles) {
if (VfsUtilCore.isAncestor(dir, file, true)) {
childFiles.add(file);
}
}
if (!childDirs.isEmpty() || !childFiles.isEmpty()) {
result.add(new NativeAndroidSourceDirectoryNode(myProject, (PsiDirectory) value, getSettings(), myFileExtensions, childDirs, childFiles));
}
}
}
return result;
}
use of com.intellij.ide.util.treeView.AbstractTreeNode in project android by JetBrains.
the class NdkModuleNode method getNativeSourceNodes.
@NotNull
public static Collection<AbstractTreeNode> getNativeSourceNodes(@NotNull Project project, @NotNull NdkModuleModel ndkModuleModel, @NotNull ViewSettings viewSettings) {
NativeAndroidProject nativeAndroidProject = ndkModuleModel.getAndroidProject();
Collection<String> sourceFileExtensions = nativeAndroidProject.getFileExtensions().keySet();
NdkModuleModel.NdkVariant variant = ndkModuleModel.getSelectedVariant();
Multimap<String, NativeArtifact> nativeLibraries = HashMultimap.create();
for (NativeArtifact artifact : variant.getArtifacts()) {
String artifactOutputFileName = artifact.getOutputFile().getName();
nativeLibraries.put(artifactOutputFileName, artifact);
}
if (nativeLibraries.keySet().size() == 1) {
return getSourceDirectoryNodes(project, nativeLibraries.values(), viewSettings, sourceFileExtensions);
}
List<AbstractTreeNode> children = Lists.newArrayList();
for (String name : nativeLibraries.keySet()) {
String nativeLibraryType = "";
String nativeLibraryName = trimEnd(name, ".so");
if (nativeLibraryName.length() < name.length()) {
nativeLibraryType = "Shared Library";
} else {
nativeLibraryName = trimEnd(name, ".a");
if (nativeLibraryName.length() < name.length()) {
nativeLibraryType = "Static Library";
}
}
nativeLibraryName = trimStart(nativeLibraryName, "lib");
children.add(new NativeAndroidLibraryNode(project, nativeLibraryName, nativeLibraryType, nativeLibraries.get(name), viewSettings, sourceFileExtensions));
}
return children;
}
use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-plugins by JetBrains.
the class DartTreeStructureProvider method modify.
@NotNull
public Collection<AbstractTreeNode> modify(@NotNull final AbstractTreeNode parentNode, @NotNull final Collection<AbstractTreeNode> children, final ViewSettings settings) {
if (parentNode instanceof ExternalLibrariesNode) {
return ContainerUtil.map(children, node -> {
if (node instanceof NamedLibraryElementNode && (DartPackagesLibraryType.DART_PACKAGES_LIBRARY_NAME.equals(node.getName()) || DartSdk.DART_SDK_LIB_NAME.equals(node.getName()))) {
final boolean isSdkRoot = DartSdk.DART_SDK_LIB_NAME.equals(node.getName());
return new NamedLibraryElementNode(node.getProject(), ((NamedLibraryElementNode) node).getValue(), settings) {
@Override
public boolean canNavigate() {
return isSdkRoot;
}
@Override
public void navigate(boolean requestFocus) {
final Project project = getProject();
if (project != null) {
DartConfigurable.openDartSettings(project);
}
}
};
}
return node;
});
}
if (parentNode instanceof NamedLibraryElementNode && (DartPackagesLibraryType.DART_PACKAGES_LIBRARY_NAME.equals(parentNode.getName()) || DartSdk.DART_SDK_LIB_NAME.equals(parentNode.getName()))) {
final boolean isSdkRoot = DartSdk.DART_SDK_LIB_NAME.equals(parentNode.getName());
return ContainerUtil.map(children, node -> {
final VirtualFile dir = node instanceof PsiDirectoryNode ? ((PsiDirectoryNode) node).getVirtualFile() : null;
if (dir != null && dir.isInLocalFileSystem() && dir.isDirectory() && (isSdkRoot || "lib".equals(dir.getName()))) {
return new DartSdkOrLibraryRootNode(node.getProject(), ((PsiDirectoryNode) node).getValue(), settings);
}
return node;
});
}
// root/packages/ThisProject and root/packages/PathPackage folders are excluded in dart projects (see DartProjectComponent.excludeBuildAndPackagesFolders),
// this provider adds location string tho these nodes in Project View like "ThisProject (ThisProject/lib)"
final Project project = parentNode.getProject();
final VirtualFile packagesDir = parentNode instanceof PsiDirectoryNode && project != null ? ((PsiDirectoryNode) parentNode).getVirtualFile() : null;
final VirtualFile parentFolder = packagesDir != null && packagesDir.isDirectory() && PACKAGES_FOLDER_NAME.equals(packagesDir.getName()) ? packagesDir.getParent() : null;
final VirtualFile pubspecYamlFile = parentFolder != null ? parentFolder.findChild(PUBSPEC_YAML) : null;
if (pubspecYamlFile != null && !pubspecYamlFile.isDirectory()) {
final ArrayList<AbstractTreeNode> modifiedChildren = new ArrayList<>(children);
final DartUrlResolver resolver = DartUrlResolver.getInstance(project, pubspecYamlFile);
resolver.processLivePackages((packageName, packageDir) -> {
final VirtualFile folder = packagesDir.findChild(packageName);
if (folder != null) {
final AbstractTreeNode node = getFolderNode(children, folder);
if (node == null) {
modifiedChildren.add(new SymlinkToLivePackageNode(project, packageName, packageDir));
} else {
node.getPresentation().setLocationString(getPackageLocationString(packageDir));
}
}
});
return modifiedChildren;
}
return children;
}
use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-plugins by JetBrains.
the class FlexCompositeSdkProjectViewStructureProvider method modify.
@NotNull
@Override
public Collection<AbstractTreeNode> modify(@NotNull final AbstractTreeNode parent, @NotNull final Collection<AbstractTreeNode> children, final ViewSettings settings) {
if (!(parent instanceof ExternalLibrariesNode)) {
return children;
}
Set<Sdk> processedSdks = new HashSet<>();
Collection<AbstractTreeNode> result = new ArrayList<>();
for (AbstractTreeNode child : children) {
Object value = child.getValue();
if (!(value instanceof NamedLibraryElement)) {
result.add(child);
continue;
}
NamedLibraryElement libraryElement = (NamedLibraryElement) value;
OrderEntry orderEntry = libraryElement.getOrderEntry();
if (!(orderEntry instanceof JdkOrderEntry)) {
result.add(child);
continue;
}
Sdk sdk = ((JdkOrderEntry) orderEntry).getJdk();
if (!(sdk instanceof FlexCompositeSdk)) {
result.add(child);
continue;
}
Sdk[] sdks = ((FlexCompositeSdk) sdk).getSdks();
for (Sdk individualSdk : sdks) {
if (processedSdks.add(individualSdk)) {
IndividualSdkOrderEntry entry = new IndividualSdkOrderEntry(individualSdk, orderEntry.getOwnerModule());
result.add(new NamedLibraryElementNode(parent.getProject(), new NamedLibraryElement(null, entry), ((ExternalLibrariesNode) parent).getSettings()));
}
}
}
return result;
}
use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.
the class SlicePanel method createTree.
@NotNull
private JTree createTree() {
DefaultMutableTreeNode root = new DefaultMutableTreeNode();
final Tree tree = new Tree(new DefaultTreeModel(root));
tree.setOpaque(false);
tree.setToggleClickCount(-1);
SliceUsageCellRendererBase renderer = myProvider.getRenderer();
renderer.setOpaque(false);
tree.setCellRenderer(renderer);
UIUtil.setLineStyleAngled(tree);
tree.setRootVisible(false);
tree.setShowsRootHandles(true);
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
tree.setSelectionPath(new TreePath(root.getPath()));
//ActionGroup group = (ActionGroup)ActionManager.getInstance().getAction(IdeActions.GROUP_METHOD_HIERARCHY_POPUP);
//PopupHandler.installPopupHandler(tree, group, ActionPlaces.METHOD_HIERARCHY_VIEW_POPUP, ActionManager.getInstance());
EditSourceOnDoubleClickHandler.install(tree);
new TreeSpeedSearch(tree);
TreeUtil.installActions(tree);
ToolTipManager.sharedInstance().registerComponent(tree);
myAutoScrollToSourceHandler.install(tree);
tree.getSelectionModel().addTreeSelectionListener(e -> treeSelectionChanged());
tree.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (KeyEvent.VK_ENTER == e.getKeyCode()) {
List<Navigatable> navigatables = getNavigatables();
if (navigatables.isEmpty())
return;
for (Navigatable navigatable : navigatables) {
if (navigatable instanceof AbstractTreeNode && ((AbstractTreeNode) navigatable).getValue() instanceof Usage) {
navigatable = (Usage) ((AbstractTreeNode) navigatable).getValue();
}
if (navigatable.canNavigateToSource()) {
navigatable.navigate(false);
if (navigatable instanceof Usage) {
((Usage) navigatable).highlightInEditor();
}
}
}
e.consume();
}
}
});
tree.addTreeWillExpandListener(new TreeWillExpandListener() {
@Override
public void treeWillCollapse(TreeExpansionEvent event) {
}
@Override
public void treeWillExpand(TreeExpansionEvent event) {
TreePath path = event.getPath();
SliceNode node = fromPath(path);
node.calculateDupNode();
}
});
return tree;
}
Aggregations