Eclipse RCP application - multi-window design for multiple monitors
Asked Answered
G

1

5

Question about Eclipse RCP and whole perspective/view/editor design - what is the best way to create application which will display multiple windows on multiple monitors? Tutorials and book I've seen always pack RCP/SWT design into views inside perspective within single application window.

Should one window rule all others or they all should be equal (closing last one exits application)? How deal with the perspectives and views? Are there any other things we should know?

Environment: Eclipse Ganymede, Windows XP.

Guardroom answered 26/3, 2009 at 15:26 Comment(0)
U
7

A single Eclipse workbench can create multiple windows. Each window is laid out using a perspective, so different windows could be set to different perspectives, or the same perspective, and you can switch perspectives in each window independently of the other windows.

You can also set input for each window. This is useful if each window is working on different data (for example, each window could be connected to a different server or could be showing data from different databases that all have the same schema but different data).

It may be that you are using windows only so that you can see different perspectives of the same data on different monitors. In that case you do not need to programatically create the windows but need only add the action supplied by the workbench. This can be done by modifying your ActionBarAdvisor class:

add to the field declarations:

private IWorkbenchAction newWindowAction;

add to the code where you make the actions (typically a method called makeActions):

    newWindowAction = ActionFactory.OPEN_NEW_WINDOW.create(window);
    register(newWindowAction);

add to the code where you create the menus:

    menu.add(newWindowAction);

where menu is typically the Window menu. If you don't have a Window menu already in your application and would like to create one, the following line will work:

    MenuManager menu = new MenuManager(
      "&Window", 
      IWorkbenchActionConstants.M_WINDOW);

This will give you a menu item that will create a new window in the same way as the Window->New Window menu item in the Eclipse IDE.

If, on the other hand, you want each window to show different data then you will need to open the new windows programatically. This allows you to set different input for each window. You will need a line of code something like:

IWorkbenchPage newPage = window.openPage(inputObject);

where inputObject contains information that identifies the data shown in the window. If you want to set the initial perspective this can be done by calling setPerspective on the page.

You will want to set the title in each window:

newPage.getWorkbenchWindow().getShell().setText(windowTitle);

where windowTitle is a string describing the input to the window.

You can fetch the input for a window as follows:

window.getActivePage().getInput()

You can then cast this to whatever class you are using as your window input.

Unmistakable answered 31/3, 2009 at 23:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.