I'm facing the problem, that a implemented CheckboxTreeViewer
works perfect on Linux Debian, but under Windows doesn't. First of all I don't understand the concept of "setGrayed()".. Is it to show, that only part of the children from a element are selected?
So the problem: When I check an item under Windows, it checks all other elements in the tree. Somehow the whole logic is ignored.
Here is my code from ICheckStateListener
:
@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);
}
}
}
EDIT: I'm using Eclipse Indigo
Thanks in advance!