List of usage examples for com.vaadin.server VaadinSession getCurrent
public static VaadinSession getCurrent()
From source file:annis.visualizers.component.AudioVisualizer.java
License:Apache License
@Override public MediaElementPlayer createComponent(VisualizerInput input, VisualizationToggle visToggle) { List<String> corpusPath = CommonHelper.getCorpusPath(input.getDocument().getGraph(), input.getDocument()); String binaryServletPath = ""; String corpusName = corpusPath.get(corpusPath.size() - 1); String documentName = corpusPath.get(0); corpusName = urlPathEscape.escape(corpusName); documentName = urlPathEscape.escape(documentName); WebResource resMeta = Helper.getAnnisWebResource().path("meta/binary").path(corpusName).path(documentName); List<AnnisBinaryMetaData> meta = resMeta.get(new GenericType<List<AnnisBinaryMetaData>>() { });//ww w .j a v a 2 s . c o m // if there is no document at all don't fail String mimeType = meta.size() > 0 ? null : "audio/ogg"; for (AnnisBinaryMetaData m : meta) { if (m.getMimeType().startsWith("audio/")) { mimeType = m.getMimeType(); break; } } Validate.notNull(mimeType, "There must be at least one binary file for the document with a audio mime type"); String mimeTypeEncoded = mimeType; mimeTypeEncoded = urlParamEscape.escape(mimeType); binaryServletPath = input.getContextPath() + "/Binary?" + "documentName=" + documentName + "&toplevelCorpusName=" + corpusName + "&mime=" + mimeTypeEncoded; MediaElementPlayer player = new MediaElementPlayer(MediaElement.audio, binaryServletPath, mimeType); if (VaadinSession.getCurrent().getAttribute(MediaController.class) != null) { VaadinSession.getCurrent().getAttribute(MediaController.class).addMediaPlayer(player, input.getId(), visToggle); } return player; }
From source file:annis.visualizers.component.grid.GridVisualizer.java
License:Apache License
@Override public GridComponent createComponent(VisualizerInput visInput, VisualizationToggle visToggle) { MediaController mediaController = VaadinSession.getCurrent().getAttribute(MediaController.class); PDFController pdfController = VaadinSession.getCurrent().getAttribute(PDFController.class); GridComponent component = null;/*from w ww . java 2 s. co m*/ try { component = new GridComponent(visInput, mediaController, pdfController, true, null); } catch (Exception ex) { log.error("create {} failed", GridComponent.class.getName(), ex); } return component; }
From source file:annis.visualizers.component.kwic.KWICVisualizer.java
License:Apache License
@Override public KWICInterface createComponent(VisualizerInput visInput, VisualizationToggle visToggle) { MediaController mediaController = VaadinSession.getCurrent().getAttribute(MediaController.class); PDFController pdfController = VaadinSession.getCurrent().getAttribute(PDFController.class); List<STextualDS> texts = visInput.getDocument().getDocumentGraph().getTextualDSs(); // having the KWIC nested in a panel can slow down rendering if (texts.size() == 1) { // directly return the single non-nested KWIC panel return new KWICComponent(visInput, mediaController, pdfController, texts.get(0)); } else {//from w w w. j av a2 s. c om // return a more complicated implementation which can handle several texts return new KWICMultipleTextComponent(visInput, mediaController, pdfController); } }
From source file:annis.visualizers.component.KWICPanel.java
License:Apache License
@Override public KWICInterface createComponent(VisualizerInput visInput, VisualizationToggle visToggle) { MediaController mediaController = VaadinSession.getCurrent().getAttribute(MediaController.class); PDFController pdfController = VaadinSession.getCurrent().getAttribute(PDFController.class); EList<STextualDS> texts = visInput.getDocument().getSDocumentGraph().getSTextualDSs(); // having the KWIC nested in a panel can slow down rendering if (texts.size() == 1) { // directly return the single non-nested KWIC panel return new KWICPanelImpl(visInput, mediaController, pdfController, texts.get(0)); } else {/*ww w . j a v a2 s . c o m*/ // return a more complicated implementation which can handle several texts return new KWICMultipleTextImpl(visInput, mediaController, pdfController); } }
From source file:annis.visualizers.component.pdf.PDFVisualizer.java
License:Apache License
@Override public Panel createComponent(VisualizerInput input, VisualizationToggle visToggle) { PDFViewer pdfViewer = null;/*w ww . java2 s .c o m*/ try { if (VaadinSession.getCurrent().getAttribute(PDFController.class) != null) { VaadinSession session = VaadinSession.getCurrent(); PDFController pdfController = session.getAttribute(PDFController.class); pdfViewer = new PDFViewerImpl(input, visToggle); pdfController.addPDF(input.getId(), pdfViewer); } } catch (Exception ex) { log.error("could not create pdf vis", ex); } return (Panel) pdfViewer; }
From source file:annis.visualizers.component.VideoVisualizer.java
License:Apache License
@Override public MediaElementPlayer createComponent(VisualizerInput input, VisualizationToggle visToggle) { List<String> corpusPath = CommonHelper.getCorpusPath(input.getDocument().getGraph(), input.getDocument()); String binaryServletPath = ""; String corpusName = corpusPath.get(corpusPath.size() - 1); String documentName = corpusPath.get(0); corpusName = urlPathEscape.escape(corpusName); documentName = urlPathEscape.escape(documentName); WebResource resMeta = Helper.getAnnisWebResource().path("meta/binary").path(corpusName).path(documentName); List<AnnisBinaryMetaData> meta = resMeta.get(new GenericType<List<AnnisBinaryMetaData>>() { });// w ww . j a v a2 s. com // if there is no document at all don't fail String mimeType = meta.size() > 0 ? null : "video/webm"; for (AnnisBinaryMetaData m : meta) { if (m.getMimeType().startsWith("video/")) { mimeType = m.getMimeType(); break; } } Validate.notNull(mimeType, "There must be at least one binary file for the document with a video mime type"); String mimeTypeEncoded = mimeType; mimeTypeEncoded = urlParamEscape.escape(mimeType); binaryServletPath = input.getContextPath() + "/Binary?" + "documentName=" + documentName + "&toplevelCorpusName=" + corpusName + "&mime=" + mimeTypeEncoded; MediaElementPlayer player = new MediaElementPlayer(MediaElement.video, binaryServletPath, mimeType); if (VaadinSession.getCurrent().getAttribute(MediaController.class) != null) { VaadinSession.getCurrent().getAttribute(MediaController.class).addMediaPlayer(player, input.getId(), visToggle); } return player; }
From source file:ch.bfh.ti.soed.hs16.srs.black.SupervisingController.java
License:Open Source License
@Override protected void init(VaadinRequest vaadinRequest) { // Set the title of the site in the browser Page.getCurrent().setTitle("SRS - Smart ReservationEntity System"); dataModel = JPADataAccess.getInstance(); loginView = new LoginView(); reservationView = new ReservationView(); signUpView = new SignUpView(); navigator = new Navigator(this, this); // Adding the login view to the navigator navigator.addView(LoginView.NAME, loginView); // Setting the error view of the navigator to the login view // This way the navigator will always default to the login view navigator.setErrorView(loginView);/*from w ww. j a v a 2 s .c o m*/ // Adding the reservation view to the navigator navigator.addView(ReservationView.NAME, reservationView); // Adding the sign up view to the navigator navigator.addView(SignUpView.NAME, signUpView); // Instantiating the controllers for the two views reservationController = new ReservationController(dataModel, reservationView, navigator); new LoginController(dataModel, loginView, navigator); new SignUpController(dataModel, signUpView, navigator); // We use a view change handler to ensure the user is always redirected // to the login view if the user is not logged in navigator.addViewChangeListener(new ViewChangeListener() { @Override public boolean beforeViewChange(ViewChangeEvent event) { // Check if a user has logged in boolean isLoggedIn = VaadinSession.getCurrent().getAttribute("user") != null; boolean isLoginView = event.getNewView() instanceof LoginView; boolean isSignUpView = event.getNewView() instanceof SignUpView; boolean isReservationView = event.getNewView() instanceof ReservationView; if (!isLoggedIn && isReservationView) { // Always redirect to login view if a user has not yet logged in navigator.navigateTo(LoginView.NAME); return false; } else if (isLoggedIn && (isLoginView || isSignUpView)) { // Access attempt to the login or signup view while already logged in gets cancelled return false; } return true; } @Override public void afterViewChange(ViewChangeEvent event) { try { reservationController.createList((String) VaadinSession.getCurrent().getAttribute("user")); } catch (Exception e) { System.out.println(e.getMessage()); } } }); }
From source file:ch.bfh.ti.soed.hs16.srs.black.view.loginView.LoginController.java
License:Open Source License
public void login(Button.ClickEvent event) { String userName = loginView.getUsernameField().getValue(); String password = loginView.getPasswordField().getValue(); try {/* ww w .j a va 2 s. com*/ Customer customer = dataModel.getCustomer(userName); if (customer.getPassword().equals(password)) { // Store the current user in the service session VaadinSession.getCurrent().setAttribute("user", userName); // Navigate to the reservation view navigator.navigateTo(ReservationView.NAME); // Clear the fields of the login view loginView.getUsernameField().clear(); loginView.getPasswordField().clear(); } else { throw new AuthenticationException(); } } catch (Exception e) { Notification accessDeniedNf = new Notification("Access Denied!", "Please enter a valid username/password combination."); accessDeniedNf.show(Page.getCurrent()); accessDeniedNf.setDelayMsec(2000); loginView.getPasswordField().clear(); loginView.getPasswordField().focus(); } }
From source file:ch.bfh.ti.soed.hs16.srs.black.view.reservationView.ReservationController.java
License:Open Source License
public ReservationController(DataModel dataModel, ReservationView reservationView, Navigator navigator) { this.dataModel = dataModel; this.reservationView = reservationView; this.navigator = navigator; reservationView.getLogoutButton().addClickListener(clickEvent -> { // Logout the user / end the session VaadinSession.getCurrent().setAttribute("user", null); // Refresh this view, the navigator should redirect to login view$ navigator.navigateTo(LoginView.NAME); });/* w w w . j a v a 2 s.com*/ reservationView.getRoomSelect() .addValueChangeListener(e -> roomNumber = Integer.parseInt(e.getProperty().getValue().toString())); for (int i = 1; i < dataModel.getRooms().size() + 1; i++) { reservationView.getRoomSelect().addItem(i); reservationView.getRoomSelect().setItemCaption(i, "Room " + i); } reservationView.getMakeReservationButton().addClickListener(clickEvent -> { Date begin = reservationView.getFromField().getValue(); Date end = reservationView.getToField().getValue(); SimpleDateFormat df = new SimpleDateFormat("dd.MM.yyyy HH:mm"); Notification notification = new Notification(""); notification.setDelayMsec(2000); String username = String.valueOf(VaadinSession.getCurrent().getAttribute("user")); try { Customer customer = dataModel.getCustomer(username); Room room = dataModel.getRoom(roomNumber); dataModel.addReservation(customer, room, begin, end); notification.setCaption("Success"); notification.setDescription("Added reservation for: " + username + ", Room Nr.: " + roomNumber + ", From: " + df.format(begin) + " until " + df.format(end)); notification.show(Page.getCurrent()); try { createList(username); } catch (Exception e) { e.printStackTrace(); } } catch (IllegalArgumentException iae) { notification.setCaption("Error!"); notification.setDescription("Please check the entries you made for your reservation."); notification.show(Page.getCurrent()); } catch (RuntimeException re) { notification.setCaption("Error!"); notification.setDescription("Room couldn't be found.\nCurrently available rooms: " + dataModel.getRooms().stream().map(Object::toString).collect(Collectors.joining(", ")) .replaceAll("[^\\d , ][^\\@]*\\@", "")); notification.show(Page.getCurrent()); } catch (Exception e) { notification.setCaption("Error!"); notification.setDescription("There already exists a reservation for the chosen time range."); notification.show(Page.getCurrent()); } }); reservationView.getLogoutButton().addClickListener(clickEvent -> { reservationView.getFromField().clear(); reservationView.getToField().clear(); reservationView.getRoomSelect().clear(); }); }
From source file:ch.bfh.ti.soed.hs16.srs.purple.controller.LoginController.java
License:Open Source License
/** * Function logs an user in with the given username and password * * @param username// w ww .j av a 2 s . c om * - The username of the user * @param password * - The password of the user * * @return true if user logged in, false if user was not found with the * username and password */ public boolean loginWithUser(String username, String password) { if (username != null && password != null && !username.isEmpty() && !password.isEmpty()) { if (checkIfUserExists(username) && checkPasswordForUsername(password)) { if (VaadinSession.getCurrent() != null) { VaadinSession.getCurrent().setAttribute(USER_SESSION_ATTRIBUTE, username); } return true; } } return false; }