@Override protected void internalSetDataProvider(DataProvider<T, ?> dataProvider) { super.internalSetDataProvider(dataProvider); for (Column<T, ?> column : getColumns()) { column.updateSortable(); } } }
/** * Removes all columns from this Grid. * * @since 8.0.2 */ public void removeAllColumns() { for (Column<T, ?> column : getColumns()) { removeColumn(column); } }
/** * Adds a cell to this section for given column. * * @param column * the column for which to add a cell */ protected void addCell(Column<?, ?> column) { if (!section.getGrid().getColumns().contains(column)) { throw new IllegalArgumentException( "Given column does not exist in this Grid"); } internalAddCell(section.getInternalIdForColumn(column)); }
/** * Adds a new row at the given index. * * @param index * the index of the new row * @return the added row * @throws IndexOutOfBoundsException * if {@code index < 0 || index > getRowCount()} */ public ROW addRowAt(int index) { ROW row = createRow(); rows.add(index, row); getState(true).rows.add(index, row.getRowState()); getGrid().getColumns().stream().forEach(row::addCell); return row; }
/** * Sets the columns and their order based on their column ids. Columns * currently in this grid that are not present in the list of column ids are * removed. This includes any column that has no id. Similarly, any new * column in columns will be added to this grid. New columns can only be * added for a <code>Grid</code> created using {@link Grid#Grid(Class)} or * {@link #withPropertySet(PropertySet)}. * * * @param columnIds * the column ids to set * * @see Column#setId(String) */ public void setColumns(String... columnIds) { // Must extract to an explicitly typed variable because otherwise javac // cannot determine which overload of setColumnOrder to use Column<T, ?>[] newColumnOrder = Stream.of(columnIds) .map((Function<String, Column<T, ?>>) id -> { Column<T, ?> column = getColumn(id); if (column == null) { column = addColumn(id); } return column; }).toArray(Column[]::new); setColumnOrder(newColumnOrder); // The columns to remove are now at the end of the column list getColumns().stream().skip(columnIds.length) .forEach(this::removeColumn); }
private void writeRow(Element container, T item, DesignContext context) { Element tableRow = container.appendElement("tr"); tableRow.attr("item", serializeDeclarativeRepresentation(item)); if (getSelectionModel().isSelected(item)) { tableRow.attr("selected", true); } for (Column<T, ?> column : getColumns()) { Object value = column.valueProvider.apply(item); tableRow.appendElement("td") .append(Optional.ofNullable(value).map(Object::toString) .map(DesignFormatter::encodeForTextNode) .orElse("")); } }
private void addColumn(String identifier, Column<T, ?> column) { if (getColumns().contains(column)) { return; } column.extend(this); columnSet.add(column); columnKeys.put(identifier, column); column.setInternalId(identifier); addDataGenerator(column.getDataGenerator()); getState().columnOrder.add(identifier); getHeader().addColumn(identifier); getFooter().addColumn(identifier); if (getDefaultHeaderRow() != null) { getDefaultHeaderRow().getCell(column).setText(column.getCaption()); } column.updateSortable(); }
getParent().getColumns().stream().filter(Column::isEditable) .forEach(c -> { Binding<T, ?> binding = c.getEditorBinding();
private void writeStructure(Element design, DesignContext designContext) { if (getColumns().isEmpty()) { return; } Element tableElement = design.appendElement("table"); Element colGroup = tableElement.appendElement("colgroup"); getColumns().forEach(column -> column .writeDesign(colGroup.appendElement("col"), designContext)); // Always write thead. Reads correctly when there no header rows getHeader().writeDesign(tableElement.appendElement("thead"), designContext); if (designContext.shouldWriteData(this)) { Element bodyElement = tableElement.appendElement("tbody"); writeData(bodyElement, designContext); } if (getFooter().getRowCount() > 0) { getFooter().writeDesign(tableElement.appendElement("tfoot"), designContext); } }
for (Column<T, ?> c : getColumns()) { HeaderCell headerCell = getDefaultHeaderRow().getCell(c); if (headerCell.getCellType() == GridStaticCellType.TEXT) {
protected List<Column<E>> getColumnsOrderInternal() { List<Grid.Column<E, ?>> columnsOrder = component.getColumns(); return columnsOrder.stream() .map(this::getColumnByGridColumn) .collect(Collectors.toList()); }
@Override public List<P> getPropertyColumns() { List<Column<T, ?>> columns = getGrid().getColumns(); if (columns != null && !columns.isEmpty()) { List<P> properties = new ArrayList<>(columns.size()); for (Column<T, ?> column : columns) { properties.add(getColumnProperty(column.getId())); } return properties; } return Collections.emptyList(); }
setId("column" + getGrid().getColumns().indexOf(this));
@Override @SuppressWarnings("unchecked") protected void doEdit(T bean) { if (!itemInteractionAvailability.test(bean)) { cancel(); return; } // resolve all the columns that are editable in context of current item final List<String> activeColumns = grid.getColumns().stream() .filter(Column::isEditable) .filter(column -> cellEditingAvailability.test(column, bean)) .map(Column::getId) .collect(toList()); // collect all the related bindings final List<Binder.Binding> binding = activeColumns.stream() .map(grid::getColumn) .map(Column::getId) .map(id -> grid.getColumn(id).getEditorBinding()) .collect(toList()); // set the bindings to the binder getBinder().setBindings((List) binding); super.doEdit(bean); // remove all the currently non-editable cell components from the editor state retainOnlyActiveCellComponents(activeColumns); }
switch (getRenderingMode()) { case GRID: { List<Column> columns = getGrid().getColumns(); if (columns != null && !columns.isEmpty()) { List<P> properties = new ArrayList<>(columns.size());
@Override protected void doEdit(T bean) { Objects.requireNonNull(bean, "Editor can't edit null"); if (!isEnabled()) { throw new IllegalStateException( "Editing is not allowed when Editor is disabled."); } edited = bean; getParent().getColumns().stream().filter(Grid.Column::isEditable) .forEach(c -> { CubaEditorField<?> editorField = getEnhancedGrid().getColumnEditorField(bean, c); configureField(editorField); addComponentToGrid(editorField); columnFields.put(c, editorField); getState().columnFields.put(getInternalIdForColumn(c), editorField.getConnectorId()); }); eventRouter.fireEvent(new CubaEditorOpenEvent<>(this, edited, Collections.unmodifiableMap(columnFields))); }
/** * Sets the I18N values for the Grid itself, and also iterates the columns for column ids which are I18NKeys, and translates those as well * * @param grid the Grid to process * @param annotationValues the annotation values to apply * @param annotationInfo used primarily to identify the Field, and therefore its name */ protected void processGrid(Grid grid, AnnotationValues annotationValues, AnnotationInfo annotationInfo) { // do the grid itself applyAnnotationValues(grid, annotationValues, annotationInfo); // now do the column headers Locale locale = annotationValues.locale.isPresent() ? annotationValues.locale.get() : currentLocale.getLocale(); final List<Grid.Column> columns = grid.getColumns(); I18NKeyConverter converter = new I18NKeyConverter(); for (Grid.Column column : columns) { try { I18NKey columnKey = converter.convertToModel(column.getId()); String header = translate.from(columnKey, locale); column.setCaption(header); } catch (Exception e) { log.debug("Column id {} is not an I18NKey", column.getId()); } } }
/** * Sets the I18N values for the Grid itself, and also iterates the columns for column ids which are I18NKeys, and translates those as well * * @param grid * the Grid to process * @param annotationValues * the annotation values to apply * @param annotationInfo * used primarily to identify the Field, and therefore its name */ protected void processGrid(Grid grid, AnnotationValues annotationValues, AnnotationInfo annotationInfo) { // do the grid itself applyAnnotationValues(grid, annotationValues, annotationInfo); // now do the column headers Locale locale = annotationValues.locale.isPresent() ? annotationValues.locale.get() : currentLocale.getLocale(); final List<Grid.Column> columns = grid.getColumns(); for (Grid.Column column : columns) { if (column.getPropertyId() instanceof I18NKey) { I18NKey columnKey = (I18NKey) column.getPropertyId(); String header = translate.from(columnKey, locale); column.setHeaderCaption(header); } else { column.setHeaderCaption(column.getPropertyId() .toString()); } } }
grid.getColumns().stream() .map(Grid.Column::getEditorBinding).filter(Objects::nonNull).findFirst() .ifPresent(any -> {