List of usage examples for com.vaadin.ui JavaScriptFunction JavaScriptFunction
JavaScriptFunction
From source file:org.vaadin.tori.util.ToriScheduler.java
License:Apache License
public void scheduleDeferred(final ScheduledCommand command) { if (deferredCommands.isEmpty()) { JavaScript.eval(DEFERRED_COMMAND_FUNCTION_NAME + FUNCTION); JavaScript.getCurrent().addFunction(DEFERRED_COMMAND_FUNCTION_NAME, new JavaScriptFunction() { @Override//from w w w.ja v a2 s . c om public void call(final JSONArray arguments) throws JSONException { JavaScript.getCurrent().removeFunction(DEFERRED_COMMAND_FUNCTION_NAME); executeCommands(deferredCommands); } }); } deferredCommands.add(command); }
From source file:org.yozons.vaadin.ckeditor.CKEditor.java
License:Open Source License
public CKEditor(CKEditorConfig config) { System.out.println("CKEditor config: " + config.getInPageConfig()); setWidth(100, Unit.PERCENTAGE);//www . ja v a2 s .com setHeight(350, Unit.PIXELS); setValue(""); getState().setInPageConfig(config.getInPageConfig()); if (config.hasWriterIndentationChars()) { getState().setWriterIndentationChars(config.getWriterIndentationChars()); } if (config.hasProtectedSource()) { getState().setProtectedSources(config.getProtectedSources()); } if (config.hasWriterRules()) { java.util.Set<String> writerRulesTagNames = config.getWriterRulesTagNames(); String[] tagNames = new String[writerRulesTagNames.size()]; String[] rules = new String[writerRulesTagNames.size()]; int i = 0; for (String tagName : writerRulesTagNames) { tagNames[i] = tagName; rules[i] = config.getWriterRuleByTagName(tagName); ++i; } getState().setWriterRulesTagNames(tagNames); getState().setWriterRulesRules(rules); } addFunction("onInstanceReady", new JavaScriptFunction() { private static final long serialVersionUID = -2199710366817990634L; @Override public void call(JSONArray arguments) throws JSONException { String version = arguments.getString(0); System.out.println("CKEditor onInstanceReady(): " + version); getState().setVersion(version); } }); addFunction("onValueChange", new JavaScriptFunction() { private static final long serialVersionUID = 6707318584258721663L; @Override public void call(JSONArray arguments) throws JSONException { if (!isReadOnly()) { String value = arguments.getString(0); System.out.println("CKEditor onValueChange() >>>" + value + "<<<"); getState().setHtml(value); synchronized (valueChangeListeners) { for (ValueChangeListener listener : valueChangeListeners) { listener.valueChange(value); } } } else { System.out.println("CKEditor onValueChange() ignored because read-only"); } } }); addFunction("requestCompleted", new JavaScriptFunction() { private static final long serialVersionUID = -3928003452480701563L; @Override public void call(JSONArray arguments) throws JSONException { if (arguments.length() == 1) { String completedRequest = arguments.getString(0); System.out.println("requestCompleted - updating shared state for type: " + completedRequest); if ("focus".equals(completedRequest)) { getState().clearFocus(); } else { System.err.println( "requestCompleted: cannot update shared state for unexpected completedRequest type: " + completedRequest); } } else { System.err.println("requestCompleted: Missing required single argument."); } } }); }
From source file:sph.vaadin.ui.svg.SvgDots.java
License:Apache License
/** * Initializes the dots.//from w ww . j a va 2s . c om */ private void init() { this.setId("svg_" + this.hashCode()); this.addFunction("delegateDotEvent", new JavaScriptFunction() { private static final long serialVersionUID = -4245967454493315292L; @Override public void call(JSONArray arguments) throws JSONException { if (arguments.length() > 1) { dotEventManager.callListeners(arguments.getString(0), SvgDots.this, arguments.getInt(1)); } } }); this.addDetachListener(new DetachListener() { private static final long serialVersionUID = 5583909485994600778L; @Override public void detach(DetachEvent event) { dotEventManager.clear(); } }); }
From source file:sph.vaadin.ui.videojs.Videojs.java
License:Apache License
/** * Sets the initial properties of the Video.js player *///w ww .j a v a2 s . c o m protected void init() { this.addFunction("videoEventFired", new JavaScriptFunction() { private static final long serialVersionUID = -4245967454493315292L; @Override public void call(JSONArray arguments) throws JSONException { try { if (arguments.length() > 1) { currentTime = arguments.getDouble(1); String eventName = arguments.getString(0); double triggerTime = arguments.getDouble(1); //System.out.println(eventName + ":" + triggerTime); if (eventName.equals(VjsListener.DURATIONCHANGE_EVENT) && arguments.length() > 2) { duration = arguments.getDouble(2); //System.out.println("duration: " + duration); } if (eventName.equals(VjsListener.PLAY_EVENT)) { isPaused = false; } if (eventName.equals(VjsListener.PAUSE_EVENT)) { isPaused = true; } videojsEventManager.callListeners(VjsListener.ANY_EVENT, Videojs.this, triggerTime); videojsEventManager.callListeners(eventName, Videojs.this, triggerTime); } } catch (JSONException e) { // We'll log in the console, you might not want to JavaScript.getCurrent().execute("console.error('" + e.getMessage() + "')"); System.out.println(e.getMessage()); } } }); addDetachListener(new DetachListener() { private static final long serialVersionUID = 5583909485994600778L; @Override public void detach(DetachEvent event) { videojsEventManager.clear(); JavaScript.getCurrent().execute("videojs('" + videoJsId + "').dispose();"); } }); }