Example usage for com.vaadin.ui GridLayout addComponent

List of usage examples for com.vaadin.ui GridLayout addComponent

Introduction

In this page you can find the example usage for com.vaadin.ui GridLayout addComponent.

Prototype

public void addComponent(Component component, int column1, int row1, int column2, int row2)
        throws OverlapsException, OutOfBoundsException 

Source Link

Document

Adds a component to the grid in the specified area.

Usage

From source file:dhbw.clippinggorilla.userinterface.views.InterestProfileView.java

public VerticalLayout createTab(InterestProfile profile) {
    VerticalLayout profileSettingsLayout = new VerticalLayout();
    GridLayout tabContent = new GridLayout(3, 3);

    TextField textFieldName = new TextField();
    Language.set(Word.NAME, textFieldName);
    textFieldName.setWidth("100%");
    textFieldName.setValue(profile.getName());
    textFieldName.setMaxLength(255);//from  w  ww . j ava 2 s  .  c o m
    CheckBox checkBoxEnabled = new CheckBox();
    checkBoxEnabled.setValue(profile.isEnabled());
    Language.setCustom(Word.ENABLED, s -> checkBoxEnabled.setCaption(s));

    Button buttonDelete = new Button();
    Language.set(Word.DELETE, buttonDelete);
    buttonDelete.setIcon(VaadinIcons.TRASH);
    buttonDelete.addStyleName(ValoTheme.BUTTON_DANGER);
    buttonDelete.addClickListener(ce -> {
        InterestProfileUtils.delete(profile);
        accordion.removeTab(accordion.getTab(profileSettingsLayout));
    });

    Button buttonSave = new Button();
    Language.set(Word.SAVE, buttonSave);
    buttonSave.setIcon(VaadinIcons.CHECK);
    buttonSave.addStyleName(ValoTheme.BUTTON_PRIMARY);
    buttonSave.addClickListener(ce -> {
        InterestProfileUtils.changeName(profile, textFieldName.getValue());
        accordion.getTab(profileSettingsLayout).setCaption(textFieldName.getValue());
        InterestProfileUtils.changeEnabled(profile, checkBoxEnabled.getValue());
        InterestProfileUtils.changeSources(profile, profile.getSources());
        InterestProfileUtils.changeCategories(profile, profile.getCategories());
        InterestProfileUtils.changeAllTags(profile, profile.getTags());
        VaadinUtils.infoNotification(Language.get(Word.SUCCESSFULLY_SAVED));
    });
    buttonSave.setClickShortcut(ShortcutAction.KeyCode.ENTER, null);

    Label placeholder = new Label();
    Label placeholder2 = new Label();
    placeholder2.setWidth("100%");

    Label labelHelp = new Label(Language.get(Word.HELP_TEXT), ContentMode.HTML);
    Language.setCustom(Word.HELP_TEXT, s -> labelHelp.setValue(s));
    labelHelp.setWidth("500px");
    PopupView popupHelp = new PopupView(null, labelHelp);

    Button buttonHelp = new Button(Language.get(Word.HELP), VaadinIcons.QUESTION);
    buttonHelp.addClickListener(ce -> {
        popupHelp.setPopupVisible(true);
    });

    GridLayout footer = new GridLayout(5, 1);
    footer.setSpacing(true);
    footer.setSizeUndefined();
    footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR);
    footer.setWidth("100%");
    footer.addStyleName("menubar");
    footer.addComponents(buttonHelp, popupHelp, placeholder, buttonDelete, buttonSave);
    footer.setColumnExpandRatio(2, 5);
    footer.setComponentAlignment(buttonDelete, Alignment.MIDDLE_CENTER);
    footer.setComponentAlignment(buttonSave, Alignment.MIDDLE_CENTER);

    tabContent.addComponents(textFieldName, checkBoxEnabled, placeholder2);
    tabContent.addComponent(getSources(profile), 0, 1, 1, 1);
    tabContent.addComponent(getCategories(profile), 2, 1);
    tabContent.addComponent(getTags(profile), 0, 2, 2, 2);
    tabContent.setWidth("100%");
    tabContent.setSpacing(true);
    tabContent.setMargin(true);
    tabContent.addStyleName("profiles");
    tabContent.setComponentAlignment(textFieldName, Alignment.MIDDLE_LEFT);
    tabContent.setComponentAlignment(checkBoxEnabled, Alignment.MIDDLE_CENTER);
    profileSettingsLayout.addComponents(tabContent, footer);
    profileSettingsLayout.setMargin(false);
    profileSettingsLayout.setSpacing(false);
    profileSettingsLayout.setWidth("100%");
    return profileSettingsLayout;
}

From source file:dhbw.clippinggorilla.userinterface.windows.GroupProfileWindow.java

public GroupProfileWindow(GroupInterestProfile p, Runnable onClose, boolean isAdmin) {
    VerticalLayout profileSettingsLayout = new VerticalLayout();
    GridLayout windowContent;
    Button buttonSave = new Button();

    if (isAdmin) {
        windowContent = new GridLayout(3, 3);

        TextField textFieldName = new TextField();
        Language.set(Word.NAME, textFieldName);
        textFieldName.setWidth("100%");
        textFieldName.setValue(p.getName());
        textFieldName.setMaxLength(255);

        Language.set(Word.SAVE, buttonSave);
        buttonSave.setIcon(VaadinIcons.CHECK);
        buttonSave.addStyleName(ValoTheme.BUTTON_PRIMARY);
        buttonSave.addClickListener(ce -> {
            GroupInterestProfileUtils.changeName(p, textFieldName.getValue());
            GroupInterestProfileUtils.changeSources(p, p.getSources());
            GroupInterestProfileUtils.changeCategories(p, p.getCategories());
            GroupInterestProfileUtils.changeAllTags(p, p.getTags());
            VaadinUtils.infoNotification(Language.get(Word.SUCCESSFULLY_SAVED));
            close();// ww w  . j  a va2  s . c o m
            onClose.run();
        });

        Label placeholder2 = new Label();
        placeholder2.setWidth("100%");
        windowContent.addComponents(textFieldName, placeholder2);
        windowContent.setComponentAlignment(textFieldName, Alignment.MIDDLE_LEFT);
        windowContent.addComponent(getSources(p, true), 0, 1, 1, 1);
        windowContent.addComponent(getCategories(p, true), 2, 1);
        windowContent.addComponent(getTags(p, true), 0, 2, 2, 2);
    } else {
        windowContent = new GridLayout(3, 2);

        Language.set(Word.CLOSE, buttonSave);
        buttonSave.setIcon(VaadinIcons.CLOSE);
        buttonSave.addStyleName(ValoTheme.BUTTON_PRIMARY);
        buttonSave.addClickListener(ce -> {
            close();
            onClose.run();
        });

        windowContent.addComponent(getSources(p, false), 0, 0, 1, 0);
        windowContent.addComponent(getCategories(p, false), 2, 0);
        windowContent.addComponent(getTags(p, false), 0, 1, 2, 1);
    }

    buttonSave.setClickShortcut(ShortcutAction.KeyCode.ENTER, null);

    Label placeholder = new Label();

    Label labelHelp = new Label(Language.get(Word.HELP_TEXT), ContentMode.HTML);
    labelHelp.setWidth("500px");
    PopupView popupHelp = new PopupView(null, labelHelp);

    Button buttonHelp = new Button(Language.get(Word.HELP), VaadinIcons.QUESTION);
    buttonHelp.addClickListener(ce -> {
        popupHelp.setPopupVisible(true);
    });

    GridLayout footer;
    if (isAdmin) {
        footer = new GridLayout(4, 1);
        footer.addComponents(buttonHelp, popupHelp, placeholder, buttonSave);
        footer.setColumnExpandRatio(2, 5);
    } else {
        footer = new GridLayout(2, 1);
        footer.addComponents(placeholder, buttonSave);
        footer.setColumnExpandRatio(0, 5);

    }
    footer.setSpacing(true);
    footer.setSizeUndefined();
    footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR);
    footer.setWidth("100%");
    footer.addStyleName("menubar");
    footer.setComponentAlignment(buttonSave, Alignment.MIDDLE_CENTER);

    windowContent.setWidth("100%");
    windowContent.setSpacing(true);
    windowContent.setMargin(true);
    windowContent.addStyleName("profiles");
    profileSettingsLayout.addComponents(windowContent, footer);
    profileSettingsLayout.setMargin(false);
    profileSettingsLayout.setSpacing(false);
    profileSettingsLayout.setWidth("100%");

    setContent(profileSettingsLayout);
    center();
    setWidthUndefined();
    setCaption(p.getName());
    setWidth("950px");
}

From source file:edu.nps.moves.mmowgli.export.BaseExporter.java

License:Open Source License

protected void getMetaStringOrCancel(final MetaListener lis, String title, final Map<String, String> params) {
    final Window dialog = new Window(title);
    final TextField[] parameterFields;

    dialog.setModal(true);/*from   w  ww  .  ja v a  2s  .  c  o  m*/

    VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    layout.setSpacing(true);
    layout.setSizeFull();
    dialog.setContent(layout);

    final TextArea ta = new TextArea();
    ta.setWidth("100%");
    ta.setInputPrompt("Type a description of this data, or the game which generated this data (optional)");

    ta.setImmediate(true);
    layout.addComponent(ta);

    Set<String> keySet = params.keySet();
    parameterFields = new TextField[keySet.size()];
    int i = 0;
    GridLayout pGL = new GridLayout();
    pGL.addStyleName("m-greyborder");
    pGL.setColumns(2);
    Label hdr = new HtmlLabel("<b>Parameters</b>");
    hdr.addStyleName("m-textaligncenter");
    pGL.addComponent(hdr, 0, 0, 1, 0); // top row
    pGL.setComponentAlignment(hdr, Alignment.MIDDLE_CENTER);
    pGL.setSpacing(false);
    for (String key : keySet) {
        pGL.addComponent(new HtmlLabel("&nbsp;" + key + "&nbsp;&nbsp;"));
        pGL.addComponent(parameterFields[i] = new TextField());
        parameterFields[i++].setValue(params.get(key));
    }
    if (i > 0) {
        layout.addComponent(pGL);
        layout.setComponentAlignment(pGL, Alignment.TOP_CENTER);
    }

    HorizontalLayout hl = new HorizontalLayout();
    hl.setSpacing(true);
    @SuppressWarnings("serial")
    Button cancelButt = new Button("Cancel", new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            dialog.close();
            lis.continueOrCancel(null);
        }
    });

    @SuppressWarnings("serial")
    Button exportButt = new Button("Export", new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            dialog.close();

            Set<String> keySet = params.keySet();
            int i = 0;
            for (String key : keySet)
                params.put(key, parameterFields[i++].getValue().toString());

            lis.continueOrCancel(ta.getValue().toString());
        }
    });
    hl.addComponent(cancelButt);
    hl.addComponent(exportButt);
    hl.setComponentAlignment(cancelButt, Alignment.MIDDLE_RIGHT);
    hl.setExpandRatio(cancelButt, 1.0f);

    // The components added to the window are actually added to the window's
    // layout; you can use either. Alignments are set using the layout
    layout.addComponent(hl);
    dialog.setWidth("385px");
    dialog.setHeight("310px");
    hl.setWidth("100%");
    ta.setWidth("100%");
    ta.setHeight("100%");
    layout.setExpandRatio(ta, 1.0f);

    UI.getCurrent().addWindow(dialog);
}

From source file:edu.nps.moves.mmowgli.modules.administration.AbstractGameBuilderPanel.java

License:Open Source License

protected void addLineComponent(GridLayout grid, int row, Component c) {
    grid.addComponent(c, 0, row, 2, row);
}

From source file:edu.nps.moves.mmowgli.modules.administration.AbstractGameBuilderPanel.java

License:Open Source License

protected void addSeparator(GridLayout grid, int row) {
    Label lab;//from  w  w  w . j  av  a2  s.  c o  m
    grid.addComponent(lab = new Label(), 0, row, 2, row);
    lab.setHeight("5px");
    lab.addStyleName("m-greybackground");
}

From source file:edu.nps.moves.mmowgliMobile.ui.UserRenderer2.java

License:Open Source License

public void setMessage(FullEntryView2 mView, ListEntry message, ListView2 messageList,
        AbstractOrderedLayout layout) {//from  w ww .java2 s  .  c  o  m
    // messageList can be null if coming in from ActionPlan
    Object key = HSess.checkInit();
    UserListEntry wu = (UserListEntry) message;
    User u = wu.getUser();
    layout.removeAllComponents();

    HorizontalLayout hlay = new HorizontalLayout();
    layout.addComponent(hlay);
    hlay.addStyleName("m-userview-top");
    hlay.setWidth("100%");
    hlay.setMargin(true);
    hlay.setSpacing(true);

    Image img = new Image();
    img.addStyleName("m-ridgeborder");
    img.setSource(mediaLocator.locate(u.getAvatar().getMedia()));
    img.setWidth("90px");
    img.setHeight("90px");
    hlay.addComponent(img);
    hlay.setComponentAlignment(img, Alignment.MIDDLE_CENTER);

    Label lab;
    hlay.addComponent(lab = new Label());
    lab.setWidth("5px");

    VerticalLayout vlay = new VerticalLayout();
    vlay.setSpacing(true);
    hlay.addComponent(vlay);
    hlay.setComponentAlignment(vlay, Alignment.MIDDLE_LEFT);
    vlay.setWidth("100%");
    hlay.setExpandRatio(vlay, 1.0f);
    HorizontalLayout horl = new HorizontalLayout();
    horl.setSpacing(false);
    vlay.addComponent(horl);
    vlay.setComponentAlignment(horl, Alignment.BOTTOM_LEFT);
    horl.addComponent(lab = new Label("name"));
    lab.addStyleName("m-user-top-label"); //light-text");
    horl.addComponent(lab = new HtmlLabel("&nbsp;&nbsp;" + u.getUserName()));
    lab.addStyleName("m-user-top-value");
    horl = new HorizontalLayout();
    horl.setSpacing(false);
    vlay.addComponent(horl);
    vlay.setComponentAlignment(horl, Alignment.TOP_LEFT);

    horl.addComponent(lab = new Label("level"));
    lab.addStyleName("m-user-top-label"); //light-text");
    Level lev = u.getLevel();
    if (u.isGameMaster()) {
        Level l = Level.getLevelByOrdinal(Level.GAME_MASTER_ORDINAL, HSess.get());
        if (l != null)
            lev = l;
    }
    horl.addComponent(lab = new HtmlLabel("&nbsp;&nbsp;&nbsp;" + lev.getDescription()));
    lab.addStyleName("m-user-top-value");

    GridLayout gLay = new GridLayout();
    // gLay.setHeight("155px");  // won't size properly
    gLay.setMargin(true);
    gLay.addStyleName("m-userview-mid");
    gLay.setColumns(2);
    gLay.setRows(11);
    gLay.setSpacing(true);
    gLay.setWidth("100%");
    gLay.setColumnExpandRatio(1, 1.0f);
    layout.addComponent(gLay);

    addRow(gLay, "user ID:", "" + getPojoId(message));
    addRow(gLay, "location:", u.getLocation());
    addRow(gLay, "expertise:", u.getExpertise());
    addRow(gLay, "affiliation:", u.getAffiliation());
    addRow(gLay, "date registered:", formatter.format(u.getRegisterDate()));

    gLay.addComponent(new Hr(), 0, 5, 1, 5);

    Container cntr = new CardsByUserContainer<Card>(u); // expects ThreadLocal session to be setup
    numCards = cntr.size();
    addRow(gLay, "cards played:", "" + numCards);
    cntr = new ActionPlansByUserContainer<Card>(u); // expects ThreadLocal session to be setup
    numAps = cntr.size();
    addRow(gLay, "action plans:", "" + numAps);

    gLay.addComponent(new Hr(), 0, 8, 1, 8);

    addRow(gLay, "exploration points:", "" + u.getBasicScore());
    addRow(gLay, "innovation points:", "" + u.getInnovationScore());

    cardListener = new CardLis(u, mView);
    apListener = new AppLis(u, mView);

    layout.addComponent(makeButtons());

    HSess.checkClose(key);
}

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/*from  w w w.  j  a  va 2  s. 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  ww  w .  j a v  a 2  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:fr.amapj.view.views.permanence.mespermanences.grille.InscriptionPopupRoleDifferent.java

License:Open Source License

/**
 * Permet de dessiner le tableau //  w  ww.  j  a  va2  s .  co  m
 */
public void drawTab(Tab tab) {
    GridLayout gl = new GridLayout(4, 1 + tab.lines.size());
    gl.setWidth("800px");
    gl.setSpacing(false);

    contentLayout.addComponent(gl);

    // Construction du titre   
    Label l = new Label(tab.titre);
    l.addStyleName(tab.styleTitre);
    l.setWidth("100%");
    gl.addComponent(l, 0, 0, 3, 0);

    List<TabLine> lines = tab.lines;
    for (int i = 0; i < lines.size(); i++) {
        TabLine line = lines.get(i);

        int height = computeHeight(line);
        // La taille minimale est de 36 pixels, pour les boutons inscrire / desincrire
        height = Math.max(height, 36);

        Label l1 = new Label(line.col1);
        l1.addStyleName(line.styleCol1);
        l1.setWidth("100%");
        l1.setHeight(height + "px");
        gl.addComponent(l1, 0, i + 1);

        Label l2 = new Label(line.col2);
        l2.addStyleName(line.styleCol2);
        l2.setWidth("100%");
        l2.setHeight(height + "px");
        gl.addComponent(l2, 1, i + 1);

        Label l3 = new Label(line.col3);
        l3.addStyleName(line.styleCol3);
        l3.setWidth("100%");
        l3.setHeight(height + "px");
        gl.addComponent(l3, 2, i + 1);

        if (line.col4 != null) {
            Button b = new Button(line.col4);
            b.addStyleName(line.styleCol4);
            b.addClickListener(e -> handleButton(line.role));
            b.setWidth("100%");
            gl.addComponent(b, 3, i + 1);
            gl.setComponentAlignment(b, Alignment.MIDDLE_CENTER);
        } else {
            Label l4 = new Label("");
            l4.addStyleName(line.styleCol4);
            l4.setWidth("100%");
            l4.setHeight(height + "px");
            gl.addComponent(l4, 3, i + 1);
        }
    }
}

From source file:fr.amapj.view.views.permanence.mespermanences.grille.InscriptionPopupToutAutorise.java

License:Open Source License

/**
 * Permet de dessiner le tableau /* w  ww.j av  a 2  s  .  c  om*/
 */
public void drawTab(Tab tab) {
    GridLayout gl = new GridLayout(3, 1 + tab.lines.size());
    gl.setWidth("600px");
    gl.setSpacing(false);

    contentLayout.addComponent(gl);

    // Construction du titre   
    Label l = new Label(tab.titre);
    l.addStyleName(tab.styleTitre);
    l.setWidth("100%");
    gl.addComponent(l, 0, 0, 2, 0);

    List<TabLine> lines = tab.lines;
    for (int i = 0; i < lines.size(); i++) {
        TabLine line = lines.get(i);

        int height = computeHeight(line);
        // La taille minimale est de 36 pixels, pour les boutons inscrire / desincrire
        height = Math.max(height, 36);

        Label l1 = new Label(line.col1);
        l1.addStyleName(line.styleCol1);
        l1.setWidth("100%");
        l1.setHeight(height + "px");
        gl.addComponent(l1, 0, i + 1);

        Label l2 = new Label(line.col2);
        l2.addStyleName(line.styleCol2);
        l2.setWidth("100%");
        l2.setHeight(height + "px");
        gl.addComponent(l2, 1, i + 1);

        if (line.col3 != null) {
            Button b = new Button(line.col3);
            b.addStyleName(line.styleCol3);
            b.addClickListener(e -> handleButton(line.cell));
            b.setWidth("100%");
            gl.addComponent(b, 2, i + 1);
            gl.setComponentAlignment(b, Alignment.MIDDLE_CENTER);
        } else {
            Label l3 = new Label("");
            l3.addStyleName(line.styleCol3);
            l3.setWidth("100%");
            l3.setHeight(height + "px");
            gl.addComponent(l3, 2, i + 1);
        }
    }
}