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

📄 rich client platform part3.mht

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

This is a multi-part message in MIME format.

------=_NextPart_000_0011_01C579EC.52DCC510
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Content-Location: http://eclipse.org/articles/Article-RCP-3/tutorial3.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-3/images/Idea.jpg" =
width=3D120=20
align=3Dmiddle></H1></DIV>
<H1 align=3Dcenter>Rich Client Tutorial Part 3</H1>
<P class=3Dsummary>The Rich Client Platform (RCP) lets you pick and =
choose=20
functionality from Eclipse for use in your own applications. Parts 1 and =
2 of=20
this tutorial introduced you to the platform and some of the =
configuration=20
classes it provides. Part 3 discusses how to add functionality such as =
menus,=20
views, and help files. </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>Much of our discussion in the previous two parts focused on taking =
things=20
away from the platform - turning off toolbars, getting rid of menus, and =
so=20
forth. For this installment we're going to look at putting things back =
in. All=20
source code for the tutorial can be downloaded from the <A=20
href=3D"http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.ui.tutorials=
.rcp.part3">Eclipse=20
project here</A>. </P>
<H2>Views</H2>
<P>Let's start with a view. Eclipse's Plug-in Development Environment =
provides a=20
nice set of extension templates to get you started writing sample views, =

editors, menus, and other components. Unfortunately, as of this writing, =
they=20
are almost useless for RCP development because the code produced =
introduces all=20
sorts of dependencies on IDE and resource packages and plug-ins. </P>
<P><IMG height=3D13 alt=3D"Tip: "=20
src=3D"http://eclipse.org/articles/Article-RCP-3/images/tip.gif" =
width=3D62> The=20
rule of thumb is that anything that references a resource is not =
intended for=20
RCP developers because of the extra code and dependencies on workspaces =
it pulls=20
in. So if you see the <CODE>org.eclipse.core.resources</CODE> plug-in in =
your=20
dependency list, or see an import for some class from that package, =
you're=20
probably doing something wrong. This is not a hard and fast rule though, =
so=20
resources should be considered an <I>optional</I> part of the Rich =
Client=20
Platform. </P>
<P>To create a view without the templates, you can use the schema-based=20
extension wizards from the Plug-in Manifest editor (Extensions pane &gt; =
Add=20
&gt; Generic Wizards &gt; Schema-based Extensions) or simply edit the =
XML in the=20
Source pane. Either way, you want to end up with extension XML like =
this: </P><PRE>	&lt;extension
	      point=3D"org.eclipse.ui.views"&gt;
	   &lt;category
	         name=3D"SampleCategory"
<IMG height=3D13 alt=3D#1 =
src=3D"http://eclipse.org/articles/Article-RCP-3/images/tag_1.gif" =
width=3D24 align=3Dcenter>	         =
id=3D"org.eclipse.ui.tutorials.rcp.part3.viewCategory"&gt;
	   &lt;/category&gt;
	   &lt;view
	         name=3D"Sample"
	         icon=3D"icons/sample.gif"
	         category=3D"org.eclipse.ui.tutorials.rcp.part3.viewCategory"
<IMG height=3D13 alt=3D#2 =
src=3D"http://eclipse.org/articles/Article-RCP-3/images/tag_2.gif" =
width=3D24 align=3Dcenter>	         =
class=3D"org.eclipse.ui.tutorials.rcp.part3.views.SampleView"
	         id=3D"org.eclipse.ui.tutorials.rcp.part3.views.SampleView"&gt;
	   &lt;/view&gt;
	&lt;/extension&gt;
</PRE>
<P>The view category (<IMG height=3D13 alt=3D#1=20
src=3D"http://eclipse.org/articles/Article-RCP-3/images/tag_1.gif" =
width=3D24=20
align=3Dcenter>) is a way to organize your views in the Show Views =
dialog. The=20
class (<IMG height=3D13 alt=3D#2=20
src=3D"http://eclipse.org/articles/Article-RCP-3/images/tag_2.gif" =
width=3D24=20
align=3Dcenter>) extends the <CODE>ViewPart</CODE> abstract class as =
shown below:=20
</P><PRE>	public class SampleView extends ViewPart {
<IMG height=3D13 alt=3D#1 =
src=3D"http://eclipse.org/articles/Article-RCP-3/images/tag_1.gif" =
width=3D24 align=3Dcenter>	    public static final String ID_VIEW =3D
	        "org.eclipse.ui.tutorials.rcp.part3.views.SampleView"; =
//$NON-NLS-1$
=09
	    private TableViewer viewer;
=09
	    public SampleView() {
	    }
=09
<IMG height=3D13 alt=3D#2 =
src=3D"http://eclipse.org/articles/Article-RCP-3/images/tag_2.gif" =
width=3D24 align=3Dcenter>	    public void createPartControl(Composite =
parent) {
	        viewer =3D
	            new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | =
SWT.V_SCROLL);
	        viewer.setContentProvider(new ViewContentProvider());
	        viewer.setLabelProvider(new ViewLabelProvider());
	        viewer.setInput(this);
	    }
=09
	    public void setFocus() {
	        viewer.getControl().setFocus();
	    }
	}
</PRE>
<P>Defining constants that start with <CODE>ID_</CODE> (<IMG height=3D13 =
alt=3D#1=20
src=3D"http://eclipse.org/articles/Article-RCP-3/images/tag_1.gif" =
width=3D24=20
align=3Dcenter>) is a pattern you'll see used over and over again in the =
Eclipse=20
source code. Here we use it to duplicate the same id used in the plug-in =

manifest. This will be used later when we need a reference to the view. =
</P>
<P>The most important part of this class is the =
<CODE>createPartControl</CODE>=20
method (<IMG height=3D13 alt=3D#2=20
src=3D"http://eclipse.org/articles/Article-RCP-3/images/tag_2.gif" =
width=3D24=20
align=3Dcenter>). It's where you create your JFace or SWT controls that =
make up=20
the view. The rest of the source was can be found in the example =
project. View=20
programming is beyond the scope of this tutorial but you can see the =
reference=20
section for more information. </P>
<H2>Perspective additions</H2>
<P>If you run the code now you won't actually see anything different. =
Why?=20
Because your new view can't appear unless it is added to the current=20
perspective. You can do this through code or though the=20
org.eclipse.ui.perspectiveExtensions extension. We'll choose the former =
because=20
it's a little more flexible. To do this, go back to the=20
<CODE>RcpPerspective</CODE> class defined earlier and modify it to look =
like=20
this: </P><PRE>	public class RcpPerspective implements =
IPerspectiveFactory {
<IMG height=3D13 alt=3D#1 =
src=3D"http://eclipse.org/articles/Article-RCP-3/images/tag_1.gif" =
width=3D24 align=3Dcenter>	    public static final String ID_PERSPECTIVE =
=3D
	        "org.eclipse.ui.tutorials.rcp.part3.RcpPerspective"; =
//$NON-NLS-1$
=09
	    public RcpPerspective() {
	    }
=09
	    public void createInitialLayout(IPageLayout layout) {
<IMG height=3D13 alt=3D#2 =
src=3D"http://eclipse.org/articles/Article-RCP-3/images/tag_2.gif" =
width=3D24 align=3Dcenter>	        layout.setEditorAreaVisible(false);
<IMG height=3D13 alt=3D#3 =
src=3D"http://eclipse.org/articles/Article-RCP-3/images/tag_3.gif" =
width=3D24 align=3Dcenter>	        layout.addView(
	            SampleView.ID_VIEW,
	            IPageLayout.TOP,
	            IPageLayout.RATIO_MAX,
	            IPageLayout.ID_EDITOR_AREA);
<IMG height=3D13 alt=3D#4 =
src=3D"http://eclipse.org/articles/Article-RCP-3/images/tag_4.gif" =
width=3D24 align=3Dcenter>	        =
layout.addPerspectiveShortcut(ID_PERSPECTIVE);
<IMG height=3D13 alt=3D#5 =
src=3D"http://eclipse.org/articles/Article-RCP-3/images/tag_5.gif" =
width=3D24 align=3Dcenter>	        =
layout.addShowViewShortcut(SampleView.ID_VIEW);
	    }
	}
</PRE>
<P>Notes: </P>
<TABLE border=3D0>
  <TBODY>
  <TR vAlign=3Dtop>
    <TD><IMG height=3D13 alt=3D#1=20
      src=3D"http://eclipse.org/articles/Article-RCP-3/images/tag_1.gif" =
width=3D24=20
      align=3Dcenter>=20
    <TD>Again, just get in the habit of defining a constant for all =
strings,=20

⌨️ 快捷键说明

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