RCP SWT export grid data

Hello Friends,

This is one of my tutorials for people working with RCP, SWT, JFace to export grid data. It is very obvious to display data in a grid/tabular form. Most of the times, user wants to export the data which is being displayed so how to export grid data from the grid to an output file. This is not that tricky to achieve. Lets see how to export grid data from a TreeViewer grid to the console. You can replace the console output to be dumped in any output file as per your convenience and instead of TreeViewer you can use any grid type of JFace/SWT.

Lets first create a SWT/JFace project and add a new Shell to it.

Below is the Tree Viewer demo class consisting of the Shell that displays the data in tree viewer and other logic to print the data to console. Since we are working on TreeViewer, I thought it would be better if we dump that data as well in Tree form, so I have used an additional logic for maintaining the tabs/spaces to be displayed. Rest you can see the code for details.

We will create a ViewModel to hold the data of tree. Below is the one. I have not used more elements in the Model as it is just a demonstration.

There should be a content provider for any Tree Viewer, so we have added our own implementation of ITreeContentProvider. It will display the content Tree Viewer.

Now we will run our application to get the below UI shell with our data in Tree Viewer –


You can see an Export button on top of the window, click it to print the current structure on console –

Hope this helps you.

Thanks !

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.