1、附录 ( 英文翻译 ) Rich Client Tutorial Part 1 The Rich Client Platform (RCP) is an exciting new way to build Java applications that can compete with native applications on any platform. This tutorial is designed to get you started building RCP applications quickly. It has been updated for Eclipse 3.1.2 By
2、 Ed Burnette, SAS July 28, 2004 Updated for 3.1.2: February 6, 2006 Introduction Try this experiment: Show Eclipse to some friends or co-workers who havent seen it before and ask them to guess what language it is written in. Chances are, theyll guess VB, C+, or C#, because those languages are used m
3、ost often for high quality client side applications. Then watch the look on their faces when you tell them it was created in Java, especially if they are Java programmers. Because of its unique open source license, you can use the technologies that went into Eclipse to create your own commercial qua
4、lity programs. Before version 3.0, this was possible but difficult, especially when you wanted to heavily customize the menus, layouts, and other user interface elements. That was because the IDE-ness of Eclipse was hard-wired into it. Version 3.0 introduced the Rich Client Platform (RCP), which is
5、basically a refactoring of the fundamental parts of Eclipses UI, allowing it to be used for non-IDE applications. Version 3.1 updated RCP with new capabilities, and, most importantly, new tooling support to make it easier to create than before. If you want to cut to the chase and look at the code fo
6、r this part you can find it in the accompanying zip file. Otherwise, lets take a look at how to construct an RCP application. Getting started RCP applications are based on the familiar Eclipse plug-in architecture, (if its not familiar to you, see the references section). Therefore, youll need to cr
7、eate a plug-in to be your main program. Eclipses Plug-in Development Environment (PDE) provides a number of wizards and editors that take some of the drudgery out of the process. PDE is included with the Eclipse SDK download so that is the package you should be using. Here are the steps you should f
8、ollow to get started. First, bring up Eclipse and select File New Project, then expand Plug-in Development and double-click Plug-in Project to bring up the Plug-in Project wizard. On the subsequent pages, enter a Project name such as org.eclipse.ui.tutorials.rcp.part1, indicate you want a Java proje
9、ct, select the version of Eclipse youre targeting (at least 3.1), and enable the option to Create an OSGi bundle manifest. Then click Next. Beginning in Eclipse 3.1 you will get best results by using the OSGi bundle manifest. In contrast to previous versions, this is now the default. In the next pag
10、e of the Wizard you can change the Plug-in ID and other parameters. Of particular importance is the question, Would you like to create a rich client application?. Select Yes. The generated plug-in class is optional but for this example just leave all the other options at their default values. Click
11、Next to continue. If you get a dialog asking if Eclipse can switch to the Plug-in Development Perspective click Remember my decision and select Yes (this is optional). Starting with Eclipse 3.1, several templates have been provided to make creating an RCP application a breeze. Well use the simplest
12、one available and see how it works. Make sure the option to Create a plug-in using one of the templates is enabled, then select the Hello RCP template. This is RCPs equivalent of Hello, world. Click Finish to accept all the defaults and generate the project (see Figure 1). Eclipse will open the Plug
13、-in Manifest Editor. The Plug-in Manifest editor puts a friendly face on the various configuration files that control your RCP application. Figure 1. The Hello World RCP project was created by a PDE wizard. Taking it for a spin Trying out RCP applications used to be somewhat tedious. You had to crea
14、te a custom launch configuration, enter the right application name, and tweak the plug-ins that were included. Thankfully the PDE keeps track of all this now. All you have to do is click on the Launch an Eclipse Application button in the Plug-in Manifest editors Overview page. You should see a bare-bones Workbench start up (see Figure 2).