标签: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; }
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