Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Back to the Basics: Display, Shell, Window ...

DZone's Guide to

Back to the Basics: Display, Shell, Window ...

· Java Zone
Free Resource

Navigate the Maze of the End-User Experience and pick up this APM Essential guide, brought to you in partnership with CA Technologies

Every Eclipse plugin developer has to deal with Shell and Window, but sometimes doesn't understand the difference between these two. In this tip, I'm trying to explain the basic things: Display, Shell, Window, Dialog, Workbench, WorkbenchPart, WorkbenchSite and WorkbenchPage. Yeah, I know, its probably the boring post you can read in this blog, if you are little bit experienced in these areas.

Display:

This class is the link between SWT and the underlying OS. It manages the interaction between widgets and the OS. The primary task for this class is to maintain the event loop ( readAndDispatch()). Unless you are writing a plain SWT app, you won't be using that. The most common methods you would be using in this class are asyncExec(), syncExec() and timerExec(), which allows you to run a piece of code in the UI thread. (aka user interface thread or display thread)

Shell:

Shell is the "window" that you see in your desktop. The one that has a title, maximize, minimize, restore and close buttons. A shell can be either a top-level shell (no parent shell) or can be a secondary shell (will have a parent shell). The style that is passed in the constructor defines which of the above mentioned buttons are displayed and also whether the Shell is modal or not. If you are on a pure SWT app, then you should be create a Shell; create controls in it; open it; run the event loop; and dispose it. Speaking in code:

Shell shell = new Shell(display);
// set layout and create widgets
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();

Window:

If you are developing plugins/JFace applications, its better to use Window rather than Shells directly, because it manages the above things for you. It is not, but think it of as a wrapper for Shell. When you use a Window, a Shell is not created until the open() method is called. Since the Shell is not created till the Window is open and windows can be reopened (yes, you can reopen it), configuration of the Shell should be done in the configureShell() method. Remember, this is an abstract class and so you cannot directly use it. You must either use Dialog or ApplicationWindow or your own concrete class.

Dialog:

When you need a specialized communication with the user, you should be using Dialogs. In all other cases, you will be using ApplicationWindow. Dialog are more of helper windows that are attached to another main window. PreferenceDialog, PropertyDialog, ErrorDialog, InputDialog & WizardDialog are some frequently used dialogs.

ApplicationWindow:

Window + menu support + toolbar support + coolbar support + status line support = ApplicationWindow :-)

IWorkbenchWindow:

WorkbenchWindow is Eclipse specific ApplicationWindow, which adds few services and a set of IWorkbenchPages to the ApplicationWindow. Although the javadoc says "Each workbench window has a collection of 0 or more pages", in reality it has only one page. I believe this is due to backward compatibility with Eclipse 1.0.

IWorkbenchPage:

The area that lies between the toolbar and the status line of the WorkbenchWindow is known as WorkbenchPage. Simply put, this is the body of the WorkbenchWindow, where all the editors and views are showed. IWorkbenchPage contains IWorkbenchParts, which are the the visual representation of the Views and Editors. Both IViewPart and IEditorPart derive from IWorkbenchPart

IWorkbenchSite:

IWorkbenchPart resides inside the IWorkbenchPage. So it has no direct access to the workbench itself. So when it needs to interact with the workbench, then it needs the IWorkbenchSite. For example to get the shell inside a view, you call getSite().getShell().

From http://blog.eclipse-tips.com/

Thrive in the application economy with an APM model that is strategic. Be E.P.I.C. with CA APM.  Brought to you in partnership with CA Technologies.

Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}