List of usage examples for com.vaadin.server Page getCurrent
public static Page getCurrent()
From source file:ch.bfh.blue.UI.AvailableSpacesView.java
License:Open Source License
/** * configure handlers and settings for the buttons here */// w w w . j a v a 2s .c o m private void configureButtons() { selectBtn.addClickListener(e -> { if (roomsCB.getValue() != null) { System.out.println(roomsCB.getValue().getClass()); getSession().setAttribute("space", roomsCB.getValue()); navigator.navigateTo("reservationBySelectedRoom"); } else { notif.setCaption(SELECT_ERROR_NO_ROOM_SELECTED); notif.show(Page.getCurrent()); } }); availableBtn.addClickListener(e -> { getSession().setAttribute("startDate", startDateField.getValue()); getSession().setAttribute("endDate", endDateField.getValue()); navigator.navigateTo("reservationBySelectedTime"); }); logoutBtn.addClickListener(e -> { navigator.navigateTo("home"); }); }
From source file:ch.bfh.blue.UI.AvailableSpacesView.java
License:Open Source License
/** * checks if a user is logged in returns true if someone is logged in * returns false if no one is logged in/* w ww. java 2s. c om*/ */ private boolean isLoggedIn() { currentPerson = (Person) getSession().getAttribute("user"); System.out.println(currentPerson); if (currentPerson == null) { notif.setCaption(LOGIN_ERROR_NOT_LOGGED_IN); notif.show(Page.getCurrent()); navigator.navigateTo("home"); return false; } return true; }
From source file:ch.bfh.blue.UI.LoginView.java
License:Open Source License
/** * configure handlers and settings for the buttons here *//*from w w w.j a v a 2 s . c om*/ private void configureButtons() { loginBtn.addClickListener(e -> { String username, password; username = user.getValue(); password = passwd.getValue(); Person pers = controller.authentication(username, password); if (pers != null) { getSession().setAttribute("user", pers); navigator.navigateTo("availableSpaces"); } else { notif.setCaption(LOGIN_ERR_INVALID_DATA); notif.show(Page.getCurrent()); } }); homeBtn.addClickListener(e -> { navigator.navigateTo("home"); }); }
From source file:ch.bfh.blue.UI.RegisterView.java
License:Open Source License
/** * configure handlers and settings for the buttons here *///w ww .j a va 2 s .co m private void configureButtons() { buttonBar.addComponents(homeBtn, registerBtn); //buttonBar.setMargin(true); buttonBar.setSpacing(true); registerBtn.addClickListener(e -> { if (passwd.getValue().equals(retypepw.getValue())) { controller.createPerson(email.getValue(), user.getValue(), passwd.getValue()); navigator.navigateTo("home"); Notification notif = new Notification(REGISTRATION_SUCCESS, Notification.Type.WARNING_MESSAGE); notif.setDelayMsec(3500); notif.show(Page.getCurrent()); } else { notif.setCaption(REGISTRATION_FAIL_PW_MISSMATCH); notif.show(Page.getCurrent()); } }); homeBtn.addClickListener(e -> { navigator.navigateTo("home"); }); }
From source file:ch.bfh.blue.UI.ReservationBySelectedRoomView.java
License:Open Source License
/** * configure handlers and settings for the buttons here */// w ww. ja va2s . co m private void configureButtons() { logoutBtn.addClickListener(e -> { navigator.navigateTo("home"); }); backBtn.addClickListener(e -> { navigator.navigateTo("availableSpaces"); }); navBtnHL.addComponents(backBtn, logoutBtn); navBtnHL.setSpacing(true); btnDay.addClickListener(new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { cal.setStartDate(new Date()); cal.setEndDate(new Date()); } }); btnWeek.addClickListener(new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { cal.setStartDate(new Date()); cal.setEndDate(addTimeToDate(new Date(), java.util.Calendar.DAY_OF_WEEK, 7)); } }); btnMonth.addClickListener(new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { cal.setStartDate(new Date()); cal.setEndDate(addTimeToDate(new Date(), java.util.Calendar.MONTH, 1)); } }); reservationBtn.addClickListener(new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { String t = resTitle.getValue(); startDate = startDateField.getValue(); endDate = endDateField.getValue(); Space spc = (Space) getSession().getAttribute("space"); Person p = (Person) getSession().getAttribute("user"); boolean nullLock = t != null && p != null && startDate != null && endDate != null && spc != null; if (nullLock) { if (isNotOverlaping()) { controller.createReservation(t, p, startDate, endDate, spc); cal.addEvent(new BasicEvent(t, "sgd", startDate, endDate)); notif.setCaption(RESERVATION_SUCCESS + " " + resTitle.getValue()); notif.show(Page.getCurrent()); } else { notif.setCaption(RESERVATION_OVERLAPING_ERROR); notif.show(Page.getCurrent()); } } else { notif.setCaption(RESERVATION_NULL_VALUE_ERROR); notif.show(Page.getCurrent()); } } }); makeReservationBtnDisabled(); calZoomHL.addComponents(btnDay, btnWeek, btnMonth); calZoomHL.setSpacing(true); }
From source file:ch.bfh.blue.UI.ReservationBySelectedTimeView.java
License:Open Source License
/** * configure handlers and settings for the buttons here *///from ww w . ja v a 2 s.c o m private void configureButtons() { reservationBtn.addClickListener(e -> { Person p = (Person) getSession().getAttribute("user"); Space spc = (Space) grid.getSelectedRow(); String t = restitle.getValue(); if (t != null && p != null && startDate != null && endDate != null && spc != null) { controller.createReservation(t, p, startDate, endDate, spc); notif.setCaption(RESERVATION_SUCCESS + " " + restitle.getValue()); notif.show(Page.getCurrent()); refreshGrid(); } else { notif.setCaption(RESERVATION_NULL_VALUE_ERROR); notif.show(Page.getCurrent()); } }); logoutBtn.addClickListener(e -> { navigator.navigateTo("home"); }); backBtn.addClickListener(e -> { navigator.navigateTo("availableSpaces"); }); navBtnHL.addComponents(backBtn, logoutBtn); navBtnHL.setSpacing(true); }
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 2s .co 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 {//from w w w.ja va 2 s. c o m 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); });// www . j a v a 2 s . co m 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.black.view.signUpView.SignUpController.java
License:Open Source License
public void addUser(Button.ClickEvent event) { String username = signUpView.getUsernameField().getValue(); String password = signUpView.getPasswordField().getValue(); String passwordRepeat = signUpView.getPasswordFieldRepeat().getValue(); Notification alertNf = new Notification(""); alertNf.setDelayMsec(2000);//from w w w .ja v a 2 s . c om if (username.isEmpty() || password.isEmpty() || passwordRepeat.isEmpty()) { alertNf.setCaption("Please fill out the complete form!"); alertNf.show(Page.getCurrent()); } else if (!password.equals(passwordRepeat)) { alertNf.setCaption("The given passwords aren't identical!"); alertNf.show(Page.getCurrent()); signUpView.getPasswordFieldRepeat().clear(); signUpView.getPasswordFieldRepeat().focus(); } else { try { dataModel.addCustomer(username, password); navigator.navigateTo(ReservationView.NAME); alertNf.setCaption("Account: " + username + " has been successfully created."); alertNf.setDescription("You can now login with your credentials."); alertNf.show(Page.getCurrent()); } catch (IllegalStateException e) { alertNf.setCaption("User already exists!"); alertNf.setDescription("Please enter a different username."); alertNf.show(Page.getCurrent()); signUpView.getUsernameField().focus(); } finally { signUpView.getUsernameField().clear(); signUpView.getPasswordField().clear(); signUpView.getPasswordFieldRepeat().clear(); } } }