项目储备库 Eclipse工具开发:建立项目[4]
Eclipse工具开发:建立项目[4]
——此文章摘自《自己动手写开发工具 基于Eclipse的工具开发》定价 ¥ 特价 ¥ 详细>>//track linktech cn/?m_id=dangdang&a_id=A &l= &l_type = width= height= border= nosave>( ) Activator java
Activator java起著此插件的生命周期控制器的作用
![项目储备库 Eclipse工具开发:建立项目[4]](http://img.zhputi.com/uploads/090e/090ed3ca26b2912e71f0aa860b062db537896.jpg)
【代码 】插件生命周期控制器 public class Activator extends AbstractUIPlugin { // The plug in ID public static final String PLUGIN_ID = EnumGenerator ; // The shared instance private static Activator plugin; public Activator() { plugin = this; } public void start(BundleContext context) throws Exception { super start(context); } public void stop(BundleContext context) throws Exception { plugin = null; super stop(context); } /** * Returns the shared instance * @return the shared instance */ public static Activator getDefault() { return plugin; } /** * Returns an image descriptor for the image file at the given * plug in relative path * * @param path the path * @return the image descriptor */ public static ImageDescriptor getImageDescriptor(String path) { return imageDescriptorFromPlugin(PLUGIN_ID path); } }
在Eclipse 以前的版本中 此类习惯于被命名为**Plugin java 它使用了单例模式 需要通过getDefault方法得到此类的实例 当插件被激活的时候start方法会被调用 插件可以在这个方法中编写初始化的代码 当插件被关闭的时候stop方法则会被调用
类中还定义了一个静态方法getImageDescriptor 用于得到插件目录下的图片资源
在Activator的父类中还定义了很多有用的方法 在这里我们简要地列出常用的一些方法 在后面的章节中会展示这些方法的用途 l getDialogSettings 得到对话框配置类实例 l getPreferenceStore 得到首选项配置的储存类实例 l getWorkbench 得到工作台 l getLog 得到日志记录类实例
( ) EnumGeneratorNewWizard java EnumGeneratorNewWizardPage java
这个两个文件是向导界面的实现代码 为什么是两个文件呢?一个向导对话框通常有不止一个界面 因此整个向导和每个向导界面要分别由不同的类来维护
EnumGeneratorNewWizard是维护所有界面的向导类 在这个例子中只有一个界面 即EnumGeneratorNewWizardPage
插件模板向导生成的EnumGeneratorNewWizard java EnumGeneratorNewWizardPage java这两个类文件并不能完全满足我们的要求 需要进行修改 因此这里暂时不讲解类中的代码
lishixinzhi/Article/program/Java/ky/201311/29053