Example usage for com.vaadin.ui Grid prependHeaderRow

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

Introduction

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

Prototype

public HeaderRow prependHeaderRow() 

Source Link

Document

Adds a new row at the top of the header section.

Usage

From source file:ch.wscr.management.ui.view.MemberView.java

/**
 * Kopfzeile fr das Grid erstellen/*  w  ww . j  a v a  2  s. co m*/
 *
 * @param grid das Grid dem die Kopfzeile hinzugefgt werden soll
 */
private void setHeaderRow(final Grid grid) {
    // TODO Erstellung neuer Mitglieder muss noch optimiert werden

    final Button addMember = new Button("Neu", clickEvent -> {
        BeanItem<Member> beanItem = memberBeanItemContainer.addItem(new Member());
        grid.setEditorEnabled(true);
        //grid.editItem(beanItem);

    });

    addMember.setStyleName(ValoTheme.BUTTON_BORDERLESS_COLORED);
    addMember.setIcon(FontAwesome.PLUS_CIRCLE);

    HorizontalLayout buttonLayout = new HorizontalLayout();
    buttonLayout.setSizeFull();
    buttonLayout.setSpacing(true);
    buttonLayout.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT);
    buttonLayout.addComponent(addMember);

    HeaderRow headerRow = grid.prependHeaderRow();
    headerRow.join("memberId", "lastName", "firstName", "adrStreet", "adrPostalCode", "adrCity", "adrCountry",
            "birthDate", "driverLicense");
    headerRow.getCell("lastName").setComponent(buttonLayout);
}

From source file:org.vaadin.allaboutgrid.AllAboutGridUI.java

License:Apache License

private void initializeGrid(final Grid grid) {

    /*/* ww  w  .  j a va  2s.  com*/
     * Let's just add some data there to get something showing
     */

    // grid.addColumn("Col 1");
    // grid.addColumn("Col 2");
    //
    // grid.addRow("Some", "data");
    // grid.addRow("Another", "row");

    /*
     * Let's use a full-featured container instead
     */

    BeanItemContainer<Order> orderContainer = createOrderContainer();
    grid.setContainerDataSource(orderContainer);

    /*
     * Changing the column order and adjusting column headers
     */

    grid.setColumnOrder("id", "customer", "product", "orderAmount", "reservedAmount", "completePercentage",
            "priority", "customized", "orderTime");

    grid.getColumn("orderAmount").setHeaderCaption("Ordered");
    grid.getColumn("reservedAmount").setHeaderCaption("Reserved");
    grid.getColumn("completePercentage").setHeaderCaption("Complete");
    grid.getColumn("customized").setHeaderCaption("Custom");

    /*
     * Removing unwanted columns
     */

    // grid.removeColumn("customer");
    // grid.removeColumn("customized");
    // grid.removeColumn("priority");
    // grid.removeColumn("orderTime");

    /*
     * Adjusting column sizes
     */

    grid.getColumn("id").setMaximumWidth(70);

    grid.getColumn("customer").setMinimumWidth(200);
    grid.getColumn("product").setMinimumWidth(200);

    /*
     * Keep some columns in view all the time
     */

    grid.getColumn("product").setLastFrozenColumn();

    /*
     * Changing the locale affects how data is presented
     */

    grid.setLocale(Locale.GERMANY);

    /*
     * Various ways of tweaking how data is shown
     */

    grid.getColumn("id").setRenderer(new NumberRenderer(idFormat));

    grid.getColumn("completePercentage")
            .setRenderer(new NumberRenderer(NumberFormat.getPercentInstance(grid.getLocale())));

    grid.getColumn("completePercentage").setRenderer(new ProgressBarRenderer());

    grid.getColumn("customized").setConverter(new BooleanToFontIconConverter());

    grid.getColumn("customized").setRenderer(new HtmlRenderer());

    grid.setCellStyleGenerator(new CellStyleGenerator() {
        @Override
        public String getStyle(CellReference cellReference) {
            if ("priority".equals(cellReference.getPropertyId())) {
                Priority priority = (Priority) cellReference.getValue();
                return "priority-" + priority.name().toLowerCase();
            } else {
                return null;
            }
        }
    });

    /*
     * Additional header spanned cells
     */

    HeaderRow extraHeader = grid.prependHeaderRow();

    extraHeader.join("orderAmount", "reservedAmount").setText("Quantity");

    extraHeader.join("priority", "customized").setText("Status");

    /*
     * Footer with various types of content
     */

    FooterRow extraFooter = grid.appendFooterRow();

    int totalOrdered = OrderUtil.getTotalOrderAmount(orderContainer);
    extraFooter.getCell("orderAmount").setText(Integer.toString(totalOrdered));

    int totalReserved = OrderUtil.getTotalReservedAmounT(orderContainer);
    extraFooter.getCell("reservedAmount").setHtml("<b>" + totalReserved + "</b>");

    extraFooter.getCell("completePercentage")
            .setComponent(new ProgressBar(totalReserved / (float) totalOrdered));

    /*
     * Enable editing
     */

    grid.setEditorEnabled(true);
    grid.setFrozenColumnCount(0);

    grid.getColumn("id").setEditable(false);
    grid.getColumn("completePercentage").setEditable(false);

    grid.getColumn("customized").getEditorField().setCaption("");

    grid.getColumn("orderTime").setEditorField(createOrderTimeField());

    Field<?> customerField = grid.getColumn("customer").getEditorField();
    customerField.setRequired(true);
    customerField.setRequiredError("Value is required");

    /*
     * Get an event when the users saves in the editor
     */

    grid.getEditorFieldGroup().addCommitHandler(new CommitHandler() {
        @Override
        public void preCommit(CommitEvent commitEvent) throws CommitException {
            // Do nothing
        }

        @Override
        public void postCommit(CommitEvent commitEvent) throws CommitException {
            Notification.show("Changes saved");
        }
    });

    /*
     * New feature going into Vaadin 7.5: Column reordering
     */

    grid.setColumnReorderingAllowed(true);

    /*
     * New feature going into Vaadin 7.5: Row details
     */

    grid.setDetailsGenerator(new DetailsGenerator() {
        @Override
        public Component getDetails(RowReference rowReference) {
            Order order = (Order) rowReference.getItemId();
            String detailsMessage = "This is a label with information about the order of " + order.getProduct()
                    + " by " + order.getCustomer() + ".";

            Button deleteButton = new Button("Delete order", new Button.ClickListener() {
                @Override
                public void buttonClick(ClickEvent event) {
                    Notification.show("Button clicked");
                }
            });

            VerticalLayout layout = new VerticalLayout(new Label(detailsMessage), deleteButton);
            layout.setMargin(true);
            layout.setSpacing(true);

            return layout;
        }
    });

    grid.addItemClickListener(new ItemClickListener() {
        @Override
        public void itemClick(ItemClickEvent event) {
            if (event.isDoubleClick()) {
                Object itemId = event.getItemId();
                grid.setDetailsVisible(itemId, !grid.isDetailsVisible(itemId));
            }
        }
    });

    grid.setEditorEnabled(false);

    /*
     * That's all. Thank you for watching!
     */
}