How to work with intellij Project tree objects

Hi

I was searching some information about how to get reference to the project tree files, to get the tree path or even selected file in the tree and I couldn't find the answers. In the eclipse there are such objects like TreePath or IFolder etc. Is there something similiar in Intellij? I saw the concept of VirtualFiles, Documents ans PSI Elements, but I think this is not what I'm looking for.

5 comments
Comment actions Permalink

Hi,

Actually I don't really understand what are you asking. Indeed IDEA has VirtualFiles and PSI subsystems that are taking a part in Project View in some way. Also there is ProjectView entity (ProjectView#getInstance) and ProjectViewImpl has AbstractProjectViewPane that could provide you some data like selected elements. Probably I can help you if you tell me what exactly do you want to implement.

0
Comment actions Permalink

What I would like to know is what file has been selected in the project tree, what is the tree path (because if file which was selected is too deep, I would need to get the folder few levels higher in the tree hierarchy). When I will get the file object, I will probably need to change it's content (file which I'm looking for arre xml files). If the object will be a folder, I will need to get one of the files which are in that folder (also XML). Plugin also will merge files (it will be a vault plugin which will import/export content from adobe aem). In case when file will be changed in the application and by me in the code, I will have to merge those two versions of the same file. This is only one of the few scenarios

0
Comment actions Permalink

Well I still didn't get why do you need Project tree for this. As far as I undestand you need just Virtual File System (and maybe some util classes like VfsUtil or FileUtil) to manage file paths and its content. You can retrieve "selected" virtual files via DataContexts, e.g. if you're going to implement explicitly invokable action that you can extract selected files in the following way:

 
@Override
public void actionPerformed(AnActionEvent e) {
    VirtualFile[] files = e.getData(PlatformDataKeys.VIRTUAL_FILE_ARRAY);
 
}


More information you can find at http://confluence.jetbrains.com/display/IDEADEV/IntelliJ+IDEA+Architectural+Overview and http://confluence.jetbrains.com/display/IDEADEV/PluginDevelopment

0
Comment actions Permalink

I have already read that but Icouldn't find solution for my issues. I will read it again and I will play with VFS again. If I will have more question, probably I will return to this topic. Thank you.

0
Comment actions Permalink

From what I understand You rather need to use PsiFile (XmlFile in Your case) than VirtualFile - you expect to receive up to date file content for merging, but Vitural File could not be up to date, PsiFile will be (or Document from Editor).
You looking for XML files and search for some directories up from those to some level - I think it would be better if You search them by IDEA index mechanism for XML files in particular module of project (I assume You search for some module files in opened project).
Also, it would be nice if You post more information about what You really need to acheive (maybe You should use references to files instead searching for files in particular folders).

0

Please sign in to leave a comment.