Search in sources :

Example 11 with Element

use of com.google.gwt.user.client.Element in project rstudio by rstudio.

the class MenuBar method removeItemElement.

/**
   * Removes the specified item from the {@link MenuBar} and the physical DOM
   * structure.
   *
   * @param item the item to be removed
   * @return true if the item was removed
   */
private boolean removeItemElement(UIObject item) {
    int idx = allItems.indexOf(item);
    if (idx == -1) {
        return false;
    }
    Element container = getItemContainerElement();
    DOM.removeChild(container, DOM.getChild(container, idx));
    allItems.remove(idx);
    return true;
}
Also used : Element(com.google.gwt.user.client.Element)

Example 12 with Element

use of com.google.gwt.user.client.Element in project rstudio by rstudio.

the class MenuBar method init.

private void init(boolean vertical, AbstractImagePrototype subMenuIcon) {
    this.subMenuIcon = subMenuIcon;
    Element table = DOM.createTable();
    body = DOM.createTBody();
    DOM.appendChild(table, body);
    if (!vertical) {
        Element tr = DOM.createTR();
        DOM.appendChild(body, tr);
    }
    this.vertical = vertical;
    com.google.gwt.dom.client.Element outer = FocusPanel.impl.createFocusable();
    DOM.appendChild(outer, table);
    setElement(outer);
    Accessibility.setRole(getElement(), Accessibility.ROLE_MENUBAR);
    sinkEvents(Event.ONCLICK | Event.ONMOUSEOVER | Event.ONMOUSEOUT | Event.ONFOCUS | Event.ONKEYDOWN);
    setStyleName(STYLENAME_DEFAULT);
    if (vertical) {
        addStyleDependentName("vertical");
    } else {
        addStyleDependentName("horizontal");
    }
    // Hide focus outline in Mozilla/Webkit/Opera
    DOM.setStyleAttribute(getElement(), "outline", "0px");
    // Hide focus outline in IE 6/7
    DOM.setElementAttribute(getElement(), "hideFocus", "true");
    // Deselect items when blurring without a child menu.
    addDomHandler(new BlurHandler() {

        public void onBlur(BlurEvent event) {
            if (shownChildMenu == null) {
                selectItem(null);
            }
        }
    }, BlurEvent.getType());
}
Also used : BlurHandler(com.google.gwt.event.dom.client.BlurHandler) Element(com.google.gwt.user.client.Element) BlurEvent(com.google.gwt.event.dom.client.BlurEvent)

Example 13 with Element

use of com.google.gwt.user.client.Element in project rstudio by rstudio.

the class MenuBar method clearItems.

/**
   * Removes all menu items from this menu bar.
   */
public void clearItems() {
    // Deselect the current item
    selectItem(null);
    Element container = getItemContainerElement();
    while (DOM.getChildCount(container) > 0) {
        DOM.removeChild(container, DOM.getChild(container, 0));
    }
    // Set the parent of all items to null
    for (UIObject item : allItems) {
        setItemColSpan(item, 1);
        if (item instanceof MenuItemSeparator) {
            ((MenuItemSeparator) item).setParentMenu(null);
        } else {
            ((MenuItem) item).setParentMenu(null);
        }
    }
    // Clear out all of the items and separators
    items.clear();
    allItems.clear();
}
Also used : Element(com.google.gwt.user.client.Element)

Example 14 with Element

use of com.google.gwt.user.client.Element in project rstudio by rstudio.

the class MenuBar method addItemElement.

/**
   * Physically add the td element of a {@link MenuItem} or
   * {@link MenuItemSeparator} to this {@link MenuBar}.
   *
   * @param beforeIndex the index where the separator should be inserted
   * @param tdElem the td element to be added
   */
private void addItemElement(int beforeIndex, Element tdElem) {
    if (vertical) {
        Element tr = DOM.createTR();
        DOM.insertChild(body, tr, beforeIndex);
        DOM.appendChild(tr, tdElem);
    } else {
        Element tr = DOM.getChild(body, 0);
        DOM.insertChild(tr, tdElem, beforeIndex);
    }
}
Also used : Element(com.google.gwt.user.client.Element)

Example 15 with Element

use of com.google.gwt.user.client.Element in project rstudio by rstudio.

the class MenuBar method selectItem.

/**
   * Select the given MenuItem, which must be a direct child of this MenuBar.
   *
   * @param item the MenuItem to select, or null to clear selection
   */
public void selectItem(MenuItem item) {
    assert item == null || item.getParentMenu() == this;
    if (item == selectedItem) {
        return;
    }
    if (selectedItem != null) {
        selectedItem.setSelectionStyle(false);
        // Set the style of the submenu indicator
        if (vertical) {
            Element tr = DOM.getParent(selectedItem.getElement());
            if (DOM.getChildCount(tr) == 2) {
                Element td = DOM.getChild(tr, 1);
                setStyleName(td, "subMenuIcon-selected", false);
            }
        }
        if (vertical && shownChildMenu != null && shownChildMenu == selectedItem.getSubMenu()) {
            shownChildMenu.onHide(false);
            popup.hide();
            shownChildMenu = null;
        }
    }
    if (item != null) {
        item.setSelectionStyle(true);
        // Set the style of the submenu indicator
        if (vertical) {
            Element tr = DOM.getParent(item.getElement());
            if (DOM.getChildCount(tr) == 2) {
                Element td = DOM.getChild(tr, 1);
                setStyleName(td, "subMenuIcon-selected", true);
            }
        }
        Accessibility.setState(getElement(), Accessibility.STATE_ACTIVEDESCENDANT, DOM.getElementAttribute(item.getElement(), "id"));
    }
    selectedItem = item;
}
Also used : Element(com.google.gwt.user.client.Element)

Aggregations

Element (com.google.gwt.user.client.Element)27 BlurEvent (com.google.gwt.event.dom.client.BlurEvent)1 BlurHandler (com.google.gwt.event.dom.client.BlurHandler)1 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1 FlexCellFormatter (com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter)1 FormValidator (cz.metacentrum.perun.webgui.client.applicationresources.FormValidator)1 RegistrarFormItemGenerator (cz.metacentrum.perun.webgui.client.applicationresources.RegistrarFormItemGenerator)1