In an application like Yahoo Messenger or Skype, you don't want to quit the application when the main window is closed. Most of these applications will move themselves to System Tray when the main window is closed and clicking on the Tray icon would bring back the window. Lets try to see how to do it in an Eclipse RCP Application.

When the window is closed, the WorkbenchWindowAdvisor.preWindowShellClose() method is called. If this returns false, then the close request will not be honored. So all we need to do is to override this method; create a TrayItem; hide the window and return false.

trayItem = new TrayItem(Display.getDefault().getSystemTray(), SWT.NONE);
trayItem.setText("My RCP App");
trayItem.setImage(getAppIcon());
trayItem.addSelectionListener(getSelectionListener());
getWindowConfigurer().getWindow().getShell().setVisible(false);
return false;

In the SelectionListener, we can add code to bring up the window:

Shell workbenchWindowShell = getWindowConfigurer().getWindow().getShell();
workbenchWindowShell.setVisible(true);
workbenchWindowShell.setActive();
workbenchWindowShell.setFocus();
workbenchWindowShell.setMinimized(false);
trayItem.dispose();

Simple :-)

More articles :

» Commands Tutorial

As you would have seen, there are two different ways to contributing to the Workbench: Actions and Commands. Although Commands are newer and advanced, I've always preferred using Actions, simply because of my comfort level in using them. Now that...

» A short tutorial on Intro/Welcome

 Welcome page in Eclipse provides you a unique way to introduce your product to the new users. Its very flexible and can be extended by other plugins. You can create the entire Welcome view by yourself by extending the org.eclipse.ui.intro and...

» Remember the State

As a rule of thumb, your application should try to remember the state across sessions. So when a user hits the close button and then opens it after few mins/days, it should present exactly in the same way where he left. In this tip, I'm going to...

» e4: First e4 RCP Application

The next big thing in Eclipse is Eclipse 4.0 dubbed as e4. It will be released in 2010. That doesn't mean that the 3.x stream will be deprecated or discontinued. The 3.x releases will go on for "few" years till everyone boards the 4.0. But clearly...

» Top 10 mistakes in Eclipse Plug-in Development

Having trained a lot of new comers to the Eclipse plug-in development, I've seen certain common mistakes repeated all the time. I've tried to compile a top 10 list of such common mistakes, so next time you hit them, you will know that you are not...

Subscribe To

Unless stated, all the text contents of this site is available under Eclipse Public License