Eclipse RCP应用程序-用于多个监视器的多窗口设计(Eclipse RCP application - multi-window design for multiple monitors)

17 IT屋

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.

解决方案

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.

有关Eclipse RCP和整个透视图/视图/编辑器设计的问题-创建在多个显示器上显示多个窗口的应用程序的最佳方法是什么?我见过的教程和书总是将RCP / SWT设计打包到单个应用程序窗口的透视图中。



应该由一个窗口来统治所有其他窗口,否则它们应该相等(关闭最后一个退出应用程序)?如何处理观点和观点?还有什么我们应该知道的吗?



环境:Eclipse Ganymede,Windows XP。


解决方案

单个Eclipse工作台可以创建多个窗口。每个窗口都使用透视图进行布局,因此可以将不同的窗口设置为不同的透视图或相同的透视图,并且可以独立于其他窗口在每个窗口中切换透视图。



您还可以为每个窗口设置输入。如果每个窗口正在处理不同的数据(例如,每个窗口可以连接到不同的服务器,或者可能显示来自具有相同模式但不同数据的不同数据库的数据),则此功能很有用。



可能是您仅使用Windows,因此您可以在不同的显示器上看到相同数据的不同视角。在这种情况下,您无需以编程方式创建窗口,而只需添加工作台提供的操作。这可以通过修改ActionBarAdvisor类来完成:



添加到字段声明中:



 < code> private IWorkbenchAction newWindowAction; 


添加到执行操作的代码中(通常称为makeActions的方法):



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


添加到创建菜单的代码中:



  menu.add(newWindowAction); 


其中的菜单通常是"窗口"菜单。如果您的应用程序中没有Window菜单,并且想创建一个Window菜单,那么以下行将起作用:



  MenuManager菜单=新的MenuManager(
"& Window",
IWorkbenchActionConstants.M_WINDOW);


这将为您提供一个菜单项,该菜单项将以与Window- > Eclipse中的"新建窗口"菜单项。



另一方面,如果您希望每个窗口显示不同的数据,则需要以编程方式打开新窗口。这使您可以为每个窗口设置不同的输入。您将需要以下代码行:



  IWorkbenchPage newPage = window.openPage(inputObject); 


其中inputObject包含标识窗口中显示的数据的信息。如果要设置初始视角,可以通过在页面上调用setPerspective来完成。



您需要在每个窗口中设置标题:



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


其中windowTitle是描述窗口输入的字符串。



您可以按如下方式获取窗口的输入:



  window.getActivePage()。getInput() 


然后可以将其强制转换为您用作窗口输入的任何类。


本文地址:IT屋 » Eclipse RCP应用程序-用于多个监视器的多窗口设计