Go Basics of Eclipse Plug-in development (1) Plug-in development basics

Source: Internet
Author: User

Original Address: http://www.cnblogs.com/liuzhuo/archive/2010/08/13/eclipse_plugin_1_0_2.html

noun translation

There are some nouns in the process of translation may appear ambiguous, in here unified.

アーキテクチャ=architecture= Architecture

プラットフォーム=platform= Platform

コンポーネント=component= components

The rest is always replenished.

Architecture of the 1.Eclipse

Eclipse is widely used as a Java IDE (integrated development environment), but in essence Eclipse is a platform that integrates a variety of development tools. Therefore, it adopts the plug-in architecture technology which can add various functions freely. The basic architecture of the Eclipse platform is shown in 1-1.

?

Figure 1-1 Eclipse's architecture

Here, at the lowest level, the OSGi runtime is the backbone of the Eclipse plugin architecture. Although the plug-in architecture was already in use in earlier versions of Eclipse, OSGi was introduced for the first time in Eclipse3.0. OSGi is the abbreviation of Open Services Gateway initiative, which was originally developed for embedded hardware, enabling service providers and users on the network to interact (びつける) with the registration service. Eclipse uses OSGi to manage plug-ins.

All configured component groups on top of the OSGi runtime are provided as plug-ins. SWT and JFace provide the API for user interface (users Interface). Because SWT and jface are not dependent on eclipse, they can also be used as a class library alone. Eclipse not only provides the basic user interface as the Platform API (WorkBench API), but also the resources within the workspace (Workspace) that are referred to later are provided as basic APIs in the form of the resource API (Resource API). On top of this, the Help system and Automatic Updates based on the update Manager are built.

From the Eclipse platform perspective, the SWT, JFace, and workbench parts are ECLIPSERCP (Rich Client Platform). ECLIPSERCP is a rich client-side technology based on Eclipse, and Eclipse is not only a development tool, it can also be used as a common application platform. ECLIPSERCP is a subset of the Eclipse platform, and eclipse itself is an example of a ECLIPSERCP application.

2. Extension points

Plug-ins put forward the concept of extension points for their ability to extend other plugins. This extension point can be used when adding functionality to the plugin. On the basis of the extension point, the plug-ins can be connected to each other.

Figure 1-2 scaling with extension points

  

The extension and extension point connections are established when the program executes, and the plug-in that provides the extension point does not know beforehand what behavior the extension point actually extends. Plug-ins that use extension points need to declare the extension using the extension element in the manifest file (plugin.xml), as in code 1-1.

The schema in the extension element is determined by the plug-in that provides the extension point, and the contents of the element must be written according to the schema.

Code 1-1 plugin.xml declaring the extension

?
1 2 3 <extension point="被使用扩展点的ID">     ......</extension>

Expansion points and extensions like the above have accumulated overlapping, allowing the eclipse platform to achieve a wide variety of functions. The Eclipse platform provides an extension point with

    • Add Menu item
    • Add view
    • Add Editor

And so on, the number is very much. This article will focus on the more frequently used extensibility points, which are described in Eclipse's help with all the extensibility points provided by Eclipse, which you can refer to when you use them.

Of course, it is absolutely possible to define a new homemade plugin. The method of defining extension points is described in detail in the [Extension point definition] section.

3. Work desk (Workbench)

It is thought that the students who have seen this article have done Java development with eclipse. The names of the various parts of eclipse may already be known to everyone. In order to unify consciousness in future articles, we will review it here.

The workbench is the general term for Eclipse's entire user interface. The structure in the workbench is shown in Figure 1-3

Figure 1-3 Workbench

  

    • Workbench Window

Eclipse's window. Usually a workbench opens a window, but it is possible for a workbench to correspond to multiple windows.

    • Workbench Page

Each perspective that is opened on the workbench (for a specific purpose view, the layout of the editor), and a page correspond. Can contain multiple views and editors.

    • Menu bar

The same menu bar area as the normal GUI application.

    • Tool bar

The same toolbar area as the General GUI application. The right-hand area of the toolbar is used by default to display a list of perspectives

    • Status bar

The area that is usually displayed at the bottom of the screen. The editor's cursor position, build progress status, etc., displays various information based on the action on the workbench.

    • View

The role is to provide the information that the developer wants. You can receive the status bar and then open it if necessary (high-speed view). Basically a view can only open one in a workbench.

    • Editor

Mainly used for editing of files. and view different editors can open multiple simultaneously. You can also open multiple editors for the same file.

Access the workbench from the plug-in code using the Org.eclipse.ui.PlatformUI class. Code 1-2 illustrates the code example of getting the workbench and workbench windows from Platformui.

Code 1-2 accessing the workbench using Platformui

?
1 2 3 4 5 6 7 8 //取得工作台 IWorkbench workbench = PlatformUI.getWorkbench(); //取得工作台窗口 IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); //取得工作台页面 IWorkbenchPage page = window.getActivePage(); //取得当前处于活动状态的编辑器窗口IEditorPart part = page.getActiveEditor();

4. Workspaces and Resource APIs

Use the workspace as the developer's job area in Eclipse. A workspace is a physical folder that you specify when eclipse starts. Developers who build projects on Eclipse, create files, and so on, generate actual files in the folder specified in the workspace.

Resources within the workspace are used within eclipse to operate on virtual objects defined in the Org.eclipse.core.resources package, such as when the project is Iproject, the folder is Ifolder, and the file is ifile.

Figure 1-4 Resources in the workspace

  

In the development of plug-ins in many cases will be used in the workspace files or folders. These objects can then be used.

Access to the workspace requires the use of org.eclipse.core.resources.ResourcesPlugin. Code 1-3 is a code example that leverages Iworkspaceroot to go to a project in the workspace

Code 1-3 Accessing the workspace using Resourcesplugin

?
1 2 3 4 //取得工作区的root IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot(); //取得项目IProject[] projects = wsroot.getProjects();

  

The Workbench and resource access APIs are the most basic of the APIs that eclipse provides, using APIs that are more frequently used in plug-in development. No detailed instructions are given here, and some of these APIs will appear in later examples. The entry point using Platformui as the Workbench access and the entry point to use Resourcesplugin as the workspace access are remembered anyway.

Go Basics of Eclipse Plug-in development (1) Plug-in development basics

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.