Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[riena-dev] getActiveWorkbenchWindow() and SwtApplication problem

Hi all,

I wanted to point out that I consider PlatformUI.getWorkbench().getActiveWorkbenchWindow() to be harmful. 

This method will return null when no window is active (for example the user is in another application like Firefox). This has caused NPEs in apps I have written in the past, because something would call getActiveWorkbenchWindow() while the app did not have the focus. In general you should use this.getShell() or parent.getShell() in widgets or getSite().getShell() in views and editors.

I suggest to get rid of the RcpUtilities class that provides this. I have refactored DialogView to not use it.

The other usage of RcpUtilities is in SwtApplication. This suffers exactly from the problem described above. If I understand correctly a Thread tries to hide the active window after some time of inactivity. If the application is not in the foreground there is no active window and so the inactive window will still be accessible.  Also that code assumes there is only one window and will not work correctly with several windows. It should be refactored to use PlatformUI.getWorkbench().getWorkbenchWindows() and iterate over each window.

Hope this helps,
Elias.

--
Elias Volanakis | Technical Lead | EclipseSource Portland
elias@xxxxxxxxxxxxxxxxx | +1 503 929 5537 | http://eclipsesource.com



Back to the top