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!

4 thoughts on “Close a welcome page programmatically

  1. Or if you simply want to close the primary intro screen altogether, I use:

    IIntroManager introManager = PlatformUI.getWorkbench().getIntroManager();
    IIntroPart intro = introManager.getIntro();

  2. I tried this “IIntroManager introManager = PlatformUI.getWorkbench().getIntroManager();
    IIntroPart intro = introManager.getIntro();
    introManager.closeIntro(intro);” but still welcome screen is shown on launch… i have added the code in Activator class.. is that right?

    1. The code given here closes the intro page on a user action.
      However, it is possible that your bundle starts before the intro page is shown. In this case, the code will do nothing. If you want to make sure the intro page does not show up again on every Eclipse launching, I’d rather dig in preferences. Make sure the right preference is set so that the intro page does not show anymore.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s