Example usage for com.vaadin.ui GridLayout GridLayout

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

Introduction

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

Prototype

public GridLayout(int columns, int rows) 

Source Link

Document

Constructor for a grid of given size (number of columns and rows).

Usage

From source file:org.vaadin.addons.sitekit.grid.ValidatingEditor.java

License:Apache License

/**
 * Constructor which initializes the form.
 * @param fieldDescriptors The field definitions.
 *//*from  w  w  w.  j ava 2 s.  c om*/
public ValidatingEditor(final List<FieldDescriptor> fieldDescriptors) {
    this.fieldDescriptors = fieldDescriptors;

    form = new Form();
    form.setBuffered(true);
    form.setFormFieldFactory(this);
    form.setImmediate(true);
    setCompositionRoot(form);

    formLayout = new GridLayout(3, fieldDescriptors.size());
    formLayout.setSpacing(true);
    formLayout.setMargin(new MarginInfo(true, false, true, false));
    form.setLayout(formLayout);

    fieldIds = new Object[fieldDescriptors.size()];
    fields = new Field[fieldDescriptors.size()];
    fieldLabels = new Label[fieldDescriptors.size()];
    fieldIcons = new Embedded[fieldDescriptors.size()];
    for (int i = 0; i < fieldDescriptors.size(); i++) {
        final FieldDescriptor fieldDescriptor = fieldDescriptors.get(i);
        fieldIds[i] = fieldDescriptor.getId();
        fieldLabels[i] = new Label(fieldDescriptor.getLabel());
        fieldIcons[i] = new Embedded(null, noneIcon);
        fieldIcons[i].setWidth(20, UNITS_PIXELS);
        fieldIcons[i].setHeight(20, UNITS_PIXELS);

        formLayout.addComponent(fieldLabels[i], 0, i);
        formLayout.addComponent(fieldIcons[i], 2, i);
        formLayout.setComponentAlignment(fieldLabels[i], Alignment.MIDDLE_RIGHT);
    }
}

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 ww.  j a  va  2 s .co 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();/*from   w ww. j a va2 s . co 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 .j  a v a2s. 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 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.viewlet.administrator.company.CompaniesFlowlet.java

License:Apache License

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

    gridLayout = new GridLayout(1, 2);
    gridLayout.setSizeFull();//from www  .  j av  a  2 s.  c om
    gridLayout.setMargin(false);
    gridLayout.setSpacing(true);
    gridLayout.setRowExpandRatio(1, 1f);
    setViewContent(gridLayout);

    final List<FieldDescriptor> fieldDefinitions = SiteFields.getFieldDescriptors(Company.class);

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

    entityContainer = new EntityContainer<Company>(entityManager, true, false, false, Company.class, 1000,
            new String[] { "companyName" }, new boolean[] { false }, "companyId");
    for (final FieldDescriptor fieldDefinition : fieldDefinitions) {
        entityContainer.addContainerProperty(fieldDefinition.getId(), fieldDefinition.getValueType(),
                fieldDefinition.getDefaultValue(), fieldDefinition.isReadOnly(), fieldDefinition.isSortable());
    }

    final Table table = new Table();
    entityGrid = new Grid(table, entityContainer);
    entityGrid.setFields(fieldDefinitions);
    entityGrid.setFilters(filterDefinitions);

    table.setColumnCollapsed("created", true);
    table.setColumnCollapsed("modified", true);
    table.setColumnCollapsed("company", true);
    table.setColumnCollapsed("emailPasswordReset", true);
    table.setColumnCollapsed("openIdLogin", true);
    table.setColumnCollapsed("maxFailedLoginCount", true);
    table.setColumnCollapsed("salesEmailAddress", true);
    table.setColumnCollapsed("supportEmailAddress", true);
    table.setColumnCollapsed("invoicingEmailAddress", true);
    gridLayout.addComponent(entityGrid, 0, 1);

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

    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 Company company = new Company();
            company.setCreated(new Date());
            company.setModified(company.getCreated());
            company.setInvoicingAddress(new PostalAddress());
            company.setDeliveryAddress(new PostalAddress());
            final CompanyFlowlet companyView = getFlow().forward(CompanyFlowlet.class);
            companyView.edit(company, 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 Company entity = entityContainer.getEntity(entityGrid.getSelectedItemId());
            final CompanyFlowlet companyView = getFlow().forward(CompanyFlowlet.class);
            companyView.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();
        }
    });

}

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();/*  w  w w  . java 2s  .co  m*/
    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();//from  w  w w  .jav  a 2s .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());
    }//from   w  ww .ja  v  a2s.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();
        }
    });

}

From source file:org.vaadin.addons.sitekit.viewlet.administrator.directory.UserDirectoriesFlowlet.java

License:Apache License

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

    for (final FieldDescriptor fieldDescriptor : fieldDefinitions) {
        if (fieldDescriptor.getId().equals("loginPassword")) {
            fieldDefinitions.remove(fieldDescriptor);
            break;
        }/* w  ww  .  jav  a 2 s.c  om*/
    }

    final List<FilterDescriptor> filterDefinitions = new ArrayList<FilterDescriptor>();

    final EntityManager entityManager = getSite().getSiteContext().getObject(EntityManager.class);
    entityContainer = new EntityContainer<UserDirectory>(entityManager, true, false, false, UserDirectory.class,
            1000, new String[] { "address", "port" }, new boolean[] { true, true }, "userDirectoryId");

    for (final FieldDescriptor fieldDefinition : fieldDefinitions) {
        entityContainer.addContainerProperty(fieldDefinition.getId(), fieldDefinition.getValueType(),
                fieldDefinition.getDefaultValue(), fieldDefinition.isReadOnly(), fieldDefinition.isSortable());
    }

    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("loginDn", true);
    table.setColumnCollapsed("userEmailAttribute", true);
    table.setColumnCollapsed("userSearchBaseDn", true);
    table.setColumnCollapsed("groupSearchBaseDn", true);
    table.setColumnCollapsed("remoteLocalGroupMapping", true);
    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 UserDirectory userDirectory = new UserDirectory();
            userDirectory.setCreated(new Date());
            userDirectory.setModified(userDirectory.getCreated());
            userDirectory.setOwner((Company) getSite().getSiteContext().getObject(Company.class));
            final UserDirectoryFlowlet userDirectoryView = getFlow().forward(UserDirectoryFlowlet.class);
            userDirectoryView.edit(userDirectory, 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 UserDirectory entity = entityContainer.getEntity(entityGrid.getSelectedItemId());
            final UserDirectoryFlowlet userDirectoryView = getFlow().forward(UserDirectoryFlowlet.class);
            userDirectoryView.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();
        }
    });

}

From source file:org.vaadin.addons.sitekit.viewlet.administrator.directory.UserDirectoryFlowlet.java

License:Apache License

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

    final GridLayout gridLayout = new GridLayout(1, 2);
    gridLayout.setSizeFull();/*from  w ww  .ja  va  2s  .c  o m*/
    gridLayout.setMargin(false);
    gridLayout.setSpacing(true);
    gridLayout.setRowExpandRatio(1, 1f);
    setViewContent(gridLayout);

    userDirectoryEditor = new ValidatingEditor(SiteFields.getFieldDescriptors(UserDirectory.class));
    userDirectoryEditor.setCaption("UserDirectory");
    userDirectoryEditor.addListener((ValidatingEditorStateListener) this);
    gridLayout.addComponent(userDirectoryEditor, 0, 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) {
            userDirectoryEditor.commit();
            if (entity.getUserDirectoryId() == null) {
                UserDirectoryDao.addUserDirectory(entityManager, entity);
            } else {
                entity = entityManager.merge(entity);
                UserDirectoryDao.updateUserDirectory(entityManager, 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) {
            userDirectoryEditor.discard();
        }
    });

}