mirror of
https://github.com/JetBrains/intellij-sdk-code-samples.git
synced 2025-07-28 01:07:49 +08:00
[code] TreeStructureProvider example
This commit is contained in:
parent
c7857ab1cf
commit
fef2cfc1d1
@ -13,7 +13,7 @@
|
|||||||
<depends>com.intellij.modules.lang</depends>
|
<depends>com.intellij.modules.lang</depends>
|
||||||
|
|
||||||
<extensions defaultExtensionNs="com.intellij">
|
<extensions defaultExtensionNs="com.intellij">
|
||||||
<treeStructureProvider implementation="org.jetbrains.plugins.sample.tree.CustomTreeStructureProvider"/>
|
<treeStructureProvider implementation="org.jetbrains.plugins.sample.tree.TextOnlyTreeStructureProvider"/>
|
||||||
</extensions>
|
</extensions>
|
||||||
|
|
||||||
<application-components>
|
<application-components>
|
||||||
|
@ -1,27 +0,0 @@
|
|||||||
package org.jetbrains.plugins.sample.tree;
|
|
||||||
|
|
||||||
import com.intellij.ide.projectView.TreeStructureProvider;
|
|
||||||
import com.intellij.ide.projectView.ViewSettings;
|
|
||||||
import com.intellij.ide.util.treeView.AbstractTreeNode;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Anna Bulenkova
|
|
||||||
*/
|
|
||||||
public class CustomTreeStructureProvider implements TreeStructureProvider {
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public Collection<AbstractTreeNode> modify(@NotNull AbstractTreeNode parent, @NotNull Collection<AbstractTreeNode> children, ViewSettings viewSettings) {
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public Object getData(Collection<AbstractTreeNode> collection, String s) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,40 @@
|
|||||||
|
package org.jetbrains.plugins.sample.tree;
|
||||||
|
|
||||||
|
import com.intellij.ide.projectView.TreeStructureProvider;
|
||||||
|
import com.intellij.ide.projectView.ViewSettings;
|
||||||
|
import com.intellij.ide.projectView.impl.nodes.PsiFileNode;
|
||||||
|
import com.intellij.ide.util.treeView.AbstractTreeNode;
|
||||||
|
import com.intellij.openapi.fileTypes.PlainTextFileType;
|
||||||
|
import com.intellij.openapi.vfs.VirtualFile;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Anna Bulenkova
|
||||||
|
*/
|
||||||
|
public class TextOnlyTreeStructureProvider implements TreeStructureProvider {
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Collection<AbstractTreeNode> modify(@NotNull AbstractTreeNode parent, @NotNull Collection<AbstractTreeNode> children, ViewSettings settings) {
|
||||||
|
ArrayList<AbstractTreeNode> nodes = new ArrayList<AbstractTreeNode>();
|
||||||
|
for (AbstractTreeNode child : children) {
|
||||||
|
if (child instanceof PsiFileNode) {
|
||||||
|
VirtualFile file = ((PsiFileNode) child).getVirtualFile();
|
||||||
|
if (file != null && !file.isDirectory() && !(file.getFileType() instanceof PlainTextFileType)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
nodes.add(child);
|
||||||
|
}
|
||||||
|
return nodes;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public Object getData(Collection<AbstractTreeNode> collection, String s) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user