List of usage examples for com.vaadin.ui Grid Grid
public Grid(String caption, Collection<T> items)
From source file:com.mycompany.controller.DayGrid.java
public Grid getGrid() { dbutil dbu = new dbutil(); ArrayList rs = null;/* ww w. ja v a 2 s .co m*/ try { rs = dbu.selectAllByDay(nameOfDay); } catch (SQLException | ClassNotFoundException | InstantiationException | IllegalAccessException ex) { Logger.getLogger(MyUI.class.getName()).log(Level.SEVERE, null, ex); } BeanItemContainer<Food> container = new BeanItemContainer<>(Food.class); //grid feltlt container.addAll(rs); container.setItemSorter(new DefaultItemSorter(new Comparator() { //anonim innner class @Override public int compare(Object o1, Object o2) { Days a = (Days) o1; Days b = (Days) o2; return a.getPriority() - b.getPriority(); } })); grid = new Grid(nameOfDay, container); grid.addItemClickListener(new ItemClickEvent.ItemClickListener() { //anonim innner class @Override public void itemClick(ItemClickEvent event) { System.err.println(event); } }); grid.setStyleName("monday"); //stlus neve grid.setEditorEnabled(true); //szerkeszts engedlyezs grid.getColumn("name").setEditable(false); //szerk. tiltsa grid.getColumn("price").setEditable(false); grid.getColumn("menu").setEditable(false); Grid.FooterRow mondayFooter = grid.appendFooterRow(); //lblc hozzads mondayFooter.setStyleName("mondayFooter"); grid.setFooterVisible(true); //lthat mondayFooter.join("name", "price", "menu", "quantity"); //cellaegyests grid.setSelectionMode(Grid.SelectionMode.MULTI); //tbb cella kijellse grid.setWidth(100, Sizeable.Unit.PERCENTAGE); //mretezs grid.setHeight("600px"); return grid; }
From source file:net.sourceforge.javydreamercsw.validation.manager.web.dashboard.DashboardProvider.java
License:Apache License
@Override public Component getContent() { try {/* w w w . j a v a 2 s . c o m*/ BorderLayout bl = new BorderLayout(); //Add activity stream List<Activity> activities = ActivityServer.getActivities(); BeanItemContainer<Activity> container = new BeanItemContainer<>(Activity.class, activities); GeneratedPropertyContainer gpc = new GeneratedPropertyContainer(container); gpc.addGeneratedProperty("avatar", new PropertyValueGenerator<Resource>() { @Override public Resource getValue(Item item, Object itemId, Object propertyId) { VmUser user = ((Activity) itemId).getSourceUser(); Resource image = new ThemeResource("VMSmall.png"); AvatarProvider ap = Lookup.getDefault().lookup(AvatarProvider.class); Resource icon = ap == null ? null : ap.getAvatar(user, 30); if (icon != null) { image = icon; } return image; } @Override public Class<Resource> getType() { return Resource.class; } }); Grid grid = new Grid(TRANSLATOR.translate("general.activity.stream"), gpc); Column at = grid.getColumn("activityType"); at.setHeaderCaption(TRANSLATOR.translate("activity.type")); at.setConverter(new Converter<String, ActivityType>() { int type; @Override public ActivityType convertToModel(String value, Class<? extends ActivityType> targetType, Locale locale) throws Converter.ConversionException { return new ActivityTypeJpaController(DataBaseManager.getEntityManagerFactory()) .findActivityType(type); } @Override public String convertToPresentation(ActivityType value, Class<? extends String> targetType, Locale locale) throws Converter.ConversionException { type = value.getId(); return TRANSLATOR.translate(value.getTypeName()); } @Override public Class<ActivityType> getModelType() { return ActivityType.class; } @Override public Class<String> getPresentationType() { return String.class; } }); Column type = grid.getColumn("activityType"); type.setHeaderCaption(TRANSLATOR.translate("general.type")); Column desc = grid.getColumn("description"); desc.setHeaderCaption(TRANSLATOR.translate("general.description")); Column user = grid.getColumn("sourceUser"); user.setHeaderCaption(TRANSLATOR.translate("general.user")); user.setConverter(new Converter<String, VmUser>() { private int user; @Override public String convertToPresentation(VmUser value, Class<? extends String> targetType, Locale l) throws Converter.ConversionException { try { user = value.getId(); return new VMUserServer(user).toString(); } catch (Exception ex) { Exceptions.printStackTrace(ex); } return ""; } @Override public Class<VmUser> getModelType() { return VmUser.class; } @Override public Class<String> getPresentationType() { return String.class; } @Override public VmUser convertToModel(String value, Class<? extends VmUser> targetType, Locale locale) throws Converter.ConversionException { return new VmUserJpaController(DataBaseManager.getEntityManagerFactory()).findVmUser(user); } }); Column avatar = grid.getColumn("avatar"); avatar.setHeaderCaption(""); avatar.setRenderer(new ImageRenderer()); Column time = grid.getColumn("activityTime"); time.setHeaderCaption(TRANSLATOR.translate("general.time")); grid.setColumns("avatar", "sourceUser", "activityType", "description", "activityTime"); grid.sort("activityTime", SortDirection.DESCENDING); bl.addComponent(grid, BorderLayout.Constraint.CENTER); bl.setId(getComponentCaption()); return bl; } catch (IllegalArgumentException | IllegalStateException ex) { Exceptions.printStackTrace(ex); } return null; }
From source file:net.sourceforge.javydreamercsw.validation.manager.web.notification.NotificationScreenProvider.java
License:Apache License
@Override public Component getContent() { VerticalLayout vs = new VerticalLayout(); //On top put a list of notifications BeanItemContainer<Notification> container = new BeanItemContainer<>(Notification.class); ValidationManagerUI.getInstance().getUser().getNotificationList().forEach(n -> { container.addBean(n);/* www . jav a2s. co m*/ }); // Unable to use VerticalSplitPanel as I hoped. // See: https://github.com/vaadin/framework/issues/9460 // VerticalSplitPanel vs = new VerticalSplitPanel(); // vs.setSplitPosition(25, Sizeable.Unit.PERCENTAGE); TextArea text = new TextArea(TRANSLATOR.translate("general.text")); text.setWordwrap(true); text.setReadOnly(true); text.setSizeFull(); Grid grid = new Grid(TRANSLATOR.translate("general.notifications"), container); grid.setColumns("notificationType", "author", "creationDate", "archieved"); if (container.size() > 0) { grid.setHeightMode(HeightMode.ROW); grid.setHeightByRows(container.size() > 5 ? 5 : container.size()); } GridCellFilter filter = new GridCellFilter(grid); filter.setBooleanFilter("archieved", new GridCellFilter.BooleanRepresentation(VaadinIcons.CHECK, TRANSLATOR.translate("general.yes")), new GridCellFilter.BooleanRepresentation(VaadinIcons.CLOSE, TRANSLATOR.translate("general.no"))); filter.setDateFilter("creationDate", new SimpleDateFormat(VMSettingServer.getSetting("date.format").getStringVal()), true); grid.sort("creationDate"); Column nt = grid.getColumn("notificationType"); nt.setHeaderCaption(TRANSLATOR.translate("notification.type")); nt.setConverter(new Converter<String, NotificationType>() { @Override public NotificationType convertToModel(String value, Class<? extends NotificationType> targetType, Locale locale) throws Converter.ConversionException { for (NotificationType n : new NotificationTypeJpaController( DataBaseManager.getEntityManagerFactory()).findNotificationTypeEntities()) { if (Lookup.getDefault().lookup(InternationalizationProvider.class).translate(n.getTypeName()) .equals(value)) { return n; } } return null; } @Override public String convertToPresentation(NotificationType value, Class<? extends String> targetType, Locale locale) throws Converter.ConversionException { return Lookup.getDefault().lookup(InternationalizationProvider.class) .translate(value.getTypeName()); } @Override public Class<NotificationType> getModelType() { return NotificationType.class; } @Override public Class<String> getPresentationType() { return String.class; } }); Column author = grid.getColumn("author"); author.setConverter(new UserToStringConverter()); author.setHeaderCaption(TRANSLATOR.translate("notification.author")); Column creation = grid.getColumn("creationDate"); creation.setHeaderCaption(TRANSLATOR.translate("creation.time")); Column archive = grid.getColumn("archieved"); archive.setHeaderCaption(TRANSLATOR.translate("general.archived")); archive.setConverter(new Converter<String, Boolean>() { @Override public Boolean convertToModel(String value, Class<? extends Boolean> targetType, Locale locale) throws Converter.ConversionException { return value.equals(TRANSLATOR.translate("general.yes")); } @Override public String convertToPresentation(Boolean value, Class<? extends String> targetType, Locale locale) throws Converter.ConversionException { return value ? TRANSLATOR.translate("general.yes") : TRANSLATOR.translate("general.no"); } @Override public Class<Boolean> getModelType() { return Boolean.class; } @Override public Class<String> getPresentationType() { return String.class; } }); grid.setSelectionMode(SelectionMode.SINGLE); grid.setSizeFull(); ContextMenu menu = new ContextMenu(grid, true); menu.addItem(TRANSLATOR.translate("notification.mark.unread"), (MenuItem selectedItem) -> { Object selected = ((SingleSelectionModel) grid.getSelectionModel()).getSelectedRow(); if (selected != null) { NotificationServer ns = new NotificationServer((Notification) selected); ns.setAcknowledgeDate(null); try { ns.write2DB(); ((VMUI) UI.getCurrent()).updateScreen(); ((VMUI) UI.getCurrent()).showTab(getComponentCaption()); } catch (VMException ex) { LOG.log(Level.SEVERE, null, ex); } } }); menu.addItem(TRANSLATOR.translate("notification.archive"), (MenuItem selectedItem) -> { Object selected = ((SingleSelectionModel) grid.getSelectionModel()).getSelectedRow(); if (selected != null) { NotificationServer ns = new NotificationServer((Notification) selected); ns.setArchieved(true); try { ns.write2DB(); ((VMUI) UI.getCurrent()).updateScreen(); ((VMUI) UI.getCurrent()).showTab(getComponentCaption()); } catch (VMException ex) { LOG.log(Level.SEVERE, null, ex); } } }); grid.addSelectionListener(selectionEvent -> { // Get selection from the selection model Object selected = ((SingleSelectionModel) grid.getSelectionModel()).getSelectedRow(); if (selected != null) { text.setReadOnly(false); Notification n = (Notification) selected; text.setValue(n.getContent()); text.setReadOnly(true); if (n.getAcknowledgeDate() != null) { try { //Mark as read NotificationServer ns = new NotificationServer((Notification) n); ns.setAcknowledgeDate(new Date()); ns.write2DB(); } catch (VMException ex) { LOG.log(Level.SEVERE, null, ex); } } } }); vs.addComponent(grid); vs.addComponent(text); vs.setSizeFull(); vs.setId(getComponentCaption()); return vs; }
From source file:org.vaadin.peholmst.samples.dddwebinar.ui.appointments.BillingSection.java
@PostConstruct void init() {/*from www. jav a2 s. c o m*/ setSpacing(true); setMargin(false); setSizeFull(); Label title = new Label("Billing"); title.addStyleName(ValoTheme.LABEL_H2); addComponent(title); ledgerContainer = new BeanItemContainer<>(LedgerEntry.class); ledger = new Grid("Ledger", ledgerContainer); ledger.setSizeFull(); ledger.setSelectionMode(Grid.SelectionMode.NONE); ledger.setColumns("entryDate", "entryDescription", "entryAmount"); ledger.getColumn("entryDate").setHeaderCaption("Date"); ledger.getColumn("entryDescription").setHeaderCaption("Description"); ledger.getColumn("entryAmount").setHeaderCaption("Amount").setConverter(new MoneyConverter()); ledger.addFooterRowAt(0).getCell("entryDescription").setText("Outstanding"); addComponent(ledger); setExpandRatio(ledger, 1.0f); Accordion receivables = new Accordion(); receivables.setSizeFull(); addComponent(receivables); setExpandRatio(receivables, 1.0f); claimSubSection = new ClaimSubSection(); receivables.addTab(claimSubSection, "Insurance Claim"); invoiceSubSection = new InvoiceSubSection(); receivables.addTab(invoiceSubSection, "Invoice"); model.addObserver(this); // Same scope, no need to remove afterwards }
From source file:org.vaadin.peholmst.samples.dddwebinar.ui.appointments.DoctorSection.java
@PostConstruct void init() {//from w w w. j a v a 2 s . c o m setSizeFull(); setSpacing(true); Label title = new Label("Doctor"); title.addStyleName(ValoTheme.LABEL_H2); addComponent(title); doctorName = new TextField("Name"); doctorName.setWidth("100%"); addComponent(doctorName); licenseContainer = new BeanItemContainer<>(License.class); licenseContainer.addNestedContainerProperty("type.name"); Grid doctorLicenses = new Grid("Licenses", licenseContainer); doctorLicenses.setColumns("number", "type.name"); doctorLicenses.setSizeFull(); doctorLicenses.setSelectionMode(Grid.SelectionMode.NONE); addComponent(doctorLicenses); setExpandRatio(doctorLicenses, 1.0f); model.addObserver(this); // Same scope, no need to remove afterwards }
From source file:ru.schernolyas.mongodbogmwar.web.MondoDbUI.java
@Override protected void init(VaadinRequest request) { VerticalLayout layout = new VerticalLayout(); layout.setSpacing(true);//from w w w . ja va 2 s .c om BeanItemContainer<Person> persons = new BeanItemContainer<>(Person.class); try { persons.addAll(EJBUtil.getInstance().findPersonFacade().findAll()); } catch (NamingException ne) { throw new RuntimeException(ne); } Grid grid = new Grid("Persons", persons); grid.setColumns("id", "name"); grid.setWidth(100, Unit.PERCENTAGE); layout.addComponent(grid); setContent(layout); }