gwt-material-addins
gwt-material-addins copied to clipboard
MaterialTreeItem should be configurable to open/close separately from selection or should have a subclass which does this
I have created a custom subclass in my own code, which uses doubleclick for open/close and single click for selection.
Maybe this is something you want to implement in the MaterialTreeItem class or add a sub class.
Code for a potential subclass:
private HandlerRegistration doubleClickRegistration;
@Override
public void select() {
SelectionEvent.fire(getTree(), this);
}
@Override
protected void onLoad() {
super.onLoad();
this.doubleClickRegistration = getDivHeader().addDoubleClickHandler(event -> onDoubleClick());
}
@Override
protected void onUnload() {
super.onUnload();
if(this.doubleClickRegistration != null) {
this.doubleClickRegistration.removeHandler();
this.doubleClickRegistration = null;
}
}
private void onDoubleClick() {
final List<MaterialTreeItem> treeItems = getTreeItems();
if(!treeItems.isEmpty()) {
for(MaterialTreeItem treeItem : treeItems) {
if(isHide()) {
treeItem.setVisible(false);
} else {
treeItem.setVisible(true);
}
}
if(isHide()) {
CloseEvent.fire(getTree(), this);
setHide(false);
} else {
OpenEvent.fire(getTree(), this);
setHide(true);
}
}
}
Hi there, thanks for this enhancement and idea. I think we can note this as an improvements on future implementation. We need to discuss this a little more about the implementation. Maybe we can have Tree Selection Types (Single / Double Click) marked as enum type. I will hear for more ideas.
Personally, I would separate the binding of the click handler or double click handler from the load/unload methods, by moving the handler logic into separate methods, which are called from the load/unload methods.
This allows for more targeted overriding and would allow both easy switching from the default ClickHandler and also the option of not adding the ClickHandler to the span, but (seperate-) handler(s) to the image/divHeader.