Get started with RCP (Rich Client Platform) (4)

xiaoxiao2021-03-06  116

4, define the WorkbenChadvisor class and Application class

(1) Creating a WorkbenChadvisor class

l The core task of building an RCP application is to create a class that implements abstract class org.eclipse.ui.Application.Workbenchadvisor

l The WorkbenChadvisor class is responsible for configuring the workbench displayed when executing the RCP application

Package com.xqtu.google;

Import org.eclipse.ui.Application.iworkbbenchwindowconfigure;

Import org.eclipse.ui.Application.workbenchadvisor;

Import org.eclipse.swt.graphics.point;

Public class GoogleworkBenchadvisor Extends Workbenchadvisor {

Public string getinitialWindowPERSPECTIVEID () {

Return "com.xqtu.google.googlePerspective";

}

Public void Prewindowen (iWorkbenchWindowconfigurer Configure) {

Super.prewindowopen (Configure);

Configurer.Settitle ("Google");

Configurer.setInitialSize (New Point (300, 300));

Configurer.SetShowmenUbar (FALSE);

Configurer.SetShowStatusline (false);

Configurer.SetShowCoolbar (False);

}

}

l In the GetInitialWindowPerspectiveID () method, returns the identifier of the initial perspective to the new worktural window window.

l Increase the preWindowOpen () method, set the window title and size of the workbench

(2) Creating an Application class

l Before performing an application, you need to create an Application class, which is similar to the main method in the Java class, which is the entry point of the RCP application.

l This type needs to implement org.eclipse.core.Runtime.iplatformRunnable interface

Package com.xqtu.google;

Import org.eclipse.core.runtime.iplatformrunnable;

Import org.eclipse.swt.widgets.display;

Import org.eclipse.ui.platformui;

Import org.eclipse.ui.Application.workbenchadvisor;

Public class GoogleApplication Implements iplatformrunnable {

Public Object Run (Object Args) throws Exception {

Workbenchadvisor Workbenchadvisor = New GoogleworkBenchadvisor ();

Display Display = platformui.createdISPlay ();

Int returncode = platformui.createAndrunworkbench (Display,

Workbenchadvisor;

if (ReturnCode == Platformui.Return_Restart) {Return iPlatformRunnable.exit_Restart;

} else {

Return iPlatformRunnable.exit_ok;

}

}

}

l The Run () method of most of the RCP applications does not need to be customized, and reuse

L As shown in the previous, you need to specify the APPLICATION class that is running in Plugin.xml org.eclipse.core.Runtime.Applications extension point

ID = "GoogleApplication"

Point = "org.eclipse.core.runtime.Applications">

(3) Run the application

l Run> RUN ...

l Select Run-Time Workbench in the Configurations list and click the New button.

l Type Google in the NAME field

l On the Arguments page, select Google.googleApplication in the Run An Application drop-down box.

l Click on the Plug-INS page, select Choose Plug-Ins and Fragments to Launch from the List

l Click the DeSelect all button

l Select the Workspace Plug-INS option contains the choice of Google items.

l Click the Add Required Plug-INS button to automatically contain the plugins that perform the application

l Click the Apply button

l Click the Run button to execute the application

l If all configurations are properly configured, a window titled "Google" should be displayed, this is a normal workbench frame

转载请注明原文地址:https://www.9cbs.com/read-125347.html

New Post(0)