Friday, October 26, 2007

IFolderLayout and Multiple Tabbed Views in Eclipse RCP/SWT

I ran across another issue that needed fixing this week. It isn't a very big problem but I figured even the little problems can be hard for some to solve since I consider the RCP / SWT documentation to be so weak.

This most recent problem had to do with having multiple views in an IFolderLayout. I had two as you will see in the image below (look at top right of image circled in red) with the table being the currently displayed view, albeit with no data.


Now what the user may do is click on the chart preview in the window on the left side view (It is a PDF viewer). The problem I had is the chart view, which is the "hidden" view on the right behind the table view, would not come to the fore ground.

This is a simple fix once you know what to do. I have a function called public void updateChartView(IWorkbenchPage page) which gets called to update the chart with new data or whatever. All I needed to do was, using the IWorkbenchPage passed was to call page.bringToTop(view) If you attempt to use activate(view) you may get errors.. How did I get my view in here? I did this: ChartView view = (ChartView)page.findView(ChartView.ID). This only works if you have one instance of chartview but there are primary and secondary id's used in another form of findView if you have multiple instances of the same view.

So by adding the bringToTop(view) function it now works properly when the user clicks on the left chart preview. See below:

Communication between Views using eventLoopIdle

I have been working on an application that is now up to 3 swing components embedded in my Eclipse RCP / SWT application. This has become problematic having these 3rd party components to communicate properly with each other. While it is easy to communicate with these other components embedded in other views I was having a problem with RCP not properly repainting the screen. So I have come up with a work around that works for me and I thought I would share it with any other Eclipse Rich Client Platform developer out there that may be struggling.

If you open up ApplicationWorkbenchAdvisor.java - there is a function in there called public void eventLoopIdle(Display display). In this function I put my calls. I used my Application Singleton class to facilitate communication. By adding a semaphore type variable I can see if other views need to go and update their screen. In my specific case a user has a view of a PDF and when they click on an action object this needs to send the file information to a chart window that then opens the file clicked on in the PDF view, parse it and display the chart with the give options defined by the PDF link.

If you have any questions on this just email or leave me a comment. Good luck!