Skip to content

Commit

Permalink
#1: NPE on event generation by rebuild of tab panel
Browse files Browse the repository at this point in the history
Optimized fix implementation
  • Loading branch information
esocode committed Feb 12, 2018
1 parent 801ec68 commit 8706b28
Showing 1 changed file with 20 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,24 @@ public void collectInput(List<DataElement<?>> rModifiedElements)

if (nSelection >= 0)
{
getDataElementUI(nSelection).collectInput(rModifiedElements);
DataElementUI<?> rDataElementUI = getDataElementUI(nSelection);

rDataElementUI.collectInput(rModifiedElements);
}
}

/***************************************
* {@inheritDoc}
*/
@Override
public void dispose()
{
// remove event listener to avoid event handling for non-existing UIs
aSwitchPanel.removeEventListener(EventType.SELECTION, this);

super.dispose();
}

/***************************************
* Returns the index of the currently selected page element.
*
Expand All @@ -130,14 +144,7 @@ public void handleEvent(EWTEvent rEvent)

if (nSelection >= 0)
{
DataElementUI<?> rDataElementUI = getDataElementUI(nSelection);

// can be NULL because GWT tab panel fires selection events on
// clear() which is performed on a rebuild
if (rDataElementUI != null)
{
rDataElementUI.update();
}
getDataElementUI(nSelection).update();
}
}

Expand All @@ -151,15 +158,6 @@ public void setSelectedElement(int nElement)
aSwitchPanel.setSelection(nElement);
}

/***************************************
* {@inheritDoc}
*/
@Override
public void update(DataElementList rNewDataElementList, boolean bUpdateUI)
{
super.update(rNewDataElementList, bUpdateUI);
}

/***************************************
* {@inheritDoc}
*/
Expand Down Expand Up @@ -221,6 +219,8 @@ protected void buildElementUIs()
setSelectedElement(getDataElementList().getProperty(CURRENT_SELECTION,
0));
}

aSwitchPanel.addEventListener(EventType.SELECTION, this);
}

/***************************************
Expand Down Expand Up @@ -257,7 +257,6 @@ protected ContainerBuilder<? extends Panel> createPanel(
}

aSwitchPanel = aPanelBuilder.getContainer();
aSwitchPanel.addEventListener(EventType.SELECTION, this);

return aPanelBuilder;
}
Expand All @@ -275,6 +274,8 @@ protected ContainerBuilder<? extends Panel> createPanel(
*/
private DataElementUI<?> getDataElementUI(int nIndex)
{
assert nIndex >= 0 && nIndex < getDataElementUIs().size();

Iterator<DataElementUI<?>> rUIs =
getDataElementUIs().values().iterator();

Expand Down

0 comments on commit 8706b28

Please sign in to comment.