Ejemplo n.º 1
0
 /** {@inheritDoc} */
 @Override
 protected void onBlur(ComponentEvent ce) {
   final Rectangle rec = button.el().getBounds();
   if (rec.contains(BaseEventPreview.getLastXY())) {
     ce.stopEvent();
     return;
   }
   super.onBlur(ce);
   focusPreview.remove();
 }
Ejemplo n.º 2
0
  /**
   * Makes this the active window by showing its shadow, or deactivates it by hiding its shadow.
   * This method also fires the activate or deactivate event depending on which action occurred.
   */
  public void setActive(boolean active) {
    if (active) {
      if (rendered && !maximized && layer != null) {
        if (getShadow()) {
          layer.enableShadow();
        }
        layer.sync(true);
      }
      if (isVisible()) {
        eventPreview.push();

        if (modal && modalPanel == null) {
          modalPanel = ModalPanel.pop();
          modalPanel.setBlink(blinkModal);
          modalPanel.show(this);
        }
      }

      fireEvent(Events.Activate, new WindowEvent(this));
    } else {
      if (modalPanel != null) {
        ModalPanel.push(modalPanel);
        modalPanel = null;
      }
      hideShadow();
      fireEvent(Events.Deactivate, new WindowEvent(this));
    }
  }
Ejemplo n.º 3
0
Archivo: Menu.java Proyecto: Jullil/gxt
  /** Creates a new menu. */
  public Menu() {
    baseStyle = "x-menu";
    shim = true;
    monitorWindowResize = true;
    setShadow(true);
    setLayoutOnChange(true);

    enableLayout = true;
    setLayout(new MenuLayout());
    eventPreview =
        new BaseEventPreview() {

          @Override
          protected boolean onPreview(PreviewEvent pe) {
            Menu.this.onAutoHide(pe);
            return super.onPreview(pe);
          }

          @Override
          protected void onPreviewKeyPress(PreviewEvent pe) {
            super.onPreviewKeyPress(pe);
            onEscape(pe);
          }
        };
    eventPreview.setAutoHide(false);
  }
Ejemplo n.º 4
0
  @Override
  protected void onRender(Element target, int index) {
    setElement(DOM.createDiv(), target, index);
    el().makePositionable(true);
    super.onRender(target, index);

    ul = new El(DOM.createDiv());
    ul.addStyleName(baseStyle + "-list");

    getElement().appendChild(ul.dom);

    // add menu to ignore list
    eventPreview.getIgnoreList().add(getElement());

    el().setTabIndex(0);
    el().setElementAttribute("hideFocus", "true");

    el().addStyleName("x-ignore");
    if (GXT.isAriaEnabled()) {
      Accessibility.setRole(getElement(), "menu");
      Accessibility.setRole(ul.dom, "presentation");
      handleRadioGroups();
    }

    if (plain) {
      addStyleName("x-menu-plain");
    }
    if (!showSeparator) {
      addStyleName("x-menu-nosep");
    }

    sinkEvents(Event.ONCLICK | Event.MOUSEEVENTS | Event.KEYEVENTS | Event.ONMOUSEWHEEL);
  }
Ejemplo n.º 5
0
  /**
   * Displays this menu at a specific xy position.
   *
   * @param x the x coordinate
   * @param y the y coordinate
   */
  public void showAt(int x, int y) {
    MenuEvent me = new MenuEvent(this);
    if (fireEvent(Events.BeforeShow, me)) {
      RootPanel.get().add(this);

      el().makePositionable(true);

      onShow();
      el().updateZIndex(0);

      showing = true;
      doAutoSize();

      if (constrainViewport) {
        Point p = el().adjustForConstraints(new Point(x, y));
        x = p.x;
        y = p.y;
      }
      setPagePosition(x + XDOM.getBodyScrollLeft(), y + XDOM.getBodyScrollTop());
      if (enableScrolling) {
        constrainScroll(y);
      }

      el().show();
      eventPreview.add();

      if (focusOnShow) {
        focus();
      }

      fireEvent(Events.Show, me);
    }
  }
Ejemplo n.º 6
0
 @Override
 protected void onDetach() {
   super.onDetach();
   if (eventPreview != null) {
     eventPreview.remove();
   }
 }
Ejemplo n.º 7
0
 /** {@inheritDoc} */
 @Override
 protected void onDetach() {
   super.onDetach();
   if (focusPreview != null) {
     focusPreview.remove();
   }
 }
Ejemplo n.º 8
0
  /**
   * Displays this menu relative to another element.
   *
   * @param elem the element to align to
   * @param pos the {@link El#alignTo} anchor position to use in aligning to the element (defaults
   *     to defaultAlign)
   * @param offsets the menu align offsets
   */
  public void show(Element elem, String pos, int[] offsets) {
    MenuEvent me = new MenuEvent(this);
    if (fireEvent(Events.BeforeShow, me)) {
      RootPanel.get().add(this);

      el().makePositionable(true);

      onShow();
      el().updateZIndex(0);

      showing = true;
      doAutoSize();

      el().alignTo(elem, pos, offsets);

      if (enableScrolling) {
        constrainScroll(el().getY());
      }
      el().show();

      eventPreview.add();

      if (focusOnShow) {
        focus();
      }

      fireEvent(Events.Show, me);
    }
  }
Ejemplo n.º 9
0
  @Override
  protected void onRender(Element parent, int pos) {
    super.onRender(parent, pos);

    el().makePositionable(true);

    if (manager == null) {
      manager = WindowManager.get();
    }

    if (plain) {
      addStyleName("x-window-plain");
    }

    eventPreview =
        new BaseEventPreview() {

          @Override
          protected boolean onAutoHide(PreviewEvent ce) {
            if (autoHide) {
              if (resizing) {
                return false;
              }
              hide();
              return true;
            }
            return false;
          }

          @Override
          protected void onPreviewKeyPress(PreviewEvent pe) {
            WindowEvent we = new WindowEvent(Window.this, pe.getEvent());
            onKeyPress(we);
          }
        };
    eventPreview.getIgnoreList().add(getElement());

    sinkEvents(Event.ONMOUSEDOWN | Event.ONKEYPRESS);

    el().setTabIndex(0);
    el().setElementAttribute("hideFocus", "true");

    if (GXT.isAriaEnabled()) {
      Accessibility.setRole(getElement(), "alertdialog");
      Accessibility.setState(getElement(), "aria-labelledby", head.getId() + "-label");
      Accessibility.setState(getElement(), "aria-hidden", "true");
    }

    if (modal || maximizable || constrain) {
      monitorWindowResize = true;
    }

    if (super.width == null) {
      setWidth(Math.max(initialWidth, minWidth));
    }
  }
Ejemplo n.º 10
0
  protected void onRender(Element target, int index) {
    if (template == null) {
      if (buttonTemplate == null) {
        StringBuffer sb = new StringBuffer();
        sb.append(
            "<table cellspacing=\"0\" class=\"x-btn\" role=\"presentation\"><tbody class=\"{2}\" >");
        sb.append(
            "<tr><td class=\"x-btn-tl\"><i>&#160;</i></td><td class=\"x-btn-tc\"></td><td class=\"x-btn-tr\"><i>&#160;</i></td></tr>");
        sb.append(
            "<tr><td class=\"x-btn-ml\"><i>&#160;</i></td><td class=\"x-btn-mc\"><em class=\"{3}\" unselectable=\"on\"><button class=\"x-btn-text\" type=\"{1}\">{0}</button></em></td><td class=\"x-btn-mr\"><i>&#160;</i></td></tr>");
        sb.append(
            "<tr><td class=\"x-btn-bl\"><i>&#160;</i></td><td class=\"x-btn-bc\"></td><td class=\"x-btn-br\"><i>&#160;</i></td></tr>");
        sb.append("</tbody></table>");

        buttonTemplate = new Template(sb.toString());
      }
      template = buttonTemplate;
    }

    setElement(
        template.create(
            (text != null && text.length() > 0) ? text : "&nbsp;",
            getType(),
            "x-btn-"
                + scale.name().toLowerCase()
                + " x-btn-icon-"
                + scale.name().toLowerCase()
                + "-"
                + iconAlign.name().toLowerCase(),
            getMenuClass()),
        target,
        index);

    super.onRender(target, index);

    buttonEl = el().selectNode(buttonSelector);
    buttonEl.makePositionable();

    if (getFocusEl() != null) {
      getFocusEl().addEventsSunk(Event.FOCUSEVENTS);
    }

    preview.getIgnoreList().add(getElement());

    buttonEl.setTabIndex(0);

    if (GXT.isAriaEnabled()) {
      Accessibility.setRole(buttonEl.dom, Accessibility.ROLE_BUTTON);
      if (menu != null) {
        Accessibility.setState(buttonEl.dom, "aria-haspopup", "true");
      }
    }

    sinkEvents(Event.ONCLICK | Event.MOUSEEVENTS | Event.FOCUSEVENTS);
  }
Ejemplo n.º 11
0
 protected void startDrag(DragEvent de) {
   dragging = true;
   WindowManager.get().bringToFront(this);
   hideShadow();
   ghost = ghost();
   if (eventPreview != null && ghost != null) {
     eventPreview.getIgnoreList().add(ghost.dom);
   }
   showWindow(false);
   Draggable d = de.getDraggable();
   d.setProxy(ghost);
 }
Ejemplo n.º 12
0
  /**
   * Hides the window.
   *
   * @param buttonPressed the button that was pressed or null
   */
  public void hide(Button buttonPressed) {
    if (hidden || !fireEvent(Events.BeforeHide, new WindowEvent(this, buttonPressed))) {
      return;
    }

    if (dragger != null) {
      dragger.cancelDrag();
    }

    hidden = true;

    if (!maximized) {
      restoreSize = getSize();
      restorePos = getPosition(true);
    }

    if (modalPreview != null) {
      modalPreview.removeHandler();
      modalPreview = null;
    }

    onHide();
    manager.unregister(this);
    if (removeFromParentOnHide) {
      removeFromParent();
    }

    if (modalPanel != null) {
      ModalPanel.push(modalPanel);
      modalPanel = null;
    }

    eventPreview.remove();
    notifyHide();

    if (restoreWindowScrolling != null) {
      com.google.gwt.dom.client.Document.get()
          .enableScrolling(restoreWindowScrolling.booleanValue());
    }

    fireEvent(Events.Hide, new WindowEvent(this, buttonPressed));
  }
Ejemplo n.º 13
0
 /**
  * Hides this menu and optionally all parent menus
  *
  * @param deep true to close all parent menus
  * @return this
  */
 public Menu hide(boolean deep) {
   if (showing) {
     MenuEvent me = new MenuEvent(this);
     if (fireEvent(Events.BeforeHide, me)) {
       if (activeItem != null) {
         activeItem.deactivate();
         activeItem = null;
       }
       onHide();
       RootPanel.get().remove(this);
       eventPreview.remove();
       showing = false;
       hidden = true;
       fireEvent(Events.Hide, me);
       if (deep && parentItem != null) {
         parentItem.parentMenu.hide(true);
       }
     }
   }
   return this;
 }
Ejemplo n.º 14
0
 protected void onMouseOver(ComponentEvent ce) {
   if (!disabled && handleMouseEvents) {
     addStyleName(baseStyle + "-over");
   }
   preview.add();
 }
Ejemplo n.º 15
0
 @Override
 protected void onDetach() {
   super.onDetach();
   preview.remove();
 }
Ejemplo n.º 16
0
 /** Creates a new file upload field. */
 public ButtonFileUploadField() {
   focusPreview = new BaseEventPreview();
   focusPreview.setAutoHide(false);
   ensureVisibilityOnSizing = true;
   setWidth(150);
 }
Ejemplo n.º 17
0
 /** {@inheritDoc} */
 @Override
 protected void onFocus(ComponentEvent ce) {
   focusPreview.add();
 }
Ejemplo n.º 18
0
  protected void afterShow() {
    hidden = false;

    // layout early to render window's content for size calcs
    if (!layoutExecuted || isLayoutNeeded()) {
      layout();
    }

    if (restorePos != null) {
      setPosition(restorePos.x, restorePos.y);
      if (restoreSize != null) {
        setSize(restoreSize.width, restoreSize.height);
      }
    }
    if (restoreWindowScrolling != null) {
      com.google.gwt.dom.client.Document.get().enableScrolling(false);
    }

    int h = getHeight();
    int w = getWidth();
    if (h < minHeight && w < minWidth) {
      setSize(minWidth, minHeight);
    } else if (h < minHeight) {
      setHeight(minHeight);
    } else if (w < minWidth) {
      setWidth(minWidth);
    }

    // not positioned, then center
    if (!positioned) {
      el().center(true);
    }

    el().updateZIndex(0);
    if (modal) {
      modalPreview =
          Event.addNativePreviewHandler(
              new NativePreviewHandler() {
                public void onPreviewNativeEvent(NativePreviewEvent event) {
                  if (Element.is(event.getNativeEvent().getEventTarget())) {
                    Element target = (Element) Element.as(event.getNativeEvent().getEventTarget());

                    String tag = target.getTagName();
                    // ignore html and body because of frames
                    if (!resizing
                        && !dragging
                        && !tag.equalsIgnoreCase("html")
                        && !tag.equalsIgnoreCase("body")
                        && event.getTypeInt() != Event.ONLOAD
                        && manager.getActive() == Window.this
                        && (modalPanel == null
                            || (modalPanel != null
                                && !modalPanel.getElement().isOrHasChild(target)))
                        && !Window.this.getElement().isOrHasChild(target)
                        && fly(target).findParent(".x-ignore", -1) == null) {
                      ArrayList<Component> col =
                          new ArrayList<Component>(ComponentManager.get().getAll());
                      for (Component c : col) {
                        if (c instanceof TriggerField<?>) {
                          triggerBlur((TriggerField<?>) c);
                        } else if (c instanceof Menu) {
                          ((Menu) c).hide(true);
                        }
                      }
                      Window.this.focus();
                    }
                  }
                }

                private native void triggerBlur(TriggerField<?> field) /*-{
    [email protected]::triggerBlur(Lcom/extjs/gxt/ui/client/event/ComponentEvent;)(null);
  }-*/;
              });
    }

    // missing cursor workaround
    if (GXT.isGecko) {
      El e = el().selectNode(".x-window-bwrap");
      if (e != null) {
        e.dom.getStyle().setProperty("overflow", "auto");
        e.dom.getStyle().setProperty("position", "static");
      }
    }

    eventPreview.add();

    if (maximized) {
      maximize();
    }
    removeStyleName(HideMode.VISIBILITY.value());

    if (GXT.isAriaEnabled()) {
      Accessibility.setState(getElement(), "aria-hidden", "false");
    }

    fireEvent(Events.Show, new WindowEvent(this));
    toFront();
  }