Example usage for com.vaadin.ui Grid Grid

List of usage examples for com.vaadin.ui Grid Grid

Introduction

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

Prototype

public Grid(DataProvider<T, ?> dataProvider) 

Source Link

Document

Creates a new Grid using the given DataProvider .

Usage

From source file:com.scipionyx.butterflyeffect.frontend.configuration.ui.view.AboutView.java

License:Apache License

/**
 * /*from w ww  .  j a  v a 2  s . c  o m*/
 * @param instancesBackend
 * @param justclean
 */
private void loadClusterInformation(List<ServiceInstance> instancesBackend, GridLayout layout,
        boolean justclean) {

    layout.removeAllComponents();

    int i = 0;
    for (ServiceInstance instance : instancesBackend) {

        Grid<GridProperty<?>> tableCluster = new Grid<>("Node [" + i + "]");
        tableCluster.addStyleName(ValoTheme.TABLE_COMPACT);
        tableCluster.setSizeFull();

        tableCluster.addColumn(GridProperty::getName).setCaption("Property");
        tableCluster.addColumn(GridProperty::getValue).setCaption("Value");

        List<GridProperty<?>> list = new ArrayList<>();
        list.add(new GridProperty<>("Host", instance.getHost()));
        list.add(new GridProperty<>("Service Id", instance.getServiceId()));
        list.add(new GridProperty<>("Port", instance.getPort()));
        list.add(new GridProperty<>("Uri", instance.getUri()));

        for (String key : instance.getMetadata().keySet()) {
            list.add(new GridProperty<>("Metadata[" + key + "]", instance.getMetadata().get(key)));
        }

        tableCluster.setItems(list);

        layout.addComponent(tableCluster);

        i++;

    }

}

From source file:de.kaiserpfalzEdv.vaadin.about.AboutViewImpl.java

License:Apache License

private void initializeModuleVersions() {
    versionLayout = createVerticalLayout("about.modules.caption", "about.modules.description",
            FontAwesome.LIST);/*from www. j  a  v a2 s .co m*/

    BeanItemContainer<ModuleVersion> data = new BeanItemContainer<>(ModuleVersion.class);
    data.addAll(versions);

    Grid display = new Grid(data);
    display.setSizeFull();
    display.setFrozenColumnCount(1);
    display.setColumns("caption", "description", "version");

    formatColumn(display, "caption", "about.modules", 25);
    formatColumn(display, "description", "about.modules", 50);
    formatColumn(display, "version", "about.modules", 25);
    versionLayout.addComponent(display);
}

From source file:de.kaiserpfalzEdv.vaadin.about.AboutViewImpl.java

License:Apache License

private void initializeDatabaseChangeLog() {
    changelogLayout = createVerticalLayout("about.database.caption", "about.database.description",
            FontAwesome.TABLE);/*  w  w w.  j a v  a  2s.c o  m*/

    BeanItemContainer<DatabaseChangeLog> data = new BeanItemContainer<>(DatabaseChangeLog.class);
    data.addAll(changeLog);

    Grid display = new Grid(data);
    display.setSizeFull();
    display.setFrozenColumnCount(1);
    display.setColumns("id", "fileName", "dateExecuted", "comments", "liquibase");

    formatColumn(display, "id", "about.database", 10);
    formatColumn(display, "fileName", "about.database", 20);
    formatColumn(display, "dateExecuted", "about.database", 20);
    formatColumn(display, "comments", "about.database", 40);
    formatColumn(display, "liquibase", "about.database", 10);
    changelogLayout.addComponent(display);
}

From source file:de.kaiserpfalzEdv.vaadin.auth.list.UserListViewImpl.java

License:Apache License

@Override
public void enter(ViewChangeListener.ViewChangeEvent event) {
    LOG.debug("Opened view: {}", event);

    if (layout == null) {
        layout = new GridLayout(5, 2);
        layout.setSizeFull();// ww w .  ja  va 2  s  .c  o  m
        layout.setResponsive(true);
        layout.setMargin(true);
        layout.setSpacing(true);
        setCompositionRoot(layout);

        data = JPAContainerFactory.makeReadOnly(User.class, em);
        users = new Grid(presenter.translate("users.list.title"));
        users.setContainerDataSource(data);

        users.setColumns("id", "login", "surName", "givenName", "commonName");
        users.getColumn("id").setHeaderCaption(presenter.translate("user.id"));
        users.getColumn("login").setHeaderCaption(presenter.translate("user.login"));
        users.getColumn("login").setLastFrozenColumn();
        users.getColumn("surName").setHeaderCaption(presenter.translate("user.sur-name"));
        users.getColumn("givenName").setHeaderCaption(presenter.translate("user.given-name"));
        users.getColumn("commonName").setHeaderCaption(presenter.translate("user.common-name"));

        layout.addComponent(users, 0, 0, 4, 0);
    } else {
        refresh();
    }
}

From source file:de.kaiserpfalzEdv.vaadin.ui.defaultviews.list.impl.BaseListViewImpl.java

License:Apache License

private void initializeData() {
    LOG.trace("Initializing data: {}", this);

    data = dataContainerProvider.getReadOnlyContainer(clasz);

    grid = new Grid(data);
    grid.setSizeFull();/*from ww w . java 2s  .  co  m*/
    grid.setFrozenColumnCount(1);

    setGridColumns();

    grid.setSelectionMode(Grid.SelectionMode.SINGLE);
    grid.addSelectionListener(event -> {
        if (!event.getSelected().isEmpty())
            presenter.startEditor((Long) event.getSelected().iterator().next());
    });

    if (layout != null)
        layout.addComponent(grid);
}

From source file:de.uni_tuebingen.qbic.qbicmainportlet.SearchResultsView.java

License:Open Source License

void buildLayout(int browserHeight, int browserWidth, WebBrowser browser) {
    // this.setMargin(new MarginInfo(true, true, false, false));
    // clean up first
    searchResultsLayout.removeAllComponents();
    searchResultsLayout.setWidth("100%");
    // searchResultsLayout.setSpacing(true);

    searchResultsLayout.setCaption("Search results for query '" + queryString + "'");
    // Label header = new Label("Search results for query '" + queryString + "':");
    // searchResultsLayout.addComponent(header);

    // updateView(browserWidth, browserWidth, browser);

    VerticalLayout viewContent = new VerticalLayout();
    viewContent.setWidth("100%");
    viewContent.setSpacing(true);/* w ww  . java 2 s  . c o m*/
    viewContent.setMargin(new MarginInfo(true, false, false, false));

    List<String> showOptions = datahandler.getShowOptions();

    if (showOptions.contains("Projects")) {
        projectGrid = new Grid(projBeanContainer);
        projectGrid.setCaption("Found Projects");
        projectGrid.setColumnOrder("projectID", "description");
        projectGrid.setSizeFull();

        projectGrid.setHeightMode(HeightMode.ROW);
        projectGrid.setHeightByRows(5);
        projectGrid.setSelectionMode(SelectionMode.SINGLE);

        projectGrid.addItemClickListener(new ItemClickListener() {

            @Override
            public void itemClick(ItemClickEvent event) {
                // TODO Auto-generated method stub
                String cellType = new String(event.getPropertyId().toString());

                if (cellType.equals("projectID")) {
                    String cellContent = new String(
                            projBeanContainer.getContainerProperty(event.getItemId(), event.getPropertyId())
                                    .getValue().toString());

                    State state = (State) UI.getCurrent().getSession().getAttribute("state");
                    ArrayList<String> message = new ArrayList<String>();
                    message.add("clicked");
                    message.add(cellContent);
                    message.add("project");
                    state.notifyObservers(message);
                }
            }
        });

        if (projBeanContainer.size() == 0) {
            Label noSamples = new Label("no projects were found");
            noSamples.setCaption("Found Projects");
            viewContent.addComponent(noSamples);
        } else {
            viewContent.addComponent(projectGrid);
        }
    }

    if (showOptions.contains("Experiments")) {
        // expGrid = new Grid(expBeanContainer);
        expGrid = new Grid(expBeanContainer);
        expGrid.setCaption("Found Experiments");
        expGrid.setColumnOrder("experimentID", "experimentName", "matchedField");
        expGrid.setSizeFull();

        expGrid.getColumn("experimentID").setExpandRatio(0);
        expGrid.getColumn("experimentName").setExpandRatio(1);
        expGrid.getColumn("matchedField").setExpandRatio(1);

        expGrid.setHeightMode(HeightMode.ROW);
        expGrid.setHeightByRows(5);
        expGrid.setSelectionMode(SelectionMode.SINGLE);

        expGrid.addItemClickListener(new ItemClickListener() {
            @Override
            public void itemClick(ItemClickEvent event) {
                String cellType = new String(event.getPropertyId().toString());

                if (cellType.equals("experimentID")) {
                    String cellContent = new String(
                            expBeanContainer.getContainerProperty(event.getItemId(), event.getPropertyId())
                                    .getValue().toString());

                    State state = (State) UI.getCurrent().getSession().getAttribute("state");
                    ArrayList<String> message = new ArrayList<String>();
                    message.add("clicked");
                    message.add(cellContent);
                    message.add("experiment");
                    state.notifyObservers(message);
                }
            }
        });

        if (expBeanContainer.size() == 0) {
            Label noExps = new Label("no experiments were found");
            noExps.setCaption("Found Experiments");
            viewContent.addComponent(noExps);
        } else {
            viewContent.addComponent(expGrid);
        }

    }

    if (showOptions.contains("Samples")) {
        sampleGrid = new Grid(sampleBeanContainer);
        sampleGrid.setCaption("Found Samples");
        sampleGrid.setColumnOrder("sampleID", "sampleName", "matchedField");
        sampleGrid.setSizeFull();

        sampleGrid.getColumn("sampleID").setExpandRatio(0);
        sampleGrid.getColumn("sampleName").setExpandRatio(1);
        sampleGrid.getColumn("matchedField").setExpandRatio(1);

        sampleGrid.setHeightMode(HeightMode.ROW);
        sampleGrid.setHeightByRows(5);
        sampleGrid.setSelectionMode(SelectionMode.SINGLE);

        sampleGrid.addItemClickListener(new ItemClickListener() {
            @Override
            public void itemClick(ItemClickEvent event) {
                String cellType = new String(event.getPropertyId().toString());

                if (cellType.equals("sampleID")) {
                    String cellContent = new String(
                            sampleBeanContainer.getContainerProperty(event.getItemId(), event.getPropertyId())
                                    .getValue().toString());

                    State state = (State) UI.getCurrent().getSession().getAttribute("state");
                    ArrayList<String> message = new ArrayList<String>();
                    message.add("clicked");
                    message.add(cellContent);
                    message.add("sample");
                    state.notifyObservers(message);
                }
            }
        });

        if (sampleBeanContainer.size() == 0) {
            Label noSamples = new Label("no samples were found");
            noSamples.setCaption("Found Samples");
            viewContent.addComponent(noSamples);
        } else {
            viewContent.addComponent(sampleGrid);
        }
    }

    searchResultsLayout.addComponent(viewContent);

    this.addComponent(searchResultsLayout);
}

From source file:facs.components.BookAdmin.java

License:Open Source License

private Component newDeviceGrid(final String deviceName) {
    VerticalLayout devicesLayout = new VerticalLayout();
    devicesLayout.setCaption(deviceName);
    // 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  v a  2  s.  co  m
    devicesLayout.setMargin(true);
    devicesLayout.setSpacing(true);

    BeanItemContainer<BookingBean> booking = getBookingList(deviceName);

    GeneratedPropertyContainer gpc = new GeneratedPropertyContainer(booking);
    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;
        }
    });

    gridMap.put(deviceName, new Grid(gpc));
    // Create a grid

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

    // Render a button that deletes the data row (item)
    gridMap.get(deviceName).getColumn("delete")
            .setRenderer(new ButtonRenderer(new ClickableRenderer.RendererClickListener() {
                /**
                 * 
                 */
                private static final long serialVersionUID = 3544662150370497152L;

                @Override
                public void click(RendererClickEvent event) {
                    removeBooking(gridMap.get(deviceName), (BookingBean) event.getItemId());
                }
            }));

    // devicesGrid.setEditorEnabled(true);

    // devicesLayout.addComponent(buttonLayout);
    devicesLayout.addComponent(gridMap.get(deviceName));

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

    return devicesLayout;
}

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/* w w w  .j av a  2  s.co m*/
    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.BookAdmin.java

License:Open Source License

private Component awaitingRequestsGrid() {
    VerticalLayout devicesLayout = new VerticalLayout();
    devicesLayout.setCaption("Awaiting Requests");
    // 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/*  w w  w  . j  ava  2  s .c o m*/
    devicesLayout.setMargin(true);
    devicesLayout.setSpacing(true);
    // buttonLayout.setMargin(true);
    // buttonLayout.setSpacing(true);

    // buttonLayout.addComponent(add);

    BeanItemContainer<BookingBean> booking = getAwaitingRequests();

    GeneratedPropertyContainer gpc = new GeneratedPropertyContainer(booking);

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

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

        }

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

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

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

        }

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

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

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

    // Render a button that deletes the data row (item)
    devicesGridConfirm.getColumn("delete")
            .setRenderer(new ButtonRenderer(new ClickableRenderer.RendererClickListener() {
                /**
                 * 
                 */
                private static final long serialVersionUID = -5479714386381863679L;

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

    devicesGridConfirm.getColumn("confirm")
            .setRenderer(new ButtonRenderer(new ClickableRenderer.RendererClickListener() {
                /**
                 * 
                 */
                private static final long serialVersionUID = 7944939118917004114L;

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

    // devicesGrid.setEditorEnabled(true);

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

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

    return devicesLayout;
}

From source file:facs.components.Booking.java

License:Open Source License

private Component myNext24HoursBookings() {
    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  . jav  a 2s.  c o  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 = getMyNext24HoursBookings(bookingModel.getLDAP(), serverTime,
            nextDayTime);
    // System.out.println(bookingModel.getLDAP());

    GeneratedPropertyContainer gpc = new GeneratedPropertyContainer(users);

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

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

    return devicesLayout;
}