Beginner of Eclipse plug-in development _jsp programming

Source: Internet
Author: User
Tags extend
Now on the Internet you can see a lot of the introduction of Eclipse plug-in development, here I write the purpose of this article is to tell you my own experience and the first learning. It is also hoped that this article will use the easiest way to get a sense of the basics of developing eclipse plug-ins. Note that to learn about Eclipse's plug-in development, you need to:

will use eclipse to develop Java applications

Understand the concept of the plug-in word

Learn some knowledge of XML this article is an introductory article, just to show you the simple steps to develop a plug-in, and understand the technical side of the development of plug-ins involved.

  Eclipse SDK Overview

The eclipse we typically use is what we call the Eclipse SDK, which includes a lot of content, as shown in the following illustration:




Runtime core (Eclipse Platform)-The SDK must be an Eclipse Platform, and it does not have any meaningful functionality for end users, it is a basic platform for loading all plug-ins. That is, the runtime minimum collection of eclipse.

Java Development Tools (JDT)-All of our Java-related development is done by this plugin, which forms the most basic editing, compiling, running, debugging, and publishing environment for Java.

Plug-in developer Environment (PDE)-Plug-in plugin development, if we want to develop plug-ins, we will find that all the work environment is provided by it. It provides tools for automating the creation, processing, debugging, and deployment of Plug-ins.

The plug-ins we will develop in the future are loaded and run by the platform, while PDE is the development environment for developing plug-ins, JDT is the development environment of Java code when developing plug-ins.

Create a plug-in project

Set Reference Project

The development of Plug-ins requires a large number of external libraries, mainly those provided by the various plug-ins in the existing eclipse. For development convenience, we first use these external libraries as a unified reference for a project.

From the resource perspective, use the file > import ... > external plug-ins and segments.
In the next step, select the Extract source archive and create the source folder in your project.
To display the screen called selection, select Org.eclipse.ui, and then click the Finish button.

Create a project

To create an empty plug-in project in Eclipse, in order for us to better understand the source of each file in the plug-in, we start with a blank plugin project:

1 Open New Project ... Wizard (File > New > project ...) and select the plug-in project from the plug-in development category.

2 use Com.huangdong.examples.helloworld as the name of the project. By default, the wizard also sets the Com.huangdong.examples.helloworld to identity.

3 Finally, make sure that you select the Create a blank plug-in project on the Plugin Code Builder page.

4 When asked if you would like to switch to the "plugin development" perspective, answer yes.

5 Select the Com.huangdong.examples.helloWorld item and open the Properties dialog box.

6 in the Java Build path attribute, select the Project tab and select Project Org.eclipse.ui. These contain the import classes that the project needs.

7) Redevelopment projects.
Create a plug-in content

Create a new view of a viewport

Let's add a very simple view to the project:

1 Create the package Com.huangdong.examples.helloworld in the SRC directory of the project.

2 Create a new class called Helloworldview in this package whose superclass is Org.eclipse.ui.part.ViewPart.

Add the following code to the Helloworldview:

Package Com.huangdong.examples.helloworld;

Import Org.eclipse.swt.SWT;
Import Org.eclipse.swt.widgets.Composite;
Import Org.eclipse.swt.widgets.Label;
Import Org.eclipse.ui.part.ViewPart;

public class Helloworldview extends Viewpart {

Label label;

public void Createpartcontrol (composite parent) {
Label = new label (parent, SWT. WRAP);
Label.settext ("Hello World");
}

public void SetFocus () {}
}

We defined a variable lable for the class, initialized and set a display string in the Createpartcontrol method.

   Exhibition extension Point

Let eclipse add this view and you need to extend the org.eclipse.ui.views extension point. All of these need to be described in Plugin.xml. The manifest file describes the plug-in, including the location of the plug-in's code and the extension that is being added.

Copy the following content to Plugin.xml:

<?xml version= "1.0" encoding= "UTF-8"?
<plugin id= "Com.huangdong.examples.helloworld"
Name= "Com.huangdong.examples.helloworld"
version= "1.0.0"
Provider-name= "Huangdong" >

<runtime>
<library name= "Helloworld.jar"/>
</runtime>
<requires>
<import plugin= "Org.eclipse.ui"/>
</requires>

<extension point= "Org.eclipse.ui.views"
<category
Name= "Hello"
Id= "Com.huangdong.examples.helloworld.hello" >
</category>
<view
Name= "Hello Greetings"
category= "Com.huangdong.examples.helloworld.hello"
Class= "Com.huangdong.examples.helloworld.HelloWorldView"
Id= "Com.huangdong.examples.helloworld.helloworldview" >
</view>
</extension>

</plugin>


The name, identity, and version of the plug-in are defined in the plugin domain. At the same time, the plug-in code defined in the runtime domain is packaged in the Helloworld.jar file. The plug-in is defined in the requires domain, and the org.eclipse.ui is listed because we want to use the SWT API and Workbench. Finally, it is explained in the extension that you want to extend the org.eclipse.ui.views extension point. First we defined the categories of views in category, and in the Workbench Display View dialog box, you can use categories to bring together related views. The category we define is named "Hello". Also defines our view, called "Hello greetings", which will be displayed in the Display View dialog box and the title bar of the view, where we also use the class ID to illustrate the final class that implements this view.

By Plugin.xml's definition, eclipse will really find the behavior that plug-ins can do, and the concrete Java classes that these behaviors ultimately implement.

A number of identities are used in the plug-in manifest file. Individual extension points typically define the configuration parameters that need to be identified (for example, the category identifier for the view extension point above). We also want to define the plug-in identity. Typically, you should use the Java package name prefix for all identities to ensure that all installed plug-ins are unique.

The specific name used after the prefix is entirely up to you. However, if the plug-in identity prefix is exactly the same as the name of one of the packages, you should avoid using the class name in the package. Otherwise, it is difficult to tell whether you are viewing the identity name or the class name.

You should also avoid using the same identity for different extended configuration parameters. In the above list, the public identification prefix (COM.HUANGDONG.EXAMPLES.HELLOWORLD) has been used, but all of our identities are unique. This naming method helps us to read the files and understand which identities are relevant.

running and testing plug-ins

Running Plug-ins is a very simple thing, which gives us good support in PDE. You only need to select run in the menu run as the "run-time Workbench", the runtime will pop up a repeating plugin prompt box, you can click OK Skip, do not care. This will start an eclipse with a plugin already installed.

Select Window > Show view in menu after startup other, in the Display View dialog box, there will be a category hello, click on the hello category will see Hello Greetings, select the Back click OK button. The following interfaces are visible in the bottom view:



Here, if you see this picture, congratulations, your first Eclipse plug-in ran successfully.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.