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 column, int row)
        throws OverlapsException, OutOfBoundsException 

Source Link

Document

Adds the component to the grid in cells column1,row1 (NortWest corner of the area.) End coordinates (SouthEast corner of the area) are the same as column1,row1.

Usage

From source file:org.lunifera.examples.runtime.web.vaadin.databinding.DatabindingDemoUI.java

License:Open Source License

private void row4(GridLayout layout) {
    Slider slider = new Slider("width");
    slider.setImmediate(true);/* w  w w  . ja v a  2s  .co  m*/
    slider.setBuffered(false);
    slider.setWidth("150px");
    layout.addComponent(slider, 0, 3);

    TextField heightInput = new TextField("height");
    heightInput.setImmediate(true);
    heightInput.setBuffered(false);
    layout.addComponent(heightInput, 1, 3);

    slider.setMax(200);
    slider.setValue(20d);
    heightInput.setValue("10px");

    TextField input2 = new TextField("sizeable");
    layout.addComponent(input2, 2, 3);

    dbc.bindValue(VaadinObservables.observeWidth(input2), VaadinObservables.observeValue(slider), null,
            new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE).setConverter(new IConverter() {
                @Override
                public Object getToType() {
                    return String.class;
                }

                @Override
                public Object getFromType() {
                    return Object.class;
                }

                @Override
                public Object convert(Object fromObject) {
                    double value = (Double) fromObject;
                    return String.format("%s%s", Double.toString(value), Unit.PIXELS.getSymbol());
                }
            }));
    dbc.bindValue(VaadinObservables.observeHeight(input2), VaadinObservables.observeValue(heightInput));

}

From source file:org.primaldev.ppm.util.ChartTypeGenerator.java

License:Apache License

protected static Component createChart(JsonNode dataNode, String[] names, Number[] values) {
    String type = dataNode.get("type").textValue();

    JsonNode xAxisNode = dataNode.get("xaxis");
    String xAxis = null;/* w  w w.ja v  a 2 s . co m*/
    if (xAxisNode != null) {
        xAxis = xAxisNode.textValue();
    }

    JsonNode yAxisNode = dataNode.get("yaxis");
    String yAxis = null;
    if (yAxisNode != null) {
        yAxis = yAxisNode.textValue();
    }

    Component chart = null;
    if (CHART_TYPE_BAR_CHART.equals(type)) {

        DataSeries dataSeries = new DataSeries().add((Object[]) values);
        SeriesDefaults seriesDefaults = new SeriesDefaults().setRenderer(SeriesRenderers.BAR);
        Axes axes = new Axes().addAxis(
                new XYaxis().setRenderer(AxisRenderers.CATEGORY).setTicks(new Ticks().add((Object[]) names)));
        Highlighter highlighter = new Highlighter().setShow(false);

        Options options = new Options().setSeriesDefaults(seriesDefaults).setAxes(axes)
                .setHighlighter(highlighter);
        options.setAnimate(true);
        options.setAnimateReplot(true);

        chart = new DCharts().setDataSeries(dataSeries).setOptions(options);

    } else if (CHART_TYPE_PIE_CHART.equals(type)) {

        DataSeries dataSeries = new DataSeries().newSeries();
        for (int i = 0; i < names.length; i++) {
            dataSeries.add(names[i], values[i]);
        }
        SeriesDefaults seriesDefaults = new SeriesDefaults().setRenderer(SeriesRenderers.PIE);

        Options options = new Options().setSeriesDefaults(seriesDefaults);
        options.setAnimate(true);
        options.setAnimateReplot(true);

        Legend legend = new Legend().setShow(true).setPlacement(LegendPlacements.INSIDE);
        options.setLegend(legend);

        Highlighter highlighter = new Highlighter().setShow(true);
        options.setHighlighter(highlighter);

        chart = new DCharts().setDataSeries(dataSeries).setOptions(options);

    } else if (CHART_TYPE_LINE_CHART.equals(type)) {

        AxesDefaults axesDefaults = new AxesDefaults().setLabelRenderer(LabelRenderers.CANVAS);
        Axes axes = new Axes()
                .addAxis(new XYaxis().setLabel(xAxis != null ? xAxis : "").setMin(names[0])
                        .setMax(names[values.length - 1]).setDrawMajorTickMarks(true))
                .addAxis(new XYaxis(XYaxes.Y).setLabel(yAxis != null ? yAxis : "").setDrawMajorTickMarks(true));
        Options options = new Options().setAxesDefaults(axesDefaults).setAxes(axes);
        DataSeries dataSeries = new DataSeries().newSeries();
        for (int i = 0; i < names.length; i++) {

            //        if (parseLong(names[i]) != null) {
            //          dataSeries.add(parseLong(names[i]), values[i]);
            //        } else if (parseDouble(names[i]) != null) {
            //          dataSeries.add(parseDouble(names[i]), values[i]);
            //        } else {
            //          dataSeries.add(names[i], values[i]);
            //        }

            dataSeries.add(names[i], values[i]);

        }

        Series series = new Series().addSeries(new XYseries().setShowLine(true).setMarkerOptions(
                new MarkerRenderer().setShadow(true).setSize(7).setStyle(MarkerStyles.CIRCLE)));
        options.setSeries(series);

        options.setAnimate(true);
        options.setAnimateReplot(true);

        Highlighter highlighter = new Highlighter().setShow(true);
        options.setHighlighter(highlighter);

        chart = new DCharts().setDataSeries(dataSeries).setOptions(options);

    } else if (CHART_TYPE_LIST.equals(type)) {

        GridLayout grid = new GridLayout(2, names.length);
        grid.setSpacing(true);

        for (int i = 0; i < names.length; i++) {
            String name = names[i];
            Label nameLabel = new Label(name);
            nameLabel.addStyleName(Reindeer.LABEL_H2);
            grid.addComponent(nameLabel, 0, i);

            Number value = values[i];
            Label valueLabel = new Label(value + "");
            grid.addComponent(valueLabel, 1, i);
        }

        chart = grid;

    }

    if (chart instanceof DCharts) {
        // Needed, otherwise the chart will not be shown
        ((DCharts) chart).show();
    }

    return chart;
}

From source file:org.vaadin.addons.sitekit.flow.AbstractFlowViewlet.java

License:Apache License

@Override
public final void attach() {
    super.attach();

    final GridLayout layout = new GridLayout(1, 3);
    layout.setSizeFull();/*from w w  w  . j a  v a  2  s.c  om*/
    this.setCompositionRoot(layout);
    layout.setRowExpandRatio(1, 1.0f);
    layout.setMargin(false);
    layout.setSpacing(true);

    topLayout = new HorizontalLayout();
    layout.addComponent(topLayout, 0, 0);

    topBackButton = new Button(getSite().localize("button-back"));
    topBackButton.setEnabled(false);
    topBackButton.addListener(this);
    topLayout.addComponent(topBackButton);
    topLayout.setExpandRatio(topBackButton, 0.0f);

    topPathLabel = new Label("", Label.CONTENT_XHTML);

    topLayout.addComponent(topPathLabel);
    topLayout.setComponentAlignment(topPathLabel, Alignment.MIDDLE_LEFT);
    topLayout.setExpandRatio(topPathLabel, 1f);

    topRightLayout = new HorizontalLayout();
    topLayout.addComponent(topRightLayout);
    topLayout.setComponentAlignment(topRightLayout, Alignment.MIDDLE_RIGHT);
    topLayout.setExpandRatio(topRightLayout, 0.0f);
    topLayout.setWidth(100, Unit.PERCENTAGE);

    bottomLayout = new HorizontalLayout();
    layout.addComponent(bottomLayout, 0, 2);

    bottomBackButton = new Button(getSite().localize("button-back"));
    bottomBackButton.setEnabled(false);
    bottomBackButton.addListener(this);
    bottomLayout.addComponent(bottomBackButton);
    bottomLayout.setExpandRatio(bottomBackButton, 0f);

    bottomPathLabel = new Label("", Label.CONTENT_XHTML);

    bottomLayout.addComponent(bottomPathLabel);
    bottomLayout.setExpandRatio(bottomPathLabel, 1f);
    bottomLayout.setComponentAlignment(bottomPathLabel, Alignment.MIDDLE_LEFT);

    bottomRightLayout = new HorizontalLayout();
    bottomLayout.addComponent(bottomRightLayout);
    bottomLayout.setComponentAlignment(bottomRightLayout, Alignment.MIDDLE_RIGHT);
    bottomLayout.setExpandRatio(bottomRightLayout, 0f);
    bottomLayout.setWidth(100, Unit.PERCENTAGE);

    tabSheet = new TabSheet();
    tabSheet.setStyleName("flow-sheet");
    tabSheet.hideTabs(true);
    tabSheet.setSizeFull();
    layout.addComponent(tabSheet, 0, 1);

    addFlowlets();

    tabSheet.setSelectedTab((Component) getRootFlowlet());
}

From source file:org.vaadin.addons.sitekit.module.audit.view.AuditLogFlowlet.java

License:Apache License

@Override
public void initialize() {
    // Get entity manager from site context and prepare container.
    final EntityManager entityManager = getSite().getSiteContext().getObject(EntityManager.class);
    entityContainer = new EntityContainer<AuditLogEntry>(entityManager, true, false, false, AuditLogEntry.class,
            1000, new String[] { "created" }, new boolean[] { false }, "auditLogEntryId");

    // Get descriptors and set container properties.
    final List<FilterDescriptor> filterDescriptors = new ArrayList<FilterDescriptor>();
    filterDescriptors.add(new FilterDescriptor("startTime", "created", getSite().localize("filter-start-time"),
            new TimestampField(), 130, ">=", Date.class, new DateTime().withTimeAtStartOfDay().toDate()));
    filterDescriptors.add(new FilterDescriptor("endTime", "created", getSite().localize("filter-end-time"),
            new TimestampField(), 130, "<=", Date.class,
            new DateTime().withTimeAtStartOfDay().plusDays(1).toDate()));
    final List<FieldDescriptor> fieldDescriptors = FieldSetDescriptorRegister
            .getFieldSetDescriptor(AuditLogEntry.class).getFieldDescriptors();
    ContainerUtil.addContainerProperties(entityContainer, fieldDescriptors);

    // Initialize layout
    final GridLayout gridLayout = new GridLayout(1, 2);
    gridLayout.setSizeFull();/*from  w  w  w .  j  a v a  2  s.c  o  m*/
    gridLayout.setMargin(false);
    gridLayout.setSpacing(true);
    gridLayout.setRowExpandRatio(1, 1f);
    setViewContent(gridLayout);
    final HorizontalLayout buttonLayout = new HorizontalLayout();
    buttonLayout.setSpacing(true);
    buttonLayout.setSizeUndefined();
    gridLayout.addComponent(buttonLayout, 0, 0);

    // Initialize grid
    entityGrid = new Grid(new Table(), entityContainer);
    entityGrid.setFields(fieldDescriptors);
    entityGrid.setFilters(filterDescriptors);
    gridLayout.addComponent(entityGrid, 0, 1);

    final Button viewButton = getSite().getButton("view");
    buttonLayout.addComponent(viewButton);
    viewButton.addClickListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            final AuditLogEntry entity = entityContainer.getEntity(entityGrid.getSelectedItemId());
            final AuditLogEntryFlowlet contentView = getFlow().forward(AuditLogEntryFlowlet.class);
            contentView.edit(entity, false);
        }
    });

}

From source file:org.vaadin.addons.sitekit.module.content.view.ContentFlowlet.java

License:Apache License

@Override
public void initialize() {
    entityManager = getSite().getSiteContext().getObject(EntityManager.class);

    final GridLayout gridLayout = new GridLayout(1, 2);
    gridLayout.setSizeFull();//w w  w  .  j av  a2s .  c  o  m
    gridLayout.setMargin(false);
    gridLayout.setSpacing(true);
    gridLayout.setRowExpandRatio(1, 1f);
    setViewContent(gridLayout);

    contentEditor = new ValidatingEditor(
            FieldSetDescriptorRegister.getFieldSetDescriptor(Content.class).getFieldDescriptors());
    contentEditor.setCaption("Content");
    contentEditor.addListener(this);
    gridLayout.addComponent(contentEditor, 0, 0);

    final HorizontalLayout buttonLayout = new HorizontalLayout();
    buttonLayout.setSpacing(true);
    gridLayout.addComponent(buttonLayout, 0, 1);

    saveButton = getSite().getButton("save");
    buttonLayout.addComponent(saveButton);
    saveButton.addClickListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            if (isValid()) {
                contentEditor.commit();
                ContentDao.saveContent(entityManager, entity);
                editPrivilegesButton.setEnabled(true);
            } else {
                Notification.show(getSite().localize("message-invalid-form-content"),
                        Notification.Type.HUMANIZED_MESSAGE);
            }
        }
    });

    discardButton = getSite().getButton("discard");
    buttonLayout.addComponent(discardButton);
    discardButton.addClickListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            contentEditor.discard();
        }
    });

    editPrivilegesButton = getSite().getButton("edit-privileges");
    buttonLayout.addComponent(editPrivilegesButton);
    editPrivilegesButton.addClickListener(new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            final PrivilegesFlowlet privilegesFlowlet = getFlow().getFlowlet(PrivilegesFlowlet.class);
            privilegesFlowlet.edit(entity.getPage(), entity.getContentId(), "view", "edit");
            getFlow().forward(PrivilegesFlowlet.class);
        }
    });
}

From source file:org.vaadin.addons.sitekit.module.content.view.ContentsFlowlet.java

License:Apache License

@Override
public void initialize() {
    // Get entity manager from site context and prepare container.
    final EntityManager entityManager = getSite().getSiteContext().getObject(EntityManager.class);
    entityContainer = new EntityContainer<Content>(entityManager, true, false, false, Content.class, 1000,
            new String[] { "page" }, new boolean[] { true }, "contentId");

    // Get descriptors and set container properties.
    final List<FilterDescriptor> filterDescriptors = new ArrayList<FilterDescriptor>();
    final List<FieldDescriptor> fieldDescriptors = FieldSetDescriptorRegister
            .getFieldSetDescriptor(Content.class).getFieldDescriptors();
    ContainerUtil.addContainerProperties(entityContainer, fieldDescriptors);

    // Initialize layout
    final GridLayout gridLayout = new GridLayout(1, 2);
    gridLayout.setSizeFull();//  ww  w .ja  v  a  2 s  .  c  om
    gridLayout.setMargin(false);
    gridLayout.setSpacing(true);
    gridLayout.setRowExpandRatio(1, 1f);
    setViewContent(gridLayout);
    final HorizontalLayout buttonLayout = new HorizontalLayout();
    buttonLayout.setSpacing(true);
    buttonLayout.setSizeUndefined();
    gridLayout.addComponent(buttonLayout, 0, 0);

    // Initialize grid
    entityGrid = new Grid(new Table(), entityContainer);
    entityGrid.setFields(fieldDescriptors);
    entityGrid.setFilters(filterDescriptors);
    gridLayout.addComponent(entityGrid, 0, 1);

    final Button addButton = getSite().getButton("add");
    buttonLayout.addComponent(addButton);
    addButton.addClickListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            final Content content = new Content();
            content.setCreated(new Date());
            content.setModified(content.getCreated());
            content.setOwner((Company) getSite().getSiteContext().getObject(Company.class));
            final ContentFlowlet contentView = getFlow().forward(ContentFlowlet.class);
            contentView.edit(content, true);
        }
    });

    final Button editButton = getSite().getButton("edit");
    buttonLayout.addComponent(editButton);
    editButton.addClickListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            final Content entity = entityContainer.getEntity(entityGrid.getSelectedItemId());
            final ContentFlowlet contentView = getFlow().forward(ContentFlowlet.class);
            contentView.edit(entity, false);
        }
    });

    final Button removeButton = getSite().getButton("remove");
    buttonLayout.addComponent(removeButton);
    removeButton.addClickListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            entityContainer.removeItem(entityGrid.getSelectedItemId());
            entityContainer.commit();
        }
    });
}

From source file:org.vaadin.addons.sitekit.site.FixedWidthView.java

License:Apache License

/**
 * {@inheritDoc}//from  w w  w .ja v a  2  s . c  om
 */
@Override
protected void initializeComponents() {
    final int columnCount = 5;
    final int rowCount = 3;

    final GridLayout layout = this;
    layout.setMargin(true);
    layout.setColumns(columnCount);
    layout.setRows(rowCount);
    layout.setColumnExpandRatio(0, MARGIN_COLUMN_EXPAND_RATIO);
    layout.setColumnExpandRatio(MARGIN_COLUMN_RIGTH_INDEX, MARGIN_COLUMN_EXPAND_RATIO);
    layout.setRowExpandRatio(1, 1.0f);
    layout.setSizeFull();
    layout.setMargin(false);
    layout.setSpacing(true);

    final AbstractComponent logoComponent = getComponent("logo");
    logoComponent.setWidth(NAVIGATION_COLUMN_WIDTH, Unit.PIXELS);
    layout.addComponent(logoComponent, 1, 0);

    final AbstractComponent navigationComponent = getComponent("navigation");
    navigationComponent.setWidth(NAVIGATION_COLUMN_WIDTH, Unit.PIXELS);
    navigationComponent.setHeight(NAVIGATION_HEIGHT, Unit.PIXELS);
    layout.addComponent(navigationComponent, 1, 1);

    final AbstractComponent headerComponent = getComponent("header");
    headerComponent.setWidth(CONTENT_COLUMN_WIDTH, Unit.PIXELS);
    headerComponent.setSizeFull();
    layout.addComponent(headerComponent, 2, 0);

    final AbstractComponent contentComponent = getComponent("content");
    contentComponent.setWidth(CONTENT_COLUMN_WIDTH, Unit.PIXELS);
    contentComponent.setSizeFull();
    layout.addComponent(contentComponent, 2, 1);

    final AbstractComponent footerComponent = getComponent("footer");
    headerComponent.setWidth(CONTENT_COLUMN_WIDTH, Unit.PIXELS);
    layout.addComponent(footerComponent, 2, 2);
}

From source file:org.vaadin.addons.sitekit.viewlet.administrator.company.CompanyFlowlet.java

License:Apache License

@Override
public void initialize() {
    entityManager = getSite().getSiteContext().getObject(EntityManager.class);

    final GridLayout gridLayout = new GridLayout(3, 2);
    gridLayout.setSizeFull();//from   w ww.j a  v  a 2  s  .  com
    gridLayout.setMargin(false);
    gridLayout.setSpacing(true);
    gridLayout.setRowExpandRatio(1, 1f);
    setViewContent(gridLayout);

    companyEditor = new ValidatingEditor(SiteFields.getFieldDescriptors(Company.class));
    companyEditor.setCaption("Site");
    companyEditor.addListener((ValidatingEditorStateListener) this);
    gridLayout.addComponent(companyEditor, 0, 0);

    invoicingAddressEditor = new ValidatingEditor(SiteFields.getFieldDescriptors(PostalAddress.class));
    invoicingAddressEditor.setCaption("Invoicing Address");
    invoicingAddressEditor.addListener((ValidatingEditorStateListener) this);
    gridLayout.addComponent(invoicingAddressEditor, 1, 0);

    deliveryAddressEditor = new ValidatingEditor(SiteFields.getFieldDescriptors(PostalAddress.class));
    deliveryAddressEditor.setCaption("Delivery Address");
    deliveryAddressEditor.addListener((ValidatingEditorStateListener) this);
    gridLayout.addComponent(deliveryAddressEditor, 2, 0);

    final HorizontalLayout buttonLayout = new HorizontalLayout();
    buttonLayout.setSpacing(true);
    gridLayout.addComponent(buttonLayout, 0, 1);

    saveButton = new Button("Save");
    saveButton.setImmediate(true);
    buttonLayout.addComponent(saveButton);
    saveButton.addListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            companyEditor.commit();
            invoicingAddressEditor.commit();
            deliveryAddressEditor.commit();
            entityManager.getTransaction().begin();
            try {
                entity = entityManager.merge(entity);
                entityManager.persist(entity);
                entityManager.getTransaction().commit();
                entityManager.detach(entity);
            } catch (final Throwable t) {
                if (entityManager.getTransaction().isActive()) {
                    entityManager.getTransaction().rollback();
                }
                throw new RuntimeException("Failed to save entity: " + entity, t);
            }
        }
    });

    discardButton = new Button("Discard");
    discardButton.setImmediate(true);
    buttonLayout.addComponent(discardButton);
    discardButton.addListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            companyEditor.discard();
            invoicingAddressEditor.discard();
            deliveryAddressEditor.discard();
        }
    });

}

From source file:org.vaadin.addons.sitekit.viewlet.administrator.customer.CustomerFlowlet.java

License:Apache License

@Override
public void initialize() {
    entityManager = getSite().getSiteContext().getObject(EntityManager.class);

    final GridLayout gridLayout = new GridLayout(3, 2);
    gridLayout.setSizeFull();//w w  w  .java2s  .c  o  m
    gridLayout.setMargin(false);
    gridLayout.setSpacing(true);
    gridLayout.setRowExpandRatio(1, 1f);
    setViewContent(gridLayout);

    customerEditor = new ValidatingEditor(SiteFields.getFieldDescriptors(Customer.class));
    customerEditor.setCaption("Customer");
    customerEditor.addListener((ValidatingEditorStateListener) this);
    gridLayout.addComponent(customerEditor, 0, 0);

    invoicingAddressEditor = new ValidatingEditor(SiteFields.getFieldDescriptors(PostalAddress.class));
    invoicingAddressEditor.setCaption("Invoicing Address");
    invoicingAddressEditor.addListener((ValidatingEditorStateListener) this);
    gridLayout.addComponent(invoicingAddressEditor, 1, 0);

    deliveryAddressEditor = new ValidatingEditor(SiteFields.getFieldDescriptors(PostalAddress.class));
    deliveryAddressEditor.setCaption("Delivery Address");
    deliveryAddressEditor.addListener((ValidatingEditorStateListener) this);
    gridLayout.addComponent(deliveryAddressEditor, 2, 0);

    final HorizontalLayout buttonLayout = new HorizontalLayout();
    buttonLayout.setSpacing(true);
    gridLayout.addComponent(buttonLayout, 0, 1);

    saveButton = new Button("Save");
    saveButton.setImmediate(true);
    buttonLayout.addComponent(saveButton);
    saveButton.addListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            customerEditor.commit();
            invoicingAddressEditor.commit();
            deliveryAddressEditor.commit();
            entity = entityManager.merge(entity);

            CustomerDao.saveCustomer(entityManager, entity);

            //entityManager.detach(entity);
        }
    });

    discardButton = new Button("Discard");
    discardButton.setImmediate(true);
    buttonLayout.addComponent(discardButton);
    discardButton.addListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            customerEditor.discard();
            invoicingAddressEditor.discard();
            deliveryAddressEditor.discard();
        }
    });

}

From source file:org.vaadin.addons.sitekit.viewlet.administrator.customer.CustomersFlowlet.java

License:Apache License

@Override
public void initialize() {
    final List<FieldDescriptor> fieldDefinitions = SiteFields.getFieldDescriptors(Customer.class);

    final List<FilterDescriptor> filterDefinitions = new ArrayList<FilterDescriptor>();
    filterDefinitions.add(new FilterDescriptor("companyName", "companyName", "Company Name", new TextField(),
            101, "=", String.class, ""));
    filterDefinitions.add(new FilterDescriptor("lastName", "lastName", "Last Name", new TextField(), 101, "=",
            String.class, ""));

    final EntityManager entityManager = getSite().getSiteContext().getObject(EntityManager.class);
    entityContainer = new EntityContainer<Customer>(entityManager, true, false, false, Customer.class, 1000,
            new String[] { "companyName", "lastName", "firstName" }, new boolean[] { true, true, true },
            "customerId");

    for (final FieldDescriptor fieldDefinition : fieldDefinitions) {
        entityContainer.addContainerProperty(fieldDefinition.getId(), fieldDefinition.getValueType(),
                fieldDefinition.getDefaultValue(), fieldDefinition.isReadOnly(), fieldDefinition.isSortable());
    }/* w  w w  .j a  v  a 2 s.  c  o m*/

    final GridLayout gridLayout = new GridLayout(1, 2);
    gridLayout.setSizeFull();
    gridLayout.setMargin(false);
    gridLayout.setSpacing(true);
    gridLayout.setRowExpandRatio(1, 1f);
    setViewContent(gridLayout);

    final HorizontalLayout buttonLayout = new HorizontalLayout();
    buttonLayout.setSpacing(true);
    buttonLayout.setSizeUndefined();
    gridLayout.addComponent(buttonLayout, 0, 0);

    final Table table = new Table();
    entityGrid = new Grid(table, entityContainer);
    entityGrid.setFields(fieldDefinitions);
    entityGrid.setFilters(filterDefinitions);
    //entityGrid.setFixedWhereCriteria("e.owner.companyId=:companyId");

    table.setColumnCollapsed("created", true);
    table.setColumnCollapsed("modified", true);
    table.setColumnCollapsed("company", true);
    gridLayout.addComponent(entityGrid, 0, 1);

    final Button addButton = new Button("Add");
    addButton.setIcon(getSite().getIcon("button-icon-add"));
    addButton.setWidth(100, UNITS_PIXELS);
    buttonLayout.addComponent(addButton);

    addButton.addListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            final Customer customer = new Customer();
            customer.setCreated(new Date());
            customer.setModified(customer.getCreated());
            customer.setInvoicingAddress(new PostalAddress());
            customer.setDeliveryAddress(new PostalAddress());
            customer.setOwner((Company) getSite().getSiteContext().getObject(Company.class));
            final CustomerFlowlet customerView = getFlow().forward(CustomerFlowlet.class);
            customerView.edit(customer, true);
        }
    });

    final Button editButton = new Button("Edit");
    editButton.setIcon(getSite().getIcon("button-icon-edit"));
    editButton.setWidth(100, UNITS_PIXELS);
    buttonLayout.addComponent(editButton);
    editButton.addListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            final Customer entity = entityContainer.getEntity(entityGrid.getSelectedItemId());
            final CustomerFlowlet customerView = getFlow().forward(CustomerFlowlet.class);
            customerView.edit(entity, false);
        }
    });

    final Button removeButton = new Button("Remove");
    removeButton.setIcon(getSite().getIcon("button-icon-remove"));
    removeButton.setWidth(100, UNITS_PIXELS);
    buttonLayout.addComponent(removeButton);
    removeButton.addListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            entityContainer.removeItem(entityGrid.getSelectedItemId());
            entityContainer.commit();
        }
    });

}