码迷,mamicode.com
首页 > 其他好文 > 详细

ComboBoxPropertyDescriptor 中使用枚举类型

时间:2014-04-30 22:31:40      阅读:261      评论:0      收藏:0      [点我收藏+]

标签:rcp

只贴出枚举相关的代码

1、实现了IPropertySource类的一部分

       protected static final String PROPERTY_TEXT = "text"; //$NON-NLS-1$
	protected static final String PROPERTY_ENABLE = "enable";	 //$NON-NLS-1$
	protected static final String PROPERTY_LEVEL="level"; //$NON-NLS-1$
	//protected static final String PROPERTY_DEVICES = "devices";	
	private EnumCompareType enumCompareType = EnumCompareType.GREAT_AND_EQUAL;

	private final Object PropertiesTable[][] = 
	{ 
	  { PROPERTY_TEXT, new TextPropertyDescriptor(PROPERTY_TEXT,Messages.ServerObject_servername)},	
	  { PROPERTY_ENABLE, new CheckBoxPropertyDescriptor(PROPERTY_ENABLE,Messages.ServerObject_status)},
	 
	 {PROPERTY_LEVEL,new ComboBoxPropertyDescriptor(PROPERTY_LEVEL, Messages.ServerObject_level, EnumCompareType.names())} //$NON-NLS-2$ //$NON-NLS-3$
	  
	  
	};	

设置部分

public void setPropertyValue(Object id, Object value) {
if(id.equals(PROPERTY_TEXT)){
this.setName(String.valueOf(value));
}
if(id.equals(PROPERTY_ENABLE)){
this.setEnable(Boolean.parseBoolean(String.valueOf(value)));
}
if(id.equals(PROPERTY_LEVEL)){
enumCompareType =EnumCompareType.fromValue(Integer.valueOf(String.valueOf(value))); //枚举值类型转换


}

}


获取部分

public Object getPropertyValue(Object id) {
		if(id.equals(PROPERTY_TEXT)){
			return this.getName();
		}
		if(id.equals(PROPERTY_ENABLE)){
			System.out.println(isEnable());
			return this.isEnable();
		}
		if(id.equals(PROPERTY_LEVEL)){
			
			return Integer.valueOf(enumCompareType.getCode()); //枚举值类型转换
			/*System.out.println(enumCompareType.name());
			return this.enumCompareType.name();*/
		}
		return null;
	}

2、枚举类

package cn.net.anna.model.type;

public enum EnumCompareType {
	ENUAL(0),GREAT_AND_EQUAL(1),LESS_AND_EQUAL(2);
	private int code;

	private EnumCompareType(int code) {
		this.code = code;
		
	}
	//获取枚举值的序号
	public int getCode() {
		return code;
	}

	public String toString() {
		return ""+this.code;
	}
	public  static EnumCompareType fromValue(int value){
		
		for (EnumCompareType iterable_element : EnumCompareType.values()) {
			if(iterable_element.code==value){
				return iterable_element;
			}
		} 
		return null;
	}
	//ComboBox 显示名称要用

	public static  String[] names(){
		String[] strings = new String[EnumCompareType.values().length];
		for (int i = 0; i < EnumCompareType.values().length; i++) {
			strings[i]=EnumCompareType.values()[i].name();
		}
		
		                              
		return strings;
	}
	
	
}


ComboBoxPropertyDescriptor 中使用枚举类型

标签:rcp

原文地址:http://blog.csdn.net/jaysuper/article/details/24808623

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!