Exemplo n.º 1
0
  private void showPopup() {
    if (position.equals("auto")) {
      int extra = 20;

      int left = getPopupPositionWidget().getAbsoluteLeft();
      int top =
          getPopupPositionWidget().getAbsoluteTop() + getPopupPositionWidget().getOffsetHeight();
      int browserWindowWidth = Window.getClientWidth() + Window.getScrollLeft();
      int browserWindowHeight = Window.getClientHeight() + Window.getScrollTop();
      if (left + popup.getOffsetWidth() > browserWindowWidth - extra) {
        left =
            getPopupPositionWidget().getAbsoluteLeft()
                - (popup.getOffsetWidth() - getPopupPositionWidget().getOffsetWidth());
      }
      if (top + popup.getOffsetHeight() > browserWindowHeight - extra) {
        top = getPopupPositionWidget().getAbsoluteTop() - popup.getOffsetHeight() - 2;
      }
      left = left + xOffset;
      if (left < 0) {
        left = 0;
      }
      popup.setPopupPosition(left, top + yOffset);
      popup.setVisible(true);
    } else if (position.equals("fixed")) {
      int extra = 20;

      int left = getPopupPositionWidget().getAbsoluteLeft();
      int top =
          getPopupPositionWidget().getAbsoluteTop()
              + getPopupPositionWidget().getOffsetHeight()
              - Window.getScrollTop();

      int browserWindowWidth = Window.getClientWidth() + Window.getScrollLeft();
      int clientHeight = Window.getClientHeight();
      if (left + popup.getOffsetWidth() > browserWindowWidth - extra) {
        left =
            getPopupPositionWidget().getAbsoluteLeft()
                - (popup.getOffsetWidth() - getPopupPositionWidget().getOffsetWidth());
      }
      if (top + popup.getOffsetHeight() > clientHeight - extra) {
        top =
            (getPopupPositionWidget().getAbsoluteTop() - Window.getScrollTop())
                - popup.getOffsetHeight()
                - 2;
      }
      left = left + xOffset;
      if (left < 0) {
        left = 0;
      }
      popup.setPopupPosition(left, top + yOffset);
      popup.addStyleName("fixed");
      popup.setShadowStyle("fixed");
      popup.setVisible(true);
    }
  }
Exemplo n.º 2
0
 private void doScrollTo(double progress) {
   Double delta;
   if (progress > 0) {
     if (Window.getScrollTop() <= newScrollTop) {
       delta = Window.getScrollTop() + (newScrollTop - Window.getScrollTop()) * progress;
       Window.scrollTo(0, delta.intValue());
     } else {
       delta = Window.getScrollTop() - (Window.getScrollTop() - newScrollTop) * progress;
       Window.scrollTo(0, delta.intValue());
     }
   }
 }
 public void center() {
   boundaryPanel.clear();
   int left = (Window.getClientWidth() - windowPanel.getOffsetWidth()) >> 1;
   int top = (Window.getClientHeight() - windowPanel.getOffsetHeight()) >> 1;
   boundaryPanel.add(windowPanel, Window.getScrollLeft() + left, Window.getScrollTop() + top);
   left = (Window.getClientWidth() - windowPanel.getOffsetWidth()) >> 1;
   top = (Window.getClientHeight() - windowPanel.getOffsetHeight()) >> 1;
   boundaryPanel.clear();
   boundaryPanel.add(windowPanel, Window.getScrollLeft() + left, Window.getScrollTop() + top);
   // hide <embeds>
   FrameUtils.toggleEmbedVisibility(false);
 }
Exemplo n.º 4
0
  private void setValueByEvent(Event event, boolean updateToServer) {
    double v = min; // Fallback to min

    final int coord = getEventPosition(event);

    final int handleSize, baseSize, baseOffset;
    if (vertical) {
      handleSize = handle.getOffsetHeight();
      baseSize = base.getOffsetHeight();
      baseOffset = base.getAbsoluteTop() - Window.getScrollTop() - handleSize / 2;
    } else {
      handleSize = handle.getOffsetWidth();
      baseSize = base.getOffsetWidth();
      baseOffset = base.getAbsoluteLeft() - Window.getScrollLeft() + handleSize / 2;
    }

    if (vertical) {
      v =
          ((baseSize - (coord - baseOffset)) / (double) (baseSize - handleSize)) * (max - min)
              + min;
    } else {
      v = ((coord - baseOffset) / (double) (baseSize - handleSize)) * (max - min) + min;
    }

    if (v < min) {
      v = min;
    } else if (v > max) {
      v = max;
    }

    setValue(v, updateToServer);
  }
Exemplo n.º 5
0
  protected void center(int offsetWidth, int offsetHeight) {
    int width = Window.getClientWidth();
    int height = Window.getClientHeight();
    int scrollLeft = Window.getScrollLeft();
    int scrollRight = Window.getScrollTop();

    int left = scrollLeft + (width - offsetWidth) / 2;
    int top = scrollRight + (height - offsetHeight) / 2;

    child.setPopupPosition(left, top);
  }
  public ContainerBuilderWidget() {
    this.setModal(false);
    this.setAutoHideEnabled(false);
    this.setAnimationEnabled(true);
    this.setPopupPosition(10, Window.getScrollTop() + 10);
    this.setText(constants.windowTitle());
    this.addStyleName("builder");

    builderContent = new VerticalPanel();
    this.add(builderContent);
    builderContent.setWidth("200px");
    builderContent.setStyleName("builder");
  }
Exemplo n.º 7
0
  private void moveIntoVisibleArea() {
    if (calendarDlg != null) {
      int w = Window.getClientWidth() + Window.getScrollLeft();
      int xd = calendarDlg.getAbsoluteLeft();
      int wd = calendarGrid.getOffsetWidth() + 40;
      if ((xd + wd) > w) {
        xd = xd - ((xd + wd) - w);
      }

      int h = Window.getClientHeight() + Window.getScrollTop();
      int yd = calendarDlg.getAbsoluteTop();
      int hd = calendarDlg.getOffsetHeight() + 20;
      if ((yd + hd) > h) {
        yd = yd - ((yd + hd) - h);
      }
      calendarDlg.setPopupPosition(xd, yd);
    }
  }
Exemplo n.º 8
0
  public S screenCenter() {
    int width = this.outerWidth();
    int height = this.outerHeight();

    int left = (Window.getClientWidth() - width) >> 1;
    int top = (Window.getClientHeight() - height) >> 1;

    int computedLeft =
        Math.max(Window.getScrollLeft() + left, 0) - Document.get().getBodyOffsetLeft();
    int computedTop = Math.max(Window.getScrollTop() + top, 0) - Document.get().getBodyOffsetTop();

    Element element = this.getElement();
    element.getStyle().setPropertyPx("left", computedLeft);
    element.getStyle().setPropertyPx("top", computedTop);
    element.getStyle().setPosition(Position.ABSOLUTE);

    return (S) this;
  }
Exemplo n.º 9
0
  /**
   * Centers the popup in the browser window and shows it. If the popup was already showing, then
   * the popup is centered.
   */
  public void center() {
    boolean initiallyShowing = showing;
    boolean initiallyAnimated = isAnimationEnabled;

    if (!initiallyShowing) {
      setVisible(false);
      setAnimationEnabled(false);
      show();
    }

    // If left/top are set from a previous center() call, and our content
    // has changed, we may get a bogus getOffsetWidth because our new content
    // is wrapping (giving a lower offset width) then it would without the
    // previous left. Setting left/top back to 0 avoids this.
    Element elem = getElement();
    elem.getStyle().setPropertyPx("left", 0);
    elem.getStyle().setPropertyPx("top", 0);

    int left = (Window.getClientWidth() - getOffsetWidth()) >> 1;
    int top = (Window.getClientHeight() - getOffsetHeight()) >> 1;
    setPopupPosition(
        Math.max(Window.getScrollLeft() + left, 0), Math.max(Window.getScrollTop() + top, 0));

    if (!initiallyShowing) {
      setAnimationEnabled(initiallyAnimated);
      // Run the animation. The popup is already visible, so we can skip the
      // call to setState.
      if (initiallyAnimated) {
        impl.setClip(getElement(), "rect(0px, 0px, 0px, 0px)");
        setVisible(true);
        resizeAnimation.run(ANIMATION_DURATION);
      } else {
        setVisible(true);
      }
    }
  }
  public ResizableDialogBox(
      final String headerText,
      String okText,
      String cancelText,
      final Widget content,
      final boolean modal) {
    this.content = content;
    boundaryPanel =
        new AbsolutePanel() {
          public void onBrowserEvent(Event event) {
            super.onBrowserEvent(event);
            if (!modal && event.getTypeInt() == Event.ONCLICK) {
              hide();
            }
          }
        };
    boundaryPanel.setSize(
        "100%",
        Window.getClientHeight() + Window.getScrollTop() + "px"); // $NON-NLS-1$ //$NON-NLS-2$
    boundaryPanel.setVisible(true);
    RootPanel.get().add(boundaryPanel, 0, 0);
    boundaryPanel.sinkEvents(Event.ONCLICK);
    boundaryPanel
        .getElement()
        .getStyle()
        .setProperty("cursor", "wait"); // $NON-NLS-1$ //$NON-NLS-2$

    // initialize window controller which provides drag and resize windows
    WindowController windowController = new WindowController(boundaryPanel);

    // content wrapper
    Button ok = new Button(okText);
    ok.setStylePrimaryName("pentaho-button");
    ok.getElement().setAttribute("id", "okButton"); // $NON-NLS-1$ //$NON-NLS-2$
    ok.addClickHandler(
        new ClickHandler() {

          @Override
          public void onClick(ClickEvent event) {
            if (validatorCallback == null
                || (validatorCallback != null && validatorCallback.validate())) {
              try {
                if (callback != null) {
                  callback.okPressed();
                }
              } catch (Throwable dontCare) {
              }
              hide();
            }
          }
        });
    final HorizontalPanel dialogButtonPanel = new HorizontalPanel();
    dialogButtonPanel.setSpacing(2);
    dialogButtonPanel.add(ok);
    if (cancelText != null) {
      Button cancel = new Button(cancelText);
      cancel.setStylePrimaryName("pentaho-button");
      cancel.getElement().setAttribute("id", "cancelButton"); // $NON-NLS-1$ //$NON-NLS-2$
      cancel.addClickHandler(
          new ClickHandler() {

            public void onClick(ClickEvent event) {
              try {
                if (callback != null) {
                  callback.cancelPressed();
                }
              } catch (Throwable dontCare) {
              }
              hide();
            }
          });
      dialogButtonPanel.add(cancel);
    }
    HorizontalPanel dialogButtonPanelWrapper = new HorizontalPanel();
    if (okText != null && cancelText != null) {
      dialogButtonPanelWrapper.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
    } else {
      dialogButtonPanelWrapper.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    }
    dialogButtonPanelWrapper.setStyleName("dialogButtonPanel"); // $NON-NLS-1$
    dialogButtonPanelWrapper.setWidth("100%"); // $NON-NLS-1$
    dialogButtonPanelWrapper.add(dialogButtonPanel);

    Grid dialogContent = new Grid(2, 1);
    dialogContent.setCellPadding(0);
    dialogContent.setCellSpacing(0);
    dialogContent.getCellFormatter().setVerticalAlignment(1, 0, HasVerticalAlignment.ALIGN_TOP);
    dialogContent
        .getCellFormatter()
        .setHorizontalAlignment(1, 0, HasHorizontalAlignment.ALIGN_LEFT);
    // add content
    dialogContent.setWidget(0, 0, content);
    dialogContent.getCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_TOP);
    // add button panel
    dialogContent.setWidget(1, 0, dialogButtonPanelWrapper);
    dialogContent.getCellFormatter().setVerticalAlignment(1, 0, HasVerticalAlignment.ALIGN_BOTTOM);
    dialogContent.setWidth("100%"); // $NON-NLS-1$
    dialogContent.setHeight("100%"); // $NON-NLS-1$

    windowPanel = new WindowPanel(windowController, headerText, dialogContent, true);
  }
 public void showPopup() {
   this.setPopupPosition(10, Window.getScrollTop() + 10);
   this.show();
 }
Exemplo n.º 12
0
 public void onBrowserEvent(Event event) {
   // the id's which are set on these menu items must be set AFTER the items are added to their
   // menu
   // when an element is added to a menu an auto-generated id will be assigned, so we must override
   // this
   if (perspective != null) {
     if ((DOM.eventGetType(event) & Event.ONDBLCLICK) == Event.ONDBLCLICK) {
       openTabInNewWindow();
     } else if (DOM.eventGetButton(event) == Event.BUTTON_RIGHT) {
       int left = Window.getScrollLeft() + DOM.eventGetClientX(event);
       int top = Window.getScrollTop() + DOM.eventGetClientY(event);
       popupMenu.setPopupPosition(left, top);
       MenuBar menuBar = new MenuBar(true);
       menuBar.setAutoOpen(true);
       if (tabContent instanceof IFrameTabPanel) {
         MenuItem backMenuItem =
             new MenuItem(
                 Messages.getString("back"),
                 new TabCommand(TABCOMMANDTYPE.BACK, popupMenu)); // $NON-NLS-1$
         menuBar.addItem(backMenuItem);
         backMenuItem.getElement().setId("back"); // $NON-NLS-1$
         menuBar.addSeparator();
         MenuItem reloadTabMenuItem =
             new MenuItem(
                 Messages.getString("reloadTab"),
                 new TabCommand(TABCOMMANDTYPE.RELOAD, popupMenu)); // $NON-NLS-1$
         menuBar.addItem(reloadTabMenuItem);
         reloadTabMenuItem.getElement().setId("reloadTab"); // $NON-NLS-1$
       }
       if (tabPanel.getTabBar().getTabCount() > 1) {
         MenuItem reloadAllTabsMenuItem =
             new MenuItem(
                 Messages.getString("reloadAllTabs"),
                 new TabCommand(TABCOMMANDTYPE.RELOAD_ALL, popupMenu)); // $NON-NLS-1$
         menuBar.addItem(reloadAllTabsMenuItem);
         reloadAllTabsMenuItem.getElement().setId("reloadAllTabs"); // $NON-NLS-1$
       } else {
         MenuItem reloadAllTabsMenuItem =
             new MenuItem(Messages.getString("reloadAllTabs"), (Command) null); // $NON-NLS-1$
         menuBar.addItem(reloadAllTabsMenuItem);
         reloadAllTabsMenuItem.getElement().setId("reloadAllTabs"); // $NON-NLS-1$
         reloadAllTabsMenuItem.setStyleName("disabledMenuItem"); // $NON-NLS-1$
       }
       menuBar.addSeparator();
       if (tabContent instanceof IFrameTabPanel) {
         MenuItem openTabInNewWindowMenuItem =
             new MenuItem(
                 Messages.getString("openTabInNewWindow"),
                 new TabCommand(TABCOMMANDTYPE.NEW_WINDOW, popupMenu)); // $NON-NLS-1$
         menuBar.addItem(openTabInNewWindowMenuItem);
         openTabInNewWindowMenuItem.getElement().setId("openTabInNewWindow"); // $NON-NLS-1$
         MenuItem createDeepLinkMenuItem =
             new MenuItem(
                 Messages.getString("createDeepLink"),
                 new TabCommand(TABCOMMANDTYPE.CREATE_DEEP_LINK, popupMenu)); // $NON-NLS-1$
         menuBar.addItem(createDeepLinkMenuItem);
         createDeepLinkMenuItem.getElement().setId("deepLink"); // $NON-NLS-1$
         menuBar.addSeparator();
       }
       menuBar.addItem(
           new MenuItem(
               Messages.getString("closeTab"),
               new TabCommand(TABCOMMANDTYPE.CLOSE, popupMenu))); // $NON-NLS-1$
       if (tabPanel.getTabBar().getTabCount() > 1) {
         MenuItem closeOtherTabsMenuItem =
             new MenuItem(
                 Messages.getString("closeOtherTabs"),
                 new TabCommand(TABCOMMANDTYPE.CLOSE_OTHERS, popupMenu)); // $NON-NLS-1$
         menuBar.addItem(closeOtherTabsMenuItem);
         closeOtherTabsMenuItem.getElement().setId("closeOtherTabs"); // $NON-NLS-1$
         MenuItem closeAllTabsMenuItem =
             new MenuItem(
                 Messages.getString("closeAllTabs"),
                 new TabCommand(TABCOMMANDTYPE.CLOSE_ALL, popupMenu)); // $NON-NLS-1$
         menuBar.addItem(closeAllTabsMenuItem);
         closeAllTabsMenuItem.getElement().setId("closeAllTabs"); // $NON-NLS-1$
       } else {
         MenuItem closeOtherTabsMenuItem =
             new MenuItem(Messages.getString("closeOtherTabs"), (Command) null); // $NON-NLS-1$
         closeOtherTabsMenuItem.setStyleName("disabledMenuItem"); // $NON-NLS-1$
         MenuItem closeAllTabsMenuItem =
             new MenuItem(Messages.getString("closeAllTabs"), (Command) null); // $NON-NLS-1$
         closeAllTabsMenuItem.setStyleName("disabledMenuItem"); // $NON-NLS-1$
         menuBar.addItem(closeOtherTabsMenuItem);
         menuBar.addItem(closeAllTabsMenuItem);
         closeOtherTabsMenuItem.getElement().setId("closeOtherTabs"); // $NON-NLS-1$
         closeAllTabsMenuItem.getElement().setId("closeAllTabs"); // $NON-NLS-1$
       }
       popupMenu.setWidget(menuBar);
       popupMenu.hide();
       popupMenu.show();
     }
   }
   super.onBrowserEvent(event);
 }
Exemplo n.º 13
0
  /**
   * Positions the popup, called after the offset width and height of the popup are known.
   *
   * @param relativeObject the ui object to position relative to
   * @param offsetWidth the drop down's offset width
   * @param offsetHeight the drop down's offset height
   */
  private void position(final UIObject relativeObject, int offsetWidth, int offsetHeight) {
    // Calculate left position for the popup. The computation for
    // the left position is bidi-sensitive.

    int textBoxOffsetWidth = relativeObject.getOffsetWidth();

    // Compute the difference between the popup's width and the
    // textbox's width
    int offsetWidthDiff = offsetWidth - textBoxOffsetWidth;

    int left;

    if (LocaleInfo.getCurrentLocale().isRTL()) { // RTL case

      int textBoxAbsoluteLeft = relativeObject.getAbsoluteLeft();

      // Right-align the popup. Note that this computation is
      // valid in the case where offsetWidthDiff is negative.
      left = textBoxAbsoluteLeft - offsetWidthDiff;

      // If the suggestion popup is not as wide as the text box, always
      // align to the right edge of the text box. Otherwise, figure out whether
      // to right-align or left-align the popup.
      if (offsetWidthDiff > 0) {

        // Make sure scrolling is taken into account, since
        // box.getAbsoluteLeft() takes scrolling into account.
        int windowRight = Window.getClientWidth() + Window.getScrollLeft();
        int windowLeft = Window.getScrollLeft();

        // Compute the left value for the right edge of the textbox
        int textBoxLeftValForRightEdge = textBoxAbsoluteLeft + textBoxOffsetWidth;

        // Distance from the right edge of the text box to the right edge
        // of the window
        int distanceToWindowRight = windowRight - textBoxLeftValForRightEdge;

        // Distance from the right edge of the text box to the left edge of the
        // window
        int distanceFromWindowLeft = textBoxLeftValForRightEdge - windowLeft;

        // If there is not enough space for the overflow of the popup's
        // width to the right of the text box and there IS enough space for the
        // overflow to the right of the text box, then left-align the popup.
        // However, if there is not enough space on either side, stick with
        // right-alignment.
        if (distanceFromWindowLeft < offsetWidth && distanceToWindowRight >= offsetWidthDiff) {
          // Align with the left edge of the text box.
          left = textBoxAbsoluteLeft;
        }
      }
    } else { // LTR case

      // Left-align the popup.
      left = relativeObject.getAbsoluteLeft();

      // If the suggestion popup is not as wide as the text box, always align to
      // the left edge of the text box. Otherwise, figure out whether to
      // left-align or right-align the popup.
      if (offsetWidthDiff > 0) {
        // Make sure scrolling is taken into account, since
        // box.getAbsoluteLeft() takes scrolling into account.
        int windowRight = Window.getClientWidth() + Window.getScrollLeft();
        int windowLeft = Window.getScrollLeft();

        // Distance from the left edge of the text box to the right edge
        // of the window
        int distanceToWindowRight = windowRight - left;

        // Distance from the left edge of the text box to the left edge of the
        // window
        int distanceFromWindowLeft = left - windowLeft;

        // If there is not enough space for the overflow of the popup's
        // width to the right of hte text box, and there IS enough space for the
        // overflow to the left of the text box, then right-align the popup.
        // However, if there is not enough space on either side, then stick with
        // left-alignment.
        if (distanceToWindowRight < offsetWidth && distanceFromWindowLeft >= offsetWidthDiff) {
          // Align with the right edge of the text box.
          left -= offsetWidthDiff;
        }
      }
    }

    // Calculate top position for the popup

    int top = relativeObject.getAbsoluteTop();

    // Make sure scrolling is taken into account, since
    // box.getAbsoluteTop() takes scrolling into account.
    int windowTop = Window.getScrollTop();
    int windowBottom = Window.getScrollTop() + Window.getClientHeight();

    // Distance from the top edge of the window to the top edge of the
    // text box
    int distanceFromWindowTop = top - windowTop;

    // Distance from the bottom edge of the window to the bottom edge of
    // the text box
    int distanceToWindowBottom = windowBottom - (top + relativeObject.getOffsetHeight());

    // If there is not enough space for the popup's height below the text
    // box and there IS enough space for the popup's height above the text
    // box, then then position the popup above the text box. However, if there
    // is not enough space on either side, then stick with displaying the
    // popup below the text box.
    if (distanceToWindowBottom < offsetHeight && distanceFromWindowTop >= offsetHeight) {
      top -= offsetHeight;
    } else {
      // Position above the text box
      top += relativeObject.getOffsetHeight();
    }
    setPopupPosition(left, top);
  }