Example usage for com.google.gwt.user.client.ui HTMLPanel createUniqueId

List of usage examples for com.google.gwt.user.client.ui HTMLPanel createUniqueId

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui HTMLPanel createUniqueId.

Prototype

public static String createUniqueId() 

Source Link

Document

A helper method for creating unique IDs for elements within dynamically- generated HTML.

Usage

From source file:cc.kune.bootstrap.client.actions.ui.BSMenuGui.java

License:GNU Affero Public License

@Override
public AbstractGuiItem create(final GuiActionDescrip descriptor) {
    this.descriptor = descriptor;
    final DropDown dropDown = new DropDown();
    dropDown.addStyleName("btn-group");
    menu = new ComplexDropDownMenu<DropDown>(dropDown);
    final String id = HTMLPanel.createUniqueId();
    dropDown.getElement().setId(id);/*from  w  w w.ja v  a  2s .c  o  m*/
    menu.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(final ClickEvent event) {
            // Note: in smartmenus is setted to showOnClick: true,
            event.stopPropagation();
            clickHandlerDefault.onClick(event);
            menu.getList().getElement().getStyle().setDisplay(Display.BLOCK);
            show();
        }
    });

    popup = new PopupBSMenuGui(menu.getList(), menu.getWidget(), descriptor);

    descriptor.putValue(ParentWidget.PARENT_UI, this);
    initWidget(dropDown);
    configureItemFromProperties();

    if ((Boolean) descriptor.getValue(MenuDescriptor.MENU_ATRIGHT)) {
        menu.getList().setPull(Pull.RIGHT);
    }
    return this;
}

From source file:cc.kune.bootstrap.client.actions.ui.BSToolbarGui.java

License:GNU Affero Public License

@Override
public AbstractGuiItem create(final GuiActionDescrip descriptor) {
    super.descriptor = descriptor;
    String id = descriptor.getId();
    if ("undefined".equals(id) || TextUtils.empty(id)) {
        id = HTMLPanel.createUniqueId();
    }/*from   w  w  w  . j  av a2 s.  co  m*/

    final Navbar navbar = new Navbar();
    navbar.addStyleName("k-toolbar-navbar");
    final NavbarHeader header = new NavbarHeader();
    final NavbarCollapseButton navbarCollapseButton = new NavbarCollapseButton();
    navbarCollapseButton.setDataTarget("#" + id);
    header.add(navbarCollapseButton);
    navbar.add(header);
    final NavbarCollapse navbarCollapse = new NavbarCollapse();
    navbarCollapse.setId(id);
    navbar.add(navbarCollapse);

    final NavbarPosition position = (NavbarPosition) descriptor.getValue(ToolbarDescriptor.POSITION);
    if (position != null) {
        navbar.setPosition(position);
    }

    navbarNav = new ComplexNavbarNav();
    navbarCollapse.add(navbarNav);

    initWidget(navbar);
    configureItemFromProperties();
    descriptor.putValue(ParentWidget.PARENT_UI, navbarNav);
    return this;
}

From source file:cc.kune.bootstrap.client.actions.ui.BSToolbarMenuGui.java

License:GNU Affero Public License

@Override
public AbstractGuiItem create(final GuiActionDescrip descriptor) {
    super.descriptor = descriptor;
    descriptor.putValue(ParentWidget.PARENT_UI, this);
    final GuiActionDescrip parent = descriptor.getParent();
    if (!(parent instanceof ToolbarDescriptor)) {
        throw new UIException("This menu should be used only in bootstrap toolbars. Menu: " + descriptor
                + " parent: " + parent);
    }//from w ww  .ja  va2s . co m

    final ListDropDown dDown = new ListDropDown();
    menu = new ComplexDropDownMenu<ListDropDown>(dDown);
    final String ddid = HTMLPanel.createUniqueId();
    dDown.getElement().setId(ddid);

    popup = new PopupBSMenuGui(menu.getList(), menu.getWidget(), descriptor);

    // TODO
    // final Boolean inline = (Boolean)
    // descriptor.getValue(MenuDescriptor.MENU_VERTICAL);
    // menu.setInline(inline);
    // descriptor.putValue(MenuDescriptor.MENU_SHOW_NEAR_TO, button);
    final ImageResource rightIcon = ((MenuDescriptor) descriptor).getRightIcon();
    if (rightIcon != null) {
        menu.setIconRightResource(rightIcon);
    }

    descriptor.addPropertyChangeListener(new PropertyChangeListener() {
        private void activeNextItem(final int increment) {
            final int count = menu.getWidgetCount();
            for (int cur = 0; cur < count && cur >= 0; cur = cur + increment) {
                final Widget item = menu.getList().getWidget(cur);
                final List<String> styles = Arrays.asList(item.getStyleName().split(" "));
                if (styles.contains(Styles.ACTIVE)) {
                    item.removeStyleName(Styles.ACTIVE);
                    final int proposed = cur + increment;
                    final int next = proposed >= count ? 0 : (proposed < 0) ? count - 1 : proposed;
                    menu.getList().getWidget(next).addStyleName(Styles.ACTIVE);
                    break;
                }
            }
        }

        @Override
        public void propertyChange(final PropertyChangeEvent event) {
            if (event.getPropertyName().equals(MenuDescriptor.MENU_SELECTION_DOWN)) {
                activeNextItem(1);
            } else if (event.getPropertyName().equals(MenuDescriptor.MENU_SELECTION_UP)) {
                activeNextItem(-1);
            } else if (event.getPropertyName().equals(MenuDescriptor.MENU_SELECT_ITEM)) {
                final HasMenuItem item = (HasMenuItem) ((MenuItemDescriptor) descriptor
                        .getValue(MenuDescriptor.MENU_SELECT_ITEM)).getValue(MenuItemDescriptor.UI);
                clearCurrentActiveItem();
                ((Widget) item).addStyleName(Styles.ACTIVE);
            }
        }
    });

    final String id = descriptor.getId();
    if (TextUtils.notEmpty(id) && !"undefined".equals(id)) {
        menu.ensureDebugId(id);
    }
    if (descriptor.isChild()) {
        child = menu.getWidget();
    } else {
        initWidget(menu.getWidget());
    }
    super.create(descriptor);
    configureItemFromProperties();
    descriptor.addPropertyChangeListener(new PropertyChangeListener() {
        @Override
        public void propertyChange(final PropertyChangeEvent event) {
            final Object newValue = event.getNewValue();
            if (event.getPropertyName().equals(MenuDescriptor.MENU_RIGHTICON)) {
                setIconRightResource((ImageResource) newValue);
            }
        }
    });
    return this;
}

From source file:cc.kune.bootstrap.client.actions.ui.BSWidgetMenuGui.java

License:GNU Affero Public License

@Override
public AbstractGuiItem create(final GuiActionDescrip descriptor) {
    final Object value = descriptor.getValue(ParentWidget.PARENT_UI);
    if (value != null) {
        // Already created ... so reset
        ((BSWidgetMenuGui) value).getMenu().clear();
        return this;
    }/* w w w .j a v a 2  s  . c  o m*/
    this.descriptor = descriptor;
    final DropDown dropDown = new DropDown();
    final Anchor anchor = new Anchor();
    anchor.setDataToggle(Toggle.DROPDOWN);
    dropDown.add(anchor);
    menu = new DropDownMenu();

    widget = (Widget) descriptor.getValue(WidgetMenuDescriptor.WIDGET);
    popup = new PopupBSMenuGui(menu, widget, descriptor);
    dropDown.add(menu);
    HasClickHandlers widgetHasClick;
    try {
        widgetHasClick = (HasClickHandlers) widget;
    } catch (final ClassCastException e) {
        throw new UIException("Cannot cast to HasClickHandlers descriptor" + descriptor);
    }
    widgetHasClick.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(final ClickEvent event) {
            event.stopPropagation();
            clickHandlerDefault.onClick(event);
            show();
        }
    });

    descriptor.addPropertyChangeListener(new PropertyChangeListener() {
        @Override
        public void propertyChange(final PropertyChangeEvent event) {
            if (event.getPropertyName().equals(MenuDescriptor.MENU_HIDE)) {
                hide();
            } else if (event.getPropertyName().equals(MenuDescriptor.MENU_SHOW)) {
                show();
            }
            // } else if
            // (event.getPropertyName().equals(MenuDescriptor.MENU_SELECTION_DOWN))
            // {
            // menu.moveSelectionDown();
            // } else if
            // (event.getPropertyName().equals(MenuDescriptor.MENU_SELECTION_UP)) {
            // menu.moveSelectionUp();
            // } else if
            // (event.getPropertyName().equals(MenuDescriptor.MENU_SELECT_ITEM)) {
            // final HasMenuItem item = (HasMenuItem) ((MenuItemDescriptor)
            // descriptor.getValue(MenuDescriptor.MENU_SELECT_ITEM)).getValue(MenuItemDescriptor.UI);
            // menu.selectItem((MenuItem) item.getMenuItem());
            // }
        }
    });

    if ((Boolean) descriptor.getValue(MenuDescriptor.MENU_ATRIGHT)) {
        menu.setPull(Pull.RIGHT);
    }

    descriptor.putValue(ParentWidget.PARENT_UI, this);
    initWidget(dropDown);
    configureItemFromProperties();
    final String id = HTMLPanel.createUniqueId();
    menu.getElement().setId(id);
    return this;
}

From source file:cc.kune.bootstrap.client.ui.ComplexDropDownMenu.java

License:GNU Affero Public License

public ComplexDropDownMenu(final T widget) {
    this.widget = widget;
    menu = new DropDownMenu();
    anchor = new ComplexAnchorButton();
    anchor.setDataToggle(Toggle.DROPDOWN);
    final String dataTarget = HTMLPanel.createUniqueId();
    anchor.setDataTarget(dataTarget);//from  w  ww.j a v a2 s. c om
    // Attributes.DATA_TARGET
    anchor.getElement().setAttribute("aria-expanded", "true");
    menu.getElement().setAttribute("aria-labelledby", dataTarget);
    widget.add(anchor);
    widget.add(menu);
    widget.addAttachHandler(new Handler() {
        @Override
        public void onAttachOrDetach(final AttachEvent event) {
            if (event.isAttached()) {
                bindJavaScriptEvents(widget.getElement());
            } else {
                unbindJavaScriptEvents(widget.getElement());
            }
        }
    });
}

From source file:com.ait.toolkit.editors.ckeditor.client.CKEditor.java

License:Open Source License

/**
 * Initialize the editor//w ww.j  a  v a 2  s  . co m
 */
private void initCKEditor() {
    div = DOM.createDiv();
    baseTextArea = DOM.createTextArea();
    name = HTMLPanel.createUniqueId();
    div.appendChild(baseTextArea);
    DOM.setElementAttribute(baseTextArea, "name", name);
    this.sinkEvents(Event.ONCLICK | Event.KEYEVENTS);

    if (config.isUsingFormPanel()) {
        FormPanel form = new FormPanel();
        Button submit = new Button();
        submit.addClickHandler(this);
        submit.getElement().setAttribute("name", "submit");
        submit.setVisible(false);
        // .getElement().setAttribute("style", "visibility:hidden");

        form.getElement().appendChild(div);
        form.add(submit);
        initWidget(form);
    } else {
        SimplePanel simplePanel = new SimplePanel();
        simplePanel.getElement().appendChild(div);
        initWidget(simplePanel);
    }
}

From source file:com.dianaui.universal.core.client.ui.TimePicker.java

License:Apache License

private void initContainer() {
    final String incrementHourId = HTMLPanel.createUniqueId();
    final String incrementMinuteId = HTMLPanel.createUniqueId();
    final String incrementSecondId = HTMLPanel.createUniqueId();
    final String hourContainerId = HTMLPanel.createUniqueId();
    final String minuteContainerId = HTMLPanel.createUniqueId();
    final String secondContainerId = HTMLPanel.createUniqueId();
    final String decrementHourId = HTMLPanel.createUniqueId();
    final String decrementMinuteId = HTMLPanel.createUniqueId();
    final String decrementSecondId = HTMLPanel.createUniqueId();
    final String periodId = HTMLPanel.createUniqueId();

    container = new HTMLPanel(new SafeHtml() {
        private String getSeparator(final String separator) {
            return "<td class=\"" + Styles.SEPARATOR + "\">" + separator + "</td>";
        }/*ww w. j  a  v a 2 s  . c  o m*/

        @Override
        public String asString() {
            return "<table>" + "<tr>" + "<td id=\"" + incrementHourId + "\"></td>" + getSeparator("&nbsp;")
                    + "<td id=\"" + incrementMinuteId + "\"></td>"
                    + (secondsEnabled ? getSeparator("&nbsp;") + "<td id=\"" + incrementSecondId + "\"></td>"
                            : "")
                    + "</tr>" + "<tr>" + "<td id=\"" + hourContainerId + "\"></td>" + getSeparator(":")
                    + "<td id=\"" + minuteContainerId + "\"></td>"
                    + (secondsEnabled ? getSeparator(":") + "<td id=\"" + secondContainerId + "\"></td>" : "")
                    + (hourFormat == HourFormat._12 ? "<td id=\"" + periodId + "\"></td>" : "") + "</tr>"
                    + "<tr>" + "<td id=\"" + decrementHourId + "\"></td>" + getSeparator("&nbsp;") + "<td id=\""
                    + decrementMinuteId + "\"></td>"
                    + (secondsEnabled ? getSeparator("&nbsp;") + "<td id=\"" + decrementSecondId + "\"></td>"
                            : "")
                    + "</tr>" + "</table>";
        }
    });
    container.setStyleName(Styles.TIMEPICKER_WIDGET);
    container.addStyleName(Styles.DROPDOWN_MENU);

    // attach widgets
    container.add(incrementHour, incrementHourId);
    container.add(incrementMinute, incrementMinuteId);
    if (secondsEnabled)
        container.add(incrementSecond, incrementSecondId);
    container.add(hourBox, hourContainerId);
    container.add(minuteBox, minuteContainerId);
    if (secondsEnabled)
        container.add(secondBox, secondContainerId);
    container.add(decrementHour, decrementHourId);
    container.add(decrementMinute, decrementMinuteId);
    if (secondsEnabled)
        container.add(decrementSecond, decrementSecondId);
    if (hourFormat == HourFormat._12)
        container.add(togglePeriodLabel, periodId);

    add(container);
}

From source file:com.edgenius.wiki.gwt.client.BaseEntryPoint.java

License:Open Source License

private void initSearch() {
    if (isOffline()) {
        return;/*  w  w w  . ja v a 2  s.com*/
    }

    String id1 = HTMLPanel.createUniqueId();
    HTMLPanel panel = new HTMLPanel("<span id='" + id1 + "'></span>");
    searchBox.addFocusHandler(KeyCaptureListener.instance());
    searchBox.addBlurHandler(KeyCaptureListener.instance());
    searchBox.setStyleName(Css.SEARCH_INPUT);
    searchBox.addKeyDownHandler(new KeyDownHandler() {
        public void onKeyDown(KeyDownEvent event) {
            if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
                doSearch(searchBox.getText());
            }
        }

    });

    panel.add(searchBox, id1);

    RootPanel.get("search").add(panel);

}

From source file:com.edgenius.wiki.gwt.client.editor.MCEMacroDialog.java

License:Open Source License

@Override
protected void okEvent() {
    if (TYPE_USER.equalsIgnoreCase(type)) {
        String filter = hbox.getText();
        if (!StringUtil.isBlank(filter)) {
            StringBuffer macro = new StringBuffer("@");
            macro.append(filter).append("@");
            MacroRequester.buildMacroFromServer(tiny.getSpaceUname(), tiny.getPageUuid(), macro.toString(),
                    null, null, this);
        }/*  w  ww.  j a va2 s . co  m*/
    } else if (TYPE_GALLERY.equalsIgnoreCase(type)) {
        String filter = hbox.getText();

        StringBuffer macro = new StringBuffer("{gallery");
        if (!StringUtil.isBlank(filter)) {
            macro.append(":filter=").append(filter);
        }
        macro.append("}");

        MacroRequester.buildMacroFromServer(tiny.getSpaceUname(), tiny.getPageUuid(), macro.toString(), null,
                tiny.getEditor().getAttachmentNodeUuidList(), this);
    } else if (TYPE_ATTACH.equalsIgnoreCase(type)) {
        String filter = hbox.getText();

        StringBuffer macro = new StringBuffer("{attach");
        if (!StringUtil.isBlank(filter)) {
            macro.append(":filter=").append(filter);
        }
        macro.append("}");
        MacroRequester.buildMacroFromServer(tiny.getSpaceUname(), tiny.getPageUuid(), macro.toString(), null,
                tiny.getEditor().getAttachmentNodeUuidList(), this);
    } else if (TYPE_HTML.equalsIgnoreCase(type)) {
        this.tiny.insertContent(area.getText());
    } else if (TYPE_PANEL.equalsIgnoreCase(type)) {

        String title = hbox.getText();
        StringBuffer buffer = new StringBuffer();
        MacroMaker.buildPanel(HTMLPanel.createUniqueId(), buffer, title, "<br>", true);
        this.tiny.insertContent(buffer.toString());

    } else if (TYPE_TOC.equalsIgnoreCase(type)) {
        StringBuffer macro = new StringBuffer("{toc");

        String levelStr = hbox.getText();
        boolean dirty = false;
        if (!StringUtil.isBlank(levelStr)) {
            int level = NumberUtil.toInt(levelStr, -1);
            if (level < 1 || level > 6) {
                Window.alert(Msg.consts.toc_levels_exceed_scope());
                return;
            }
            macro.append(":level=").append(level);
            dirty = true;
        }
        if (radio2.isChecked()) {
            macro.append(dirty ? "|" : ":").append("ordered=false");
        }
        macro.append("}");
        MacroRequester.buildMacroFromServer(tiny.getSpaceUname(), tiny.getPageUuid(), macro.toString(),
                tiny.getEditor().getText(), null, this);
    }

    this.hidebox();
}

From source file:com.edgenius.wiki.gwt.client.home.porlet.MessagePortlet.java

License:Open Source License

/**
 * A common callback success, as this portlet can accept response from Portlet invoke 
 * or from a message send refresh callback.
 *//*  w  w w .j a va 2  s .  com*/
private void callback(GeneralModel model, MessageListModel msgs) {
    busy(false);
    messagePanel.clear();
    if (!GwtClientUtils.preSuccessCheck(model, null)) {
        //show error message on item part rather than general error message on HTML page above
        messagePanel.add(ErrorCode.getMessage(model.errorCode, model.errorMsg));
        return;
    }

    if (msgs.list.size() == 0) {
        none.setStyleName(Css.PORTLET_WEAK_TEXT);
        messagePanel.add(none);
        return;
    }

    for (Iterator<MessageModel> iter = msgs.list.iterator(); iter.hasNext();) {
        final MessageModel msg = iter.next();
        String puid = HTMLPanel.createUniqueId();
        String puid1 = HTMLPanel.createUniqueId();
        String puid2 = HTMLPanel.createUniqueId();
        String puid3 = HTMLPanel.createUniqueId();
        HTMLPanel msgPanel = new HTMLPanel("<div style=\"display:inline;font-weight:bold;\" id=\"" + puid1
                + "\"></div>" + "<div style=\"display:inline\" id=\"" + puid2
                + "\"></div> <div class=\"weaktext\">" + Msg.consts.by() + "</div><div class=\"weaklink\" id=\""
                + puid + "\"></div><div class=\"weaktext\">" + Msg.consts.on() + " "
                + GwtClientUtils.toDisplayDate(msg.date) + "</div>" + "<div style=\"display:inline\" id=\""
                + puid3 + "\"></div>");

        if ((msg.targetType == SharedConstants.MSG_TARGET_USER
                //TODO: how to distinguish the contributor and admin?
                || msg.targetType == SharedConstants.MSG_TARGET_SPACE_CONTRIBUTE_USERS
                || msg.targetType == SharedConstants.MSG_TARGET_SPACE_ADMIN_ONLY)
                && !StringUtil.isBlank(msg.target)) {
            msgPanel.add(new Label(
                    (msg.targetType == SharedConstants.MSG_TARGET_USER ? "@" : "@@") + msg.target + " "),
                    puid1);
        }
        if (msg.targetType == SharedConstants.MSG_TARGET_INSTANCE_ADMIN_ONLY
                && StringUtil.isBlank(msg.target)) {
            //message to system admin
            Image msgAdmin = new Image(IconBundle.I.get().error());
            msgAdmin.setTitle(Msg.consts.msg_to_admin());
            msgPanel.add(msgAdmin, puid1);
        }

        //don't use UserProfileLink - click user link will invoke reply message, rather than jump to user profile
        //UserProfileLink authorPop = new UserProfileLink(msg.author, null,msg.author,msg.authorPortrait);
        ClickLink authorPop = new ClickLink(msg.authorUsername);
        //auto popup for user profile
        new UserPopup(authorPop, null, msg.authorUsername, msg.authorPortrait);
        authorPop.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent evt) {
                if (msg.authorUid != -1) {
                    postPanel.fillTarget(SharedConstants.MSG_TARGET_USER, msg.authorUsername);
                } else {
                    //reply anonymous means to all 
                    postPanel.fillTarget(null, null);
                }
                postPanel.focusToEnd(true);
            }
        });

        msgPanel.add(new Label(msg.text), puid2);
        msgPanel.add(authorPop, puid);
        if (msg.removable) {
            Image bin = new Image(IconBundle.I.get().bin_close());
            bin.setTitle(Msg.consts.delete());
            bin.addClickHandler(new ClickHandler() {
                public void onClick(ClickEvent event) {
                    if (Window.confirm(Msg.consts.confirm_delete_message())) {
                        NotificationControllerAsync notifyController = ControllerFactory
                                .getNotificationController();
                        notifyController.deleteMessage(currentPage, msg.uid, new NotificationCallback());
                    }
                }
            });
            msgPanel.add(bin, puid3);
        }

        DOM.setStyleAttribute(msgPanel.getElement(), "display", "inline");

        HorizontalPanel itemPanel = new HorizontalPanel();
        Widget portrait = GwtClientUtils.createUserSmallPortrait(msg.authorPortrait,
                SharedConstants.PORTRAIT_SIZE_SMALL);
        itemPanel.add(portrait);
        itemPanel.setCellWidth(portrait, "50px");
        itemPanel.add(msgPanel);
        messagePanel.add(itemPanel);
    }

    clearControl();

    controlBar.setPaginationInfo(msgs.hasPre, msgs.hasNxt, msgs.currentPage);
    addControl(controlBar);
}