List of usage examples for com.vaadin.ui JavaScriptFunction JavaScriptFunction
JavaScriptFunction
From source file:fi.m1kah.JsComponent.java
License:Open Source License
private void registerNewJavascriptFunction() { addFunction("callFromJavascript", new JavaScriptFunction() { @Override//from ww w . j a v a2 s . c o m public void call(JsonArray jsonArray) { Notification.show("JavaScript calling! " + jsonArray.getString(0)); } }); }
From source file:fi.semantum.strategia.widget.Browser.java
License:Open Source License
public Browser(BrowserNode[] nodes, BrowserLink[] links, int width, int height) { addFunction("select", new JavaScriptFunction() { private static final long serialVersionUID = -8281255257252572037L; @Override/* w w w. java 2 s . c o m*/ public void call(JsonArray arguments) throws JSONException { for (BrowserListener listener : listeners) listener.select(arguments.get(0).asNumber(), arguments.get(1).asNumber(), arguments.get(2).asString()); } }); addFunction("save", new JavaScriptFunction() { private static final long serialVersionUID = -237728055512115104L; @Override public void call(JsonArray arguments) throws JSONException { JreJsonObject o = arguments.get(1); Map<String, BrowserNodeState> states = new HashMap<String, BrowserNodeState>(); for (String uuid : o.keys()) { JreJsonObject o2 = (JreJsonObject) o.get(uuid); BrowserNodeState ns = new BrowserNodeState(); ns.x = o2.get("x").asNumber(); ns.y = o2.get("y").asNumber(); ns.fixed = o2.get("fixed").asBoolean(); states.put(uuid, ns); } for (BrowserListener listener : listeners) listener.save(arguments.getString(0), states); } }); update(nodes, links, width, height, true); }
From source file:info.magnolia.ui.vaadin.editor.JCrop.java
License:Open Source License
public JCrop(JCropHandler handler) { addFunction("doOnSelect", new JavaScriptFunction() { @Override//from ww w .j a va 2 s . c o m public void call(JsonArray args) { SelectionArea area = AreaFromJSON(args.getObject(0)); getState(false).selection = area; getParent().fireEvent(new JCropSelectionEvent(getParent(), area)); } }); addFunction("doOnRelease", new JavaScriptFunction() { @Override public void call(JsonArray args) { getState().selection = null; getParent().fireEvent(new JCropReleaseEvent(getParent())); } }); addFunction("onCreated", new JavaScriptFunction() { @Override public void call(JsonArray args) { getState(false).isValid = true; } }); }
From source file:org.lucidj.aceeditor.AceEditor.java
License:Apache License
public AceEditor() { final AceEditorState state = getState(false); final AceEditor self = this; sync_state(false);/*w w w . ja v a 2 s. co m*/ addStyleName("aceeditor"); addFunction("server_afterRender", new JavaScriptFunction() { @Override public void call(JsonArray arguments) { log.debug("server_afterRender: arguments = {}", arguments.toJson()); // When we receive afterRender event, the editor contents are already loaded. // We only use s_value to do the _initial load_ for the js component. // Afterwards we _only_ sync editor contents using client_setValue js call. // So we are safe to clear s_value now and save some byte traffic. //state.s_value = ""; --- PAGE REFRESH BUG (EMPTY ACE EDITOR) if (getWidth() == -1) { width_undefined = true; } if (width_undefined) { String width = arguments.get(0).asString() + "px"; setWidth(width); state.width = width; log.debug("setWidth = {}", (float) arguments.get(0).asNumber()); } if (getHeight() == -1) { height_undefined = true; } if (height_undefined) { String height = arguments.get(1).asString() + "px"; setHeight(height); state.height = height; log.debug("setHeight = {}", (float) arguments.get(1).asNumber()); } } }); addFunction("server_onChangeValue", new JavaScriptFunction() { @Override public void call(JsonArray arguments) { log.debug("server_onChangeValue: arguments = {}", arguments.toJson()); c_value = arguments.getString(0); for (FieldEvents.TextChangeListener listener : textChangeListeners) { listener.textChange(new AceEditorTextChangeEvent(self)); } } }); addFunction("server_onFocus", new JavaScriptFunction() { @Override public void call(JsonArray arguments) { log.debug("server_onFocus: arguments = {}", arguments.toJson()); for (FieldEvents.FocusListener listener : focusListeners) { listener.focus(new FieldEvents.FocusEvent(self)); } } }); addFunction("server_onBlur", new JavaScriptFunction() { @Override public void call(JsonArray arguments) { log.debug("server_onBlur: arguments = {}", arguments.toJson()); JsonObject cursor = arguments.getObject(0); if (cursor.hasKey("row")) { c_cursor_row = (int) arguments.getObject(0).getNumber("row"); c_cursor_column = (int) arguments.getObject(0).getNumber("column"); log.debug("server_onBlur: row={} column={}", c_cursor_row, c_cursor_column); } } }); }
From source file:org.opencms.ui.components.codemirror.CmsCodeMirror.java
License:Open Source License
/** * Constructor.<p>//from ww w . j a va2s . c om */ public CmsCodeMirror() { m_componentId = m_componentCount; m_componentCount++; m_codeValue = ""; getState().m_id = m_componentId; getState().m_contentValue = m_codeValue; CmsMessages messages = Messages.get().getBundle(UI.getCurrent().getLocale()); getState().m_shortcutsMessage = getShortcutMessages(messages); getState().m_messages = getLocalizationMessages(messages); if (CSS_URIS == null) { CSS_URIS = new String[] { CmsWorkplace.getStaticResourceUri("/editors/codemirror/dist/lib/codemirror.css"), CmsWorkplace.getStaticResourceUri("/editors/codemirror/dist/theme/eclipse.css"), CmsWorkplace.getStaticResourceUri("/editors/codemirror/dist/addon/dialog/dialog.css"), CmsWorkplace.getStaticResourceUri("/editors/codemirror/dist/addon/hint/show-hint.css") }; } getState().m_cssURIs = CSS_URIS; if (JAVASCRIPT_URIS == null) { JAVASCRIPT_URIS = new String[] { CmsWorkplace.getStaticResourceUri("/editors/codemirror/dist/lib/codemirror.js"), CmsWorkplace.getStaticResourceUri("/editors/codemirror/dist/addon/dialog/dialog.js"), CmsWorkplace.getStaticResourceUri("/editors/codemirror/dist/addon/search/searchcursor.js"), CmsWorkplace.getStaticResourceUri("/editors/codemirror/js/search.js"), CmsWorkplace.getStaticResourceUri("/editors/codemirror/dist/addon/edit/closebrackets.js"), CmsWorkplace.getStaticResourceUri("/editors/codemirror/dist/addon/edit/closetag.js"), CmsWorkplace.getStaticResourceUri("/editors/codemirror/dist/addon/edit/matchbrackets.js"), CmsWorkplace.getStaticResourceUri("/editors/codemirror/dist/addon/hint/show-hint.js"), CmsWorkplace.getStaticResourceUri("/editors/codemirror/dist/addon/hint/html-hint.js"), CmsWorkplace.getStaticResourceUri("/editors/codemirror/dist/addon/hint/javascript-hint.js"), CmsWorkplace.getStaticResourceUri("/editors/codemirror/dist/addon/hint/xml-hint.js"), CmsWorkplace.getStaticResourceUri("/editors/codemirror/dist/addon/fold/foldcode.js"), CmsWorkplace.getStaticResourceUri("/editors/codemirror/dist/addon/fold/brace-fold.js"), CmsWorkplace.getStaticResourceUri("/editors/codemirror/dist/addon/fold/xml-fold.js"), CmsWorkplace.getStaticResourceUri("/editors/codemirror/dist/addon/comment/comment.js"), CmsWorkplace.getStaticResourceUri("/editors/codemirror/dist/addon/selection/active-line.js"), CmsWorkplace.getStaticResourceUri("/editors/codemirror/dist/mode/css/css.js"), CmsWorkplace.getStaticResourceUri("/editors/codemirror/dist/mode/xml/xml.js"), CmsWorkplace.getStaticResourceUri("/editors/codemirror/dist/mode/clike/clike.js"), CmsWorkplace.getStaticResourceUri("/editors/codemirror/dist/mode/javascript/javascript.js"), CmsWorkplace.getStaticResourceUri("/editors/codemirror/dist/mode/css/css.js"), CmsWorkplace.getStaticResourceUri("/editors/codemirror/dist/mode/htmlmixed/htmlmixed.js"), CmsWorkplace.getStaticResourceUri("/editors/codemirror/js/htmlembedded_modified.js") }; } getState().m_scriptURIs = JAVASCRIPT_URIS; addFunction("onBlur", new JavaScriptFunction() { private static final long serialVersionUID = 1L; @Override public void call(JsonArray arguments) throws JSONException { onBlur(arguments.getString(0)); } }); addFunction("onChange", new JavaScriptFunction() { private static final long serialVersionUID = 1L; @Override public void call(JsonArray arguments) throws JSONException { onChange(arguments.getString(0)); } }); addStyleName("o-codemirror"); }
From source file:org.vaadin.addon.googlepicker.auth.GoogleAuthorizer.java
public GoogleAuthorizer(String clientId) { getState().clientId = clientId;// w w w . java2 s .co m addFunction("onAuthorizeScope", new JavaScriptFunction() { @Override public void call(JsonArray arguments) { String scopeString = arguments.getString(0); String accessToken = arguments.getString(1); String[] scopes = scopeString.split(" "); for (String scope : scopes) { AuthorizationListener l = authListeners.get(scope); if (l != null) { l.authorized(scope, accessToken); } } } }); }
From source file:org.vaadin.addon.googlepicker.GooglePicker.java
private GooglePicker(String developerKey, String clientId, String viewId, String scope) { super(clientId); getState().developerKey = developerKey; getState().scope = scope;//from www .j a v a2s.c om getState().viewId = viewId; addFunction("onDocumentSelected", new JavaScriptFunction() { @Override public void call(JsonArray arguments) { /* var id = doc[google.picker.Document.ID]; var serviceId = doc[google.picker.Document.SERVICE_ID]; var name = doc[google.picker.Document.NAME]; var type = doc[google.picker.Document.TYPE]; var mimeType = doc[google.picker.Document.MIME_TYPE]; var lastEdited = doc[google.picker.Document.LAST_EDITED_UTC]; var webUrl = doc[google.picker.Document.URL]; var embeddableUrl = doc[google.picker.Document.EMBEDDABLE_URL]; var iconUrl = doc[google.picker.Document.ICON_URL]; var latitude = doc[google.picker.Document.LATITUDE]; var longitude = doc[google.picker.Document.LONGITUDE]; */ Document doc = new Document(); doc.id = arguments.getString(0); doc.serviceId = arguments.getString(1); doc.name = arguments.getString(2); doc.type = arguments.getString(3); doc.mimeType = arguments.getString(4); //TODO cast exception // doc.lastEdited = arguments.getString(5); doc.url = arguments.getString(6); //doc.embeddableUrl = arguments.getString(7); doc.iconUrl = arguments.getString(8); //TODO cast exception // doc.latitude = arguments.getString(9); // doc.longitude = arguments.getString(10); document = doc; for (SelectionListener listener : listeners) { listener.documentSelected(document); } } }); }
From source file:org.vaadin.addon.paypal_button.PayPalButton.java
License:Apache License
public PayPalButton() { addFunction("succeeded", new JavaScriptFunction() { @Override//w ww . java 2s .c o m public void call(JsonArray arguments) { succeeded(); } }); addFunction("cancelled", new JavaScriptFunction() { @Override public void call(JsonArray arguments) { cancelled(); } }); }
From source file:org.vaadin.chronographer.ChronoGrapher.java
License:Apache License
private void addJavascriptClickCallback(String uniqueJSFuncName) { com.vaadin.ui.JavaScript.getCurrent().addFunction(uniqueJSFuncName, new JavaScriptFunction() { @Override//from ww w . ja v a 2 s .co m public void call(JSONArray arguments) throws JSONException { if (eventClickHandler != null) { eventClickHandler.handleClick(getEventById(arguments.getString(0))); } } }); }
From source file:org.vaadin.se.facebook.Facebook.java
License:Apache License
public Facebook(String appId) { getState().appId = appId;/*from w w w . ja v a 2 s . co m*/ addFunction("onLogin", new JavaScriptFunction() { @Override public void call(JSONArray arguments) throws JSONException { for (FacebookListener listener : Collections.unmodifiableList(listeners)) { Facebook.this.userId = arguments.getString(0); Facebook.this.authToken = arguments.getString(1); Facebook.this.loggedIn = true; listener.onFacebookLogin(userId); } } }); addFunction("onLogout", new JavaScriptFunction() { @Override public void call(JSONArray arguments) throws JSONException { Facebook.this.loggedIn = false; for (FacebookListener listener : Collections.unmodifiableList(listeners)) { listener.onFacebookLogout(); } } }); addFunction("onPostCancel", new JavaScriptFunction() { @Override public void call(JSONArray arguments) throws JSONException { for (FacebookListener listener : Collections.unmodifiableList(listeners)) { listener.onFacebookPostCancel(); } } }); addFunction("onPostSuccess", new JavaScriptFunction() { @Override public void call(JSONArray arguments) throws JSONException { for (FacebookListener listener : Collections.unmodifiableList(listeners)) { listener.onFacebookPost(arguments.getString(0)); } } }); addFunction("onApiCallback", new JavaScriptFunction() { @Override public void call(JSONArray arguments) throws JSONException { FacebookCallback cb = activeCallback; activeCallback = null; if (cb != null) { cb.facebookResponse( arguments != null && arguments.length() > 0 ? arguments.getJSONObject(0) : null); } } }); }