List of usage examples for com.vaadin.ui Grid addItemClickListener
public Registration addItemClickListener(ItemClickListener<? super T> listener)
From source file:org.jpos.qi.QIEntityView.java
License:Open Source License
public Grid createGrid() { Grid g = new Grid(); g.setSizeFull();/* w ww . jav a 2 s . c o m*/ g.setSelectionMode(Grid.SelectionMode.SINGLE); g.setColumnReorderingAllowed(true); g.addItemClickListener(event -> { navigateToSpecificView(event); }); return g; }
From source file:org.jumpmind.metl.ui.views.design.ManageProjectsPanel.java
License:Open Source License
protected Component buildVersionGrid(Project project) { context.getConfigurationService().refresh(project); List<ProjectVersion> versions = project.getProjectVersions(); BeanItemContainer<ProjectVersion> versionGridContainer = new BeanItemContainer<>(ProjectVersion.class); Grid versionGrid = new Grid(); VerticalLayout layout = new VerticalLayout(); layout.setWidth(100, Unit.PERCENTAGE); layout.setMargin(true);/* w w w .jav a2 s . c o m*/ layout.setSpacing(true); HorizontalLayout buttons = new HorizontalLayout(); buttons.setSpacing(true); Button openButton = new Button("Open", (event) -> { Collection<Object> selected = versionGrid.getSelectedRows(); for (Object object : selected) { projectNavigator.addProjectVersion(((ProjectVersion) object)); } }); buttons.addComponent(openButton); Button newButton = new Button("New Version", (event) -> newVersion(versionGrid)); buttons.addComponent(newButton); Button editButton = new Button("Edit Version", (event) -> edit(versionGrid)); buttons.addComponent(editButton); Button removeButton = new Button("Remove Version", (event) -> removeVersion(versionGrid)); buttons.addComponent(removeButton); openButton.setEnabled(false); newButton.setEnabled(false); removeButton.setEnabled(false); editButton.setEnabled(false); layout.addComponent(buttons); versionGrid.setWidth(100, Unit.PERCENTAGE); versionGrid.setHeight(3 + (versions.size() * ROW_EM), Unit.EM); versionGrid.setEditorEnabled(true); versionGrid.setSelectionMode(SelectionMode.MULTI); versionGrid.addColumn("versionLabel", String.class).setHeaderCaption("Version").setExpandRatio(2); versionGrid.addColumn("description", String.class).setHeaderCaption("Description").setExpandRatio(1); versionGrid.addColumn("readOnly", Boolean.class).setHeaderCaption("Read Only").setMaximumWidth(100) .setRenderer(new HtmlRenderer(), new StringToBooleanConverter() { private static final long serialVersionUID = 1L; protected String getTrueString() { return FontAwesome.CHECK.getHtml(); }; protected String getFalseString() { return ""; }; }); versionGrid.addColumn("createTime", Date.class).setHeaderCaption("Create Time").setWidth(185) .setMaximumWidth(200).setRenderer(new DateRenderer(UiConstants.DATETIME_FORMAT)).setEditable(false); versionGrid.setContainerDataSource(versionGridContainer); versionGrid.setEditorFieldFactory(new FieldFactory()); versionGrid.getEditorFieldGroup().addCommitHandler(new FieldGroup.CommitHandler() { private static final long serialVersionUID = 1L; @Override public void preCommit(CommitEvent commitEvent) throws CommitException { } @Override public void postCommit(CommitEvent commitEvent) throws CommitException { ProjectVersion item = (ProjectVersion) versionGrid.getEditedItemId(); IConfigurationService configurationService = context.getConfigurationService(); configurationService.save(item); projectGrid.markAsDirty(); } }); versionGrid.addSelectionListener((event) -> { int numberSelected = versionGrid.getSelectedRows().size(); boolean currentlyEditing = projectGrid.getEditedItemId() != null; boolean selected = numberSelected > 0 && !currentlyEditing; openButton.setEnabled(selected); newButton.setEnabled(selected); removeButton.setEnabled(selected); editButton.setEnabled(selected); }); versionGrid.addItemClickListener(new GridClickListener(versionGrid)); layout.addComponent(versionGrid); layout.setExpandRatio(versionGrid, 1); layout.addComponent(new Label(" ")); versionGridContainer.addAll(versions); versionGrid.sort("versionLabel", SortDirection.DESCENDING); return layout; }
From source file:org.vaadin.allaboutgrid.AllAboutGridUI.java
License:Apache License
private void initializeGrid(final Grid grid) { /*/*from ww w .j a v a 2 s .c o m*/ * Let's just add some data there to get something showing */ // grid.addColumn("Col 1"); // grid.addColumn("Col 2"); // // grid.addRow("Some", "data"); // grid.addRow("Another", "row"); /* * Let's use a full-featured container instead */ BeanItemContainer<Order> orderContainer = createOrderContainer(); grid.setContainerDataSource(orderContainer); /* * Changing the column order and adjusting column headers */ grid.setColumnOrder("id", "customer", "product", "orderAmount", "reservedAmount", "completePercentage", "priority", "customized", "orderTime"); grid.getColumn("orderAmount").setHeaderCaption("Ordered"); grid.getColumn("reservedAmount").setHeaderCaption("Reserved"); grid.getColumn("completePercentage").setHeaderCaption("Complete"); grid.getColumn("customized").setHeaderCaption("Custom"); /* * Removing unwanted columns */ // grid.removeColumn("customer"); // grid.removeColumn("customized"); // grid.removeColumn("priority"); // grid.removeColumn("orderTime"); /* * Adjusting column sizes */ grid.getColumn("id").setMaximumWidth(70); grid.getColumn("customer").setMinimumWidth(200); grid.getColumn("product").setMinimumWidth(200); /* * Keep some columns in view all the time */ grid.getColumn("product").setLastFrozenColumn(); /* * Changing the locale affects how data is presented */ grid.setLocale(Locale.GERMANY); /* * Various ways of tweaking how data is shown */ grid.getColumn("id").setRenderer(new NumberRenderer(idFormat)); grid.getColumn("completePercentage") .setRenderer(new NumberRenderer(NumberFormat.getPercentInstance(grid.getLocale()))); grid.getColumn("completePercentage").setRenderer(new ProgressBarRenderer()); grid.getColumn("customized").setConverter(new BooleanToFontIconConverter()); grid.getColumn("customized").setRenderer(new HtmlRenderer()); grid.setCellStyleGenerator(new CellStyleGenerator() { @Override public String getStyle(CellReference cellReference) { if ("priority".equals(cellReference.getPropertyId())) { Priority priority = (Priority) cellReference.getValue(); return "priority-" + priority.name().toLowerCase(); } else { return null; } } }); /* * Additional header spanned cells */ HeaderRow extraHeader = grid.prependHeaderRow(); extraHeader.join("orderAmount", "reservedAmount").setText("Quantity"); extraHeader.join("priority", "customized").setText("Status"); /* * Footer with various types of content */ FooterRow extraFooter = grid.appendFooterRow(); int totalOrdered = OrderUtil.getTotalOrderAmount(orderContainer); extraFooter.getCell("orderAmount").setText(Integer.toString(totalOrdered)); int totalReserved = OrderUtil.getTotalReservedAmounT(orderContainer); extraFooter.getCell("reservedAmount").setHtml("<b>" + totalReserved + "</b>"); extraFooter.getCell("completePercentage") .setComponent(new ProgressBar(totalReserved / (float) totalOrdered)); /* * Enable editing */ grid.setEditorEnabled(true); grid.setFrozenColumnCount(0); grid.getColumn("id").setEditable(false); grid.getColumn("completePercentage").setEditable(false); grid.getColumn("customized").getEditorField().setCaption(""); grid.getColumn("orderTime").setEditorField(createOrderTimeField()); Field<?> customerField = grid.getColumn("customer").getEditorField(); customerField.setRequired(true); customerField.setRequiredError("Value is required"); /* * Get an event when the users saves in the editor */ grid.getEditorFieldGroup().addCommitHandler(new CommitHandler() { @Override public void preCommit(CommitEvent commitEvent) throws CommitException { // Do nothing } @Override public void postCommit(CommitEvent commitEvent) throws CommitException { Notification.show("Changes saved"); } }); /* * New feature going into Vaadin 7.5: Column reordering */ grid.setColumnReorderingAllowed(true); /* * New feature going into Vaadin 7.5: Row details */ grid.setDetailsGenerator(new DetailsGenerator() { @Override public Component getDetails(RowReference rowReference) { Order order = (Order) rowReference.getItemId(); String detailsMessage = "This is a label with information about the order of " + order.getProduct() + " by " + order.getCustomer() + "."; Button deleteButton = new Button("Delete order", new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { Notification.show("Button clicked"); } }); VerticalLayout layout = new VerticalLayout(new Label(detailsMessage), deleteButton); layout.setMargin(true); layout.setSpacing(true); return layout; } }); grid.addItemClickListener(new ItemClickListener() { @Override public void itemClick(ItemClickEvent event) { if (event.isDoubleClick()) { Object itemId = event.getItemId(); grid.setDetailsVisible(itemId, !grid.isDetailsVisible(itemId)); } } }); grid.setEditorEnabled(false); /* * That's all. Thank you for watching! */ }