List of usage examples for com.vaadin.server Page getCurrent
public static Page getCurrent()
From source file:com.porotype.iconfont.FontAwesome.java
/** * Loads the FontAwesome CSS, and thus actual font, from the given location. * <p>//from ww w . ja v a 2 s .com * <code> * FontAwesome.load(new ThemeResource("font-awesome/css/font-awesome.min.css")); * </code> * </p> * * @param fontAwesomeCss */ public static void load(Resource fontAwesomeCss) { Page.getCurrent().getStyles().add(fontAwesomeCss); }
From source file:com.salsaw.msalsa.HomePageView.java
License:Apache License
/** * The constructor should first build the main layout, set the * composition root and then do any custom initialization. * * The constructor will not be automatically regenerated by the * visual editor.//from ww w . j a v a2 s . com * @param navigator */ public HomePageView(SalsaParameters salsaParameters) { if (salsaParameters == null) { throw new IllegalArgumentException("salsaParameters"); } buildMainLayout(); // Create form with salsa parameters BeanItem<SalsaParameters> salsaParametersBeanItem = new BeanItem<SalsaParameters>(salsaParameters); SalsaParametersForm salsaParametersForm = new SalsaParametersForm(salsaParametersBeanItem); Button toogleSalsaParametersButton = new Button("Show/Hide M-SALSA Parameters"); toogleSalsaParametersButton.addClickListener(new Button.ClickListener() { /** * */ private static final long serialVersionUID = 1L; public void buttonClick(ClickEvent event) { salsaParametersForm.setVisible(!salsaParametersForm.isVisible()); } }); toogleSalsaParametersButton.setWidth("-1px"); toogleSalsaParametersButton.setHeight("-1px"); mainLayout.addComponent(toogleSalsaParametersButton); mainLayout.setComponentAlignment(toogleSalsaParametersButton, new Alignment(48)); salsaParametersForm.setWidth("-1px"); salsaParametersForm.setHeight("-1px"); mainLayout.addComponent(salsaParametersForm); mainLayout.setComponentAlignment(salsaParametersForm, new Alignment(48)); setCompositionRoot(mainLayout); // TODO add user code here // Implement both receiver that saves upload in a file and // listener for successful upload class AligmentUploader implements Receiver, SucceededListener { /** * */ private static final long serialVersionUID = 1L; public File file; public OutputStream receiveUpload(String filename, String mimeType) { // Create upload stream FileOutputStream fos = null; // Stream to write to try { // Load server configuration String tmpFolder = ConfigurationManager.getInstance().getServerConfiguration() .getTemporaryFilePath(); // Open the file for writing. file = Paths.get(tmpFolder, filename).toFile(); fos = new FileOutputStream(file); } catch (final java.io.FileNotFoundException e) { new Notification("Could not open file<br/>", e.getMessage(), Notification.Type.ERROR_MESSAGE) .show(Page.getCurrent()); return null; } return fos; // Return the output stream to write to } public void uploadSucceeded(SucceededEvent event) { try { for (IHomePageListener listener : listeners) { listener.buttonClick(file); } } catch (SALSAException | IOException | InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); new Notification("ERROR: ", e.getMessage(), Notification.Type.ERROR_MESSAGE) .show(Page.getCurrent()); } } } ; AligmentUploader receiver = new AligmentUploader(); uploadInput.setReceiver(receiver); uploadInput.addSucceededListener(receiver); }
From source file:com.save.reports.maintenance.MaintenanceReportUI.java
void processExportDataToExcel() { ExportDataGridToExcel export = new ExportDataGridToExcel(mrDataGrid); export.workSheet();/*from ww w. ja v a2s .co m*/ StreamResource.StreamSource source = () -> { try { File f = new File(export.getFilePath()); FileInputStream fis = new FileInputStream(f); return fis; } catch (Exception e) { ErrorLoggedNotification.showErrorLoggedOnWindow(e.toString(), this.getClass().getName()); return null; } }; Date date = new Date(); StreamResource resource = new StreamResource(source, "MaintenanceReport" + "-" + date.getTime() + ".xls"); resource.setMIMEType("application/vnd.ms-office"); Page.getCurrent().open(resource, null, false); }
From source file:com.save.reports.promodeals.PromoDealReportUI.java
void processExportDataToExcel() { ExportDataGridToExcel export = new ExportDataGridToExcel(promoDealGrid); export.workSheet();/* w ww. ja v a 2s . co m*/ StreamResource.StreamSource source = () -> { try { File f = new File(export.getFilePath()); FileInputStream fis = new FileInputStream(f); return fis; } catch (Exception e) { ErrorLoggedNotification.showErrorLoggedOnWindow(e.toString(), this.getClass().getName()); return null; } }; Date date = new Date(); StreamResource resource = new StreamResource(source, "PromoDealsReport" + "-" + date.getTime() + ".xls"); resource.setMIMEType("application/vnd.ms-office"); Page.getCurrent().open(resource, null, false); }
From source file:com.save.reports.reimbursement.ReimbursementReportUI.java
void processExportDataToExcel() { ExportDataGridToExcel export = new ExportDataGridToExcel(mrDataGrid); export.workSheet();// w ww . j av a2 s .c o m StreamResource.StreamSource source = () -> { try { File f = new File(export.getFilePath()); FileInputStream fis = new FileInputStream(f); return fis; } catch (Exception e) { ErrorLoggedNotification.showErrorLoggedOnWindow(e.toString(), this.getClass().getName()); return null; } }; Date date = new Date(); StreamResource resource = new StreamResource(source, "ReimbursementReport" + "-" + date.getTime() + ".xls"); resource.setMIMEType("application/vnd.ms-office"); Page.getCurrent().open(resource, null, false); }
From source file:com.savoirfairelinux.presentations.QuoteView.java
License:Open Source License
/** * Listeners allow us to attach actions to different events. For example, a value change listener is triggered * when a UI component such a drop down menu has a change in its value. Or, a click listener is triggered when * an action is performed on a button./*from w w w.ja v a 2 s . c o m*/ */ private void addClickListeners() { // We basically indicate that aside from the initial setup, we can't have a null or empty value, avoids things // like null pointer exceptions. vehicleType.setNullSelectionAllowed(false); /* Slightly quick and dirty, and in terms of space and time complexity, it isn't ideal: We have detected that we switched to an item Remove all existing data in the dropdown boxes Add appropriate data to the boxes Make sure that the boxes are modifiable */ vehicleType.addValueChangeListener(valueChangeEvent -> { if (valueChangeEvent.getProperty().getValue().equals("Motorcycle")) { year.setEnabled(true); } else if (valueChangeEvent.getProperty().getValue().equals("Automobile")) { year.setEnabled(true); } }); // We only allow a user to click next if we validated the current form. Otherwise, we should throw an error. next.addClickListener(e -> { if (personalGroup.isValid()) { setEnabled(true); setSelectedTab(1); } else { new Notification("Required Fields", "Please check that all fields are filled correctly", Notification.Type.ERROR_MESSAGE).show(Page.getCurrent()); } }); }
From source file:com.scipionyx.butterflyeffect.frontend.configuration.ui.view.AboutView.java
License:Apache License
/** * /*from w w w . jav a 2 s . c om*/ * @param justclean * @throws UnknownHostException */ @SuppressWarnings("deprecation") private void loadFrontEndInformation(boolean loadData) throws UnknownHostException { // Remove all before adding tableFrontEndInformation.setItems(new ArrayList<>()); if (!loadData) return; List<GridProperty<?>> items = new ArrayList<>(); // Server Ip Address items.add(new GridProperty<String>("Server Ip 4 Host Address", Inet4Address.getLocalHost().getHostAddress(), "")); items.add(new GridProperty<String>("Server Ip 6 Host Address", Inet6Address.getLocalHost().getHostAddress(), "")); // Server Id // Server Memory items.add(new GridProperty<Long>("Free Memory", Runtime.getRuntime().freeMemory(), "")); items.add(new GridProperty<Long>("Max Memory", Runtime.getRuntime().maxMemory(), "")); items.add(new GridProperty<Long>("Total Memory", Runtime.getRuntime().totalMemory(), "")); // Server items.add(new GridProperty<String>("Availabe Processors", Runtime.getRuntime().availableProcessors() + "", "")); // Session items.add(new GridProperty<String>("Session Id", VaadinSession.getCurrent().getSession().getId(), "")); items.add(new GridProperty<String>("Session CreationTime", (new Date(VaadinSession.getCurrent().getSession().getCreationTime()).toGMTString()), "")); items.add(new GridProperty<String>("Session Last Access Time", (new Date(VaadinSession.getCurrent().getSession().getLastAccessedTime()).toGMTString()), "")); items.add(new GridProperty<String>("User", SecurityContextHolder.getContext().getAuthentication().getName(), "")); Collection<? extends GrantedAuthority> authorities = SecurityContextHolder.getContext().getAuthentication() .getAuthorities(); String roles = null; for (GrantedAuthority grantedAuthority : authorities) { if (roles == null) roles = grantedAuthority.getAuthority(); else roles = roles + "," + grantedAuthority.getAuthority(); } items.add(new GridProperty<String>("Roles", roles, "")); items.add(new GridProperty<String>("Client Ip", Page.getCurrent().getWebBrowser().getAddress(), "")); tableFrontEndInformation.setItems(items); }
From source file:com.snowy.data.java
public String genToken(String username, String password) { if (login(username, password)) { String unameToke = username; for (int i = username.length(); i < 40; i++) { unameToke += "0"; }/*from w ww . ja v a 2 s . com*/ unameToke += "00000"; //uname 45 //ip = 15 111.111.111.111 String tok = ""; String address = Page.getCurrent().getWebBrowser().getAddress(); String addLat = ""; if (address.indexOf('.') != -1) { for (String i : address.split("\\.")) { if (i.length() < 3) { for (int x = i.length(); x < 3; x++) { i = "0" + i; } addLat += i; } else { addLat += i; } addLat += "."; } addLat = addLat.substring(0, addLat.length() - 1); } else { addLat = address; } int zz = 0; int bb = 0; for (int b = 0; b < 60; b++) { if (b % 4 == 0) { tok += addLat.charAt(bb); bb++; } else { tok += unameToke.charAt(zz); zz++; } } tok += System.currentTimeMillis() / 1000L; String hash = org.apache.commons.codec.digest.DigestUtils.sha256Hex(tok); hash += org.apache.commons.codec.digest.DigestUtils.sha256Hex(hash) + hash; VaadinSession.getCurrent().setAttribute("token", hash); try { //return hash; PreparedStatement ps = con .prepareStatement("update users set token = ?, active =1 where Username =?"); ps.setString(1, VaadinSession.getCurrent().getCsrfToken()); //ps.setString(1, "balls"); //ps.setString(2, "true"); ps.setString(2, username); ps.executeUpdate(); //ps.close(); //rs.close(); } catch (SQLException ex) { Logger.getLogger(data.class.getName()).log(Level.SEVERE, null, ex); } return hash; } else { return "false"; } }
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 a v a 2 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.snowy.PostLoginView.java
@Override public void enter(ViewChangeListener.ViewChangeEvent event) { //this.getSession().getConfiguration(). d = ((MyVaadinUI) event.getNavigator().getUI()).getDataObject(); if (d.getUsernameFromToken() == "") { Page.getCurrent().setLocation(""); }/* w ww .java2 s. co m*/ }