📄 rich client platform part1.mht
字号:
From: <由 Microsoft Internet Explorer 5 保存>
Subject: Rich Client Platform
Date: Sun, 26 Jun 2005 01:14:12 +0800
MIME-Version: 1.0
Content-Type: multipart/related;
boundary="----=_NextPart_000_002A_01C579EC.5D013490";
type="text/html"
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
This is a multi-part message in MIME format.
------=_NextPart_000_002A_01C579EC.5D013490
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Content-Location: http://eclipse.org/articles/Article-RCP-1/tutorial1.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Rich Client Platform</TITLE>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1"><LINK=20
href=3D"http://eclipse.org/articles/default_style.css" rel=3Dstylesheet>
<META content=3D"MSHTML 6.00.2800.1498" name=3DGENERATOR></HEAD>
<BODY>
<DIV align=3Dright><FONT face=3D"Times New Roman, Times, serif" =
size=3D2>Copyright =A9=20
2003-2004 Ed Burnette.</FONT>=20
<TABLE cellSpacing=3D0 cellPadding=3D2 width=3D"100%" border=3D0>
<TBODY>
<TR>
<TD vAlign=3Dtop align=3Dleft bgColor=3D#0080c0 colSpan=3D2><B><FONT =
face=3DArial,Helvetica><FONT color=3D#ffffff>Eclipse=20
Article</FONT></FONT></B></TD></TR></TBODY></TABLE></DIV>
<DIV align=3Dleft>
<H1 title=3D"RCP Tutorial"><IMG height=3D86=20
src=3D"http://eclipse.org/articles/Article-RCP-1/images/Idea.jpg" =
width=3D120=20
align=3Dmiddle></H1></DIV>
<H1 align=3Dcenter>Rich Client Tutorial Part 1</H1>
<P class=3Dsummary>The Rich Client Platform (RCP) is an exciting new way =
to build=20
Java applications that can compete with native applications on any =
platform.=20
This tutorial is designed to get you started building RCP applications=20
quickly.</P>
<P><B>By Ed Burnette, SAS</B><BR><FONT size=3D-1>July 28, =
2004</FONT></P>
<HR width=3D"100%">
<H2>Introduction</H2>
<P>Try this experiment: Show Eclipse to some friends or co-workers who =
haven't=20
seen it before and ask them to guess what language it is written in. =
Chances=20
are, they'll guess VB, C++, or C#, because those languages are used most =
often=20
for high quality client side applications. Then watch the look on their =
faces=20
when you tell them it was created in Java, especially if they are Java=20
programmers.</P>
<P>Because of its unique open source license, you can use the =
technologies that=20
went into Eclipse to create your own commercial quality programs With =
previous=20
version of Eclipse, this was possible but difficult, especially when you =
wanted=20
to heavily customize the menus, layouts, and other user interface =
elements. That=20
was because the "IDE-ness" of Eclipse was hard-wired into it. Version 3=20
introduces the Rich Client Platform, which is basically a refactoring of =
the=20
fundamental parts of Eclipse's UI, allowing it to be used for non-IDE=20
applications.</P>
<P>If you want to cut to the chase and look at the code for this part =
you can=20
use Eclipse's built-in <A =
href=3D"http://dev.eclipse.org/cvshowto.html">CVS=20
client</A> to download the <A=20
href=3D"http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.ui.tutorials=
.rcp.part1">source=20
code</A> to your workspace. Otherwise, let's take a look at how to =
construct an=20
RCP application.</P>
<H2><A name=3Dsection_1></A>Getting started</H2>
<P>RCP applications are based on the familiar Eclipse plug-in =
architecture, (if=20
it's not familiar to you, see the references section). Therefore, you'll =
need to=20
create a plug-in to be your main program. Select New > Project > =
Plug-in=20
Development > Plug-in Project to bring up the Plug-in Project wizard. =
On the=20
subsequent pages, enter a Project name such as=20
<B>org.eclipse.ui.tutorials.rcp.part1</B>, indicate you want a Java =
project, and=20
enter a Plug-in Id (this should match the project name). </P>
<P><IMG height=3D13 alt=3D"Note: "=20
src=3D"http://eclipse.org/articles/Article-RCP-1/images/note.gif" =
width=3D62> Don't=20
select the Alternate Format option that says Create an OSGi bundle =
manifest for=20
the plug-in. See the section on Compatibility and migration for more =
details.=20
</P>
<P>The generated plug-in class that you may be familiar with in previous =
releases is no longer required in Eclipse 3.0. You can still have one to =
hold=20
global data if you like, but for this example just remove it altogether =
to save=20
a little space. To do this, turn off the option that says Generate the =
Java=20
class that controls the plug-ins life cycle. Then Click on Finish to =
generate=20
the template. If you get a dialog asking if Eclipse can switch to the =
Plug-in=20
Development Perspective click Yes (this is optional).</P>
<H2>Plug-in manifest</H2>
<P>The plug-in manifest, plugin.xml, ties all the code and resources =
together.=20
When you first create a plug-in, Eclipse will edit the manifest for you=20
automatically. You need to define the class name of the main program =
with the=20
<CODE>org.eclipse.core.runtime.applications</CODE> extension and the =
perspective=20
with <CODE>org.eclipse.ui.perspectives</CODE>. To add these extensions =
use the=20
Add button on the Extensions tab, or just type in the XML in the =
plugin.xml tab.=20
Also, you need to tell Eclipse that the plug-in will depend on two other =
Eclipse=20
plugins, <CODE>org.eclipse.core.runtime</CODE> and =
<CODE>org.eclipse.ui</CODE>,=20
so those need to be added to the Dependencies tab or in the XML. While =
you're=20
editing it you can change the version number, provider name, and other =
options=20
to your liking. When you're done your plugin.xml should look something =
like=20
listing 1. The classes refered to here will be defined in the next =
section and=20
the tags starting with percents (%) will be defined later in =
plugin.properties.=20
</P>
<P><B>Listing 1. plugin.xml </B></P><PRE><?xml version=3D"1.0" =
encoding=3D"UTF-8"?>
<?eclipse version=3D"3.0"?>
<plugin
id=3D"org.eclipse.ui.tutorials.rcp.part1"
name=3D"%pluginName"
version=3D"0.0.0"
provider-name=3D"%providerName">
<runtime>
<library name=3D"part1.jar">
<export name=3D"*"/>
</library>
</runtime>
<requires>
<import plugin=3D"org.eclipse.core.runtime"/>
<import plugin=3D"org.eclipse.ui"/>
</requires>
<extension
id=3D"RcpApplication"
point=3D"org.eclipse.core.runtime.applications">
<application>
<run
=
class=3D"org.eclipse.ui.tutorials.rcp.part1.RcpApplication">
</run>
</application>
</extension>
<extension
point=3D"org.eclipse.ui.perspectives">
<perspective
name=3D"%perspectiveName"
class=3D"org.eclipse.ui.tutorials.rcp.part1.RcpPerspective"
id=3D"org.eclipse.ui.tutorials.rcp.part1.RcpPerspective">
</perspective>
</extension>
</plugin>
</PRE>
<P><IMG height=3D13 alt=3D"Note: "=20
src=3D"http://eclipse.org/articles/Article-RCP-1/images/note.gif" =
width=3D62>=20
Although it's not an absolute requirement, I recommend keeping your id's =
and=20
your class names the same. For example,=20
<CODE>org.eclipse.ui.tutorials.rcp.part1.RcpApplication</CODE> is both =
the fully=20
qualified id for the application and the class name of the main program. =
For=20
historical reasons, Eclipse prepends the plug-in's id to the id of your =
top=20
level plug-in elements (like <CODE>extension</CODE>) so even though =
plugin.xml=20
says <CODE>id=3D"RcpApplication"</CODE> the fully qualified id for that =
extension=20
is <CODE>org.eclipse.ui.tutorials.rcp.part1.RcpApplication</CODE>. Since =
the=20
perspective's id is written on a sub-element (<CODE>perspective</CODE>) =
it has=20
to be spelled out completely in the manifest=20
(<CODE>org.eclipse.ui.tutorials.rcp.part1.RcpPerspective</CODE>). </P>
<H2>The main program</H2>
<P>The <CODE>org.eclipse.core.runtime.applications</CODE> extension =
tells the=20
Eclipse runtime the name of your main program. Create a new Java class =
with that=20
name, make it implement <CODE>IPlatformRunnable</CODE>, and put your =
program=20
code in the <CODE>run()</CODE> method. Listing 2 shows a simple =
implementation=20
with the minimum you have to do. The <CODE>RcpWorkbenchAdvisor</CODE> =
class will=20
be defined shortly. </P>
<P><B>Listing 2. RcpApplication class </B></P><PRE>package =
org.eclipse.ui.tutorials.rcp.part1;
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 RcpApplication implements IPlatformRunnable {
public Object run(Object args) {
WorkbenchAdvisor workbenchAdvisor =3D new RcpWorkbenchAdvisor();
Display display =3D PlatformUI.createDisplay();
try {
int returnCode =3D PlatformUI.createAndRunWorkbench(display,
workbenchAdvisor);
if (returnCode =3D=3D PlatformUI.RETURN_RESTART) {
return IPlatformRunnable.EXIT_RESTART;
} else {
return IPlatformRunnable.EXIT_OK;
}
} finally {
display.dispose();
}
}
}
</PRE>
<H2>Creating a default perspective</H2>
<P>Next, you must define at least one perspective and make it the =
default.=20
Perspectives are created by implementing =
<CODE>IPerspectiveFactory</CODE> using=20
the class name referred to by the =
<CODE>org.eclipse.ui.perspectives</CODE>=20
extension (see listing 3). The important part of this interface is the=20
<CODE>createInitialLayout()</CODE> method where you position and open =
any views=20
and/or editors you'd like the user to start with. In this example we're =
not=20
going to create any views so it will be a pretty boring perspective. =
</P>
<P><B>Listing 3. RcpPerspective class </B></P><PRE>package =
org.eclipse.ui.tutorials.rcp.part1;
import org.eclipse.ui.IPageLayout;
import org.eclipse.ui.IPerspectiveFactory;
public class RcpPerspective implements IPerspectiveFactory {
public RcpPerspective() {
}
public void createInitialLayout(IPageLayout layout) {
}
}
</PRE>
<H2>Workbench Advisor</H2>
<P>The Workbench Advisor class, which you referred to in the main =
program, helps=20
customize the workbench to add and subtract toolbars, perspectives, and =
so=20
forth. This will covered in more detail in part 2 of the tutorial. For =
now, the=20
absolute minimum you have to do here is define which perspective is the =
default=20
one. See listing 4 for the code. </P>
<P><B>Listing 4. RcpWorkbenchAdvisor class </B></P><PRE>package =
org.eclipse.ui.tutorials.rcp.part1;
import org.eclipse.ui.application.WorkbenchAdvisor;
public class RcpWorkbenchAdvisor extends WorkbenchAdvisor {
public String getInitialWindowPerspectiveId() {
return "org.eclipse.ui.tutorials.rcp.part1.RcpPerspective";
}
}
</PRE>
<H2>Miscellaneous</H2>
<P>The build.properties file (see listing 5) will be needed when =
exporting the=20
application for others to use.</P>
<P><B>Listing 5. build.properties </B></P><PRE>bin.includes =3D =
plugin.xml,\
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -