List of usage examples for com.vaadin.ui GridLayout setRowExpandRatio
public void setRowExpandRatio(int rowIndex, float ratio)
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();//from w w w . j a v a2 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 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}// w ww . j a v a 2s . c o m */ @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();//w ww . j a v a 2 s . c om 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. j ava 2 s . 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()); }//ww w .jav a2 s. com 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 w w .j a v a 2s .c o m*/ } 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 ww w . ja v a 2s .c om 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(); } }); }
From source file:org.vaadin.addons.sitekit.viewlet.administrator.group.GroupFlowlet.java
License:Apache License
@Override public void initialize() { entityManager = getSite().getSiteContext().getObject(EntityManager.class); final GridLayout layout = new GridLayout(2, 3); layout.setSizeFull();/* w ww . j av a2 s . c o m*/ layout.setMargin(false); layout.setSpacing(true); layout.setRowExpandRatio(1, 1f); setViewContent(layout); groupEditor = new ValidatingEditor(SiteFields.getFieldDescriptors(Group.class)); groupEditor.setCaption("Group"); groupEditor.addListener((ValidatingEditorStateListener) this); groupEditor.setReadOnly(detailsReadonly); layout.addComponent(groupEditor, 0, 1); final List<FieldDescriptor> childFieldDescriptors = SiteFields.getFieldDescriptors(GroupMember.class); final List<FilterDescriptor> childFilterDescriptors = new ArrayList<FilterDescriptor>(); childContainer = new EntityContainer<GroupMember>(entityManager, GroupMember.class, "groupMemberId", 1000, true, false, false); childContainer.getQueryView().getQueryDefinition().setDefaultSortState( new String[] { "user.firstName", "user.lastName" }, new boolean[] { true, true }); ContainerUtil.addContainerProperties(childContainer, childFieldDescriptors); final Table childTable = new FormattingTable(); childGrid = new Grid(childTable, childContainer); childGrid.setFields(childFieldDescriptors); childGrid.setFilters(childFilterDescriptors); childTable.setColumnCollapsed("created", true); layout.addComponent(childGrid, 1, 1); final HorizontalLayout editorButtonLayout = new HorizontalLayout(); editorButtonLayout.setSpacing(true); layout.addComponent(editorButtonLayout, 0, 2); saveButton = new Button("Save"); saveButton.setImmediate(true); editorButtonLayout.addComponent(saveButton); saveButton.addListener(new ClickListener() { /** Serial version UID. */ private static final long serialVersionUID = 1L; @Override public void buttonClick(final ClickEvent event) { groupEditor.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); editorButtonLayout.addComponent(discardButton); discardButton.addListener(new ClickListener() { /** Serial version UID. */ private static final long serialVersionUID = 1L; @Override public void buttonClick(final ClickEvent event) { groupEditor.discard(); } }); childListButtonLayout = new HorizontalLayout(); childListButtonLayout.setSpacing(true); childListButtonLayout.setSizeUndefined(); layout.addComponent(childListButtonLayout, 1, 0); final Button addButton = getSite().getButton("add"); childListButtonLayout.addComponent(addButton); addButton.addClickListener(new ClickListener() { /** Serial version UID. */ private static final long serialVersionUID = 1L; @Override public void buttonClick(final ClickEvent event) { final GroupMember groupMember = new GroupMember(); groupMember.setGroup(entity); groupMember.setCreated(new Date()); final GroupUserMemberFlowlet userGroupMemberFlowlet = getFlow() .forward(GroupUserMemberFlowlet.class); userGroupMemberFlowlet.edit(groupMember, true); } }); final Button removeButton = getSite().getButton("remove"); childListButtonLayout.addComponent(removeButton); removeButton.addClickListener(new ClickListener() { /** Serial version UID. */ private static final long serialVersionUID = 1L; @Override public void buttonClick(final ClickEvent event) { childContainer.removeItem(childGrid.getSelectedItemId()); childContainer.commit(); } }); }
From source file:org.vaadin.addons.sitekit.viewlet.administrator.group.GroupsFlowlet.java
License:Apache License
@Override public void initialize() { final List<FieldDescriptor> fieldDescriptors = SiteFields.getFieldDescriptors(Group.class); final List<FilterDescriptor> filterDefinitions = new ArrayList<FilterDescriptor>(); final EntityManager entityManager = getSite().getSiteContext().getObject(EntityManager.class); container = new EntityContainer<Group>(entityManager, true, false, false, Group.class, 1000, new String[] { "name" }, new boolean[] { true }, "groupId"); ContainerUtil.addContainerProperties(container, fieldDescriptors); final GridLayout gridLayout = new GridLayout(1, 2); gridLayout.setSizeFull();/*ww w . j av a2 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); final Table table = new FormattingTable(); grid = new Grid(table, container); grid.setFields(fieldDescriptors); grid.setFilters(filterDefinitions); table.setColumnCollapsed("created", true); table.setColumnCollapsed("modified", true); gridLayout.addComponent(grid, 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 Group group = new Group(); group.setCreated(new Date()); group.setModified(group.getCreated()); group.setOwner((Company) getSite().getSiteContext().getObject(Company.class)); final GroupFlowlet groupView = getFlow().forward(GroupFlowlet.class); groupView.edit(group, 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 Group entity = container.getEntity(grid.getSelectedItemId()); final GroupFlowlet groupView = getFlow().forward(GroupFlowlet.class); groupView.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) { final Group entity = container.getEntity(grid.getSelectedItemId()); final List<User> users = UserDao.getGroupMembers(entityManager, (Company) getSite().getSiteContext().getObject(Company.class), entity); for (final User user : users) { UserDao.removeGroupMember(entityManager, entity, user); } final List<Privilege> privileges = UserDao.getGroupPrivileges(entityManager, entity); for (final Privilege privilege : privileges) { UserDao.removeGroupPrivilege(entityManager, entity, privilege.getKey(), privilege.getDataId()); } container.removeItem(grid.getSelectedItemId()); container.commit(); } }); final Company company = getSite().getSiteContext().getObject(Company.class); container.removeDefaultFilters(); container.addDefaultFilter(new Compare.Equal("owner.companyId", company.getCompanyId())); grid.refresh(); }
From source file:org.vaadin.addons.sitekit.viewlet.administrator.group.GroupUserMemberFlowlet.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 a va 2 s . c o m*/ gridLayout.setMargin(false); gridLayout.setSpacing(true); gridLayout.setRowExpandRatio(1, 1f); setViewContent(gridLayout); final List<FieldDescriptor> fieldDescriptors = new ArrayList<FieldDescriptor>( SiteFields.getFieldDescriptors(GroupMember.class)); for (final FieldDescriptor fieldDescriptor : fieldDescriptors) { if ("group".equals(fieldDescriptor.getId())) { fieldDescriptors.remove(fieldDescriptor); break; } } groupMemberEditor = new ValidatingEditor(fieldDescriptors); groupMemberEditor.setCaption("GroupMember"); groupMemberEditor.addListener(this); gridLayout.addComponent(groupMemberEditor, 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) { groupMemberEditor.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) { groupMemberEditor.discard(); } }); }