Doug Stephen
Doug Stephen

Reputation: 7351

SWT Tree and TreeItem: Remove or change the drawing behavior of the expand/collapse indicator

I'm working in SWT (no JFace), and I'm attempting to customize the behavior of a Tree that I'm using a sidebar.

The top-level items in the tree shouldn't be selectable; they're basically headers. Only the children of these items should be selectable. As a result, I would like the UI to behave in a way that indicates this; clicking on one of these top-level items should expand or collapse but shouldn't provide any sort of visual feedback outside of the indicator changing its state and the children's visibility changing.

The problem seems to be that on OS X, the expand/collapse indicator is a triangle (don't know if it's an image or a unicode character) that either points right or down, but is also colored based on the "selection" state. I've managed to override all of the relevant behavior for the top-level items except for the arrow changing color.

Not Selected:

Not Selected

Selected

Selected and Ugly

Some of the things that I've attempted to do, all of which have failed:

I'm aware that a lot of this behavior is highly coupled to the behavior of the underlying native widgets, but I was wondering if there was any way to get the behavior that I'm looking for without roll a custom widget from scratch?

Upvotes: 1

Views: 2779

Answers (1)

Waqas Ilyas
Waqas Ilyas

Reputation: 3241

I think in a situation as yours you should ideally not allow selection on a tree header.

You can either cancel the selection event, by not allowing it to be clickable. But that might be a little kludgy implementation, especially for key navigation.

The safer approach, if possible with your data, would be to just move the selection whenever a tree parent node is selected. So it should work like this that if a parent node is selected, either by keyboard or mouse: you expand the node and move the selection to the first child.

This way you can avoid all the paint trickery to hide the selection state.

Upvotes: 3

Related Questions