구현 된 CheckboxTreeViewer
은 Linux 데비안에서 완벽하게 작동하지만 Windows에서는 그렇지 않습니다. 무엇보다도 먼저 "setGrayed()"개념을 이해하지 못합니다. 엘리먼트의 하위 부분 만 선택된다는 것을 보여 주나요?CheckboxTreeViewer를 올바르게 사용하는 방법은 무엇입니까?
그래서 문제 : Windows에서 항목을 검사하면 트리의 다른 모든 요소를 검사합니다. 어떻게 든 전체 논리는 무시됩니다.
@Override
public void checkStateChanged(final CheckStateChangedEvent event) {
// object checked
final TreePath path = ((ITreeSelection) this.treeViewer.getSelection()).getPaths()[0];
checkChildren(path, event.getChecked());
checkParents(path.getParentPath());
syncData();
}
public void checkParents(final TreePath path) {
if (path == null) {
return;
}
final IFieldElement<Object> treeElement = (IFieldElement<Object>) path.getLastSegment();
if (treeElement != null) {
boolean allChecked = true;
boolean allUnchecked = true;
for (final Object fieldElement : treeElement.getChildrenElements()) {
allChecked = allChecked && this.treeViewer.getChecked(fieldElement);
allUnchecked = allUnchecked && !this.treeViewer.getChecked(fieldElement);
}
if (allUnchecked) {
this.treeViewer.setChecked(treeElement, false);
this.treeViewer.setGrayed(treeElement, false);
} else
if (allChecked) {
this.treeViewer.setChecked(treeElement, true);
this.treeViewer.setGrayed(treeElement, false);
} else
if (!allUnchecked && !allChecked) {
this.treeViewer.setChecked(treeElement, true);
this.treeViewer.setGrayed(treeElement, true);
}
}
checkParents(path.getParentPath());
}
public void checkChildren(final TreePath path, final boolean checked) {
if (path == null) {
return;
}
final Object element = path.getLastSegment();
if (element != null) {
this.treeViewer.setChecked(element, checked);
this.treeViewer.setGrayed(element, false);
this.treeViewer.setSubtreeChecked(element, checked);
if (element instanceof EventMethod) {
checkEventMethod(path, element, checked);
}
}
}
편집 :
여기 ICheckStateListener
에서 내 코드 내가
감사합니다 사전에 이클립스 인디고
를 사용하고 있습니다!