minLeft = spaceAssurance;
}
// get the max right position
int maxRight = minLeft + space;
// get the middle button position
PositionBean buttonPosition = PositionBean.generatePositionInfo(button.getElement());
int buttonMiddle = (buttonPosition.getLeft() - Window.getScrollLeft()) + (buttonPosition.getWidth() / 2);
// get the content width
int contentWidth = popup.getOffsetWidth();
// the optimum left position is in the middle of the button minus the half content width
// assume that the optimum fits into the space
int contentLeft = buttonMiddle - (contentWidth / 2);
if (minLeft > contentLeft) {
// if the optimum left position of the popup is outside the min left position:
// move the popup to the right (take the min left position as left)
contentLeft = minLeft;
} else if ((contentLeft + contentWidth) > maxRight) {
// if the left position plus the content width is outside the max right position:
// move the popup to the left (take the max right position minus the content width)
contentLeft = maxRight - contentWidth;
}
// limit the right position if the popup is right outside the window
if ((contentLeft + contentWidth + spaceAssurance) > windowWidth) {
contentLeft = windowWidth - contentWidth - spaceAssurance;
}
// limit the left position if the popup is left outside the window
if (contentLeft < spaceAssurance) {
contentLeft = spaceAssurance;
}
int arrowSpace = 10;
int arrowWidth = I_LayoutBundle.INSTANCE.gwtImages().menuArrowTopImage().getWidth();
int arrowHeight = I_LayoutBundle.INSTANCE.gwtImages().menuArrowTopImage().getHeight();
// the optimum position for the arrow is in the middle of the button
int arrowLeft = buttonMiddle - contentLeft - (arrowWidth / 2);
if ((arrowLeft + arrowWidth + arrowSpace) > contentWidth) {
// limit the arrow position if the maximum is reached (content width 'minus x')
arrowLeft = contentWidth - arrowWidth - arrowSpace;
} else if ((arrowLeft - arrowSpace) < 0) {
// limit the arrow position if the minimum is reached ('plus x')
arrowLeft = arrowWidth + arrowSpace;
}
int arrowTop = -(arrowHeight - 2);
String arrowClass = I_LayoutBundle.INSTANCE.dialogCss().menuArrowTop();
int contentTop = (((buttonPosition.getTop() + buttonPosition.getHeight()) - Window.getScrollTop()) + arrowHeight) - 2;
if (!isToolbarMode) {
contentTop = (buttonPosition.getTop() + buttonPosition.getHeight() + arrowHeight) - 2;
int contentHeight = popup.getOffsetHeight();
int windowHeight = Window.getClientHeight();
if (((contentHeight + spaceAssurance) < windowHeight)
&& ((buttonPosition.getTop() - Window.getScrollTop()) > contentHeight)
&& (((contentHeight + spaceAssurance + contentTop) - Window.getScrollTop()) > windowHeight)) {
// content fits into the window height,
// there is enough space above the button
// and there is to little space below the button
// so show above
contentTop = ((buttonPosition.getTop() - arrowHeight) + 2) - contentHeight;
arrowTop = contentHeight - 1;
arrowClass = I_LayoutBundle.INSTANCE.dialogCss().menuArrowBottom();
}
} else {
contentLeft = contentLeft - Window.getScrollLeft();