ListButton listButton = (ListButton)button;
if (listButton.getListData().getLength() > 0) {
// Determine the popup's location and preferred size, relative
// to the button
Display display = listButton.getDisplay();
if (display != null) {
int width = getWidth();
int height = getHeight();
// Adjust for list size
if (listSize == -1) {
listViewBorder.setPreferredHeight(-1);
} else {
if (!listViewBorder.isPreferredHeightSet()) {
ListView.ItemRenderer itemRenderer = listView.getItemRenderer();
int borderHeight = itemRenderer.getPreferredHeight(-1) * listSize + 2;
if (listViewBorder.getPreferredHeight() > borderHeight) {
listViewBorder.setPreferredHeight(borderHeight);
} else {
listViewBorder.setPreferredHeight(-1);
}
}
}
// Ensure that the popup remains within the bounds of the display
Point buttonLocation = listButton.mapPointToAncestor(display, 0, 0);
Dimensions displaySize = display.getSize();
listViewPopup.setPreferredSize(-1, -1);
Dimensions popupSize = listViewPopup.getPreferredSize();
int popupWidth = Math.max(popupSize.width, listButton.getWidth() - TRIGGER_WIDTH - 1);
int popupHeight = popupSize.height;