List of usage examples for com.vaadin.ui Button setWidth
@Override public void setWidth(float width, Unit unit)
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()); }/* www .ja v a2 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(); } }); }
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; }/*from ww w .ja va 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(); } }); }