@SuppressWarnings("unchecked") @Override public HeaderCell join(P... propertyIdsToMerge) { ObjectUtils.argumentNotNull(propertyIdsToMerge, "Property ids to merge must be not null"); return row.join(Arrays.asList(propertyIdsToMerge).stream().map(id -> converter.apply(id)) .collect(Collectors.toList()).toArray(new String[0])); }
/** * Adds the generic grid header row configured in the header configs * * @param gridHeaderCell * the grid header cell * @param myCell * the my cell */ public static void addGenericGridHeaderRow(final HeaderCell gridHeaderCell, final Cell myCell) { if (gridHeaderCell.getCellType() .equals(GridStaticCellType.TEXT)) { myCell.setCellValue(gridHeaderCell.getText()); } else if (gridHeaderCell.getCellType() .equals(GridStaticCellType.HTML)) { myCell.setCellValue(gridHeaderCell.getHtml()); } else if (gridHeaderCell.getCellType() .equals(GridStaticCellType.WIDGET)) { myCell.setCellValue(gridHeaderCell.getComponent() .toString()); } }
@Override public HeaderCell getCell(P propertyId) { return row.getCell(converter.apply(propertyId)); }
@Override public HeaderCell join(Set<HeaderCell> cellsToMerge) { return row.join(cellsToMerge); }
@Override public HeaderCell join(HeaderCell... cellsToMerge) { return row.join(cellsToMerge); }
public WeaponTypeGrid() { super(); // withProperties("name", "proficiencyType", "handleType", "usageType", "oneHandBaseDamage", // "twoHandBaseDamage", "damageType", "isReach", "isFinesse", "isLoading"); // withColumnHeaders("Nom", "Maitrise", "Manipulation", "Usage", "1 main", "2 mains", // "Type de dommage", "Allonge", "Finesse", "Load"); // // Grid.Column reach = getColumn("isReach"); // reach.setRenderer(new HtmlRenderer(), // new StringToBooleanConverter(FontAwesome.CHECK_CIRCLE_O.getHtml(), FontAwesome.CIRCLE_O.getHtml())); // // Grid.Column finesse = getColumn("isFinesse"); // finesse.setRenderer(new HtmlRenderer(), // new StringToBooleanConverter(FontAwesome.CHECK_CIRCLE_O.getHtml(), FontAwesome.CIRCLE_O.getHtml())); // // Grid.Column loading = getColumn("isLoading"); // loading.setRenderer(new HtmlRenderer(), // new StringToBooleanConverter(FontAwesome.CHECK_CIRCLE_O.getHtml(), FontAwesome.CIRCLE_O.getHtml())); // // Grid.HeaderRow groupingHeader = prependHeaderRow(); // Grid.HeaderCell namesCell = groupingHeader.join(groupingHeader.getCell("oneHandBaseDamage"), // groupingHeader.getCell("twoHandBaseDamage")); // namesCell.setText("Dommage"); StringToBooleanConverter converter = new StringToBooleanConverter("", VaadinIcons.CHECK_CIRCLE_O.getHtml(), VaadinIcons.CIRCLE_THIN.getHtml()); addColumn(WeaponType::getName).setCaption("Nom").setId("name"); addColumn(WeaponType::getProficiencyType).setCaption("Maitrise").setId("proficiencyType"); addColumn(WeaponType::getHandleType).setCaption("Manipulation").setId("handleType"); addColumn(WeaponType::getUsageType).setCaption("Usage").setId("usage"); addColumn(WeaponType::getOneHandBaseDamage).setCaption("1 main").setId("oneHandBaseDamage"); addColumn(WeaponType::getTwoHandBaseDamage).setCaption("2 mains").setId("twoHandBaseDamage"); addColumn(WeaponType::getDamageType).setCaption("Type de dommage").setId("damageType"); addColumn(weaponType -> converter.convertToPresentation(weaponType.getIsReach(), new ValueContext()), new HtmlRenderer()) .setCaption("Allonge"); addColumn(weaponType -> converter.convertToPresentation(weaponType.getIsFinesse(), new ValueContext()), new HtmlRenderer()) .setCaption("Finesse"); addColumn(weaponType -> converter.convertToPresentation(weaponType.getIsLoading(), new ValueContext()), new HtmlRenderer()) .setCaption("Recharge"); HeaderRow groupingHeader = prependHeaderRow(); HeaderCell namesCell = groupingHeader.join(groupingHeader.getCell("oneHandBaseDamage"), groupingHeader.getCell("twoHandBaseDamage")); namesCell.setText("Dommage"); }
@Override protected void init(final VaadinRequest request) { // Creating the Export Tool Bar MenuBar exportToolBar = createToolBar(); final VerticalLayout layout = new VerticalLayout(); layout.setSizeFull(); // Adding the Export Tool Bar to the Layout layout.addComponent(exportToolBar); /********* * Adding Components to the Layout namely Tables, Grids and Tree Table *******/ this.gridDefault = new Grid<>(DataModel.class); this.gridDefault.setDataProvider(new ListDataProvider<>(DataModelGenerator.generate(20))); this.gridDefault.setSizeFull(); this.gridDefault.setColumns(this.visibleColumns); this.gridMergedCells = new Grid<>(DataModel.class); this.gridMergedCells.setDataProvider(new ListDataProvider<>(DataModelGenerator.generate(20))); this.gridMergedCells.setColumns(this.visibleColumns); this.gridMergedCells.setSizeFull(); HeaderRow headerRow = this.gridMergedCells.addHeaderRowAt(0); HeaderCell joinHeaderColumns1 = headerRow.join("country", "productType"); joinHeaderColumns1.setText("mergedCell"); HeaderCell joinHeaderColumns2 = headerRow.join("cheapest", "contractor"); joinHeaderColumns2.setText("mergedCell"); FooterRow footerRow1 = this.gridMergedCells.addFooterRowAt(0); FooterCell joinFooterColumns1 = footerRow1.join("country", "productType"); joinFooterColumns1.setText("mergedCell"); FooterCell joinFooterColumns2 = footerRow1.join("cheapest", "contractor"); joinFooterColumns2.setText("mergedCell"); FooterRow footerRow2 = this.gridMergedCells.addFooterRowAt(0); for (int i = 0; i < this.visibleColumns.length; i++) { footerRow2.getCell(this.visibleColumns[i]) .setText(this.columnHeaders[i]); } this.gridFrozenColumns = new Grid<>(DataModel.class); this.gridFrozenColumns.setDataProvider(new ListDataProvider<>(DataModelGenerator.generate(20))); this.gridFrozenColumns.setColumns(this.visibleColumns); this.gridFrozenColumns.getColumn("country") .setWidth(300); this.gridFrozenColumns.getColumn("productType") .setWidth(300); this.gridFrozenColumns.getColumn("catalogue") .setWidth(300); this.gridFrozenColumns.setSizeFull(); this.gridFrozenColumns.setFrozenColumnCount(3); TabSheet tabSheet = new TabSheet(); tabSheet.setSizeFull(); tabSheet.addTab(this.gridDefault, "Grid (Default)"); tabSheet.addTab(this.gridMergedCells, "Grid (Merged Cells)"); tabSheet.addTab(this.gridFrozenColumns, "Grid (Frozen Columns&Rows)"); layout.addComponent(tabSheet); layout.setExpandRatio(tabSheet, 1); /********* * Adding Components to the Layout namely Tables, Grids and Tree Table *******/ /********* * Adding the above data to the containers or components *******/ setContent(layout); }
/** * Returns the cell on this row corresponding to the given property id. * @param propertyId the id of the property/column whose header cell to get, not null * @return the header cell * @throws IllegalArgumentException if there is no such column in the grid */ HeaderCell getCell(P propertyId);
/** * Merges cells corresponding to the given property ids in the row. Original cells are hidden, and new merged * cell is shown instead. The cell has a width of all merged cells together, inherits styles of the first merged * cell but has empty caption. * @param propertyIdsToMerge the ids of the property/column of the cells that should be merged. The cells should * not be merged to any other cell set. * @return the remaining visible cell after the merge */ @SuppressWarnings("unchecked") HeaderCell join(P... propertyIdsToMerge);
/** * Merges column cells in the row. Original cells are hidden, and new merged cell is shown instead. The cell has * a width of all merged cells together, inherits styles of the first merged cell but has empty caption. * @param cellsToMerge the cells which should be merged. The cells should not be merged to any other cell set. * @return the remaining visible cell after the merge */ HeaderCell join(Set<HeaderCell> cellsToMerge);
/** * Merges column cells in the row. Original cells are hidden, and new merged cell is shown instead. The cell has * a width of all merged cells together, inherits styles of the first merged cell but has empty caption. * @param cellsToMerge the cells which should be merged. The cells should not be merged to any other cell set. * @return the remaining visible cell after the merge */ HeaderCell join(HeaderCell... cellsToMerge);