Close a welcome page programmatically


Here is a small snippet that may avoid some waste of time.
I spent almost 3 hours to find a solution. This is why I share it here.

Let’s first introduce what I wanted to do.

I have a welcome page, which extends IntroPart and is able to launch wizards on user actions. I coded it manually. It does not rely on the CustomizableIntroPart class. What I wanted to do was to close it when a wizard launched from this page had completed. This behavior is visible in the default welcome page of Eclipse. When you click “Go to workbench”, the welcome page is closed and a perspective is shown.

The first idea was to programmatically close the view that embeds the welcome page after the wizard has executed (with IWorkbenchPage#hideView( String )).
I did try, and it was unsuccessful. The workbench shows an empty widget, and no perspective is shown.

I then tried to close the page in IntroPart#setStandBy( boolean ). Unsuccessfully.
I then tried to reuse what is implemented in the org.eclipse.ui.intro plug-in, in the method IntroURL#switchToLaunchBar().
Therefore, one solution I tried to close the Eclipse welcome page is:

IntroURL url = new IntroURLParser( "http://org.eclipse.ui.intro/" + IntroURL.SWITCH_TO_LAUNCH_BAR );

Still unsuccessful.

In fact, no matter what you use, if the welcome page tries to close itself, it will fail.
The solution was to make my welcome page implement IPartListener and register itself on its page.
When the page is deactivated (when it losts the focus), the welcome page is closed, using:

PlatformUI.getWorkbench().getIntroManager().closeIntro( part );

That was that simple!

About this entry