Example usage for com.google.gwt.dom.client Document getElementById

List of usage examples for com.google.gwt.dom.client Document getElementById

Introduction

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

Prototype

public Element getElementById(String elementId) 

Source Link

Usage

From source file:com.cgxlib.xq.client.impl.SelectorEngine.java

License:Apache License

public static NodeList<Element> veryQuickId(String id, Node ctx) {
    Document d = ctx.getNodeType() == Node.DOCUMENT_NODE ? ctx.<Document>cast() : ctx.getOwnerDocument();
    return JsNodeArray.create(d.getElementById(id));
}

From source file:com.google.appinventor.client.jsonp.JsonpConnection.java

License:Open Source License

/**
 * Sends a JSONP request by embedding a SCRIPT tag into the document.
 *
 * @param id the id used for the script tag and to identify the callback
 * @param request the request to be made
 * @param parameters the parameters for the request
 * @param function a function that transforms the response into the type
 *        that the callback needs/*from   ww  w  .  ja v a  2  s.  c o m*/
 * @param callback the callback that should be called with the transformed
 *        response
 */
private <T> void sendJsonpRequest(String id, String request, Map<String, Object> parameters,
        final Function<String, ? extends T> function, final AsyncCallback<T> callback) {
    Preconditions.checkNotNull(id);

    // Prepare an intermediate callback that converts the String result to T.
    if (callback != null) {
        Preconditions.checkNotNull(function);
        CALLBACKS.put(id, new AsyncCallback<String>() {
            @Override
            public void onSuccess(String jsonResult) {
                T result;
                try {
                    result = function.apply(jsonResult);
                } catch (RuntimeException e) {
                    callback.onFailure(e);
                    return;
                }
                callback.onSuccess(result);
            }

            @Override
            public void onFailure(Throwable caught) {
                callback.onFailure(caught);
            }
        });
    }

    // Insert a script tag into the document.
    Document document = Document.get();
    ScriptElement script = document.createScriptElement();
    String uri = makeURI(request, parameters, id);
    script.setSrc(uri);
    script.setId(id);
    Element bodyElement = document.getElementsByTagName("body").getItem(0);
    Element previous = document.getElementById(id);
    if (previous != null) {
        bodyElement.replaceChild(script, previous);
    } else {
        bodyElement.appendChild(script);
    }
}

From source file:com.google.appinventor.client.jsonp.JsonpConnection.java

License:Open Source License

/**
 * Removes the script tag with the given id from the document.
 *///  www  .j  a v a  2 s.  co m
private static void removeScriptTag(String id) {
    Document document = Document.get();
    Element element = document.getElementById(id);
    if (element != null) {
        document.getElementsByTagName("body").getItem(0).removeChild(element);
    }
}

From source file:com.google.livingstories.client.lsp.LivingStory.java

License:Apache License

@Override
public void onModuleLoad() {
    // Inject the contents of the CSS file
    Resources.INSTANCE.css().ensureInjected();

    AjaxLoader.init();//from   ww w.  j  ava  2s  . co m

    String cookieName = Constants.getCookieName(LivingStoryData.getLivingStoryUrl());
    String cookieValue = Cookies.getCookie(cookieName);

    if (cookieValue != null) {
        try {
            LivingStoryData.setCookieBasedLastVisitDate(new Date(Long.valueOf(cookieValue)));
        } catch (NumberFormatException e) {
        }
    }

    // note the visit.
    Date now = new Date();
    Date cookieExpiry = new Date(now.getTime() + SIXTY_DAYS_IN_MILLISECONDS);
    Cookies.setCookie(cookieName, String.valueOf(now.getTime()), cookieExpiry);

    RootPanel.get("storyBody").add(new LivingStoryPage());

    HistoryManager.initialize();

    // Also set appropriate i18n text for a couple of constants:
    Document doc = Document.get();
    doc.getElementById("rssLink").setAttribute("title",
            LspMessageHolder.msgs.rssFeedTitle(LivingStoryData.getLivingStoryTitle()));
    doc.getElementById("readOtherStories").setInnerText(LspMessageHolder.consts.otherStories());
}

From source file:com.google.livingstories.client.start.StartPage.java

License:Apache License

@Override
public void onModuleLoad() {
    // Inject the contents of the CSS file
    // TODO: extract start page styles into its own resource so this doesn't import
    // from the client/lsp/views package.
    Resources.INSTANCE.css().ensureInjected();

    RootPanel.get("managementLinks").add(new ManagementLinks());
    startPageWidget = new VerticalPanel();
    startPageWidget.setWidth("100%");
    RootPanel.get("storyList").add(startPageWidget);

    String title = ClientMessageHolder.consts.startPageTitle();
    Document doc = Document.get();
    doc.setTitle(title);/* www. j ava 2  s  .c o  m*/
    doc.getElementById("logoImage").setAttribute("alt", title);

    livingStoryService.getStartPageBundle(new AsyncCallback<StartPageBundle>() {
        @Override
        public void onFailure(Throwable t) {
            startPageWidget.add(new Label(ClientMessageHolder.consts.startPageLoadFailed()));
        }

        @Override
        public void onSuccess(StartPageBundle bundle) {
            populate(bundle.getStories(), bundle.getStoryIdToUpdateMap());
        }
    });
}

From source file:com.google.maps.gwt.samples.layers.client.LayerPanoramio.java

License:Apache License

@Override
public void onModuleLoad() {
    LatLng fremont = LatLng.create(47.651743, -122.349243);
    MapOptions mapOpts = MapOptions.create();
    mapOpts.setZoom(16);//from w  w  w  .  j  a  v  a 2s.co m
    mapOpts.setCenter(fremont);
    mapOpts.setMapTypeId(MapTypeId.ROADMAP);
    final GoogleMap map = GoogleMap.create(Document.get().getElementById("map_canvas"), mapOpts);

    PanoramioLayer panoramioLayer = PanoramioLayer.create();
    panoramioLayer.setMap(map);

    panoramioLayer.addClickListener(new ClickHandler() {
        @Override
        public void handle(PanoramioMouseEvent event) {
            Document document = Document.get();
            Element photoDiv = document.getElementById("photo_panel");
            Text attribution = document.createTextNode(
                    event.getFeatureDetails().getTitle() + ": " + event.getFeatureDetails().getAuthor());
            Element br = document.createElement("br");
            Element link = document.createElement("a");
            link.setAttribute("href", event.getFeatureDetails().getUrl());
            link.appendChild(attribution);
            photoDiv.appendChild(br);
            photoDiv.appendChild(link);
        }
    });
}

From source file:com.jwh.gwt.fasttable.sample.client.FastTableSample.java

License:Open Source License

private CellListener<SampleModel> buildCellListener() {
    return new CellListener<SampleModel>() {

        /**//  w  w w.jav a2  s  . c  o m
         * @param event
         */
        @Override
        public void handlerCellEvent(final CellEvent<SampleModel> event) {
            final Document document = tablePanel.getElement().getOwnerDocument();
            switch (event.getOnEvent()) {
            case onClick:
                SelectionListener<SampleModel> listener = new SelectionListener<SampleModel>() {
                    @Override
                    public void select(SampleModel object) {
                        try {
                            showDetailPanel(event, document);
                        } catch (NotFound e) {
                        }
                    }

                    @Override
                    public void unselect(SampleModel object) {
                        try {
                            builder.findRowElement(object).getNextSibling().removeFromParent();
                        } catch (NotFound e) {
                        }
                    }
                };
                try {
                    final Element rowElement = event.getRowElement(document);
                    final Element columnElement = rowElement.getFirstChildElement();
                    // Test multi vs single select by changing this flag
                    boolean isMultiSelect = true;
                    isMultiSelect = false;
                    if (isMultiSelect) {
                        builder.multiSelect(columnElement, event.domainObject, listener);
                    } else {
                        builder.singleSelect(columnElement, event.domainObject, listener);
                    }
                } catch (NotFound e) {
                } catch (AbortOperation e) {
                }
                break;
            case onMouseOver:
                try {
                    event.getRowElement(document).addClassName(HIGHLIGHT);
                } catch (final NotFound e1) {
                }
                break;
            case onMouseOut:
                try {
                    event.getRowElement(document).removeClassName(HIGHLIGHT);
                } catch (final NotFound e1) {
                }
                break;
            default:
                break;
            }

        }

        /**
         * Show a panel under the selected item
         * 
         * @param event
         * @param document
         * @throws NotFound
         */
        private void showDetailPanel(CellEvent<SampleModel> event, final Document document) throws NotFound {
            final SampleModel d = event.getDomainObject();
            final TableRowElement newRow = event.insertRowAfter(document);
            final TableCellElement td = document.createTDElement();
            td.addClassName(DROP_PANEL);
            // Note: "colSpan" must have uppercase 'S' for IE
            td.setAttribute("colSpan", "6");
            newRow.appendChild(td);
            try {
                LabelValueUtil util = new LabelValueUtil();
                util.table.setStyle(Style.BORDER_NONE);
                util.labelValue("Name", d.name);
                util.prepareAttribute("rowSpan", "2");
                final String buttonId = util.button("OK");
                util.newRow();
                util.labelValue("Street", d.street);
                util.newRow();
                util.labelValue("City, State ", d.city + ", " + d.state);
                util.newRow();
                util.labelValue("Zip", d.zip);
                util.newRow();
                final String html = util.toHtml();
                td.setInnerHTML(html);
                final Element okButton = document.getElementById(buttonId);
                DOM.setEventListener((com.google.gwt.user.client.Element) okButton, new EventListener() {
                    @Override
                    public void onBrowserEvent(Event event) {
                        switch (event.getTypeInt()) {
                        case Event.ONMOUSEDOWN:
                            Window.alert(
                                    "This demonstrates how to attach events to content created with setInnerHtml()");
                            break;
                        case Event.ONMOUSEOVER:
                            okButton.addClassName(Style.BUTTON_OVER);
                            break;
                        case Event.ONMOUSEOUT:
                            okButton.removeClassName(Style.BUTTON_OVER);
                            break;
                        default:
                            break;
                        }
                    }
                });
                DOM.sinkEvents((com.google.gwt.user.client.Element) okButton,
                        Event.ONMOUSEOUT | Event.ONMOUSEDOWN | Event.ONMOUSEOVER);
            } catch (Exception e) {
            }
        }
    };
}

From source file:forplay.html.HtmlGraphics.java

License:Apache License

protected HtmlGraphics() {
    Document doc = Document.get();

    dummyCanvas = doc.createCanvasElement();
    dummyCtx = dummyCanvas.getContext2d();

    rootElement = doc.getElementById("forplay-root");
    if (rootElement == null) {
        rootElement = doc.getBody();/*from www  .ja  v  a  2  s.  c o m*/
    } else {
        // clear the contents of the "forplay-root" element, if present
        rootElement.setInnerHTML("");
    }
}

From source file:org.ednovo.gooru.application.client.home.HomePresenter.java

License:Open Source License

@Override
public void onReveal() {
    super.onReveal();
    /*Window.enableScrolling(true);
    Window.scrollTo(0, 0);*//*from w  w w  . ja va  2  s.c  o m*/
    if (AppClientFactory.isAnonymous()) {
        AppClientFactory.setBrowserWindowTitle(SeoTokens.HOME_TITLE_ANONYMOUS);
    } else {
        AppClientFactory.setBrowserWindowTitle(SeoTokens.HOME_TITLE_LOGGEDIN);
    }
    AppClientFactory.setMetaDataDescription(SeoTokens.HOME_META_DESCRIPTION);
    AppClientFactory.fireEvent(new HomeEvent(HeaderTabType.HOME));
    if (AppClientFactory.getPlaceManager().getCurrentPlaceRequest().getNameToken() != null) {
        AppClientFactory.fireEvent(
                new SetFooterEvent(AppClientFactory.getPlaceManager().getCurrentPlaceRequest().getNameToken()));
    }

    Document doc = Document.get();
    doc.getElementById("uvTab").getStyle().setDisplay(Display.BLOCK);
}

From source file:org.ednovo.gooru.application.client.newhome.NewHomePresenter.java

License:Open Source License

@Override
protected void onReveal() {
    super.onReveal();
    Window.enableScrolling(true);

    if (AppClientFactory.isAnonymous()) {
        AppClientFactory.setBrowserWindowTitle(SeoTokens.HOME_TITLE_ANONYMOUS);
    } else {/*from  ww w .  jav a  2 s  .co m*/
        AppClientFactory.setBrowserWindowTitle(SeoTokens.HOME_TITLE_LOGGEDIN);
    }
    AppClientFactory.setMetaDataDescription(SeoTokens.HOME_META_DESCRIPTION);
    AppClientFactory.fireEvent(new HomeEvent(HeaderTabType.HOME));
    if (AppClientFactory.getPlaceManager().getCurrentPlaceRequest().getNameToken() != null) {
        AppClientFactory.fireEvent(
                new SetFooterEvent(AppClientFactory.getPlaceManager().getCurrentPlaceRequest().getNameToken()));
    }

    Document doc = Document.get();
    if (doc.getElementById("uvTab") != null) {
        doc.getElementById("uvTab").getStyle().setDisplay(Display.BLOCK);
    }

}