Example usage for com.google.gwt.dom.client UListElement setAttribute

List of usage examples for com.google.gwt.dom.client UListElement setAttribute

Introduction

In this page you can find the example usage for com.google.gwt.dom.client UListElement setAttribute.

Prototype

@Override
    public void setAttribute(String name, String value) 

Source Link

Usage

From source file:io.reinert.requestor.examples.showcase.Showcase.java

License:Apache License

@Override
public void onModuleLoad() {

    // Populate the menu
    final Element menu = Document.get().getElementById("menu-list");
    for (MenuOption o : MenuOption.values()) {
        if (o != MenuOption.HOME) {
            if (o.isGroup()) {
                AnchorElement a = Document.get().createAnchorElement();
                a.getStyle().setCursor(Style.Cursor.POINTER);
                a.setClassName("dropdown-toggle");
                a.setAttribute("role", "button");
                a.setAttribute("data-toggle", "dropdown");
                a.setInnerHTML(o.getLabel() + " <span class=\"caret\"></span>");

                UListElement ul = Document.get().createULElement();
                ul.setClassName("dropdown-menu");
                ul.setAttribute("role", "menu");
                ul.setId(getMenuGroupId(o));

                LIElement li = Document.get().createLIElement();
                li.setClassName("dropdown");
                li.appendChild(a);/*from  w w  w .  j  a v  a  2  s  .c o  m*/
                li.appendChild(ul);

                menu.appendChild(li);
            } else {
                AnchorElement a = Document.get().createAnchorElement();
                a.setInnerText(o.getLabel());
                a.setHref("#" + o.getToken());

                LIElement li = Document.get().createLIElement();
                li.appendChild(a);

                if (o.hasParent()) {
                    MenuOption parent = o.getParent();
                    UListElement ul = (UListElement) Document.get().getElementById(getMenuGroupId(parent));
                    ul.appendChild(li);
                } else {
                    menu.appendChild(li);
                }
            }
        }
    }

    final SimplePanel container = new SimplePanel();
    container.setStyleName("container requestor-showcase-container");
    RootPanel.get().add(container);

    // Main Factory (Dependency Injector)
    ShowcaseClientFactory clientFactory = CLIENT_FACTORY;
    EventBus eventBus = clientFactory.getEventBus();
    PlaceController placeController = clientFactory.getPlaceController();

    // Activity-Place binding
    ActivityMapper activityMapper = new ShowcaseActivityMapper();
    ActivityManager activityManager = new ActivityManager(activityMapper, eventBus);
    activityManager.setDisplay(container);

    // Place-History binding
    PlaceHistoryMapper historyMapper = new ShowcasePlaceHistoryMapper();
    PlaceHistoryHandler historyHandler = new PlaceHistoryHandler(historyMapper);
    historyHandler.register(placeController, eventBus, defaultPlace);

    // Add Loading widget
    RootPanel.get().add(new Loading(eventBus));

    // Goes to place represented on URL or default place
    historyHandler.handleCurrentHistory();
}

From source file:org.overlord.rtgov.ui.client.local.pages.situations.CallTraceWidget.java

License:Apache License

/**
 * Creates a single tree node from the given trace node.
 * @param node/*from ww  w  . ja  va 2  s  . c  o m*/
 */
protected LIElement createTreeNode(TraceNodeBean node) {
    String nodeId = String.valueOf(nodeIdCounter++);
    nodeMap.put(nodeId, node);

    boolean isCall = "Call".equals(node.getType()); //$NON-NLS-1$
    boolean hasChildren = !node.getTasks().isEmpty();
    LIElement li = Document.get().createLIElement();
    li.setClassName(hasChildren ? "parent_li" : "leaf_li"); //$NON-NLS-1$ //$NON-NLS-2$
    if (hasChildren)
        li.setAttribute("role", "treeitem"); //$NON-NLS-1$ //$NON-NLS-2$
    SpanElement span = Document.get().createSpanElement();
    span.setAttribute("data-nodeid", nodeId); //$NON-NLS-1$
    Element icon = Document.get().createElement("i"); //$NON-NLS-1$
    span.appendChild(icon);
    span.appendChild(Document.get().createTextNode(" ")); //$NON-NLS-1$
    if (isCall) {
        span.setClassName(node.getStatus());
        icon.setClassName("icon-minus-sign"); //$NON-NLS-1$
        span.appendChild(Document.get().createTextNode(node.getOperation()));
        span.appendChild(Document.get().createTextNode(":")); //$NON-NLS-1$
        span.appendChild(Document.get().createTextNode(node.getComponent()));
    } else {
        span.appendChild(Document.get().createTextNode(node.getDescription()));
        span.setClassName("Info"); //$NON-NLS-1$
        icon.setClassName("icon-info-sign"); //$NON-NLS-1$
    }
    li.appendChild(span);
    if (node.getDuration() != -1) {
        li.appendChild(Document.get().createTextNode(" [")); //$NON-NLS-1$
        li.appendChild(Document.get().createTextNode(String.valueOf(node.getDuration())));
        li.appendChild(Document.get().createTextNode("ms]")); //$NON-NLS-1$
    }
    if (node.getPercentage() != -1) {
        li.appendChild(Document.get().createTextNode(" (")); //$NON-NLS-1$
        li.appendChild(Document.get().createTextNode(String.valueOf(node.getPercentage())));
        li.appendChild(Document.get().createTextNode("%)")); //$NON-NLS-1$
    }

    if (hasChildren) {
        UListElement ul = Document.get().createULElement();
        ul.setAttribute("role", "group"); //$NON-NLS-1$ //$NON-NLS-2$
        li.appendChild(ul);

        List<TraceNodeBean> tasks = node.getTasks();
        for (TraceNodeBean task : tasks) {
            LIElement tn = createTreeNode(task);
            ul.appendChild(tn);
        }
    }
    return li;
}