gwtproject / gwt

GWT Open Source Project
http://www.gwtproject.org
1.5k stars 371 forks source link

CellBrowser doesn't render child panel when selected leaf changes to a node #6993

Closed dankurka closed 9 years ago

dankurka commented 9 years ago

Originally reported on Google Code with ID 6994

Found in GWT Release (e.g. 2.4.0, 2.5.0 RC): 2.4.0

Encountered on OS / Browser (e.g. WinXP, IE8-9, FF7): WinXP, FF3.6

Detailed description (please be as specific as possible):
If a selected leaf within a cell browser changes to a node and the cell list is redrawn
it correctly renders the cell as a selected node, but it never tries to load the NodeInfo
from the model and append the child panel.

The issue is in CellBrowser.updateChildState().  It identifies the node as a previously
opened node, however because isFocusedOpen is false due to the fact it was a leaf openNode
remains null and it never tries to load the child's info.  I see 2 possible solutions
to this problem:

1) Try to reload the child as long as isFocusedOpen is false, however a side effect
would be that it would try to reload the info for nodes where the model returned a
null NodeInfo every time the method is called possibly resulting in undesirable behavior(however
it would be nice to be able to force this in some situations).

2) Add another flag in BrowserCellList to identify whether the focusedKey is a Leaf
or not and if the the focusedKey is a leaf so if it changes you try to reload the child
panel.

Shortest code snippet which demonstrates issue (please indicate where
actual result differs from expected result):

private final ListDataProvider<String> dataProvider = new ListDataProvider<String>(Arrays.asList("Leaf"));
private boolean leaf = true;

@Override
public void onModuleLoad()
{
    TreeViewModel model = new TreeViewModel()
    {
        @SuppressWarnings({ "unchecked", "rawtypes" })
        @Override
        public <T> NodeInfo<?> getNodeInfo(T value)
        {
            return new DefaultNodeInfo(dataProvider, new TextCell());
        }

        @Override
        public boolean isLeaf(Object value)
        {
            return leaf;
        }
    };
    CellBrowser cb = new CellBrowser(model, null);
    RootLayoutPanel.get().add(cb);
    Button button = new Button("Switch");
    button.addClickHandler(new ClickHandler()
    {
        @Override
        public void onClick(ClickEvent event)
        {
            leaf = false;
            dataProvider.refresh();
        }
    });
    final PopupPanel popupPanel = new PopupPanel();
    popupPanel.setWidget(button);
    popupPanel.setPopupPositionAndShow(new PositionCallback()
    {
        @Override
        public void setPosition(int offsetWidth, int offsetHeight)
        {
            popupPanel.setPopupPosition(Document.get().getClientWidth() - popupPanel.getOffsetWidth()
- 5, Document.get().getClientHeight()
                    - popupPanel.getOffsetHeight() - 5);
        }
    });
}

Workaround if you have one:
No workaround if the node is the only child.  if it isn't the only child you can select
another child and then re-select the node in question.  Will submit another bug because
when a leaf is unselected or a node with a null NodeInfo is closed the focusKey never
gets cleared.

Reported by lineman78 on 2011-11-16 04:49:52

dankurka commented 9 years ago
To see the error in the sample code, click the leaf "Leaf" in the cell browser, then
click the "Switch" button.  To see how it should act, reload and click "Switch" before
clicking "Leaf".

Reported by lineman78 on 2011-11-16 19:29:48

dankurka commented 9 years ago

Reported by stephen.haberman on 2011-11-19 04:53:39

dankurka commented 9 years ago

Reported by dankurka@google.com on 2013-05-27 06:40:04