PsiStructureViewFactory

Hallo,
I tried to modify the StructureView, so it only contains files that contain "test".
I defined my own Factory, a Model, and an Element.(See Code bellow). I also registered it in the plugin.xml.
However when i run the Code in the Debugger and set an breakpoint in the constructor of the Factory class, it shows that my code is never reached.
Can somone tell my why it isnt working?

Thank you for your help,
Tobi.

-------------

 
<lang.psiStructureViewFactory language="JAVA" implementationClass="Action2.SimpleStructureViewFactory"/>
  
-------

 
public class SimpleStructureViewFactory implements PsiStructureViewFactory {
    @Nullable
    @Override
    public
StructureViewBuilder getStructureViewBuilder(PsiFile psiFile) {
        if(!(psiFile instanceof PsiJavaFile)) return null;
        return new
TreeBasedStructureViewBuilder() {
            @NotNull
            @Override
            public
StructureViewModel createStructureViewModel(@Nullable Editor editor) {
                return new MyJavaFileTreeModel((PsiJavaFile)psiFile,editor);
            
}

        };
    
}
 
-----------------------------------------------------------------------------------------------------
 
public class MyJavaFileTreeElement extends JavaFileTreeElement {
    public MyJavaFileTreeElement(PsiClassOwner file) {
        super(file);
    
}


    @Override
    public
Collection<StructureViewTreeElement> getChildrenBase() {
        PsiClass[] classes = getElement().getClasses();
        
ArrayList<StructureViewTreeElement> result = new ArrayList<StructureViewTreeElement>();
        for
(PsiClass aClass : classes) {
            if (aClass.getName().contains("Test")) {
                {
                    result.add(new JavaClassTreeElement(aClass, false, new HashSet<PsiClass>()));
                
}
            }}
            return result;


    
}
}


---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 
public class MyJavaFileTreeModel extends JavaFileTreeModel {
    public MyJavaFileTreeModel(PsiClassOwner file, Editor editor) {
        super(file, editor);
    
}

    @Override
    public
StructureViewTreeElement getRoot(){
        return new MyJavaFileTreeElement(getPsiFile());
    
}
}
6 comments
Comment actions Permalink

This isn't working because Java already has an implementation of psiStructureViewFactory. What are you trying to accomplish?

0
Comment actions Permalink

My goal is to have another Structure view, that can be seleected in the group, where project,packages, project files and so on is in.
This group is supposed to show all classes as they are in the project panel, just with a filter applied to them. (i just want certain ones to be shown, for example the ones that contain "test").


Thank you for your help,
Tobi

0
Comment actions Permalink

The group containing the project, packages and so on is not a structure view at all, it is a project view.

If you want to show all classes containg "test", you don't need to write a plugin. You can go to Settings | Appearance and Behavior | Scopes, define the scope that you want to see, and it will automatically appear as one of the views in the Project view.

0
Comment actions Permalink

Thank you for the answer.
One more question, i want to add some more functionality based on this new scope i have created.
Is there a way to add it to my plugin, so if someone would install it, he would automaticly have the scope come with it?

0
Comment actions Permalink

You can create a scope from your plugin code using NamedScopesHolder.getScopes() and .setScopes().

0

Please sign in to leave a comment.