我想将我的EMF模型绑定到TreeViewer
。我的模型看起来像这样:
Facility : Name
- Part : Name
- SubPart : SubPartName
- SubSubPart : SubSubPartName
- SubSubPart : SubSubPartName
- SubSubPart : SubSubPartName
- SubPart : SubPartName
- Part : Another Name
- SubPart : SubPartName
我遵循了Tom Schindl的教程,但我仍然不明白如何实现TreeFactoryImpl
。到目前为止它看起来像这样:
@Override
public IObservable createObservable(Object target) {
if (target instanceof IObservableList) {
return (IObservable) target;
} else if (target instanceof Facility) {
IEMFListProperty multi = EMFProperties.multiList(ModelPackage.Literals.FACILITY__NAME);
return multi.observe(target);
} else if (target instanceof Part) {
IEMFListProperty multi = EMFProperties.multiList(ModelPackage.Literals.PART__NAME);
return multi.observe(target);
}
return null;
}
问题是只显示设施。现在感到奇怪,因为TreeStructureAdvisor
似乎只接收字符串。
我想要完成的是:
1.) Update the TreeViewrt if new nodes are added
2.) Update the name label if the name is changed
答案 0 :(得分:0)
从这里采取:some googlecode此方法与您正在使用的方法不同。
private static class TreeFactoryImpl implements IObservableFactory {
private IEMFListProperty multi = EMFProperties.multiList(
WorkspacePackage.Literals.PROJECT_SPACE__PROJECT,
MetamodelPackage.Literals.PROJECT__MODEL_ELEMENTS);
public IObservable createObservable(final Object target) {
if (target instanceof IObservableList) {
return (IObservable) target;
} else if (target instanceof ProjectSpace) {
return multi.observe(target);
} else if (target instanceof Project) {
return multi.observe(target);
}
return null;
}
}
从我所看到的,大多数示例调用多列表都是使用两个列表。你有没有理由使用它?
答案 1 :(得分:0)
以下作品:
@Override
public IObservable createObservable(Object target) {
if (target instanceof IObservableList) {
return (IObservable) target;
} else if (target instanceof Facility) {
IEMFListProperty list = EMFProperties.list(ModelPackage.Literals.FACILITY__SUBPARTS);
return list.observe(target);
} else if (target instanceof SUBPART) {
IEMFListProperty list = EMFProperties.list(ModelPackage.Literals.SUBPART__SUBPARTS);
return list.observe(target);
} else {
return null;
}
}
这里的关键是收听收藏品。这解决了要求1(如果添加了新节点,则更新TreeView)
之后我添加了一个TreeLabelProvider,如Tom Schindl的博客文章中所述。 这解决了要求2(如果名称被更改,则更新名称标签)。