Search code examples
eclipsetreeviewswteclipse-rcprcp

How do I make eclipse custom view take data from the file currently active in the editor?


I recently went into creating my own personal DSL with xtext and manage to create a mini programming language based on C (simple expressions and basic functions). My current task it to create a custom tree view for the language that would allow me to see all the functions as root elements and the instructions inside them as children.

My actual problem that I can't seem to resolve is exactly how do I make the custom tree view I wish to create take the data from the file that I'm currently working on.
I have an RCP product ready for the DSL that I can use and I would like to include this view over there. I have created the interface for the view with WindowBuilder and made it as a ViewPart.
In the end I wish it to look close to what the standard outline for a java program looks like.

Thanks for the help in advance.


Solution

  • If you work with your own view, you can add an IPartListener implementation that will notify you on when an editor is activated with the following code:

            getViewSite().getPage().addPartListener(new IPartListener() {
    
            @Override
            public void partOpened(IWorkbenchPart part) {
    
            }
    
            @Override
            public void partDeactivated(IWorkbenchPart part) {
    
            }
    
            @Override
            public void partClosed(IWorkbenchPart part) {
    
            }
    
            @Override
            public void partBroughtToTop(IWorkbenchPart part) {
    
            }
    
            @Override
            public void partActivated(IWorkbenchPart part) {
                // Add view initialization from the new part
    
            }
        });