Wednesday, November 11, 2009

Section 15.3.  WorkbenchWindowAdvisor










15.3. WorkbenchWindowAdvisor


In Hyperbola, WorkbenchWindowAdvisor plays a more visible role than WorkbenchAdvisor. It configures the window's title, the visibility of the menu bar, toolbar, and status line, and many more things. Essentially, this advisor controls the appearance of each Workbench window.


The methods on WorkbenchWindowAdvisor relate to the lifecycle of the window instead of the Workbench's lifecycle. Within the lifecycle methods, the advisor can configure the window via its IWorkbenchWindowConfigurer. Think of the configurer as providing special APIs that allow the advisor to fine-tune elements of the WorkbenchWindow that are not available via the standard IWorkbenchWindow APIs. As such, the configurer has several useful methods such as setInitialSize(Point), setShowToolbar(boolean), setTitle(String), and setShowMenuBar(boolean). The following snippet shows a typical use of this advisor:


org.eclipsercp.hyperbola/ApplicationWorkbenchWindowAdvisor
public void preWindowOpen() {
IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
configurer.setInitialSize(new Point(400, 300));
configurer.setShowCoolBar(true);
configurer.setShowStatusLine(true);
configurer.setShowMenuBar(true);
}

public void dispose() {
statusImage.dispose();
trayImage.dispose();
trayItem.dispose();
}

public void postWindowOpen() {
initStatusLine();
final IWorkbenchWindow window = getWindowConfigurer().getWindow();
trayItem = initTaskItem(window);
if (trayItem != null) {
hookPopupMenu(window);
hookMinimize(window);
}
}


The Hyperbola WorkbenchWindowAdvisor overrides a few methods such as:


preWindowOpen() Configures the parts of the window that should be visible and sets the initial window size, as shown in the snippet above.

postWindowOpen() Configures things that need the window to be created, for example, to set up system tray integration.


Working through the tutorial in Part II is the best way to understand how a WorkbenchWindowAdivsor is used. For more advanced Workbench window customization, see Chapter 18, "Customizing Workbench Windows," and Chapter 19, "Customizing the Presentation of Views and Editors."



15.3.1. IWorkbenchWindowConfigurer


As shown in the previous code snippet, the window's configurer is most often used in the WorkbenchWindowAdvisor to show and hide items in the window. It can also be used to:


  • Set and get properties on the configurer using the setData(String, Object) and geTData(String) methods. This is useful for passing data from this advisor to the ActionBarAdvisor.

  • Allow the advisor to create the menu, toolbar, and status line itself and arrange these controls in different ways. See Chapter 17, "Actions," for examples of using these methods with Hyperbola.

  • Configure the drag and drop behavior of the editor's area. See Section 16.4, "Drag and Drop with Editors."













No comments:

Post a Comment