Eclipse RCP plug-in programming to learn shorthand

First, install a new Eclipse for RCP and RAP

To facilitate the test and does not affect the normal work of Eclipse,

Best to install a specific Eclipse environment.


Choose this version of the Eclipse

Eclipse for RCP and RAP Developers, 181 MB

You must extract to your hard drive, then create a batch start_rcp.bat,

Point to their own jdk path, as follows:

set PATH=
set PATH=D:\java\jdk1.6.0_20\bin;%PATH%
start eclipse.exe

Then double-click execution, set a different workspace directory, for example

C: \ Documents and Settings \ Administrator \ workspace_rcp

Into the Eclipse RCP, turn off the beginning of the welcome screen.

Second, understand the use of SWT

SWT RCP write much need to know the preparation method.

Can refer to the official website of the introduction.

Can work independently of the Eclipse SWT, so it is necessary to add in the classpath of its own specific jar library.

The RCP dependent on Eclipse, Eclipse provides the framework to be considered,

But the benefits do not need to take into account the swt jar (because Eclipse already using it).

SWT official website provides lots of code snippets,

Try to run these small programs can quickly understand the SWT's SWT control without the need to look at the documentation.

They generally use this package:

import org.eclipse.swt.widgets .*;

You'll see later, SWT and RCP programs have a strong program interchangeability.

Third, create a custom view of plug-ins.

My goal is to create a simple plug-in -

Create a custom view, and then display a picture on the inside.

Creating an RCP project:

File-> New-> Project ...

Select a wizard-> Plugin Development-> Plug-in Project

Plugin-in Project

Project name: fill org.eclipse.examples.nanami, press the Next button.


Default settings, press the Next button.


Select the Plug-in with a view, then press the Next button.

Main View Settings

Default settings, then press the Finish button.

Fourth, test engineering.

Because the view is too complex to create a template, you can simplify it.

Has created two classes:



View icon is a small icon, for display in the view:

/ Org.eclipse.examples.nanami / icons / sample.gif

Project settings can double-click the file list

/ Org.eclipse.examples.nanami / META-INF / MANIFEST.MF

First test the View (not to make any changes to the current)

Open file, then click the Debug button on the toolbar.

Select Eclipse Application, click OK to open a new Eclipse environment.

Window-> Show View-> Others-> Sample Category-> Sample View

Open to change the view (display a list of three items).

Direct exit to the Eclipse environment.

Fifth, modify view properties

Right Project -> Properties-> Resource-> Text file encoding-> Other: UTF-8 filling

Double-click, switch to the label,

Edit this file at the end add:

javacDefaultEncoding .. = UTF-8

This release compiled code using UTF-8.

Next, modify the title of the view and replace their icons.

Icon.gif copy the new icon to the icons /, and then double-click the plugin.xml file.


            name="Sample View"



            name="Nanami View "



            name="Sample Category"



So that you can modify the view of classification, name and small icon.

Re-commissioning works, to see whether the purpose.

Sixth, change the view code.

View of the main code in this file.

SampleView inheritance ViewPart, the entry point in

public void createPartControl (Composite parent)

As used in this entry


This class seems to be jface controls, using up more difficult.

This class can be simplified into this:

package org.eclipse.examples.nanami.views;

import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.SWT;
import org.eclipse.ui.part.ViewPart;

public class SampleView extends ViewPart {
        public static final String ID = "org.eclipse.examples.nanami.views.SampleView";

        private Canvas canvas;

        public Control getControl() {
                return canvas;

        public void createPartControl(Composite parent) {
                //  Create a Canvas control
                final Image image = new Image(Display.getCurrent(),
                canvas = new Canvas(parent, SWT.BORDER);
                canvas.setBounds(0, 0, 800, 600);
                canvas.addPaintListener(new PaintListener() {
                        public void paintControl(PaintEvent event) {
                                event.gc.drawImage(image, 0, 0);
                //  Create the right-click menu
                Menu menu = new Menu(parent.getShell(), SWT.POP_UP);
                final MenuItem copyItem = new MenuItem(menu, SWT.PUSH);
                copyItem.setText(" Version information ");
                copyItem.addSelectionListener(new SelectionAdapter() {
                        public void widgetSelected(SelectionEvent e) {
                                SampleView.this.showMessage("Nanami View , v0.0.1.\n"
                                                + "Copyright weimingtom. All rights reserved.");
                menu.addMenuListener(new MenuAdapter() {
                        public void menuShown(MenuEvent e) {

         *  Pop-up dialog boxes
         * @param message
        private void showMessage(String message) {
                MessageDialog.openInformation(getControl().getShell(), "Nanami View ",

        public void setFocus() {

Then copy the picture to org.eclipse.examples.nanami.views nanami.jpg this package, the

Easy to read view this image.

The above code uses

public void createPartControl (Composite parent)

The parameters parent as a parent container,

Create a new Canvas, and then display the picture.

You can use the same method to create additional SWT controls.

Debugging results like this:

Eclipse RCP plug-in programming to learn shorthand

Seven, install one: directly to the local warehouse


Switch to the Overview,

Exporting part of the

1. ... Organize Manifests Wizard

Automatically modify the META-INF/MANIFEST.MF

Add Export-Package

4. ... Export Wizard

Choose Install into host. Repository

Although it is quite fast,

However, RCP can only be installed at compile on Eclipse RCP project.

Eight, the installation method two: Create a site project.

Another method is to create a plug-in update site, then let the local Eclipse installation.

File-> New-> Others

Select the Plug-in Development-> Feature Project

Project name: fill nanami_feature

Feature ID: fill org.eclipse.examples.nanami

Feature Name: fill Nanami

Click Next.

By Finisth.

Feature.xml settings in the pop-up switched to Plug-ins tab

Add just write plug-ins


Then Ctrl + S to save the configuration file.

Best to create a plug-in site.

File-> New-> Others

Select the Plug-in Development-> Update Site Porject

Project name: fill nanami

Click Finish to open site.xml configuration

Click Add Feature ... add just created Feature Project ID:


Press Ctrl + S to save.

At the top left corner of the Build All ... compilation.

Generated plugins, features several directories and jar files.

Project -> right click -> Properties -> Properties

Copy this site local path name, for example, my path is:

C: \ Documents and Settings \ Administrator \ workspace_rcp \ nanami

Help-> Install New Software ...

Click the Add button -> press the Local button

In the "Browse For Folder" dialog box enter the folder path above:

C: \ Documents and Settings \ Administrator \ workspace_rcp \ nanami

Location is populated:

file: / C: / Documents and Settings / Administrator / workspace_rcp / nanami /

Press OK to return just the dialog box:

Barring unforeseen circumstances, the following appeared Uncategorized-> Nanami this plug-in.

To speed up the installation, but my plugin does not rely on other plug-ins, so the following

Contact all update sites during install to find required software

Before removing the hook.

Check Nanami plug-in, and then click Next.

Select Nanami, click Next.

Select I accept the terms of the license agreement. Click Finish.

Pop-up warning box, ignore it, just press OK.

Then press the Restart Now to restart Eclipse.

Window-> Show View-> Others-> Nanami-> Nanami view

Open your own custom view that the effect is as follows:

Eclipse RCP plug-in programming to learn shorthand

If you want to uninstall the plug-in

Help-> About Eclipse-> Installation Details

Nanami then select the Uninstall ... uninstall it below.

分类:Industry 时间:2011-07-09 人气:179
blog comments powered by Disqus


iOS 开发

Android 开发

Python 开发



PHP 开发

Ruby 开发






Javascript 开发

.NET 开发



Copyright (C), All Rights Reserved. 版权所有 黔ICP备15002463号-1

processed in 0.229 (s). 12 q(s)