Example usage for com.vaadin.ui ProgressBar ProgressBar

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

Introduction

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

Prototype

public ProgressBar(float progress) 

Source Link

Document

Creates a new progress bar with the given initial value.

Usage

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

License:Apache License

private void initializeGrid(final Grid grid) {

    /*/*  w  w  w  . j  a va  2  s . co m*/
     * 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!
     */
}