`
wislin
  • 浏览: 76186 次
  • 性别: Icon_minigender_1
  • 来自: 四川
社区版块
存档分类
最新评论

Creating an Eclipse View (1)

阅读更多
简介
在Eclipse平台里,一个workbench包含一个workbench window集合。每个workbench window包含一个以上的page,每个page包含一个editor和view的集合。一个editor主要用于编辑和查看文档或输入对象(input object)。对editor进行变更,接下来就是open-save-close 生命周期模式。一个view主要用于遍历结构化信息、打开一个editor或显示一个激活editor的属性。与editor相比,view的变更立即得到保存。editor和view在page里面的布局是通过perspective来完成的。

在workbench里面包括了许多的描述view功能的标准部件。例如,Navigator view就是用于显示和导航workspace。假如在导航器(Navigate)里选定了一个文件,那么你可以打开一个editor,并显示该文件的内容。一旦editor打开,就可以使用Outline view来显示文档的结构化信息,使用properties view来修改文档的属性。

增加一个新view
向workbench里面添加一个view,只需要简单的三步:
     1.创建一个插件;
     2.增加一个view extension 到 plugin.xml里面;
     3.为这个extension定义一个view类

第一步:创建一个插件
此时,plugin.xml里面的内容为:
    <?xml version = "1.0" encode = "UTF-8"?>
    <?eclipse version ="3.2"?>
    <plugin></plugin>        

第二步:往plugin.xml增加一个view扩展
     <?xml version = "1.0" encode = "UTF-8"?>
    <?eclipse version ="3.2"?>
    <plugin>
            <extension point = "org.eclipse.ui.views"
                       name = "Label View"
                       class = "org.eclipse.ui.articles.views.LabelView"
                       icon = "icons\view.gif"/>
     </plugin> 

     `其中
      id- 唯一标识符用来描述这个view
      name - 可以在UI里面显示的名字
      class-  a fully quified name,这个类implements org.eclipse.ui.IViewPart.一般情况下,都是从org.eclipse.ui.part.ViewPart类继承下来。
      icon - 用于这个view的图片的相对路径

第三步:定义该类
package org.eclipse.ui.articles.views;
import org.eclipse.swt.widgets.*;
import org.eclipse.ui.part.ViewPart;
public class LabelView extends ViewPart{
     private Lable labe;
     public LabelView(){
           super()
     }
     public void setFocus(){
           label.setFocus();
     }
     public void createPartControl(Composite parent){
           lable = new Lable(parent,SWT.NONE);
           lable.setText("Hello World");
     }
}


view的生命周期
当一个view被添加到workbench page里面时,其生命周期就开始了。如果用户从Perspective->Show View启动view,则生命周期始于于page创建的过程中,或创建之后。以下任何一步被执行都导致view生命周期的开始:
(1)An instance of the view class is instantiated.
(2)The IViewPart.init method is called to initialize the context for the view. An IViewSite object is passed, and contains methods to get the containing page, window, and other services is passed.
(3)The IViewPart.createPartControl method is called. Within this method the view can create any number of SWT controls within a parent Composite. These provide the presentation for some underlying, view specific model.
当view被关闭时,生命周期也就终止了。
(1)The parent Composite passed to createPartControl is disposed.This children are also implicitly disposed. If you wish to run any code   at this time, you must hook the control dispose event.
(2)The IViewPart.dispose method is called to terminate the part liflecycle. This is the last method which the workbench will call on the part. It is an ideal time to release any fonts, image.etc.


为什么不能够通过API来声明View呢?
所有用于workbench里面的views都必须用XML来声明,理由有以下两点:

1.在eclipse里面,一个extension的presence都是用XML来声明的。
2.view的声明也是用于workbench的持久化。当workbench被关闭时,workbench里面的所有的view的ID和position都被存储到文件里,It is possible to save the specific view class.  However, the persistence of class names in general is brittle, so view id's are used instead.  On startup, the view id is mapped to a view extension within the plugin registry.  Then a new instance of the view class is instantiated.
分享到:
评论

相关推荐

    Eclipse 4 Plug-in Development by Example: Beginner's Guide

    "Eclipse Plugin Development by Example: Beginner's Guide" takes the reader through the full journey of plug-in development, starting with an introduction to Eclipse plug-ins, continued through ...

    EclipseHTMLEditor jar

    Web Browser (It works as an Eclipse's editor) Image Viewer Tag Palette CSS code completion and outline DTD code completion, outline and validation JavaScript code completion, outline and ...

    Learning Android: Develop Mobile Apps Using Java and Eclipse(第二版)

    Anatomy of an Android Project Drawable Resources Building the Project Android Emulator Summary Chapter 5 Main Building Blocks A Real-World Example Activities Intents Services Content Providers ...

    EGit用户指南

    Eclipse Git用户指南 目录 1 Getting Started 1.1 Overview 1.2 Basic Tutorial: Adding a project to version control 1.2.1 Configuration 1.2.1.1 Identifying yourself 1.2.1.2 Setting up the Home ...

    Introduction.to.Android.Application.Development(4th,2013.12) pdf

    Creating an AVD for Your Snake Project 61 Creating a Launch Configuration for Your Snake Project 62 Running the Snake Application in the Android Emulator 66 Building Your First Android Application ...

    Apache Geronimo 2.1_ Quick Reference.pdf

    Creating an application-scoped database pool 62 Creating a client-scoped pool 64 Editing an existing pool 66 Importing a pool from another application server 67 Creating an XA pool 69 Using a ...

    android-a programmer's guide

    Creating Your First Android Project in Eclipse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 Examining the Android-Created Files . . . . . . . . . . . . . . . . . . . . . . . . . . ...

    ORACLE OSB开发指南

    1 Introduction to Oracle Service Bus 2 Tasks Working with Projects, Folders, Resources, and Configurations ................................................... 2-1 Resource Naming Restrictions ...........

    The Definitive Guide to NetBeans Platform

    ■CHAPTER 16 From Eclipse RCP to the NetBeans Platform . . . . . . . . . . . . . . . . . . 279 ■CHAPTER 17 Tips and Tricks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ...

    AndroidEssentials

    Customizing the View.................................................................................67 Creating the Game Loop............................................................................

Global site tag (gtag.js) - Google Analytics