Example usage for com.google.gwt.user.client Element getId

List of usage examples for com.google.gwt.user.client Element getId

Introduction

In this page you can find the example usage for com.google.gwt.user.client Element getId.

Prototype

@Override
    public String getId() 

Source Link

Usage

From source file:org.xwiki.gwt.wysiwyg.client.WysiwygEditorApi.java

License:Open Source License

/**
 * Creates a new {@link WysiwygEditor} based on the given configuration object.
 * //  www  .j a v a2  s.com
 * @param jsConfig the {@link JavaScriptObject} used to configure the newly created editor
 */
public WysiwygEditorApi(JavaScriptObject jsConfig) {
    if (!isRichTextEditingSupported()) {
        return;
    }

    Config config = new DefaultConfig(jsConfig);

    // Get the element that will be replaced by the WYSIWYG editor.
    Element hook = DOM.getElementById(config.getParameter("hookId"));
    if (hook == null) {
        return;
    }

    // Prepare the DOM by creating a container for the editor.
    final Element container = DOM.createDiv();
    String containerId = hook.getId() + "_container" + Math.round(Math.random() * 1000);
    container.setId(containerId);
    hook.getParentElement().insertBefore(container, hook);

    editor = WysiwygEditorFactory.getInstance().newEditor(config);

    // Attach the editor to the browser's document.
    if (editor.getConfig().isDebugMode()) {
        RootPanel.get(containerId).add(new WysiwygEditorDebugger(editor));
    } else {
        RootPanel.get(containerId).add(editor.getUI());
    }

    // Cleanup when the window is closed. This way the HTML form elements generated on the server preserve their
    // index and thus can be cached by the browser.
    Window.addCloseHandler(new CloseHandler<Window>() {
        public void onClose(CloseEvent<Window> event) {
            if (editor != null) {
                editor.destroy();
            }
            if (container.getParentNode() != null) {
                container.getParentNode().removeChild(container);
            }
        }
    });
}

From source file:sf.wicklet.gwt.client.util.DomCache.java

License:Apache License

private void init(final com.google.gwt.dom.client.Element top) {
    for (com.google.gwt.dom.client.Element e = top; e != null; e = e.getNextSiblingElement()) {
        final Element elm = e.cast();
        for (final String name : names) {
            if ("id".equals(name)) {
                final String id = elm.getId();
                if (!GwtTextUtil.isEmpty(id)) {
                    byids.put(id, elm);/*ww w . ja v  a 2s.  c  o  m*/
                }
            } else if ("class".equals(name)) {
                final String css = elm.getClassName();
                if (!GwtTextUtil.isEmpty(css)) {
                    for (final String s : GwtTextUtil.tokenize(css)) {
                        GwtStructUtil.addToList(byclasses, s, elm);
                    }
                }
            } else if (TAGS.equals(name)) {
                GwtStructUtil.addToList(bytags, elm.getTagName(), elm);
            } else {
                final String value = elm.getAttribute(name);
                if (value != null) {
                    Map<String, List<Element>> m = bynames.get(name);
                    if (m == null) {
                        bynames.put(name, m = new TreeMap<String, List<Element>>());
                    }
                    List<Element> a = m.get(value);
                    if (a == null) {
                        m.put(value, a = new ArrayList<Element>());
                    }
                    a.add(elm);
                }
            }
        }
        init(e.getFirstChildElement());
    }
}