PropertyView中的Java Eclipse多行/列表属性
我有一个PropertyView中的Java Eclipse多行/列表属性,java,eclipse,list,view,properties,Java,Eclipse,List,View,Properties,我有一个TreeViewer,其中包含我希望在Eclipse中的默认PropertiesView中显示信息的对象。我创建了一个AdapterFactory,它使用Override方法实现IAdapterFactory接口: @Override public Object getAdapter(Object adaptableObject, Class adapterType) { if(adapterType == IPropertySource.class && ada
TreeViewer
,其中包含我希望在Eclipse中的默认PropertiesView
中显示信息的对象。我创建了一个AdapterFactory,它使用Override方法实现IAdapterFactory
接口:
@Override
public Object getAdapter(Object adaptableObject, Class adapterType)
{
if(adapterType == IPropertySource.class && adaptableObject instanceof UATreeNode)
{
return new UATreeNodeAdapter((UATreeNode) adaptableObject);
}
return null;
}
然后,我创建了一个适配器,它使用我自己的PropertyDescriptor实现了IPropertySource
接口,例如:
public static final String OBJECT_ID_VALUE = "Obj.value";
private static final String OBJECT_LABEL_VALUE = "Value";
private static final String CATEGORY_VALUE = "Value";
protected PropertyDescriptor objectAccessLevelDescriptor = new PropertyDescriptor(OBJECT_ID_VALUE, OBJECT_LABEL_VALUE);
@Override
public IPropertyDescriptor[] getPropertyDescriptors()
{
objectValueDescriptor.setCategory(CATEGORY_VALUE);
return new IPropertyDescriptor[] { objectValueDescriptor };
}
@Override
public Object getPropertyValue(Object id)
{
if(id.equals(OBJECT_ID_VALUE))
return uaTreeNode.getValue();
}
其中一些属性应显示字符串列表
Value
---String 1
---String 2
---String 3
“Value”的第一个出现是我设置的类别,但第二个出现应该已经显示了我提供的列表的实际值
问题是,列表是动态的,在我的树节点之间可能会有所不同。
我现在的问题是,有没有办法做到这一点,以及如何实现我想要的?如果
getPropertyValue
方法返回一个实现或适应IPropertySource
的对象,那么该属性源中的属性描述符将用于创建子节点
因此,在您的示例中,需要一个属性源为三个字符串返回三个描述符。这可能不是最好的解决方案,但下面是我所做的: 我创建了一个新类,它还实现了
IPropertySource
接口:
public class UATreeNodeValue implements IPropertySource
{
public static final String OBJECT_ID_STARTTIME = "Obj.startTime";
public static final String OBJECT_ID_CURRENTTIME = "Obj.currentTime";
public static final String OBJECT_ID_STATE = "Obj.state";
private static final String OBJECT_LABEL_STARTTIME = "StartTime";
private static final String OBJECT_LABEL_CURRENTTIME = "CurrentTime";
private static final String OBJECT_LABEL_STATE = "State";
String size = "";
String objectType = "";
ArrayList<String> arrayList = new ArrayList<String>();
protected PropertyDescriptor descriptor;
protected PropertyDescriptor objectStartTimeDescriptor = new PropertyDescriptor(
OBJECT_ID_STARTTIME, OBJECT_LABEL_STARTTIME);
protected PropertyDescriptor objectCurrentTimeDescriptor = new PropertyDescriptor(
OBJECT_ID_CURRENTTIME, OBJECT_LABEL_CURRENTTIME);
protected PropertyDescriptor objectStateDescriptor = new PropertyDescriptor(
OBJECT_ID_STATE, OBJECT_LABEL_STATE);
public UATreeNodeValue()
{
}
public void addValues(String value)
{
arrayList.add(value);
}
public void setObjectType(String string)
{
objectType = string;
}
@Override
public IPropertyDescriptor[] getPropertyDescriptors()
{
IPropertyDescriptor[] iPropertyDescriptor = new IPropertyDescriptor[arrayList.size()];
if(objectType.equals("ServerStatusDataType"))
{
return new IPropertyDescriptor[] { objectStartTimeDescriptor, objectCurrentTimeDescriptor,
objectStateDescriptor };
}
else
{
for(int i = 0; i < arrayList.size(); i++)
{
size = "[" + i + "]";
iPropertyDescriptor[i] = new PropertyDescriptor("obj." + "[" + i + "]", size);
}
return iPropertyDescriptor;
}
}
@Override
public Object getPropertyValue(Object id)
{
if(objectType.equals("ServerStatusDataType"))
{
if(id.equals(OBJECT_ID_STARTTIME))
return arrayList.get(0);
if(id.equals(OBJECT_ID_CURRENTTIME))
return arrayList.get(1);
if(id.equals(OBJECT_ID_STATE))
return arrayList.get(2);
}
else
{
if(id.equals("obj." + "[" + 0 + "]"))
return arrayList.get(0);
if(id.equals("obj." + "[" + 1 + "]"))
return arrayList.get(1);
if(id.equals("obj." + "[" + 2 + "]"))
return arrayList.get(2);
if(id.equals("obj." + "[" + 3 + "]"))
return arrayList.get(3);
if(id.equals("obj." + "[" + 4 + "]"))
return arrayList.get(4);
if(id.equals("obj." + "[" + 5 + "]"))
return arrayList.get(5);
if(id.equals("obj." + "[" + 6 + "]"))
return arrayList.get(6);
}
return null;
}
}
@Override
public Object getPropertyValue(Object id)
{
if(id.equals(OBJECT_ID_VALUE))
return uaTreeNode.getValue();
return null;
}
UATreeNode类:
public class UATreeNode
{
private UATreeNodeValue value = null;
public UATreeNodeValue getValue()
{
return value;
}
public void setValue(UATreeNodeValue value)
{
this.value = value;
}
}
我希望我能帮助有类似问题的人。
多亏了greg-449的帮助。好的,带子节点的部分现在适合我了,但是我如何才能实现动态设置多个描述符?我不知道列表的确切长度。在调用对象的getPropertyValue时,必须创建一个具有正确描述符数的属性源对象。