1
votes

I want to disable (only virtual) some specific nodes in my treeviewer, but it seems to have no effect on my nodes. I also tried to set an backgound which also don't work. Any ideas on this?

private void setSelectedElements(TreeItem[] treeItems) {
        for (TreeItem item : treeItems) {
            Object obj = item.getData();
            if (item.getParentItem() != null) {
                Object parentElement = item.getParentItem().getData();
                if (parentElement instanceof Mandatory) {
                    setChecked(item);
                    Display display = Display.getCurrent();
                    item.setGrayed(true);
                    item.setBackground(display.getSystemColor(SWT.COLOR_GRAY));
                }
            }
            setSelectedElements(item.getItems());
        }
    }
1

1 Answers

0
votes

setGrayed is used to change the state of a check box in a check box tree or table. It does not change the tree item color. From the JavaDoc for setGrayed:

Sets the grayed state of the checkbox for this item. This state change only applies if the Tree was created with the SWT.CHECK style.

If you want to change the color of a tree item use a LabelProvider which implements IColorProvider or a label provider derived from StyledCellLabelProvider.