gwt-material-addins icon indicating copy to clipboard operation
gwt-material-addins copied to clipboard

MaterialTreeItem should be configurable to open/close separately from selection or should have a subclass which does this

Open Hoagiex opened this issue 9 years ago • 2 comments

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);
            }
        }
    }

Hoagiex avatar Nov 19 '16 19:11 Hoagiex

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.

kevzlou7979 avatar Dec 23 '16 04:12 kevzlou7979

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.

Hoagiex avatar Dec 30 '16 20:12 Hoagiex