2.2 简单的案例插件功能描述
在Internet搜索引擎中以“Eclipse 插件开发”为关键字搜索就可以找到数篇讲述Eclipse插件开发的经典入门文章,按着文章中的例子一步一步地做,就可以做出一个显示Hello world对话框的例子。这个例子虽然简单,但是却是一个真正的插件开发项目,通过这个项目我们就可以理解插件的工作原理以及配置文件各个配置项的作用。
在本节中我们来讲解一个有一定实用价值的简单插件,通过这个插件就可以对Eclipse的插件开发有更多的认识,并且可以立即应用到实际的开发中去。
JDK 1.5提供的枚举大大简化了我们的开发工作,但是在有的情况下我们暂时还不能使用JDK 1.5,那么此时如果需要枚举的话就只能自己写代码,比如:
public class CustomerTypeEnum
{
private String type;
public CustomerTypeEnum VIP = new CustomerTypeEnum("VIP");
public CustomerTypeEnum MEMBER = new CustomerTypeEnum("MEMBER");
public CustomerTypeEnum NORMAL = new CustomerTypeEnum("NORMAL");
private CustomerTypeEnum(String type)
{
super();
this.type = type;
}
public int hashCode()
{
final int PRIME = 31;
int result = 1;
result = PRIME * result + ((type == null) ? 0 : type.hashCode());
return result;
}
public boolean equals(Object obj)
{
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final CustomerTypeEnum other = (CustomerTypeEnum) obj;
if (type == null)
{
if (other.type != null)
return false;
} else if (!type.equals(other.type))
return false;
return true;
}
}
如果需要很多枚举定义的话就会非常繁琐,因此我们下面就来开发这样一个代码生成器插件来简化这个操作。







