List of usage examples for com.vaadin.ui JavaScript getCurrent
public static JavaScript getCurrent()
From source file:com.selzlein.lojavirtual.vaadin.core.LspsUI.java
License:Open Source License
/** * Sets theme for UI and then refreshes page to propagate the change correctly. * <p></p>/*from w ww. j a va2s . c o m*/ * If the page is not reloaded and the theme metrics changes, all Vaadin components will have trouble recomputing its sizes * (e.g. table). * @param theme */ public void setThemeAndReload(String theme) { log.info("Setting theme to " + theme); this.getUser().setSetting("theme", theme); VaadinService.getCurrentRequest().getWrappedSession().setAttribute("theme", theme); storeThemeInStorage(theme); JavaScript.getCurrent().execute("" + "window.location.reload();" + ""); }
From source file:com.selzlein.lojavirtual.vaadin.core.LspsUI.java
License:Open Source License
private void storeThemeInStorage(String theme) { // store theme in browser local storage, so if default theme is changed, next time // user will see his chosen theme even before login.. and refresh JavaScript.getCurrent() .execute("" + "var storage = window.localStorage;" + "if(typeof(Storage)!=='undefined')" + "storage.setItem('loja-virtuallication-theme-name', '" + theme + "');" + ""); }
From source file:com.selzlein.lojavirtual.vaadin.page.SettingsView.java
License:Open Source License
private void createView() { ui = (LspsUI) getUI();//from w w w.j a v a 2s.co m user = ui.getUser().getPerson(); userRights = user.getRights(); setTitle(ui.getMessage(TITLE)); Panel panel = new Panel(); panel.addStyleName("l-border-none"); setContent(panel); VerticalLayout layout = new VerticalLayout(); layout.addStyleName("l-settings"); layout.setSizeFull(); layout.setSpacing(true); layout.setMargin(true); panel.setContent(layout); //user data and settings will be laid out next to each other HorizontalLayout topSection = new HorizontalLayout(); topSection.setSpacing(true); topSection.setWidth("100%"); layout.addComponent(topSection); VerticalLayout userData = createUserDataSection(ui, user); topSection.addComponent(userData); topSection.setExpandRatio(userData, 1); Label spacer = new Label(); spacer.setWidth("20px"); topSection.addComponent(spacer); VerticalLayout settings = createSettingsSection(ui); topSection.addComponent(settings); topSection.setExpandRatio(settings, 1); //substitution section VerticalLayout substitution = createSubstitutionSection(); layout.addComponent(substitution); layout.setExpandRatio(substitution, 2); //buttons HorizontalLayout buttons = new HorizontalLayout(); buttons.setSpacing(true); Button saveButton = new Button(ui.getMessage("action.save"), new ClickListener() { @Override public void buttonClick(ClickEvent event) { if (save()) { if (requestReload) { JavaScript.getCurrent().execute("window.location.reload()"); } else { close(); } } } }); saveButton.setData(BUTTON_TYPE_SAVE); buttons.addComponent(saveButton); Button cancelButton = new Button(ui.getMessage("action.cancel"), new ClickListener() { @Override public void buttonClick(ClickEvent event) { close(); } }); buttons.addComponent(cancelButton); layout.addComponent(buttons); }
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/"); }/*www . j av a 2s. 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:de.metas.procurement.webui.util.SwipeHelper.java
License:Open Source License
public synchronized void enable(final Component component, final SwipeHandler handler) { Preconditions.checkNotNull(component, "component is null"); final String componentId = component.getId(); Preconditions.checkNotNull(componentId, "componentId is null"); final ComponentSwipe swipe = new ComponentSwipe(componentId, handler); component2swipe.put(component, swipe); componentId2swipe.put(componentId, swipe); registerJavaScriptFunctionsIfNeeded(); final JavaScript javaScript = JavaScript.getCurrent(); javaScript.execute("" + "if (!window.swipesMap) { window.swipesMap={}; }" ///* w w w.ja va2 s . co m*/ + "window.swipesMap['" + componentId + "'] = Swiped.init({" + "query: '#" + componentId + "'" + ", left: 300" + ", right: 300" + ", tolerance: 200" + ", onOpen: function() { " + JS_FUNC_OnSwipe + "('" + componentId + "'); }" + "});" // + "\n console.log('Enabled swiping for element: " + componentId + "');"); }
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 }// w w w . j a v a 2 s. c om 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.sebastianrothbucher.vaadin.meetup.userauth.FakeUserAuthentication.java
License:Apache License
@Override public void requireUser(Presenter returnPresenter, int delay, Map<String, Object> context) { // (no presenter to be called EVER as we re-init the application // afterwards => pointless to remember it) JavaScript.getCurrent() .execute("setTimeout(\"location.href='?fakeid=55&fakeuser=Sebastian%20R.&fakemember=true';\", " + delay + ");"); }
From source file:de.sebastianrothbucher.vaadin.meetup.userauth.MeetupUserAuthentication.java
License:Apache License
@Override public void requireUser(Presenter returnPresenter, int delay, Map<String, Object> context) { // System.out.println(OAUTH_KEY_PROP); // kill the current user - so we can have a new one session.setAttribute(LAST_USER_SESSION_ATTR, null); // (no presenter to be called EVER as we re-init the application // afterwards => pointless to remember it) JavaScript.getCurrent() .execute("setTimeout(\"location.href='https://secure.meetup.com/oauth2/authorize?client_id=" + OAUTH_KEY_PROP + "&response_type=code&redirect_uri=" + APPLICATION_ADDRESS + "';\", " + delay + ");"); }
From source file:de.unioninvestment.eai.portal.portlet.crud.CrudUI.java
License:Apache License
private void tryToSetPortletTitle(String title) { String realTitle = title != null ? title : Context.getMessage("portlet.crud.window.name"); String escapedTitle = StringEscapeUtils.escapeJavaScript(realTitle); PortletResponse portletResponse = VaadinPortletService.getCurrentResponse().getPortletResponse(); if (portletResponse instanceof RenderResponse) { ((RenderResponse) portletResponse).setTitle(realTitle); } else {/*w ww .j a v a2 s .c o m*/ // document.querySelectorAll("#portlet_crudportlet_WAR_eaiadministration_INSTANCE_qeH6QK9czlb6 .portlet-title-text")[0].childNodes[0].nodeValue // = 'Releaseplaner - Applikationen' String ie8plusUpdate = "document.querySelectorAll('#portlet_" + getPortletId() + " .portlet-title-text')[0]" + ".childNodes[0].nodeValue = '" + escapedTitle + "'"; String defaultUpdate = "document.getElementById('portlet_" + getPortletId() + "').getElementsByClassName('portlet-title-text')[0]" + ".childNodes[0].nodeValue = '" + escapedTitle + "'"; String all = "if (document.querySelectorAll) { " + ie8plusUpdate + " } else { " + defaultUpdate + " };"; JavaScript.getCurrent().execute(all); } }
From source file:edu.nps.moves.mmowgli.Mmowgli2UI.java
License:Open Source License
public void navigateTo(AppEvent ev) { navigator.navigateTo(ev.getFragmentString()); JavaScript.getCurrent().execute(JS_SHIP_STATS); // if debug enabled will update load numbers }