Example usage for com.vaadin.ui JavaScript getCurrent

List of usage examples for com.vaadin.ui JavaScript getCurrent

Introduction

In this page you can find the example usage for com.vaadin.ui JavaScript getCurrent.

Prototype

public static JavaScript getCurrent() 

Source Link

Document

Get the JavaScript object for the current Page, or null if there is no current page.

Usage

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 . j ava  2s  .  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:sph.vaadin.ui.videojs.Videojs.java

License:Apache License

/**
 * Sets the initial properties of the Video.js player
 *///  w w w.  j  av a  2 s  .  co  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();");
        }
    });
}