Example usage for com.vaadin.server Page getCurrent

List of usage examples for com.vaadin.server Page getCurrent

Introduction

In this page you can find the example usage for com.vaadin.server Page getCurrent.

Prototype

public static Page getCurrent() 

Source Link

Document

Gets the Page to which the current uI belongs.

Usage

From source file:com.snowy.PostLoginView.java

@PostConstruct
void init() {//from  w ww . j av  a2s.  c o  m
    //Logger.getLogger(PostLoginView.class.getName()).info(d);
    d = ((MyVaadinUI) UI.getCurrent()).getDataObject();
    //Logger.getLogger(PostLoginView.class.getName()).info(d);
    g = new GameWindow(d);
    c = new ChatWindow(d);
    HorizontalLayout hl = new HorizontalLayout();
    setMargin(true);
    /*this.getUI().addPollListener(new UIEvents.PollListener(){
    @Override
    public void poll(UIEvents.PollEvent event) {
        c.getUsersList().retrieveActiveUsers();
    }
            
    });*/

    this.setSizeFull();
    Button b = new Button("Logout");
    b.addClickListener(e -> {

        d.logout(VaadinSession.getCurrent().getCsrfToken());
        VaadinSession.getCurrent().close();

        Page.getCurrent().setLocation("/");
    });
    Button ccc = new Button("Unpause polling");
    ccc.setEnabled(false);
    Button cc = new Button("Pause polling");
    cc.addClickListener(e -> {
        if (ccc.isEnabled() == false) {
            UI.getCurrent().setPollInterval(1000000000);
            cc.setEnabled(false);
            ccc.setEnabled(true);
        }
    });
    ccc.addClickListener(e -> {
        if (cc.isEnabled() == false) {
            UI.getCurrent().setPollInterval(1000);
            cc.setEnabled(true);
            ccc.setEnabled(false);
        }
    });
    hl.setSizeFull();
    hl.setSpacing(true);
    //whdjwandjawd
    //this.addComponent(cc);
    //this.addComponent(ccc);
    this.addComponent(b);

    //this.setHeightUndefined();
    this.setSpacing(true);
    this.setComponentAlignment(b, Alignment.TOP_RIGHT);
    //this.addComponent(c);
    //this.addComponent(ul);
    hl.addComponent(g);

    hl.addComponent(c);

    //this.addComponent(c);
    hl.setExpandRatio(c, 1);
    hl.setExpandRatio(g, 3);
    g.setSizeFull();
    c.setSizeFull();
    this.addComponent(hl);
    //this.setExpandRatio(g, 2);
    this.setExpandRatio(hl, 1);
}

From source file:com.sonoport.util.UISessionState.java

License:Apache License

public boolean staleSessionCheck(VaadinSession inSession, VaadinRequest request) {
    if (!vaadinSession.equals(inSession)) {
        LOG.log(Level.INFO, "Stale session detected, invalidating HTTPSession and reloading!");
        HttpSession httpSession = ((WrappedHttpSession) request.getWrappedSession()).getHttpSession();
        httpSession.invalidate();//from   w  w w  .  java2 s  .  c om
        Page.getCurrent().setLocation("/");
        replaceSession = true;
        return true;
    }
    return false;
}

From source file:com.squadd.UI.UploadGroupImageWindow.java

protected void configureDownload() {
    // Show uploaded file in this placeholder
    image = new Image("");
    image.setVisible(false);//from w ww  .j  a v a 2  s  .com
    image.setHeight("256px");

    // Implement both receiver that saves upload in a file and
    // listener for successful upload
    class ImageReceiver implements Upload.Receiver, Upload.SucceededListener {
        private static final long serialVersionUID = -1276759102490466761L;

        public java.io.File file;

        public OutputStream receiveUpload(String filename, String mimeType) {
            // Create upload stream
            FileOutputStream fos = null; // Stream to write to
            try {
                // Open the file for writing.
                grp.setLastUploadDate(System.currentTimeMillis());
                String path = new ImageGetter().getPath(grp);
                file = new java.io.File(path);
                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(Upload.SucceededEvent event) {
            // Show the uploaded file in the image viewer
            userImageFile = new File();
            userImageFile.setPath(file.getPath());

            image.setVisible(true);
            image.setSource(new FileResource(file));

        }
    }
    ;
    ImageReceiver receiver = new ImageReceiver();

    // Create the upload with a caption and set receiver later
    upload = new Upload("", receiver);
    //upload.setButtonCaption("Ok");
    upload.addSucceededListener(receiver);
}

From source file:com.terralcode.frontend.vista.widgets.alumno.AlumnoVista.java

@Override
protected Component buildContent() {

    createContainers();/*w ww .  j  a  v a  2s .c o m*/
    Component layout = buildLayout();

    WebBrowser webBrowser = Page.getCurrent().getWebBrowser();
    window = new Window(this);
    window.addStyleName("profile-window");
    window.setModal(true);
    if (webBrowser.getScreenWidth() < 1024) {
        window.setSizeFull();
    } else {
        window.setHeight(90.0f, Unit.PERCENTAGE);
        window.setWidth(90.0f, Unit.PERCENTAGE);
    }
    addMenuItems(saveOperation, trashOperation);

    return layout;
}

From source file:com.terralcode.frontend.vista.widgets.empresa.EmpresaVista.java

@Override
protected Component buildContent() {
    Component layout = buildLayout();

    WebBrowser webBrowser = Page.getCurrent().getWebBrowser();
    window = new Window(this);
    window.addStyleName("profile-window");
    window.setModal(true);/*www. j ava2  s . c om*/
    if (webBrowser.getScreenWidth() < 1024) {
        window.setSizeFull();
    } else {
        window.setHeight(90.0f, Unit.PERCENTAGE);
        window.setWidth(90.0f, Unit.PERCENTAGE);
    }

    return layout;
}

From source file:com.terralcode.gestion.frontend.view.widgets.appointment.AppointmentComplaintsPanel.java

private void openComplaintWindow(Complaint complaint) {

    WebBrowser webBrowser = Page.getCurrent().getWebBrowser();

    Window window = new Window("Registro de Queja");
    window.setModal(true);//from   w  ww .j  ava 2  s  .com
    if (webBrowser.getScreenWidth() < 1024) {
        window.setSizeFull();
    } else {
        window.setHeight(90.0f, Unit.PERCENTAGE);
        window.setWidth(90.0f, Unit.PERCENTAGE);
    }

    //        TextField nameField = new TextField();
    //        nameField.setInputPrompt("Introduzca el ttulo de la queja");
    //        nameField.setWidth("100%");
    TextArea notesArea = new TextArea();
    notesArea.setInputPrompt("Introduzca el contenido de la queja");
    notesArea.setSizeFull();
    //        CheckBox doneField = new CheckBox("Atendido");

    HorizontalLayout horizontal = new HorizontalLayout();
    horizontal.setSpacing(true);
    horizontal.addComponent(createDeleteButton(window));
    horizontal.addComponent(createOkButton(window));

    VerticalLayout layout = new VerticalLayout();
    layout.setSizeFull();
    layout.setMargin(true);
    layout.addComponent(complaintType);
    layout.addComponent(notesArea);
    //        layout.addComponent(doneField);
    layout.addComponent(horizontal);
    layout.setComponentAlignment(horizontal, Alignment.MIDDLE_RIGHT);
    layout.setExpandRatio(complaintType, 1);
    layout.setExpandRatio(notesArea, 8);
    //        layout.setExpandRatio(doneField, 1);
    layout.setExpandRatio(horizontal, 1);

    BeanItem beanItem = new BeanItem<>(complaint);
    fieldGroup = new BeanFieldGroup<>(Complaint.class);
    fieldGroup.setItemDataSource(beanItem);
    fieldGroup.bind(complaintType, "complaintType");
    fieldGroup.bind(notesArea, "notes");
    //        fieldGroup.bind(doneField, "done");

    window.setContent(layout);
    getUI().addWindow(window);

    //        Window windowComplaint = new Window(complaintView);
    //        WidgetActions actions = new WidgetActions(){
    //
    //            @Override
    //            public void saveAction() {
    //                refreshBind();
    //                windowComplaint.close();
    //            }
    //
    //            @Override
    //            public void deleteAction() {
    //                appointment.getComplaints().remove(complaint);
    //                refreshBind();
    //                windowComplaint.close();
    //            }
    //            
    //        };
    //        complaintView.bind(complaint);
    //        complaintView.setActions(actions);
    //        getUI().addWindow(windowComplaint);
}

From source file:com.terralcode.gestion.frontend.view.widgets.appointment.AppointmentView.java

public Window open() {
    WebBrowser webBrowser = Page.getCurrent().getWebBrowser();

    Window window = new Window(this);
    window.addStyleName("profile-window");
    window.setModal(true);//from   w ww  .ja va  2s  . co  m
    if (webBrowser.getScreenWidth() < 1024) {
        window.setSizeFull();
    } else {
        window.setHeight(90.0f, Unit.PERCENTAGE);
        window.setWidth(90.0f, Unit.PERCENTAGE);
    }
    UI.getCurrent().addWindow(window);
    window.focus();
    return window;
}

From source file:com.terralcode.gestion.frontend.view.widgets.appointment.AppointmentView.java

private MenuBar.Command save() {
    return (MenuBar.MenuItem selectedItem) -> {

        if (fieldGroup.isValid()) {

            try {
                fieldGroup.commit();/*from  w w w  . ja  v a2  s .  co  m*/

                if (appointment.getTimeLapse() != null) {
                    appointment.setProgramDateEnd(timeLapseCalculator
                            .calculateLapse(appointment.getProgramDateStart(), appointment.getTimeLapse()));
                } else {
                    //Si no se ha especificado intervalo de tiempo, se pone la hora de inicio
                    appointment.setProgramDateEnd(appointment.getProgramDateStart());
                }
                appointment = appointmentService.edit(appointment);

                Notification success = new PrettyNotification("Cita guardada correctamente.");
                success.show(Page.getCurrent());

                eventBus.post(new DashboardEvent.NotificationsCountUpdatedEvent());
                eventBus.post(new AppointmentUpdatedEvent());
            } catch (Validator.InvalidValueException | FieldGroup.CommitException e) {
                Notification.show(e.getMessage(), Notification.Type.ERROR_MESSAGE);
            }
        } else {
            Notification.show("Complete los datos obligatorios.", Notification.Type.ERROR_MESSAGE);
        }

    };
}

From source file:com.terralcode.gestion.frontend.view.widgets.appointment.AppointmentView.java

private void duplicateAppointment(Appointment app) {

    InlineDateField date = new InlineDateField();
    //date.setTextFieldEnabled(false);
    date.setLocale(new Locale("es", "ES"));
    date.setResolution(Resolution.MINUTE);
    date.setValue(app.getProgramDateStart().getTime());
    VerticalLayout layout = new VerticalLayout();
    layout.addComponent(date);//from w w  w  .  j a va2s . co m
    layout.setComponentAlignment(date, Alignment.MIDDLE_CENTER);

    DialogWindow dlgWin = new DialogWindow("Seleccione una fecha", layout, DialogWindow.DialogButton.OK,
            DialogWindow.DialogButton.CANCEL) {

        @Override
        protected void onButtonCancelClicked() {
            this.close();
        }

        @Override
        protected void onButtonOKClicked() {
            java.util.Calendar cal;
            cal = new java.util.Calendar.Builder().build();
            cal.setTime(date.getValue());
            try {
                Appointment newAppointment = appointmentService.duplicate(app, cal);

                Notification success = new PrettyNotification("Cita duplicada correctamente");
                success.show(Page.getCurrent());

                eventBus.post(new DashboardEvent.NotificationsCountUpdatedEvent());
                eventBus.post(new AppointmentUpdatedEvent());
                this.close();

                bind(newAppointment);
            } catch (InstantiationException | IllegalAccessException ex) {
                Logger.getLogger(AppointmentView.class.getName()).log(Level.SEVERE, null, ex);
                Notification.show(ex.getMessage(), Notification.Type.ERROR_MESSAGE);
            }
        }

    };

    dlgWin.setModal(true);
    dlgWin.setCaption("Seleccione nueva fecha");
    UI.getCurrent().addWindow(dlgWin);
    dlgWin.focus();
}

From source file:com.terralcode.gestion.frontend.view.widgets.customer.CustomerView.java

@Override
protected Component buildContent() {
    addMenuItems(saveOperation);/* w w  w . j  a  va2s  . com*/
    addMenuItems(trashOperation);

    Component layout = buildLayout();

    WebBrowser webBrowser = Page.getCurrent().getWebBrowser();
    window = new Window(this);
    window.addStyleName("profile-window");
    window.setModal(true);
    if (webBrowser.getScreenWidth() < 1024) {
        window.setSizeFull();
    } else {
        window.setHeight(90.0f, Unit.PERCENTAGE);
        window.setWidth(90.0f, Unit.PERCENTAGE);
    }

    return layout;
}