.forEach(this::removeColumn);
}
+ /**
+ * Sets the columns and their order based on their column ids provided that
+ * collection supports preserving of the order. Columns currently in this
+ * grid that are not present in the collection 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)
+ * @see #setColumns(String...)
+ */
+ public void setColumns(Collection<String> columnIds) {
+ Objects.requireNonNull(columnIds, "columnIds can't be null");
+ String[] columns = columnIds.toArray(new String[columnIds.size()]);
+ setColumns(columns);
+ }
+
private String getGeneratedIdentifier() {
String columnId = "" + counter;
counter++;
assertEquals("name", columns.get(1).getId());
}
+ @Test
+ public void setColumns_addColumns_v2_beangrid() {
+ Grid<Person> grid = new Grid<>(Person.class);
+
+ // Remove so we can add it back
+ grid.removeColumn("name");
+
+ List<String> columnIds = new ArrayList<>();
+ columnIds.add("born");
+ columnIds.add("name");
+
+ grid.setColumns(columnIds);
+
+ List<Column<Person, ?>> columns = grid.getColumns();
+ assertEquals(2, columns.size());
+ assertEquals("born", columns.get(0).getId());
+ assertEquals("name", columns.get(1).getId());
+ }
+
@Test
public void setColumnOrder_byColumn() {
grid.setColumnOrder(randomColumn, lengthColumn);