List of usage examples for com.google.gwt.dom.client ScriptElement setId
@Override
public void setId(String id)
From source file:com.extjs.gxt.ui.client.data.ScriptTagProxy.java
License:sencha.com license
public void load(DataReader<D> reader, Object loadConfig, AsyncCallback<D> callback) { this.callback = callback; this.reader = reader; this.config = loadConfig; String transId = "transId" + ID++; String prepend = url.indexOf("?") != -1 ? "&" : "?"; String u = url + prepend + "callback=" + CALLBACK_CONTAINER + "." + transId + generateUrl(loadConfig); createCallback(this, CALLBACK_CONTAINER, transId); ScriptElement script = Document.get().createScriptElement(); script.setId(transId); script.setType("text/javascript"); head.appendChild(script);//from w w w .j a va 2s .co m script.setSrc(u); }
From source file:com.ghusse.dolomite.core.SignedJsonpRequest.java
License:Apache License
/** * Finally sends the request.// w ww. j av a2s .c om * @param baseUri Uri where to send the request * @param arguments Arguments of the request */ void send(final String baseUri, final Map<String, String> arguments) { registerCallbacks(CALLBACKS); String prefix = CALLBACKS_NAME + "." + callbackId; arguments.put(this.callbackParam, prefix + ".onSuccess"); if (failureCallbackParam != null) { arguments.put(this.failureCallbackParam, prefix + ".onFailure"); } UrlBuilder.sign(arguments, this.signatureParam, this.secret); final String uri = UrlBuilder.getUri(baseUri, arguments); ScriptElement script = Document.get().createScriptElement(); script.setType("text/javascript"); script.setId(callbackId); script.setSrc(uri.toString()); timer = new Timer() { @Override public void run() { onFailure(new TimeoutException("Timeout while calling " + baseUri)); } }; timer.schedule(timeout); getHeadElement().appendChild(script); }
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 w ww . jav a 2s.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.pdmaf.ui.gwt.client.rpc.JsonpRequest.java
License:Apache License
/** * Sends a request using the JSONP mechanism. * * @param baseUri To be sent to the server. *//* w w w . j ava 2 s .c o m*/ void send(final String baseUri) { registerCallbacks(CALLBACKS); StringBuffer uri = new StringBuffer(baseUri); uri.append(baseUri.contains("?") ? "&" : "?"); String prefix = CALLBACKS_NAME + "." + callbackId; uri.append(callbackParam).append("=").append(prefix).append(".onSuccess"); if (failureCallbackParam != null) { uri.append("&"); uri.append(failureCallbackParam).append("=").append(prefix).append(".onFailure"); } ScriptElement script = Document.get().createScriptElement(); script.setType("text/javascript"); script.setId(callbackId); script.setSrc(uri.toString()); getDocumentElement().getFirstChild().appendChild(script); timer = new Timer() { @Override public void run() { onFailure(new TimeoutException("Timeout while calling " + baseUri)); } }; timer.schedule(timeout); }
From source file:grails.plugin.console.charts.client.application.ApplicationDesktopView.java
License:Apache License
@Override public void view(String type, JSONObject result) { clear();/*w ww . j ava 2s . com*/ DivElement div = Document.get().createDivElement(); div.setId(CHART_ID); div.getStyle().setWidth(AppUtils.DEFAULT_WIDTH, Style.Unit.PX); div.getStyle().setProperty("margin", "0 auto"); rightContainer.getElement().appendChild(div); Document.get().getElementById(CHART_ID).removeAllChildren(); if (result.get("columns") == null) { Window.alert("Columns is empty!"); return; } JSONArray columns = result.get("columns").isArray(); JSONObject override = result.get("override") != null ? result.get("override").isObject() : null; String axes = "{\n" + "\"id\": \"v1\",\n" + "\"axisThickness\": 2,\n" + "\"gridAlpha\": 0,\n" + "\"axisAlpha\": 1,\n" + "\"position\": \"left\"\n" + "}"; String graphs = ""; for (int i = 1; columns.size() > i; i++) { String col = columns.get(i).toString(); graphs += (graphs.equals("") ? "" : ",") + "{\n" + "\"id\": \"g" + i + "\",\n" + "\"balloonText\": \"" + (columns.size() > 2 ? "[[title]]: [[value]]" : "[[value]]") + "\",\n" + "\"valueField\": " + col + ",\n" + "\"valueAxis\": \"v" + i + "\",\n" + "\"bullet\": \"round\",\n" + "\"bulletBorderThickness\": 1,\n" + "\"hideBulletsCount\": 30,\n" + "\"title\": " + (override != null && override.get(col) != null && override.get(col).isString() != null ? override.get(col) : col) + ",\n" + "\"fillAlphas\": 0\n" + "}"; } String scrollbar = (columns.size() > 1) ? "{\n" + " \"autoGridCount\": true,\n" + " \"graph\": \"g1\",\n" + " \"scrollbarHeight\": 40\n" + "}," : "{},"; String cursor = (columns.size() > 5) ? "{\n" + " \"cursorAlpha\": 0.1,\n" + " \"cursorColor\": \"#000000\",\n" + " \"fullWidth\": true,\n" + " \"valueBalloonsEnabled\": false,\n" + " \"zoomable\": true\n" + "}," : "{},"; String content = "AmCharts.makeChart(\"" + CHART_ID + "\", {" + "\"type\": \"serial\",\n" + "\"theme\": \"none\",\n" + "\"pathToImages\": \"http://www.amcharts.com/lib/3/images/\",\n" + "\"legend\": {\n" + " \"align\": \"center\",\n" + " \"equalWidths\": true,\n" + " \"periodValueText\": \"total: [[value.sum]]\",\n" + " \"valueAlign\": \"left\",\n" + " \"valueText\": \"[[value]] ([[percents]]%)\",\n" + " \"valueWidth\": 100\n" + "},\n" + "\"dataDateFormat\": \"YYYY-MM-DD HH:NN\",\n" + "\"dataProvider\": " + result.get("content").toString() + ",\n" + "\"valueAxes\": [" + axes + "],\n" + "\"graphs\": [" + graphs + "],\n" + "\"chartScrollbar\": " + scrollbar + "\n" + "\"chartCursor\": " + cursor + "\n" + "\"categoryField\": " + columns.get(0) + ",\n" + "\"categoryAxis\": {\n" + " \"parseDates\": true,\n" + " \"axisColor\": \"#DADADA\",\n" + " \"minorGridEnabled\": true\n" + "}\n" + "});"; ScriptElement script = Document.get().createScriptElement(content); script.setId(CHART_INIT_ID); int height = ((columns.size() / 3) * 25) + 500; div.getStyle().setHeight(height, Style.Unit.PX); AppUtils.CURRENT_HEIGHT = height; rightContainer.getElement().appendChild(script); shareButton.setEnabled(true); /* TODO // update button lineChartButton.setFontAwesomeIcon(IconType.CIRCLE_O); barChartButton.setFontAwesomeIcon(IconType.CIRCLE_O); columnChartButton.setFontAwesomeIcon(IconType.CIRCLE_O); pieChartButton.setFontAwesomeIcon(IconType.CIRCLE_O); switch (type.toLowerCase()) { case "line": lineChartButton.setFontAwesomeIcon(IconType.CIRCLE); break; case "bar": barChartButton.setFontAwesomeIcon(IconType.CIRCLE); break; case "column": columnChartButton.setFontAwesomeIcon(IconType.CIRCLE); break; case "pie": pieChartButton.setFontAwesomeIcon(IconType.CIRCLE); break; } */ }
From source file:org.uberfire.client.screens.gadgets.TwitterGadgetScreen.java
License:Apache License
@PostConstruct public void init() { final ScriptElement se = Document.get().createScriptElement(); se.setId("twitter-wjs"); se.setSrc("http://platform.twitter.com/widgets.js"); this.getElement().appendChild(se); }