⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rich client platform part2.mht

📁 Rich Client Tutorial
💻 MHT
📖 第 1 页 / 共 5 页
字号:
From: <由 Microsoft Internet Explorer 5 保存>
Subject: Rich Client Platform
Date: Sun, 26 Jun 2005 01:13:24 +0800
MIME-Version: 1.0
Content-Type: multipart/related;
	boundary="----=_NextPart_000_0000_01C579EC.3FE433D0";
	type="text/html"
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441

This is a multi-part message in MIME format.

------=_NextPart_000_0000_01C579EC.3FE433D0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Content-Location: http://eclipse.org/articles/Article-RCP-2/tutorial2.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
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-2/images/Idea.jpg" =
width=3D120=20
align=3Dmiddle></H1></DIV>
<H1 align=3Dcenter>Rich Client Tutorial Part 2</H1>
<P class=3Dsummary>The Rich Client Platform (RCP) allows you to build =
Java=20
applications that can compete with native applications on any platform. =
Part 1=20
of the tutorial introduced you to the platform and the steps used to =
build the=20
smallest possible RCP program. In part 2 we'll look at what we did in =
more=20
detail and introduce some of the configuration classes that let you take =
control=20
of much of the layout and functionality of an RCP application. </P>
<P><B>By Ed Burnette, SAS</B><BR><FONT size=3D-1>August 9, =
2004</FONT></P>
<HR width=3D"100%">

<H2>Introduction</H2>
<P>In Eclipse 2.1, many functions of the Eclipse IDE were hard-wired =
into the=20
code. These included the name and location of the File menu, the title =
of the=20
Workbench Window, and the existence of the status bar. This was fine for =
the IDE=20
but when people started to use Eclipse as a basis for non-IDE programs,=20
sometimes these things didn't make sense. Although all the source code =
was=20
provided, it was inconvenient to find the right places that had to be =
changed.=20
So for Eclipse 3, the designers refactored the API to make these and =
other=20
hard-wired aspects of the user interface controllable through public =
API. </P>
<P>To this end, Eclipse 3 introduces a brand new =
<CODE>WorkbenchAdvisor</CODE>=20
class and a set of <CODE>*Configurer</CODE> interfaces. The most =
important class=20
for an RCP developer to understand is <CODE>WorkbenchAdvisor</CODE>. You =
extend=20
the base version of the <CODE>WorkbenchAdvisor</CODE> class in your RCP=20
application and override one or more of the methods to set whatever =
options you=20
want. In part 1, we implemented one of the simpler methods,=20
<CODE>getInitialWindowPerspectiveId</CODE>, in order to return the one =
and only=20
perspective (set of views, editors, and menus) for the application. </P>
<P>In the next section we'll take a look at the other advisor methods to =
get a=20
quick overview of what is possible with them. If you want to cut to the =
chase=20
and look at or download the code for this part you can view the <A=20
href=3D"http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.ui.tutorials=
.rcp.part2">Eclipse=20
project here</A>. </P>
<P>Otherwise, let's start by clearing up some possible confusion about =
the=20
relationship between Applications, Workbenches, and Workbench Windows. =
</P>
<H2>Applications, Workbenches, and Workbench Windows</H2>
<P>The Application is a class you create that acts as your RCP program's =
main=20
routine. You can think of it as the controller for the program. Just =
like the=20
controller in a Model2 architecture, it is short and sweet and doesn't =
change=20
significantly for different projects. All it does is create a Workbench =
and=20
attach a Workbench Advisor to it. </P>
<P>The Workbench is declared and maintained for you as part of the RCP=20
framework. There is only one Workbench but it can have more than one =
visible=20
top-level Workbench Window. For example, in the Eclipse IDE, when you =
first=20
start Eclipse you will see one Workbench Window, but if you select =
<B>Window=20
&gt; New Window</B> a second window pops up -- two Workbench Windows, =
but only=20
one Workbench. </P>
<P>Figure 1 shows the relationship between your Application, the =
Workbench, and=20
Workbench Windows. </P><IMG=20
src=3D"http://eclipse.org/articles/Article-RCP-2/images/Application.png">=
=20
<P><B>Figure 1. An RCP program has one Application class that you =
provide, and=20
one Workbench class provided by the framework. Typically there is only =
one=20
Workbench Window but the framework supports having more than one. =
</B></P>
<P>Ok, now that that's out of the way, let's get our feet wet with =
changing how=20
the Workbench Window looks. </P>
<H2>Customizing the Workbench Window</H2>
<P>The simple example in part 1 left room for a status line, tool bar, =
and other=20
visual elements even though they weren't used. We could argue that those =
should=20
be off by default, but for some reason they're not so if you don't want =
them=20
then you have to turn them off yourself. Also the window didn't have a =
title and=20
it opened much larger than it needed to be. A good place to take care of =
all=20
this is the <CODE>preWindowOpen</CODE> method of =
<CODE>WorkbenchAdvisor</CODE>,=20
as shown in listing 1. </P>
<P><B>Listing 1. preWindowOpen example. </B></P><PRE>    public void =
preWindowOpen(IWorkbenchWindowConfigurer configurer) {
        super.preWindowOpen(configurer);
        configurer.setInitialSize(new Point(400, 300));
        configurer.setShowCoolBar(false);
        configurer.setShowStatusLine(false);
        configurer.setTitle("Hello, RCP");
    }
</PRE>
<P>Notice how a Configurer interface (in this case,=20
<CODE>IWorkbenchWindowConfigurer</CODE>) is passed in to the advisor =
method. You=20
call methods on the Configurer interfaces to actually change the =
options. These=20
interfaces are not covered in any detail in this tutorial but you can =
refer to=20
their Javadoc for more information. See figure 2 for the final result. =
</P><IMG=20
src=3D"http://eclipse.org/articles/Article-RCP-2/images/hellotitle.png"> =

<P><B>Figure 2. Workbench window with a title. Unused controls are =
turned off=20
and a title is added using the <CODE>preWindowOpen</CODE> event of=20
<CODE>WorkbenchAdvisor</CODE>. </B></P>
<H2>Digging into the WorkbenchAdvisor class</H2>
<P>Since RCP is new and documentation is sparse, we're going to depart =
from our=20
tutorial format at this point to examine some background information =
about the=20
<CODE>WorkbenchAdvisor</CODE> class. Methods in this class are called =
from the=20
platform to notify you at every point in the lifecycle of the Workbench =
and top=20
level Workbench Windows. They also provide a way to handle exceptions in =
the=20
event loop, and provide important parameters to the Workbench such as =
the=20
default perspective. First let's take a look at the lifecycle events. =
</P>
<P><IMG height=3D13 alt=3D"Note: "=20
src=3D"http://eclipse.org/articles/Article-RCP-2/images/note.gif" =
width=3D62> Why=20
not an interface? You'll notice that <CODE>WorkbenchAdvisor</CODE> is an =

abstract class. For the most part, Eclipse APIs shun abstract classes in =
favor=20
of interfaces and base classes that implement those interfaces. In this =
case,=20
the designers intend for <CODE>WorkbenchAdvisor</CODE> to <I>always</I> =
be=20
implemented by the RCP application, the base class doesn't contain any=20
significant functionality, and it is very likely that new methods will =
need to=20
be added to the base class in the future (something that is difficult =
using=20
interfaces). So this was a deliberate design choice. See the article on =
evolving=20
Java APIs in the reference section for more tips. </P>
<H3>Lifecycle events</H3>
<P>There is only one Workbench, and typically there is also only one =
Workbench=20
Window, though you can open more than one if you like (on different =
monitors for=20
example). See figure 3 for the most important events in the lifetime of=20
Workbenches and their windows. Table 1 shows all the methods that you =
can define=20
in your own subclass of <CODE>WorkbenchAdvisor</CODE> to let you hook =
into=20
lifecycle events for the Workbench. Table 2 shows the corresponding =
methods for=20
Workbench Windows. </P><IMG=20
src=3D"http://eclipse.org/articles/Article-RCP-2/images/Lifecycle.png">=20
<P><B>Figure 3. Important events in the lifecycle of the Workbench and =
Workbench=20
Window(s). These correspond to methods in <CODE>WorkbenchAdvisor</CODE> =
that are=20
called by the Platform to let you perform custom code at these points in =
time.=20
</B></P>
<P><B>Table 1. Workbench lifecycle hooks provided by=20
<CODE>org.eclipse.ui.application.WorkbenchAdvisor</CODE>. </B></P>
<TABLE border=3D1>
  <TBODY>
  <TR>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -