Example usage for com.vaadin.ui JavaScriptFunction JavaScriptFunction

List of usage examples for com.vaadin.ui JavaScriptFunction JavaScriptFunction

Introduction

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

Prototype

JavaScriptFunction

Source Link

Usage

From source file:com.snowy.MyVaadinUI.java

@Override
protected void init(VaadinRequest request) {
    //d = new data(template);
    if (Page.getCurrent().getWebBrowser().isTooOldToFunctionProperly()) {
        Page.getCurrent().setLocation("https://www.google.com/chrome/browser/");
    }//from  w w  w.j av  a2 s. c  o  m
    //VaadinService.getCurrent().
    Page.getCurrent().setTitle("Connect 4");

    d = new data();
    //this.access(()->{

    //n.addView("postLogin", new PostLoginView());
    //Navigator n = this.getNavigator();
    //n.addProvider();
    //});
    /*
    final TextField name = new TextField();
    name.setCaption("Type your name here:");
            
    Button button = new Button("Click Me");
    button.addClickListener( e -> {
    layout.addComponent(new Label("Thanks " + name.getValue() 
            + ", it works!"));
    });
    */
    JavaScript.getCurrent().addFunction("closeMyApplication", new JavaScriptFunction() {
        @Override
        public void call(JsonArray arguments) {
            //Logger.getLogger(MyVaadinUI.class.getName()).info(VaadinSession.getCurrent().getCsrfToken());
            d.logout(VaadinSession.getCurrent().getCsrfToken());
            //new data().setInActive(VaadinSession.getCurrent().getCsrfToken());
            //VaadinSession.getCurrent().close();
        }

    });

    Page.getCurrent().getJavaScript().execute(
            "window.onbeforeunload = function (e) { var e = e || window.event; closeMyApplication(); return; };");
    VaadinService.getCurrent().addSessionDestroyListener(e -> {
        //Logger.getLogger(MyVaadinUI.class.getName()).info(e.getSession().getCsrfToken());
        d.logout(e.getSession().getCsrfToken());

    });

    //Navigator n = new Navigator(this,this);
    //n.addView("Main", new PostLoginView());
    //        this.setNavigator(n);
    //layout.setComponentAlignment(MainL, Alignment.TOP_CENTER);
    this.setPollInterval(1000);
    this.addPollListener((UIEvents.PollEvent e) -> {
        if (e.getUI().getContent().toString().contains("PostLoginView")) {
            PostLoginView plv = (PostLoginView) e.getUI().getContent();
            d.resetActiveIfNot();
            plv.getChatWindow().getUsersList().retrieveActiveUsers();

            plv.getChatWindow().updateChats();
            plv.getGameWindow().updateRequests();
            plv.getGameWindow().updateGames();
            plv.getGameWindow().checkForNewGames();
            //Logger.getLogger(MyVaadinUI.class.getName()).log(Level.INFO,plv.getChatWindow().getUsersList().getValue().toString());
        }

    });
    Navigator navigator = new Navigator(this, this);
    navigator.addProvider(viewProvider);

    navigator.addViewChangeListener(new ViewChangeListener() {
        @Override
        public boolean beforeViewChange(ViewChangeListener.ViewChangeEvent event) {

            if (Page.getCurrent().getLocation().getPath().equals("/")
                    || VaadinSession.getCurrent().getAttribute("token") != null) {

                return true;
            } else {

                //Notification.show(,Notification.Type.ERROR_MESSAGE);
                return false;
            }
        }

        @Override
        public void afterViewChange(ViewChangeListener.ViewChangeEvent event) {

        }

    });

    /*UI.getCurrent().setErrorHandler(new DefaultErrorHandler(){
     @Override
     public void error(com.vaadin.server.ErrorEvent event) {
         UI.getCurrent().setContent(new Label("error"));
     }
                
    });*/
    //VaadinService.createCriticalNotificationJSON("","", "", "");
    //navigator.setErrorView(navigator.getCurrentView());
    //layout.setComponentAlignment(link, Alignment.MIDDLE_CENTER);
    //setContent(new Login());

}

From source file:com.wcs.wcslib.vaadin.widget.recaptcha.ReCaptcha.java

License:Apache License

public ReCaptcha(String privateKey, String publicKey, ReCaptchaOptions options, String customHtml) {
    super();/*from ww  w . j a  v  a  2 s. com*/
    getState().publicKey = publicKey;
    getState().options = options;
    getState().customHtml = customHtml;
    addFunction("responseChanged", new JavaScriptFunction() {

        @Override
        public void call(JsonArray arguments) {
            challenge = arguments.getString(0);
            response = arguments.getString(1);

        }
    });
    this.privateKey = privateKey;
}

From source file:de.elomagic.vaadin.addon.networkgraph.NetworkGraph.java

License:Apache License

public NetworkGraph() {
    super();/*from   ww w.  ja  v  a2 s  . co m*/
    setStyleName("networkgraph");
    addFunction("onSelectNodes", new JavaScriptFunction() {

        @Override
        public void call(final JSONArray arguments) throws JSONException {
            JSONArray array = arguments.getJSONArray(0);
            List<String> list = new ArrayList<>();
            for (int i = 0; i < array.length(); i++) {
                list.add(array.getString(i));
            }

            selectedItems.clear();
            selectedItems.addAll(list);

            fireSelectNodeEvent(list);
        }
    });
}

From source file:de.elomagic.vaadin.addon.speechrecognition.SpeechRecognition.java

License:Apache License

public SpeechRecognition() {
    super();/*from   w  w  w  . j av  a2  s  .  c  o  m*/

    addFunction("onaudiostart", new JavaScriptFunction() {

        @Override
        public void call(final JSONArray arguments) throws JSONException {
            fireEvent(arguments, Type.AudioStart);
        }
    });
    addFunction("onsoundstart", new JavaScriptFunction() {

        @Override
        public void call(final JSONArray arguments) throws JSONException {
            fireEvent(arguments, Type.SoundStart);
        }
    });
    addFunction("onspeechstart", new JavaScriptFunction() {

        @Override
        public void call(final JSONArray arguments) throws JSONException {
            fireEvent(arguments, Type.SpeechStart);
        }
    });
    addFunction("onspeechend", new JavaScriptFunction() {

        @Override
        public void call(final JSONArray arguments) throws JSONException {
            fireEvent(arguments, Type.SpeechEnd);
        }
    });
    addFunction("onsoundend", new JavaScriptFunction() {

        @Override
        public void call(final JSONArray arguments) throws JSONException {
            fireEvent(arguments, Type.SoundEnd);
        }
    });
    addFunction("onaudioend", new JavaScriptFunction() {

        @Override
        public void call(final JSONArray arguments) throws JSONException {
            fireEvent(arguments, Type.AudioEnd);
        }
    });
    addFunction("onresult", new JavaScriptFunction() {

        @Override
        public void call(final JSONArray arguments) throws JSONException {
            fireEvent(arguments, Type.Result);
        }
    });
    addFunction("onnomatch", new JavaScriptFunction() {

        @Override
        public void call(final JSONArray arguments) throws JSONException {
            fireEvent(arguments, Type.NoMatch);
        }
    });
    addFunction("onerror", new JavaScriptFunction() {

        @Override
        public void call(final JSONArray arguments) throws JSONException {
            fireEvent(arguments, Type.Error);
        }
    });
    addFunction("onstart", new JavaScriptFunction() {

        @Override
        public void call(final JSONArray arguments) throws JSONException {
            fireEvent(arguments, Type.Start);
        }
    });
    addFunction("onend", new JavaScriptFunction() {

        @Override
        public void call(final JSONArray arguments) throws JSONException {
            fireEvent(arguments, Type.End);
        }
    });

}

From source file:de.elomagic.vaadin.addon.speechsynthesis.SpeechSynthesis.java

License:Apache License

public SpeechSynthesis() {
    super();/* w ww . j  av a2 s  .  com*/

    addFunction("onVoiceList", new JavaScriptFunction() {

        @Override
        public void call(final JSONArray arg) throws JSONException {
            JSONArray a = arg.getJSONArray(0);
            voiceList.clear();
            Gson gson = new Gson();
            for (int i = 0; i < a.length(); i++) {
                SpeechSynthesisVoice voice = gson.fromJson(a.getJSONObject(i).toString(),
                        SpeechSynthesisVoice.class);
                voiceList.add(voice);
            }
        }
    });

    addFunction("onStart", new JavaScriptFunction() {

        @Override
        public void call(final JSONArray arguments) throws JSONException {
            fireEvent(mapToEvent(arguments, Type.Start));
        }
    });
    addFunction("onEnd", new JavaScriptFunction() {

        @Override
        public void call(final JSONArray arguments) throws JSONException {
            fireEvent(mapToEvent(arguments, Type.End));
        }
    });
    addFunction("onPause", new JavaScriptFunction() {

        @Override
        public void call(final JSONArray arguments) throws JSONException {
            fireEvent(mapToEvent(arguments, Type.Pause));
        }
    });
    addFunction("onMark", new JavaScriptFunction() {

        @Override
        public void call(final JSONArray arguments) throws JSONException {
            fireEvent(mapToEvent(arguments, Type.Mark));
        }
    });
    addFunction("onBoundary", new JavaScriptFunction() {

        @Override
        public void call(final JSONArray arguments) throws JSONException {
            fireEvent(mapToEvent(arguments, Type.Boundary));
        }
    });
    addFunction("onError", new JavaScriptFunction() {

        @Override
        public void call(final JSONArray arguments) throws JSONException {
            fireEvent(mapToEvent(arguments, Type.Error));
        }
    });
    addFunction("onResume", new JavaScriptFunction() {

        @Override
        public void call(final JSONArray arguments) throws JSONException {
            fireEvent(mapToEvent(arguments, Type.Resume));
        }
    });

}

From source file:de.fatalix.vaadin.addon.codemirror.CodeMirror.java

License:Apache License

public CodeMirror() {
    super();//from   w  ww  .j a v  a 2 s. co m
    componentId = componentCount;
    componentCount++;
    addFunction("onBlur", new JavaScriptFunction() {

        @Override
        public void call(JSONArray arguments) throws JSONException {
            codeValue = arguments.getString(0);
        }
    });
}

From source file:de.metas.procurement.webui.util.SwipeHelper.java

License:Open Source License

@SuppressWarnings("serial")
private final void registerJavaScriptFunctionsIfNeeded() {
    if (jsFunctionsRegistered.getAndSet(true)) {
        return; // already registered
    }/*from  w  w w. j  a  v a  2 s  .  co  m*/

    final JavaScript javaScript = JavaScript.getCurrent();
    javaScript.addFunction(JS_FUNC_OnSwipe, new JavaScriptFunction() {
        @Override
        public void call(final JsonArray arguments) {
            invokeOnSwipe(arguments);
        }
    });
}

From source file:de.symeda.sormas.ui.map.LeafletMap.java

License:Open Source License

/**
 * Creates the chart object./*from ww  w  .j a  va  2  s . c  o m*/
 */
@SuppressWarnings("serial")
public LeafletMap() {
    setId(getDomId());
    getState().setZoom(5);
    getState().setCenterLatitude(51.505);
    getState().setCenterLongitude(-0.09);
    getState().setTileLayerVisible(true);
    getState().setTileLayerOpacity(1);

    addFunction("onClick", new JavaScriptFunction() {
        @Override
        public void call(JsonArray arguments) {
            String groupId = arguments.getString(0);
            int markerIndex = (int) arguments.getNumber(1);
            LeafletMap.this.fireEvent(new MarkerClickEvent(LeafletMap.this, groupId, markerIndex));
        }
    });
}

From source file:eu.maxschuster.vaadin.jquery.Callback.java

License:Apache License

private void addFuncs() {
    final Callback self = this;
    addFunction("callToServer", new JavaScriptFunction() {
        private static final long serialVersionUID = -6135324536871720370L;

        @Override/* www. j a v  a  2s.c om*/
        public void call(JSONArray arguments) throws JSONException {
            self.setRunning(false);
            self.call(arguments);
        }
    });
    addFunction("setRunning", new JavaScriptFunction() {
        private static final long serialVersionUID = 5142085261390695076L;

        @Override
        public void call(JSONArray arguments) throws JSONException {
            self.setRunning(arguments.getBoolean(0));
        }
    });
}

From source file:eu.maxschuster.vaadin.jquery.JQueryObject.java

License:Apache License

private void addFuncs() {
    final JQueryObject self = this;
    addFunction("targetRefreshed", new JavaScriptFunction() {
        private static final long serialVersionUID = 8978871967352479460L;

        @Override/*from ww w  .  j  a va  2s .  com*/
        public void call(JSONArray arguments) throws JSONException {
            int length = arguments.getInt(0);
            self.setLength(length);
            self.fireEvent(new TargetRefreshedEvent(self));
        }
    });
    addFunction("callCallback", new JavaScriptFunction() {
        private static final long serialVersionUID = -197344735063198908L;

        @Override
        public void call(JSONArray arguments) throws JSONException {
            int callbackId = arguments.getInt(0);
            Callback callback = self.callbacks.get(callbackId);
            if (callback != null) {
                callback.call(arguments);
            }
        }
    });
}