Java Code Examples for com.google.gwt.user.client.DOM#createUniqueId()

The following examples show how to use com.google.gwt.user.client.DOM#createUniqueId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseCheckBox.java    From gwt-material with Apache License 2.0 6 votes vote down vote up
protected BaseCheckBox(Element elem) {
    super(elem, CssName.GWT_CHECKBOX);

    inputElem = InputElement.as(DOM.createInputCheck());
    labelElem = Document.get().createLabelElement();

    getElement().appendChild(inputElem);
    getElement().appendChild(labelElem);

    String uid = DOM.createUniqueId();
    inputElem.setPropertyString("id", uid);
    labelElem.setHtmlFor(uid);

    directionalTextHelper = new DirectionalTextHelper(labelElem, true);

    // Accessibility: setting tab index to be 0 by default, ensuring element
    // appears in tab sequence. FocusWidget's setElement method already
    // calls setTabIndex, which is overridden below. However, at the time
    // that this call is made, inputElem has not been created. So, we have
    // to call setTabIndex again, once inputElem has been created.
    setTabIndex(0);
}
 
Example 2
Source File: MaterialSubHeaderContainer.java    From gwt-material-addins with Apache License 2.0 6 votes vote down vote up
@Override
public void load() {
    if (getType() == SubHeaderType.PINNED) {
        String subHeaderClass = DOM.createUniqueId();
        for (Widget w : getChildren()) {
            if (w instanceof MaterialSubHeader) {
                w.addStyleName(subHeaderClass);
                subHeaders.add((MaterialSubHeader) w);
            }
        }

        JsSubHeader.initSubheader("." + subHeaderClass, getElement());

        if (subHeaders.size() == 0) {
            $(getElement()).find(".top_holder").css("display", "none");
        }
    }
    AddinsDarkThemeReloader.get().reload(MaterialSubheaderDarkTheme.class);
}
 
Example 3
Source File: IdHelper.java    From core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static <T> String asId(String prefix, Class<T> clazz, String suffix) {
    String id;
    if (clazz == null) {
        id = DOM.createUniqueId();
        Log.error("Cannot create stable ID: No class specified! Will return generated ID: " + id);
        return id;
    } else {
        id = clazz.getName();
        int lastDot = id.lastIndexOf('.');
        if (lastDot != -1 && lastDot != id.length() - 1) {
            id = id.substring(lastDot + 1);
        }
        id = id.replace('$', '_');
    }
    id = prefix != null ? prefix + id : id;
    return suffix != null ? id + suffix : id;
}
 
Example 4
Source File: MaterialDropDown.java    From gwt-material with Apache License 2.0 5 votes vote down vote up
@Override
public void load() {
    Widget parent = getParent();
    if (parent instanceof HasActivates) {
        String uid = DOM.createUniqueId();
        ((HasActivates) parent).setActivates(uid);
        setId(uid);
        activatorElement = parent.getElement();
    } else if (activatorElement == null) {
        activatorElement = DOMHelper.getElementByAttribute("data-activates", activator);
    }

    $(activatorElement).dropdown(options);

}
 
Example 5
Source File: MaterialValueBox.java    From gwt-material with Apache License 2.0 5 votes vote down vote up
@Override
protected void onLoad() {
    super.onLoad();

    String id = DOM.createUniqueId();
    valueBoxBase.getElement().setId(id);
    label.getElement().setAttribute("for", id);
    loadEvents();
    // Make valueBoxBase the primary focus target
    getFocusableMixin().setUiObject(new MaterialWidget(valueBoxBase.getElement()));
}
 
Example 6
Source File: LanguageSelector.java    From gwt-material-addins with Apache License 2.0 5 votes vote down vote up
protected <T extends MaterialWidget & HasActivates> void setActivator(T widget) {
    String activator = DOM.createUniqueId();
    widget.setActivates(activator);
    widget.addStyleName(IncubatorCssName.LANGUAGE_ACTIVATOR);
    add(widget);
    dropdown.setActivator(activator);
    dropdown.reload();
}
 
Example 7
Source File: MaterialScrollfire.java    From gwt-material-addins with Apache License 2.0 5 votes vote down vote up
/**
 * Executes callback method depending on how far into the page you've scrolled
 */
public void apply() {
    if (element != null) {
        String uid = DOM.createUniqueId();
        element.setId(uid);
        JsScrollfire.apply("#" + uid, offset, callback::call);
    } else {
        GWT.log("You must set the element before applying the scrollfire", new IllegalStateException());
    }
}
 
Example 8
Source File: MaterialAutoComplete.java    From gwt-material-addins with Apache License 2.0 5 votes vote down vote up
/**
 * Generate and build the List Items to be set on Auto Complete box.
 */
protected void setup(SuggestOracle suggestions) {

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

    list.setStyleName(AddinsCssName.MULTIVALUESUGGESTBOX_LIST);
    this.suggestions = suggestions;
    final ListItem item = new ListItem();

    item.setStyleName(AddinsCssName.MULTIVALUESUGGESTBOX_INPUT_TOKEN);

    suggestBox = new SuggestBox(suggestions, itemBox);
    suggestBox.addSelectionHandler(selectionEvent -> {
        Suggestion selectedItem = selectionEvent.getSelectedItem();
        itemBox.setValue("");
        if (addItem(selectedItem)) {
            ValueChangeEvent.fire(MaterialAutoComplete.this, getValue());
        }
        itemBox.setFocus(true);
    });

    loadHandlers();

    setLimit(this.limit);
    String autocompleteId = DOM.createUniqueId();
    itemBox.getElement().setId(autocompleteId);

    item.add(suggestBox);
    item.add(label);
    list.add(item);

    panel.add(list);
    panel.getElement().setAttribute("onclick",
            "document.getElementById('" + autocompleteId + "').focus()");
    panel.add(errorLabel);
    suggestBox.setFocus(true);
}
 
Example 9
Source File: QRCodeWidget.java    From bitcoin-transaction-explorer with MIT License 5 votes vote down vote up
public QRCodeWidget() {
  id = DOM.createUniqueId();

  final Element div = Document.get().createDivElement();
  div.setId(id);

  setElement(div);
}
 
Example 10
Source File: ReCaptcha.java    From gwt-material-addins with Apache License 2.0 4 votes vote down vote up
public void load(RecaptchaApi recaptchaApi) {
    String uid = DOM.createUniqueId();
    setId(uid);

    reCaptcha = JsReCaptcha.initReCaptcha(uid, recaptchaApi.getApiKey(), dataCallback, expiredCallback, errorCallback, theme.getTheme(), type.getType());
}
 
Example 11
Source File: MaterialPopupMenu.java    From gwt-material-addins with Apache License 2.0 4 votes vote down vote up
public MaterialPopupMenu() {
    id = DOM.createUniqueId();
    setInitialClasses(AddinsCssName.POPUP_MENU, AddinsCssName.MENU_BAR, CssName.Z_DEPTH_3);
}