0

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.

Ikikaze
  • 15
  • 3
  • Do you mean you want an Outline View? These are handled specially by the current editor. See for example http://stackoverflow.com/q/21179360/2670892 – greg-449 Jul 31 '15 at 11:44

1 Answers1

0

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

        }
    });
Arye Shemesh
  • 582
  • 7
  • 20
  • This does help , yes, but what I really need is a way to interpret the specific file that's active in the editor in order to add its elements to a TreeView. As a bonus, this file is not a normal java file but a file made with a DSL I implemented. I feel like this should be something so obvious but I'm missing it for some reason, because I haven't really been able to find exactly what I wanted even though I have searched for way more than I should've to find this. – Ikikaze Aug 04 '15 at 11:02
  • Doesn't sound obvious at all. If this is something you implemented, how can a generic tool give you its elements? Did you use some kind of framework or standard? Maybe their documentation can provide a clue. – Arye Shemesh Aug 04 '15 at 14:45
  • Alright, I've found out how to do it. A baseline for a random DSL is made here with a view that takes input from the source. Posting it here in case someone else wants it. https://xtexterience.wordpress.com/2011/07/03/generate-graphical-visualizations-for-textual-dsls/ – Ikikaze Aug 05 '15 at 12:25