I am writing plugin for an Eclipse application. I wrote a custom perspective com.app.custom.ui.perspectives.MyCustomWorkspace
to show few custom views and some views already provided by the application. So essentially my custom perspective is similar to one of the ootb perspectives, com.app.ui.perspectives.MyWorkspace
, plus few of my custom views. One of the common views shared by my perspective and ootb perspective is com.app.ui.views.ViewerView
.
If I start the application with -perspective com.app.ui.perspectives.MyWorkspace
argument, the ViewerView
view loads just fine. However, if I start the application with -perspective com.app.custom.ui.perspectives.MyCustomWorkspace
argument, the ViewerView
view does not load and throws an exception. I went back and forth with the application vendor to get support, but no avail. Here is relevant exception stack trace:
java.lang.NullPointerException
at com.app.common.viewer.AutoCheckoutHelper.<init>(Unknown Source)
at com.app.viewer.view.PanelViewer.<init>(Unknown Source)
at com.app.ui.views.ViewerViewPart.createViewer(Unknown Source)
at com.app.ui.views.ViewerViewPart.createContent(Unknown Source)
at com.app.ui.views.ViewerViewPart.createPartControl(Unknown Source)
After some trial and error, I found that if I open MyWorkspace
first, and then open MyCustomWorkspace
, I don't get any exceptions loading ViewerView
view, regardless of if the MyWorkspace
remains open or is closed.
So, my question - After the application starts and the MyWorkspace
loads first, how do I programmatically close MyWorkspace
and open MyCustomWorkspace
? I looked for perspective listeners, but could not find one that would be fired after perspective is finished loading. Is there any workbench or workbench window or application listeners that I could use.
I thought of using org.eclipse.ui.perspectiveExtensions
to add my custom views to the ootb MyWorkspace
perspective, but some of my custom views are added conditionally depending upon who the user is. perspectiveExtensions
does not seem to provide any functionality to add conditions.
Edit-1: Removed the original reference to e4
application from my original post:
I am writing plugin for an Eclipse
e4
application
Edit-2: Adding more clarification:
All perspectives (custom as well as application provided) are defined using org.eclipse.ui.perspectives
extension point, and all views (custom as well as application provided) are defined using org.eclipse.ui.views
extension point.
Edit-3: Added exception details in the post.
After bunch of trial and errors, I found a solution (well, sort of)...
I added Perspective Listener and inside the perspectiveActivated
method, I called setPerspective
to set MyCustomWorkspace
perspective. However simply by calling PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().setPerspective()
threw exception. So I made the call as follows to set my custom perspective:
Display.getDefault().asyncExec(() ->
{
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().setPerspective(...)
}
That does not throw any exceptions. It loads MyCustomWorkspace
. However it messes with the menus and toolbar icons. Many of them don't show up. But that's the battle for some other time.