Example usage for com.vaadin.ui Window setContent

List of usage examples for com.vaadin.ui Window setContent

Introduction

In this page you can find the example usage for com.vaadin.ui Window setContent.

Prototype

@Override
public void setContent(Component content) 

Source Link

Document

Sets the content of this container.

Usage

From source file:edu.nps.moves.mmowgli.modules.gamemaster.AddAuthorEventHandler.java

License:Open Source License

@SuppressWarnings("serial")
public static void inviteAuthorsToActionPlan() {
    final Window win = new Window("Choose Action Plan");
    win.setWidth("600px");
    win.setHeight("500px");

    VerticalLayout layout = new VerticalLayout();
    win.setContent(layout);
    layout.setMargin(true);//  w  w w  .  j a v  a  2s.c  o m
    layout.setSpacing(true);
    layout.setSizeFull();

    final ActionPlanTable apt = new ActionPlanTable() {
        @Override
        public ItemClickListener getItemClickListener() {
            return new ItemClickListener() {
                public void itemClick(ItemClickEvent event) {
                }
            }; // null listener
        }
    };
    apt.setMultiSelect(false);
    apt.setPageLength(10);
    apt.setSizeFull();
    layout.addComponent(apt);
    layout.setExpandRatio(apt, 1.0f);

    HorizontalLayout buttHL = new HorizontalLayout();
    layout.addComponent(buttHL);
    buttHL.setWidth("100%");
    buttHL.setSpacing(true);
    Label sp;
    buttHL.addComponent(sp = new Label());
    sp.setWidth("1px");
    buttHL.setExpandRatio(sp, 1.0f);

    Button selectButton = new Button("Select");
    buttHL.addComponent(selectButton);
    Button cancelButton = new Button("Cancel");
    buttHL.addComponent(cancelButton);

    UI.getCurrent().addWindow(win);
    win.center();

    selectButton.addClickListener(new ClickListener() {
        @Override
        @MmowgliCodeEntry
        @HibernateOpened
        @HibernateClosed
        public void buttonClick(ClickEvent event) {
            win.close();
            Object o = apt.getValue();
            if (o != null) {
                HSess.init();
                inviteAuthorsToActionPlanTL(o);
                HSess.close();
            }
        }
    });
    cancelButton.addClickListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            win.close();
        }
    });
}

From source file:edu.nps.moves.mmowgli.modules.gamemaster.UserAdminPanel.java

License:Open Source License

@SuppressWarnings("serial")
Table createTable(TableFiller filler) {//  w w w.ja va 2 s .  com
    final Table tab = new Table();
    tab.setStyleName("m-useradmintable");
    tab.setWidth("920px");
    tab.setHeight("100%");
    tab.setPageLength(40);

    // Special column renderers
    Table.ColumnGenerator colGen = new columnCustomizer();
    tab.addGeneratedColumn(USER_ID_COL, colGen);
    tab.addGeneratedColumn(ADMIN_COL, colGen);
    tab.addGeneratedColumn(DESIGNER_COL, colGen);
    tab.addGeneratedColumn(LOCKEDOUT_COL, colGen);
    tab.addGeneratedColumn(TWEETER_COL, colGen);
    tab.addGeneratedColumn(GAMEMASTER_COL, colGen);
    tab.addGeneratedColumn(EMAIL_COL, colGen);
    tab.addGeneratedColumn(CONFIRMED_COL, colGen);

    filler.fillTable(tab);

    tab.setColumnWidth(USER_ID_COL, 25);
    tab.setColumnWidth(ADMIN_COL, 25);
    tab.setColumnWidth(GAMEMASTER_COL, 25);
    tab.setColumnWidth(DESIGNER_COL, 25);
    tab.setColumnWidth(LOCKEDOUT_COL, 43);
    tab.setColumnWidth(TWEETER_COL, 50);
    tab.setColumnWidth(UNAME_COL, 120);
    tab.setColumnWidth(FIRSTNAME_COL, 108); //128);
    tab.setColumnWidth(LASTNAME_COL, 108); //128);
    tab.setColumnWidth(EMAIL_COL, 190);
    tab.setColumnWidth(CONFIRMED_COL, 67);

    tab.setEditable(false);
    tab.setSelectable(true);
    tab.setImmediate(true); // to immed update view
    tab.setNullSelectionAllowed(false); // can't deselect a row

    tab.addItemClickListener(new ItemClickListener() {
        EditPanel ep;

        @Override
        @MmowgliCodeEntry
        @HibernateOpened
        @HibernateClosed
        @HibernateUserRead
        public void itemClick(ItemClickEvent event) {
            if (event.isDoubleClick()) {
                HSess.init();
                Window w = new Window("Edit Player Account");
                w.setWidth("620px");
                w.setHeight("505px");
                w.setModal(true);

                @SuppressWarnings({ "unchecked" })
                final QuickUser qu = (QuickUser) ((BeanItem<QuickUser>) event.getItem()).getBean();
                User u = User.getTL(qu.getId());
                if (u == null) {
                    // This has been happening infrequently...some error on signup where (maybe) a user object gets created
                    // but doesn't make it into the db.
                    Notification.show("Woops, database error!",
                            "A player account identified by id = " + qu.getId() + " is not in the database.",
                            Notification.Type.ERROR_MESSAGE);
                    HSess.close();
                    return;
                }
                VerticalLayout vl = new VerticalLayout();
                w.setContent(vl);
                vl.addComponent(ep = new EditPanel(w, qu.getId()));
                ep.setWidth("100%");
                UI.getCurrent().addWindow(w);
                w.center();

                w.addCloseListener(new CloseListener() {
                    @Override
                    public void windowClose(CloseEvent e) {
                        if (ep.user != null) {
                            BeanItem<QuickUser> bi = lastTableFiller.getContainer().getItem(ep.user.getId());
                            QuickUser qu = bi.getBean();
                            qu.update(ep.user);
                            tab.refreshRowCache();
                        }
                    }
                });
                HSess.close();
            }
        }
    });
    return tab;
}

From source file:edu.nps.moves.mmowgli.modules.registrationlogin.PasswordResetPopup.java

License:Open Source License

private void makeResetAnnounceDialogTL_5(String email, ArrayList<User> aLis) {
    UI myUI = getUI();/* ww w. j  a v  a2 s.c o  m*/
    myUI.removeWindow(PasswordResetPopup.this);

    final Window resetAnnounceDialog = new Window("Password Reset Announcement");
    resetAnnounceDialog.setModal(true);
    resetAnnounceDialog.setClosable(false);
    VerticalLayout vLay = new VerticalLayout();
    resetAnnounceDialog.setContent(vLay);
    vLay.setMargin(true);
    vLay.setSpacing(true);
    vLay.setSizeUndefined();
    vLay.setWidth("400px");

    Label message = new HtmlLabel("An email has been sent to <b>" + email + "</b>.");
    vLay.addComponent(message);

    message = new Label(
            "Follow the link in the message to confirm your password reset request to enable login to your mmowgli player account.");
    vLay.addComponent(message);

    message = new Label(
            "Please be advised that you will only have three hours to complete this process, after which time "
                    + "you will have to re-initiate a new password reset process from the game login page.");
    vLay.addComponent(message);

    message = new HtmlLabel(
            "Now, press <b>Homepage -- Return to login</b> after receiving a reset request confirmation email.");
    vLay.addComponent(message);

    @SuppressWarnings("serial")
    Button laterButt = new Button("Homepage -- Return to login", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            HSess.init();
            Mmowgli2UI.getAppUI().quitAndGoTo(GameLinks.getTL().getGameHomeUrl());
            HSess.close();
        }
    });
    vLay.addComponent(laterButt);

    @SuppressWarnings("serial")
    Button troubleButt = new Button("Send trouble report", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            HSess.init();
            Mmowgli2UI.getAppUI().quitAndGoTo(GameLinks.getTL().getTroubleLink());
            HSess.close();
        }
    });
    vLay.addComponent(troubleButt);

    myUI.addWindow(resetAnnounceDialog);
    resetAnnounceDialog.center();

    // This process generates unique uId for th3 reset process that will
    // need to be confirmed once the user receives a confirmation email and
    // click on the link containing the uId
    Iterator<User> itr = aLis.iterator();
    // sends email to all user accounts (which are at the same email address)
    // if a game name was entered, only that account receives the email
    while (itr.hasNext()) {
        User usr = itr.next();
        PasswordReset pr = new PasswordReset(usr);
        PasswordReset.saveTL(pr);

        String confirmUrl = buildConfirmUrl(pr);
        AppMaster.instance().getMailManager().sendPasswordResetEmailTL(email, usr.getUserName(), confirmUrl);
    }
}

From source file:edu.nps.moves.mmowgli.modules.registrationlogin.RegistrationPageBase.java

License:Open Source License

@SuppressWarnings("serial")
private void wereInTL(User _usr) {
    Game g = Game.getTL();//from w ww .  jav a 2s . c  o  m
    if (!g.isEmailConfirmation()/* && !g.isSMSConfirmation()*/) {
        _usr.setEmailConfirmed(true); // confirmation didn't happen, but they want to login
        wereInReallyTL(_usr); // will do update
    }
    /*  else if(g.isSMSConfirmation()) {  // if both are selected, only sms is done
                
      } */
    else {
        List<String> sLis = VHibPii.getUserPiiEmails(_usr.getId());
        String email = sLis.get(0);
        final Window emailDialog = new Window("Email Confirmation");
        emailDialog.setModal(true);
        emailDialog.setClosable(false);
        VerticalLayout vLay = new VerticalLayout();
        emailDialog.setContent(vLay);
        vLay.setMargin(true);
        vLay.setSpacing(true);
        vLay.setSizeUndefined();
        vLay.setWidth("400px");

        Label message = new HtmlLabel("A confirmation email has been sent to <b>" + email + "</b>.");
        vLay.addComponent(message);

        message = new Label("Follow the link in the message "
                + "to confirm your registration and unlock your mmowgli user account.");
        vLay.addComponent(message);

        message = new HtmlLabel("Press the <b>Am I confirmed yet?</b> button " + "to play if ready.");
        vLay.addComponent(message);

        message = new HtmlLabel(
                "Alternatively, press <b>Quit -- I'll come back later</b> to login at a future time.");
        vLay.addComponent(message);

        GridLayout grid = new GridLayout();
        vLay.addComponent(grid);

        MSysOut.println(NEWUSER_CREATION_LOGS,
                "email confirmation dialog displayed, user " + _usr.getUserName());

        final Button contButt = new Button("Am I confirmed yet?", new ClickListener() {
            boolean confirmed = false;

            @Override
            @HibernateUpdate
            @HibernateUserUpdate
            public void buttonClick(ClickEvent event) {
                MSysOut.println(DEBUG_LOGS, "\"Am I confirmed?\" button handler entered");

                HSess.init();
                User u = User.getTL(userId);
                MSysOut.println(NEWUSER_CREATION_LOGS, "\"Am I confirmed?\" clicked, user " + u.getUserName());

                if (confirmed) {
                    closePopup(emailDialog);
                    wereInReallyTL(u); //  @HibernateUserUpdate //@HibernateUserRead
                    MSysOut.println(NEWUSER_CREATION_LOGS,
                            "\"Am I confirmed?\", positive confirmation, user " + u.getUserName());
                } else {
                    MSysOut.println(DEBUG_LOGS, "User.getTL() in RegistrationPageBase.wereInTL()");
                    //User locUsr = User.getTL(userId);  why necessary?
                    //if(locUsr.isEmailConfirmed()) {
                    if (u.isEmailConfirmed()) {
                        confirmed = true;
                        event.getButton().setCaption("I'm ready to play mmowgli!");
                    } else {
                        MSysOut.println(NEWUSER_CREATION_LOGS,
                                "\"Am I confirmed?\", negative confirmation, user " + u.getUserName());
                        Notification.show("Your email is not yet confirmed");
                    }
                }
                HSess.close();
            }
        });
        grid.addComponent(contButt);
        contButt.setImmediate(true);

        Button laterButt = new Button("Quit -- I'll come back later", new ClickListener() {
            @Override
            public void buttonClick(ClickEvent event) {
                MSysOut.println(DEBUG_LOGS, "\"Quit -- I'll come back later\" button handler entered");

                HSess.init();
                Mmowgli2UI.getAppUI().quitAndGoTo(GameLinks.getTL().getThanksForInterestLink());
                HSess.close();
            }
        });
        grid.addComponent(laterButt);

        Button troubleButt = new Button("Send trouble report", new ClickListener() {
            @Override
            @MmowgliCodeEntry
            @HibernateOpened
            @HibernateClosed
            public void buttonClick(ClickEvent event) // no need for HSess
            {
                MSysOut.println(DEBUG_LOGS, "\"Send trouble report\" button handler entered");

                HSess.init();
                Mmowgli2UI.getAppUI().quitAndGoTo(GameLinks.getTL().getTroubleLink());
                HSess.close();
            }
        });
        grid.addComponent(troubleButt);

        openPopupWindowInMainWindow(emailDialog, 500);

        EmailConfirmation ec = new EmailConfirmation(_usr);
        EmailConfirmation.saveTL(ec);

        String confirmUrl = buildConfirmUrl(ec);
        AppMaster.instance().getMailManager().sendEmailConfirmationTL(email, _usr.getUserName(), confirmUrl);
    } // else weren't confirmed
}

From source file:edu.nps.moves.mmowgli.modules.registrationlogin.RegistrationPageBase.java

License:Open Source License

@SuppressWarnings("serial")
@HibernateUserRead// w  w w  .ja  v a2 s. c o  m
public void checkUserLimitsTL() {
    Serializable uid = Mmowgli2UI.getGlobals().getUserID();
    if (uid != NO_LOGGEDIN_USER_ID) { // can't do this check if we don't have a user yet
        MSysOut.println(DEBUG_LOGS, "User.getTL() in RegistrationPageBase.checkUserLimitsTL()");
        User u = User.getTL(uid);
        if (u != null) // why should it be?
            if (u.getUserName() != null) // why should it be?
                if (u.isGameMaster())//getUserName().toLowerCase().startsWith("gm_"))
                    return;
    }

    int maxIn = Game.getTL().getMaxUsersOnline();
    // List<User> lis = (List<User>)HibernateContainers.getSession().createCriteria(User.class).add(Restrictions.eq("online", true)).list();
    // if(lis.size()>=maxIn) {
    if (Mmowgli2UI.getGlobals().getSessionCount() >= maxIn) { // new improved
        lockedOut = true;
        VerticalLayout vl = new VerticalLayout();
        vl.setWidth("325px");
        vl.addStyleName("m-errorNotificationEquivalent");
        vl.setSpacing(false);
        vl.setMargin(true);
        Label lab = new Label("We're loaded to the max with players right now.");
        lab.setSizeUndefined();
        vl.addComponent(lab);
        lab = new Label("Idle players are timed-out after 15 minutes.");
        lab.setSizeUndefined();
        vl.addComponent(lab);
        lab = new Label("Please try again later.");
        lab.setSizeUndefined();
        vl.addComponent(lab);

        Window win = new Window("Sorry, but....");
        win.setSizeUndefined();
        win.addStyleName("m-transparent");
        win.setWidth("308px");
        win.setResizable(false);
        win.setContent(vl);

        openPopupWindowInMainWindow(win, 400);
        win.setModal(false);

        win.addCloseListener(new CloseListener() {
            @Override
            @MmowgliCodeEntry
            @HibernateOpened
            @HibernateClosed
            public void windowClose(CloseEvent e) {
                HSess.init();
                Mmowgli2UI.getAppUI().quitAndGoTo(GameLinks.getTL().getGameFullLink());
                HSess.close();
            }
        });
    }
}

From source file:eu.maxschuster.vaadin.autocompletetextfield.demo.DemoUI.java

License:Apache License

private void openTestWindow() {
    Window testWindow = new Window();
    DemoOverlayTest test = new DemoOverlayTest();
    test.setSuggestionProvider(languageProvider);
    testWindow.setContent(test);
    testWindow.setCaption("Window Demo");
    testWindow.center();//from  w  w  w . j  a va  2s  .  c  o m
    getUI().addWindow(testWindow);
}

From source file:facs.components.BookAdmin.java

License:Open Source License

private Component deletedBookingsGrid() {
    VerticalLayout devicesLayout = new VerticalLayout();
    devicesLayout.setCaption("Trash");
    // HorizontalLayout buttonLayout = new HorizontalLayout();

    // there will now be space around the test component
    // components added to the test component will now not stick together but have space between
    // them/*ww  w . j  av  a2s  . c  om*/
    devicesLayout.setMargin(true);
    devicesLayout.setSpacing(true);
    // buttonLayout.setMargin(true);
    // buttonLayout.setSpacing(true);

    // buttonLayout.addComponent(add);

    BeanItemContainer<BookingBean> booking = getDeletedBookings();

    GeneratedPropertyContainer gpc = new GeneratedPropertyContainer(booking);

    gpc.addGeneratedProperty("restore", new PropertyValueGenerator<String>() {
        /**
         * 
         */
        private static final long serialVersionUID = 4082425701384202280L;

        @Override
        public String getValue(Item item, Object itemId, Object propertyId) {
            // return FontAwesome.TRASH_O.getHtml(); // The caption
            return "Restore"; // The caption

        }

        @Override
        public Class<String> getType() {
            return String.class;
        }
    });

    gpc.addGeneratedProperty("delete", new PropertyValueGenerator<String>() {
        /**
         * 
         */
        private static final long serialVersionUID = 1307493624895857513L;

        @Override
        public String getValue(Item item, Object itemId, Object propertyId) {
            // return FontAwesome.TRASH_O.getHtml(); // The caption
            return "Purge"; // The caption

        }

        @Override
        public Class<String> getType() {
            return String.class;
        }
    });

    devicesGridTrash = new Grid(gpc);
    // Create a grid

    devicesGridTrash.setWidth("100%");
    devicesGridTrash.setSelectionMode(SelectionMode.SINGLE);
    devicesGridTrash.getColumn("delete").setRenderer(new HtmlRenderer());
    devicesGridTrash.getColumn("restore").setRenderer(new HtmlRenderer());
    setRenderers(devicesGridTrash);
    devicesGridTrash.setColumnOrder("ID", "deviceName", "service", "start", "end", "username", "phone",
            "price");

    // Render a button that deletes the data row (item)

    /*
     * devicesGrid.addColumn("delete", FontIcon.class).setWidth(35) .setRenderer(new
     * FontIconRenderer(new RendererClickListener() {
     * 
     * @Override public void click(RendererClickEvent e) { Notification.show("Deleted item " +
     * e.getItemId()); } }));
     */

    devicesGridTrash.getColumn("delete")
            .setRenderer(new ButtonRenderer(new ClickableRenderer.RendererClickListener() {
                /**
                 * 
                 */
                private static final long serialVersionUID = 302628105070456680L;

                @Override
                public void click(RendererClickEvent event) {

                    try {

                        Window cd = new Window("Purge Booking");

                        cd.setHeight("200px");
                        cd.setWidth("400px");
                        cd.setResizable(false);

                        GridLayout dialogLayout = new GridLayout(3, 3);

                        Button okButton = new Button("Yes");
                        okButton.addStyleName(ValoTheme.BUTTON_DANGER);
                        Button cancelButton = new Button("No, I'm actually not sure!");
                        cancelButton.addStyleName(ValoTheme.BUTTON_PRIMARY);
                        Label information = new Label("Are you sure you want to purge this item?");
                        information.addStyleName(ValoTheme.LABEL_NO_MARGIN);

                        okButton.addClickListener(new Button.ClickListener() {

                            /**
                             * 
                             */
                            private static final long serialVersionUID = 3739260172118651857L;

                            @Override
                            public void buttonClick(ClickEvent okEvent) {
                                purgeBooking((BookingBean) event.getItemId());
                                cd.close();
                                Notification("The booking was purged!",
                                        "At the end, you are the admin, you have the power.", "");
                            }
                        });

                        cancelButton.addClickListener(new Button.ClickListener() {

                            /**
                             * 
                             */
                            private static final long serialVersionUID = -3931200823633220160L;

                            @Override
                            public void buttonClick(ClickEvent okEvent) {
                                cd.close();
                            }
                        });

                        dialogLayout.addComponent(information, 0, 0, 2, 0);
                        dialogLayout.addComponent(okButton, 0, 1);
                        dialogLayout.addComponent(cancelButton, 1, 1);
                        dialogLayout.setMargin(true);
                        dialogLayout.setSpacing(true);
                        cd.setContent(dialogLayout);
                        cd.center();
                        UI.getCurrent().addWindow(cd);

                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                    FieldGroup fieldGroup = devicesGridTrash.getEditorFieldGroup();
                    fieldGroup.addCommitHandler(new FieldGroup.CommitHandler() {
                        /**
                         * 
                         */
                        private static final long serialVersionUID = 3799806709907688919L;

                        @Override
                        public void preCommit(FieldGroup.CommitEvent commitEvent)
                                throws FieldGroup.CommitException {

                        }

                        @Override
                        public void postCommit(FieldGroup.CommitEvent commitEvent)
                                throws FieldGroup.CommitException {

                            Notification("Successfully Updated",
                                    "Selected values are updated in the database. If it was a mistake, please remind that there is no 'undo' functionality yet.",
                                    "success");

                            refreshGrid();
                        }

                        private void refreshGrid() {
                            getDeletedBookings();
                        }

                    });

                }
            }));

    devicesGridTrash.getColumn("restore")
            .setRenderer(new ButtonRenderer(new ClickableRenderer.RendererClickListener() {
                /**
                 * 
                 */
                private static final long serialVersionUID = -9104571186503913834L;

                @Override
                public void click(RendererClickEvent event) {
                    restoreBooking((BookingBean) event.getItemId());
                }
            }));

    // devicesGrid.setEditorEnabled(true);

    // devicesLayout.addComponent(buttonLayout);
    devicesLayout.addComponent(devicesGridTrash);

    // TODO filtering
    // HeaderRow filterRow = devicesGrid.prependHeaderRow();

    return devicesLayout;
}

From source file:facs.components.Booking.java

License:Open Source License

private Component myUpcomingBookings() {
    VerticalLayout devicesLayout = new VerticalLayout();
    // devicesLayout.setCaption("My Bookings");
    // there will now be space around the test component
    // components added to the test component will now not stick together but have space between
    // them/*from  w  w w  .  j a v a2 s.co m*/
    devicesLayout.setMargin(true);
    devicesLayout.setSpacing(true);

    Date serverTime = new WebBrowser().getCurrentDate();
    Date nextDayTime = new Date(serverTime.getTime() + (1000 * 60 * 60 * 24));

    BeanItemContainer<BookingBean> users = getMyUpcomingBookings(bookingModel.getLDAP(), nextDayTime);
    // System.out.println(bookingModel.getLDAP());

    GeneratedPropertyContainer gpc = new GeneratedPropertyContainer(users);
    gpc.addGeneratedProperty("delete", new PropertyValueGenerator<String>() {
        /**
         * 
         */
        private static final long serialVersionUID = 1263377339178640406L;

        @Override
        public String getValue(Item item, Object itemId, Object propertyId) {
            // return FontAwesome.TRASH_O.getHtml(); // The caption
            return "Trash"; // The caption

        }

        @Override
        public Class<String> getType() {
            return String.class;
        }
    });

    /*
     * 
     * try {
     * 
     * FreeformQuery query = new FreeformQuery(
     * "SELECT * FROM booking INNER JOIN user ON booking.user_ldap = user.user_ldap WHERE deleted IS NULL AND booking.user_ldap ='"
     * + bookingModel.getLDAP() + "';", DBManager.getDatabaseInstanceAlternative(), "booking_id");
     * SQLContainer container = new SQLContainer(query);
     * 
     * // System.out.println("Print Container: " + container.size());
     * container.setAutoCommit(isEnabled());
     * 
     * myBookings = new Grid(container);
     * 
     * } catch (Exception e) { e.printStackTrace(); }
     * 
     * myBookings.setColumnOrder("booking_id", "confirmation", "device_name", "service", "start",
     * "end", "kostenstelle", "price", "project");
     * 
     * myBookings.removeColumn("user_ldap"); myBookings.removeColumn("timestamp");
     * myBookings.removeColumn("deleted"); myBookings.removeColumn("user_name");
     * myBookings.removeColumn("group_id"); myBookings.removeColumn("workgroup_id");
     * myBookings.removeColumn("email"); myBookings.removeColumn("phone");
     * myBookings.removeColumn("admin_panel"); myBookings.removeColumn("user_id");
     * 
     * myBookings.getColumn("booking_id").setHeaderCaption("Booking ID");
     */

    upcomingBookings = new Grid(gpc);
    // Create a grid
    upcomingBookings.setStyleName("my-style");
    upcomingBookings.setWidth("100%");
    upcomingBookings.setSelectionMode(SelectionMode.SINGLE);
    upcomingBookings.setEditorEnabled(false);

    upcomingBookings.setColumnOrder("ID", "confirmation", "deviceName", "service", "start", "end", "username",
            "phone", "price");
    upcomingBookings.getColumn("price").setHeaderCaption("Approx. Price");

    // System.out.println(myBookings.getColumns());
    setRenderers(upcomingBookings);
    devicesLayout.addComponent(upcomingBookings);

    upcomingBookings.getColumn("delete")
            .setRenderer(new ButtonRenderer(new ClickableRenderer.RendererClickListener() {
                /**
                 * 
                 */
                private static final long serialVersionUID = 302628105070456680L;

                @Override
                public void click(RendererClickEvent event) {

                    try {

                        Window cd = new Window("Delete Booking");

                        cd.setHeight("200px");
                        cd.setWidth("400px");
                        cd.setResizable(false);

                        GridLayout dialogLayout = new GridLayout(3, 3);

                        Button okButton = new Button("Yes");
                        okButton.addStyleName(ValoTheme.BUTTON_DANGER);
                        Button cancelButton = new Button("No, I'm actually not sure!");
                        cancelButton.addStyleName(ValoTheme.BUTTON_PRIMARY);
                        Label information = new Label("Are you sure you want to trash this item?");
                        information.addStyleName(ValoTheme.LABEL_NO_MARGIN);

                        okButton.addClickListener(new Button.ClickListener() {
                            /**
                             * 
                             */
                            private static final long serialVersionUID = 1778157399909757369L;

                            @Override
                            public void buttonClick(ClickEvent okEvent) {

                                purgeBooking((BookingBean) event.getItemId());

                                booking.setSelectedTab(myUpcomingBookings());

                                cd.close();

                                showNotification("The booking was deleted!",
                                        "You wanted to delete an upcoming booking and it wasn't within the next 24 hours. All good, item purged.");
                            }
                        });

                        cancelButton.addClickListener(new Button.ClickListener() {
                            /**
                             * 
                             */
                            private static final long serialVersionUID = -8957620319158438769L;

                            @Override
                            public void buttonClick(ClickEvent okEvent) {
                                cd.close();
                            }
                        });

                        dialogLayout.addComponent(information, 0, 0, 2, 0);
                        dialogLayout.addComponent(okButton, 0, 1);
                        dialogLayout.addComponent(cancelButton, 1, 1);
                        dialogLayout.setMargin(true);
                        dialogLayout.setSpacing(true);
                        cd.setContent(dialogLayout);
                        cd.center();
                        UI.getCurrent().addWindow(cd);

                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                }

            }));

    // TODO filtering
    // HeaderRow filterRow = devicesGrid.prependHeaderRow();

    return devicesLayout;
}

From source file:facs.components.Settings.java

License:Open Source License

private void addNewDevice() {
    final Window subWindow = new Window("Add Device");
    FormLayout form = new FormLayout();
    form.setMargin(true);// www  . jav  a 2 s .c o m
    final TextField name = new TextField();
    name.setImmediate(true);
    name.addValidator(new StringLengthValidator("The name must be 1-85 letters long (Was {0}).", 1, 85, true));
    name.setCaption("Name of new device");
    form.addComponent(name);
    final TextArea description = new TextArea();
    description.setImmediate(true);
    description.addValidator(
            new StringLengthValidator("The name must be 1-255 letters long (Was {0}).", 1, 255, true));
    description.setCaption("Description");
    form.addComponent(description);
    final OptionGroup restricted = new OptionGroup("Is Device restricted by operators?");
    restricted.addItem("yes");
    restricted.setMultiSelect(true);
    form.addComponent(restricted);
    HorizontalLayout buttons = new HorizontalLayout();
    Button save = new Button("save");
    buttons.addComponent(save);
    Button discard = new Button("discard");
    discard.setDescription("discarding will abort the process of adding a new device into the databse.");
    buttons.addComponent(discard);
    buttons.setSpacing(true);
    form.addComponent(buttons);
    subWindow.setContent(form);

    form.setMargin(true);
    form.setSpacing(true);
    buttons.setMargin(true);
    buttons.setSpacing(true);

    // Center it in the browser window
    subWindow.center();
    subWindow.setModal(true);
    subWindow.setWidth("50%");
    // Open it in the UI
    UI.getCurrent().addWindow(subWindow);

    discard.addClickListener(new ClickListener() {
        /**
         * 
         */
        private static final long serialVersionUID = -5808910314649620731L;

        @Override
        public void buttonClick(ClickEvent event) {
            subWindow.close();
        }
    });
    save.addClickListener(new ClickListener() {
        /**
         * 
         */
        private static final long serialVersionUID = 3748395242651585005L;

        @Override
        public void buttonClick(ClickEvent event) {
            if (name.isValid() && description.isValid()) {
                Set<String> restr = (Set<String>) restricted.getValue();
                int deviceId = DBManager.getDatabaseInstance().addDevice(name.getValue(),
                        description.getValue(), (restr.size() == 1));
                DeviceBean bean = new DeviceBean(deviceId, name.getValue(), description.getValue(),
                        (restr.size() == 1));
                devicesGrid.addRow(bean);
            } else {
                Notification.show("Failed to add device to database.");
            }
        }
    });

    // DeviceBean db = new DeviceBean(0, "Device 1","some description1", false);
    // TODO
    // add to database
    /*
     * boolean added = false;//DBManager.getDatabaseInstance().addDevice(db); //TODO test //add to
     * grid if(added){ devicesGrid.addRow(db); }else{ //TODO log failed operation
     * Notification.show("Failed to add device to database.", Type.ERROR_MESSAGE); }
     */
}

From source file:fi.hip.sicx.vaadin.FileguiApplication.java

License:Open Source License

@Override
public void init() {
    Window mainWindow = new Window("FileGUI Application");
    guicompo = new GUIComponent();
    mainWindow.setContent(guicompo);
    guicompo.openLoginWindow(); // Open login GUI
    setMainWindow(mainWindow);/*from  w  w  w.ja v a 2  s . c  o m*/
}