我最近CheckboxTreeViewer
在自己的Dialog
. 到目前为止,这工作正常,除了树默认情况下不允许我扩展节点。它仅在我选中复选框时才有效,如下图所示:
这是默认设置。如您所见,虽然它有子节点,但无法展开节点:
选中复选框后,它可以工作:
我已经尝试过使用setExpandPreCheckFilters
,但没有成功:
Composite container = (Composite) super.createDialogArea(parent);
tv = new CheckboxTreeViewer(container, SWT.MULTI | SWT.H_SCROLL| SWT.V_SCROLL);
GridData gridData = new GridData(GridData.FILL_BOTH);
tv.getTree().setLayoutData(gridData);
tv.setContentProvider(new FeaturePropertyDialogContentProvider());
tv.setLabelProvider(new FeaturePropertyDialogLabelProvider());
tv.setAutoExpandLevel(2);
tv.setExpandPreCheckFilters(true);
有任何想法吗?
- - - - - - - - - - - - - - - - - -更新 - - - - - - - ----------------------
我找到了问题的原因。我忘了检查hasChildren方法中的每个元素。以下代码现在为我工作:
public boolean hasChildren(Object element) {
if (element instanceof ProductLine) {
ProductLine productLine = (ProductLine) element;
if (productLine.getPropertyList() != null) {
return true;
} else {
return false;
}
}
if (element instanceof PropertyList) {
PropertyList propertyList = (PropertyList) element;
if (!(propertyList.getGeneralPlatforms().isEmpty())) {
return true;
} else {
return false;
}
} else if (element instanceof GeneralPlatform) {
GeneralPlatform platform = (GeneralPlatform) element;
if (!(platform.getHardwareElements().isEmpty())) {
return true;
} else {
return false;
}
} else if (element instanceof HardwareElement) {
HardwareElement hw = (HardwareElement) element;
if (!(hw.getHardwareElements().isEmpty())
|| !(hw.getProperties().isEmpty())) {
return true;
} else {
return false;
}
} else {
return false;
}
}
谢谢你的帮助!!