+++ /dev/null
-/*
- * Copyright 2000-2014 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package com.vaadin.ui.components.grid;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import com.vaadin.shared.ui.grid.ColumnGroupState;
-
-/**
- * Column groups are used to group columns together for adding common auxiliary
- * headers and footers. Columns groups are added to {@link ColumnGroupRow}'s.
- *
- * @since
- * @author Vaadin Ltd
- */
-public class ColumnGroup implements Serializable {
-
- /**
- * List of property ids belonging to this group
- */
- private List<Object> columns;
-
- /**
- * The grid the column group is associated with
- */
- private final Grid grid;
-
- /**
- * The column group row the column group is attached to
- */
- private final ColumnGroupRow row;
-
- /**
- * The common state between the server and the client
- */
- private final ColumnGroupState state;
-
- /**
- * Constructs a new column group
- *
- * @param grid
- * the grid the column group is associated with
- * @param state
- * the state representing the data of the grid. Sent to the
- * client
- * @param propertyIds
- * the property ids of the columns that belongs to the group
- * @param groups
- * the sub groups who should be included in this group
- *
- */
- ColumnGroup(Grid grid, ColumnGroupRow row, ColumnGroupState state,
- List<Object> propertyIds) {
- if (propertyIds == null) {
- throw new IllegalArgumentException(
- "propertyIds cannot be null. Use empty list instead.");
- }
-
- this.state = state;
- this.row = row;
- columns = Collections.unmodifiableList(new ArrayList<Object>(
- propertyIds));
- this.grid = grid;
- }
-
- /**
- * Sets the text displayed in the header of the column group.
- *
- * @param header
- * the text displayed in the header of the column
- */
- public void setHeaderCaption(String header) {
- checkGroupIsAttached();
- state.header = header;
- grid.markAsDirty();
- }
-
- /**
- * Sets the text displayed in the header of the column group.
- *
- * @return the text displayed in the header of the column
- */
- public String getHeaderCaption() {
- checkGroupIsAttached();
- return state.header;
- }
-
- /**
- * Sets the text displayed in the footer of the column group.
- *
- * @param footer
- * the text displayed in the footer of the column
- */
- public void setFooterCaption(String footer) {
- checkGroupIsAttached();
- state.footer = footer;
- grid.markAsDirty();
- }
-
- /**
- * The text displayed in the footer of the column group.
- *
- * @return the text displayed in the footer of the column
- */
- public String getFooterCaption() {
- checkGroupIsAttached();
- return state.footer;
- }
-
- /**
- * Is a property id in this group or in some sub group of this group.
- *
- * @param propertyId
- * the property id to check for
- * @return <code>true</code> if the property id is included in this group.
- */
- public boolean isColumnInGroup(Object propertyId) {
- if (columns.contains(propertyId)) {
- return true;
- }
- return false;
- }
-
- /**
- * Returns a list of property ids where all also the child groups property
- * ids are included.
- *
- * @return a unmodifiable list with all the columns in the group. Includes
- * any subgroup columns as well.
- */
- public List<Object> getColumns() {
- return columns;
- }
-
- /**
- * Checks if column group is attached to a row and throws an
- * {@link IllegalStateException} if it is not.
- *
- * @throws IllegalStateException
- * if the column is no longer attached to any grid
- */
- protected void checkGroupIsAttached() throws IllegalStateException {
- if (!row.getState().groups.contains(state)) {
- throw new IllegalStateException(
- "Column Group has been removed from the row.");
- }
- }
-}
+++ /dev/null
-/*
- * Copyright 2000-2014 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package com.vaadin.ui.components.grid;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
-import com.vaadin.server.KeyMapper;
-import com.vaadin.shared.ui.grid.ColumnGroupRowState;
-import com.vaadin.shared.ui.grid.ColumnGroupState;
-
-/**
- * A column group row represents an auxiliary header or footer row added to the
- * grid. A column group row includes column groups that group columns together.
- *
- * @since
- * @author Vaadin Ltd
- */
-public class ColumnGroupRow implements Serializable {
-
- /**
- * The common state shared between the client and server
- */
- private final ColumnGroupRowState state;
-
- /**
- * The column groups in this row
- */
- private List<ColumnGroup> groups = new ArrayList<ColumnGroup>();
-
- /**
- * Grid that the group row belongs to
- */
- private final Grid grid;
-
- /**
- * The column keys used to identify the column on the client side
- */
- private final KeyMapper<Object> columnKeys;
-
- /**
- * Constructs a new column group
- *
- * @param grid
- * The grid that the column group is associated to
- * @param state
- * The shared state which contains the data shared between server
- * and client
- * @param columnKeys
- * The column key mapper for converting property ids to client
- * side column identifiers
- */
- ColumnGroupRow(Grid grid, ColumnGroupRowState state,
- KeyMapper<Object> columnKeys) {
- this.grid = grid;
- this.columnKeys = columnKeys;
- this.state = state;
- }
-
- /**
- * Gets the shared state for the column group row. Used internally to send
- * the group row to the client.
- *
- * @return The current state of the row
- */
- ColumnGroupRowState getState() {
- return state;
- }
-
- /**
- * Add a new group to the row by using property ids for the columns.
- *
- * @param propertyIds
- * The property ids of the columns that should be included in the
- * group. A column can only belong in group on a row at a time.
- * @return a column group representing the collection of columns added to
- * the group
- */
- public ColumnGroup addGroup(Object... propertyIds)
- throws IllegalArgumentException {
- assert propertyIds != null : "propertyIds cannot be null.";
-
- for (Object propertyId : propertyIds) {
- if (hasColumnBeenGrouped(propertyId)) {
- throw new IllegalArgumentException("Column "
- + String.valueOf(propertyId)
- + " already belongs to another group.");
- }
- }
-
- validateNewGroupProperties(Arrays.asList(propertyIds));
-
- ColumnGroupState state = new ColumnGroupState();
- for (Object propertyId : propertyIds) {
- assert propertyId != null : "null items in columns array not supported.";
- state.columns.add(columnKeys.key(propertyId));
- }
- this.state.groups.add(state);
-
- ColumnGroup group = new ColumnGroup(grid, this, state,
- Arrays.asList(propertyIds));
- groups.add(group);
-
- grid.markAsDirty();
- return group;
- }
-
- private void validateNewGroupProperties(List<Object> propertyIds)
- throws IllegalArgumentException {
-
- /*
- * Validate parent grouping
- */
- int rowIndex = grid.getColumnGroupRows().indexOf(this);
- int parentRowIndex = rowIndex - 1;
-
- // Get the parent row of this row.
- ColumnGroupRow parentRow = null;
- if (parentRowIndex > -1) {
- parentRow = grid.getColumnGroupRows().get(parentRowIndex);
- }
-
- if (parentRow == null) {
- // A parentless row is always valid and is usually the first row
- // added to the grid
- return;
- }
-
- for (Object id : propertyIds) {
- if (parentRow.hasColumnBeenGrouped(id)) {
- /*
- * If a property has been grouped in the parent row then all of
- * the properties in the parent group also needs to be included
- * in the child group for the groups to be valid
- */
- ColumnGroup parentGroup = parentRow.getGroupForProperty(id);
- if (!propertyIds.containsAll(parentGroup.getColumns())) {
- throw new IllegalArgumentException(
- "Grouped properties overlaps previous grouping bounderies");
- }
- }
- }
- }
-
- /**
- * Add a new group to the row by using column instances.
- *
- * @param columns
- * the columns that should belong to the group
- * @return a column group representing the collection of columns added to
- * the group
- */
- public ColumnGroup addGroup(GridColumn... columns)
- throws IllegalArgumentException {
- assert columns != null : "columns cannot be null";
-
- List<Object> propertyIds = new ArrayList<Object>();
- for (GridColumn column : columns) {
- assert column != null : "null items in columns array not supported.";
-
- String columnId = column.getState().id;
- Object propertyId = grid.getPropertyIdByColumnId(columnId);
- propertyIds.add(propertyId);
- }
- return addGroup(propertyIds.toArray());
- }
-
- /**
- * Add a new group to the row by using other already greated groups
- *
- * @param groups
- * the subgroups of the group
- * @return a column group representing the collection of columns added to
- * the group
- *
- */
- public ColumnGroup addGroup(ColumnGroup... groups)
- throws IllegalArgumentException {
- assert groups != null : "groups cannot be null";
-
- // Gather all groups columns into one list
- List<Object> propertyIds = new ArrayList<Object>();
- for (ColumnGroup group : groups) {
- propertyIds.addAll(group.getColumns());
- }
-
- validateNewGroupProperties(propertyIds);
-
- ColumnGroupState state = new ColumnGroupState();
- ColumnGroup group = new ColumnGroup(grid, this, state, propertyIds);
- this.groups.add(group);
-
- // Update state
- for (Object propertyId : group.getColumns()) {
- state.columns.add(columnKeys.key(propertyId));
- }
- this.state.groups.add(state);
-
- grid.markAsDirty();
- return group;
- }
-
- /**
- * Removes a group from the row. Does not remove the group from subgroups,
- * to remove it from the subgroup invoke removeGroup on the subgroup.
- *
- * @param group
- * the group to remove
- */
- public void removeGroup(ColumnGroup group) {
- int index = groups.indexOf(group);
- groups.remove(index);
- state.groups.remove(index);
- grid.markAsDirty();
- }
-
- /**
- * Get the groups in the row.
- *
- * @return unmodifiable list of groups in this row
- */
- public List<ColumnGroup> getGroups() {
- return Collections.unmodifiableList(groups);
- }
-
- /**
- * Checks if a property id has been added to a group in this row.
- *
- * @param propertyId
- * the property id to check for
- * @return <code>true</code> if the column is included in a group
- */
- private boolean hasColumnBeenGrouped(Object propertyId) {
- return getGroupForProperty(propertyId) != null;
- }
-
- private ColumnGroup getGroupForProperty(Object propertyId) {
- for (ColumnGroup group : groups) {
- if (group.isColumnInGroup(propertyId)) {
- return group;
- }
- }
- return null;
- }
-
- /**
- * Is the header visible for the row.
- *
- * @return <code>true</code> if header is visible
- */
- public boolean isHeaderVisible() {
- return state.headerVisible;
- }
-
- /**
- * Sets the header visible for the row.
- *
- * @param visible
- * should the header be shown
- */
- public void setHeaderVisible(boolean visible) {
- state.headerVisible = visible;
- grid.markAsDirty();
- }
-
- /**
- * Is the footer visible for the row.
- *
- * @return <code>true</code> if footer is visible
- */
- public boolean isFooterVisible() {
- return state.footerVisible;
- }
-
- /**
- * Sets the footer visible for the row.
- *
- * @param visible
- * should the footer be shown
- */
- public void setFooterVisible(boolean visible) {
- state.footerVisible = visible;
- grid.markAsDirty();
- }
-
-}
import com.vaadin.data.RpcDataProviderExtension;
import com.vaadin.data.RpcDataProviderExtension.DataProviderKeyMapper;
import com.vaadin.server.KeyMapper;
-import com.vaadin.shared.ui.grid.ColumnGroupRowState;
import com.vaadin.shared.ui.grid.GridClientRpc;
import com.vaadin.shared.ui.grid.GridColumnState;
import com.vaadin.shared.ui.grid.GridServerRpc;
*/
private final KeyMapper<Object> columnKeys = new KeyMapper<Object>();
- /**
- * The column groups added to the grid
- */
- private final List<ColumnGroupRow> columnGroupRows = new ArrayList<ColumnGroupRow>();
-
/**
* The current sort order
*/
return columns.get(propertyId);
}
- /**
- * Sets the header rows visible.
- *
- * @param visible
- * <code>true</code> if the header rows should be visible
- */
- @Deprecated
- public void setColumnHeadersVisible(boolean visible) {
- getHeader().setVisible(visible);
- }
-
- /**
- * Are the header rows visible?
- *
- * @return <code>true</code> if the headers of the columns are visible
- */
- @Deprecated
- public boolean isColumnHeadersVisible() {
- return getHeader().isVisible();
- }
-
- /**
- * Sets the footer rows visible.
- *
- * @param visible
- * <code>true</code> if the footer rows should be visible
- */
- @Deprecated
- public void setColumnFootersVisible(boolean visible) {
- getFooter().setVisible(visible);
- }
-
- /**
- * Are the footer rows visible.
- *
- * @return <code>true</code> if the footer rows should be visible
- */
- @Deprecated
- public boolean isColumnFootersVisible() {
- return getFooter().isVisible();
- }
-
- /**
- * <p>
- * Adds a new column group to the grid.
- *
- * <p>
- * Column group rows are rendered in the header and footer of the grid.
- * Column group rows are made up of column groups which groups together
- * columns for adding a common auxiliary header or footer for the columns.
- * </p>
- * </p>
- *
- * <p>
- * Example usage:
- *
- * <pre>
- * // Add a new column group row to the grid
- * ColumnGroupRow row = grid.addColumnGroupRow();
- *
- * // Group "Column1" and "Column2" together to form a header in the row
- * ColumnGroup column12 = row.addGroup("Column1", "Column2");
- *
- * // Set a common header for "Column1" and "Column2"
- * column12.setHeader("Column 1&2");
- * </pre>
- *
- * </p>
- *
- * @return a column group instance you can use to add column groups
- */
- @Deprecated
- public ColumnGroupRow addColumnGroupRow() {
- ColumnGroupRowState state = new ColumnGroupRowState();
- ColumnGroupRow row = new ColumnGroupRow(this, state, columnKeys);
- columnGroupRows.add(row);
- getState().columnGroupRows.add(state);
- return row;
- }
-
- /**
- * Adds a new column group to the grid at a specific index
- *
- * @param rowIndex
- * the index of the row
- * @return a column group instance you can use to add column groups
- */
- @Deprecated
- public ColumnGroupRow addColumnGroupRow(int rowIndex) {
- ColumnGroupRowState state = new ColumnGroupRowState();
- ColumnGroupRow row = new ColumnGroupRow(this, state, columnKeys);
- columnGroupRows.add(rowIndex, row);
- getState().columnGroupRows.add(rowIndex, state);
- return row;
- }
-
- /**
- * Removes a column group.
- *
- * @param row
- * the row to remove
- */
- @Deprecated
- public void removeColumnGroupRow(ColumnGroupRow row) {
- columnGroupRows.remove(row);
- getState().columnGroupRows.remove(row.getState());
- }
-
- /**
- * Gets the column group rows.
- *
- * @return an unmodifiable list of column group rows
- */
- @Deprecated
- public List<ColumnGroupRow> getColumnGroupRows() {
- return Collections.unmodifiableList(new ArrayList<ColumnGroupRow>(
- columnGroupRows));
- }
-
/**
* Used internally by the {@link Grid} to get a {@link GridColumn} by
* referencing its generated state id. Also used by {@link GridColumn} to
+++ /dev/null
-/*
- * Copyright 2000-2014 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.vaadin.tests.server.component.grid;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.List;
-
-import org.junit.Before;
-import org.junit.Test;
-
-import com.vaadin.data.util.IndexedContainer;
-import com.vaadin.server.KeyMapper;
-import com.vaadin.shared.ui.grid.GridState;
-import com.vaadin.ui.components.grid.ColumnGroup;
-import com.vaadin.ui.components.grid.ColumnGroupRow;
-import com.vaadin.ui.components.grid.Grid;
-
-public class GridColumnGroups {
-
- private Grid grid;
-
- private GridState state;
-
- private Method getStateMethod;
-
- private Field columnIdGeneratorField;
-
- private KeyMapper<Object> columnIdMapper;
-
- @Before
- public void setup() throws Exception {
- IndexedContainer ds = new IndexedContainer();
- for (int c = 0; c < 10; c++) {
- ds.addContainerProperty("column" + c, String.class, "");
- }
- grid = new Grid(ds);
-
- getStateMethod = Grid.class.getDeclaredMethod("getState");
- getStateMethod.setAccessible(true);
-
- state = (GridState) getStateMethod.invoke(grid);
-
- columnIdGeneratorField = Grid.class.getDeclaredField("columnKeys");
- columnIdGeneratorField.setAccessible(true);
-
- columnIdMapper = (KeyMapper<Object>) columnIdGeneratorField.get(grid);
- }
-
- @Test
- public void testColumnGroupRows() throws Exception {
-
- // No column group rows by default
- List<ColumnGroupRow> rows = grid.getColumnGroupRows();
- assertEquals(0, rows.size());
-
- // Add some rows
- ColumnGroupRow row1 = grid.addColumnGroupRow();
- ColumnGroupRow row3 = grid.addColumnGroupRow();
- ColumnGroupRow row2 = grid.addColumnGroupRow(1);
-
- rows = grid.getColumnGroupRows();
- assertEquals(3, rows.size());
- assertEquals(row1, rows.get(0));
- assertEquals(row2, rows.get(1));
- assertEquals(row3, rows.get(2));
-
- // Header should be visible by default, footer should not
- assertTrue(row1.isHeaderVisible());
- assertFalse(row1.isFooterVisible());
-
- row1.setHeaderVisible(false);
- assertFalse(row1.isHeaderVisible());
- row1.setHeaderVisible(true);
- assertTrue(row1.isHeaderVisible());
-
- row1.setFooterVisible(true);
- assertTrue(row1.isFooterVisible());
- row1.setFooterVisible(false);
- assertFalse(row1.isFooterVisible());
-
- row1.setHeaderVisible(true);
- row1.setFooterVisible(true);
- assertTrue(row1.isHeaderVisible());
- assertTrue(row1.isFooterVisible());
-
- row1.setHeaderVisible(false);
- row1.setFooterVisible(false);
- assertFalse(row1.isHeaderVisible());
- assertFalse(row1.isFooterVisible());
- }
-
- @Test
- public void testColumnGroupsInState() throws Exception {
-
- // Add a new row
- ColumnGroupRow row = grid.addColumnGroupRow();
- assertTrue(state.columnGroupRows.size() == 1);
-
- // Add a group by property id
- ColumnGroup columns12 = row.addGroup("column1", "column2");
- assertTrue(state.columnGroupRows.get(0).groups.size() == 1);
-
- // Set header of column
- columns12.setHeaderCaption("Column12");
- assertEquals("Column12",
- state.columnGroupRows.get(0).groups.get(0).header);
-
- // Set footer of column
- columns12.setFooterCaption("Footer12");
- assertEquals("Footer12",
- state.columnGroupRows.get(0).groups.get(0).footer);
-
- // Add another group by column instance
- ColumnGroup columns34 = row.addGroup(grid.getColumn("column3"),
- grid.getColumn("column4"));
- assertTrue(state.columnGroupRows.get(0).groups.size() == 2);
-
- // add another group row
- ColumnGroupRow row2 = grid.addColumnGroupRow();
- assertTrue(state.columnGroupRows.size() == 2);
-
- // add a group by combining the two previous groups
- ColumnGroup columns1234 = row2.addGroup(columns12, columns34);
- assertTrue(columns1234.getColumns().size() == 4);
-
- // Insert a group as the second group
- ColumnGroupRow newRow2 = grid.addColumnGroupRow(1);
- assertTrue(state.columnGroupRows.size() == 3);
- }
-
- @Test
- public void testAddingColumnGroups() throws Exception {
-
- ColumnGroupRow row = grid.addColumnGroupRow();
-
- // By property id
- ColumnGroup columns01 = row.addGroup("column0", "column1");
- assertEquals(2, columns01.getColumns().size());
- assertEquals("column0", columns01.getColumns().get(0));
- assertTrue(columns01.isColumnInGroup("column0"));
- assertEquals("column1", columns01.getColumns().get(1));
- assertTrue(columns01.isColumnInGroup("column1"));
-
- // By grid column
- ColumnGroup columns23 = row.addGroup(grid.getColumn("column2"),
- grid.getColumn("column3"));
- assertEquals(2, columns23.getColumns().size());
- assertEquals("column2", columns23.getColumns().get(0));
- assertTrue(columns23.isColumnInGroup("column2"));
- assertEquals("column3", columns23.getColumns().get(1));
- assertTrue(columns23.isColumnInGroup("column3"));
-
- // Combine groups
- ColumnGroupRow row2 = grid.addColumnGroupRow();
- ColumnGroup columns0123 = row2.addGroup(columns01, columns23);
- assertEquals(4, columns0123.getColumns().size());
- assertEquals("column0", columns0123.getColumns().get(0));
- assertTrue(columns0123.isColumnInGroup("column0"));
- assertEquals("column1", columns0123.getColumns().get(1));
- assertTrue(columns0123.isColumnInGroup("column1"));
- assertEquals("column2", columns0123.getColumns().get(2));
- assertTrue(columns0123.isColumnInGroup("column2"));
- assertEquals("column3", columns0123.getColumns().get(3));
- assertTrue(columns0123.isColumnInGroup("column3"));
- }
-
- @Test
- public void testColumnGroupHeadersAndFooters() throws Exception {
-
- ColumnGroupRow row = grid.addColumnGroupRow();
- ColumnGroup group = row.addGroup("column1", "column2");
-
- // Header
- assertNull(group.getHeaderCaption());
- group.setHeaderCaption("My header");
- assertEquals("My header", group.getHeaderCaption());
- group.setHeaderCaption(null);
- assertNull(group.getHeaderCaption());
-
- // Footer
- assertNull(group.getFooterCaption());
- group.setFooterCaption("My footer");
- assertEquals("My footer", group.getFooterCaption());
- group.setFooterCaption(null);
- assertNull(group.getFooterCaption());
- }
-
- @Test
- public void testColumnGroupDetachment() throws Exception {
-
- ColumnGroupRow row = grid.addColumnGroupRow();
- ColumnGroup group = row.addGroup("column1", "column2");
-
- // Remove group
- row.removeGroup(group);
-
- try {
- group.setHeaderCaption("Header");
- fail("Should throw exception for setting header caption on detached group");
- } catch (IllegalStateException ise) {
-
- }
-
- try {
- group.setFooterCaption("Footer");
- fail("Should throw exception for setting footer caption on detached group");
- } catch (IllegalStateException ise) {
-
- }
- }
-
- @Test
- public void testColumnGroupLimits() throws Exception {
-
- ColumnGroupRow row = grid.addColumnGroupRow();
- row.addGroup("column1", "column2");
- row.addGroup("column3", "column4");
-
- try {
- row.addGroup("column2", "column3");
- fail("Adding a group with already grouped properties should throw exception");
- } catch (IllegalArgumentException iae) {
-
- }
-
- ColumnGroupRow row2 = grid.addColumnGroupRow();
-
- try {
- row2.addGroup("column2", "column3");
- fail("Adding a group that breaks previous grouping boundaries should throw exception");
- } catch (IllegalArgumentException iae) {
-
- }
-
- // This however should not throw an exception as it spans completely
- // over the parent rows groups
- row2.addGroup("column1", "column2", "column3", "column4");
-
- }
-}
+++ /dev/null
-/*
- * Copyright 2000-2013 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package com.vaadin.shared.ui.grid;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * The column group row data shared between the server and client
- *
- * @since
- * @author Vaadin Ltd
- */
-public class ColumnGroupRowState implements Serializable {
-
- /**
- * The groups that has been added to the row
- */
- public List<ColumnGroupState> groups = new ArrayList<ColumnGroupState>();
-
- /**
- * Is the header shown
- */
- public boolean headerVisible = true;
-
- /**
- * Is the footer shown
- */
- public boolean footerVisible = false;
-
-}
public GridStaticSectionState footer = new GridStaticSectionState();
- /**
- * The column groups added to the grid
- */
- public List<ColumnGroupRowState> columnGroupRows = new ArrayList<ColumnGroupRowState>();
-
/**
* The id for the last frozen column.
*
+++ /dev/null
-/*
- * Copyright 2000-2014 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-/**
- *
- */
-package com.vaadin.tests.components.grid;
-
-import com.vaadin.data.util.IndexedContainer;
-import com.vaadin.server.VaadinRequest;
-import com.vaadin.tests.components.AbstractTestUI;
-import com.vaadin.ui.components.grid.ColumnGroup;
-import com.vaadin.ui.components.grid.ColumnGroupRow;
-import com.vaadin.ui.components.grid.Grid;
-import com.vaadin.ui.components.grid.GridColumn;
-
-public class GridColumnGroups extends AbstractTestUI {
-
- private final int COLUMNS = 4;
-
- @Override
- protected void setup(VaadinRequest request) {
-
- // Setup grid
- IndexedContainer ds = new IndexedContainer();
- for (int col = 0; col < COLUMNS; col++) {
- ds.addContainerProperty("Column" + col, String.class, "");
- }
- Grid grid = new Grid(ds);
- addComponent(grid);
-
- /*-
- * ---------------------------------------------
- * | Header 1 | <- Auxiliary row 2
- * |-------------------------------------------|
- * | Header 2 | Header 3 | <- Auxiliary row 1
- * |-------------------------------------------|
- * | Column 1 | Column 2 | Column 3 | Column 4 | <- Column headers
- * --------------------------------------------|
- * | ... | ... | ... | ... |
- * | ... | ... | ... | ... |
- * --------------------------------------------|
- * | Column 1 | Column 2 | Column 3 | Column 4 | <- Column footers
- * --------------------------------------------|
- * | Footer 2 | Footer 3 | <- Auxiliary row 1
- * --------------------------------------------|
- * | Footer 1 | <- Auxiliary row 2
- * ---------------------------------------------
- -*/
-
- // Set column footers (headers are generated automatically)
- grid.setColumnFootersVisible(true);
- for (Object propertyId : ds.getContainerPropertyIds()) {
- GridColumn column = grid.getColumn(propertyId);
- column.setFooterCaption(String.valueOf(propertyId));
- }
-
- // First auxiliary row
- ColumnGroupRow auxRow1 = grid.addColumnGroupRow();
-
- // Using property id to create a column group
- ColumnGroup columns12 = auxRow1.addGroup("Column0", "Column1");
- columns12.setHeaderCaption("Header 2");
- columns12.setFooterCaption("Footer 2");
-
- // Using grid columns to create a column group
- GridColumn column3 = grid.getColumn("Column2");
- GridColumn column4 = grid.getColumn("Column3");
- ColumnGroup columns34 = auxRow1.addGroup(column3, column4);
- columns34.setHeaderCaption("Header 3");
- columns34.setFooterCaption("Footer 3");
-
- // Second auxiliary row
- ColumnGroupRow auxRow2 = grid.addColumnGroupRow();
-
- // Using previous groups to create a column group
- ColumnGroup columns1234 = auxRow2.addGroup(columns12, columns34);
- columns1234.setHeaderCaption("Header 1");
- columns1234.setFooterCaption("Footer 1");
-
- }
-
- @Override
- protected String getTestDescription() {
- return "Grid should support headers and footer groups";
- }
-
- @Override
- protected Integer getTicketNumber() {
- return 12894;
- }
-
-}
import com.vaadin.shared.ui.grid.HeightMode;
import com.vaadin.shared.ui.grid.SortDirection;
import com.vaadin.tests.components.AbstractComponentTest;
-import com.vaadin.ui.components.grid.ColumnGroup;
-import com.vaadin.ui.components.grid.ColumnGroupRow;
import com.vaadin.ui.components.grid.Grid;
import com.vaadin.ui.components.grid.Grid.SelectionMode;
import com.vaadin.ui.components.grid.GridColumn;
createFooterActions();
- createColumnGroupActions();
-
createRowActions();
addHeightActions();
return "Column " + c;
}
- protected void createColumnGroupActions() {
- createCategory("Column groups", null);
-
- createClickAction("Add group row", "Column groups",
- new Command<Grid, String>() {
-
- @Override
- public void execute(Grid grid, String value, Object data) {
- final ColumnGroupRow row = grid.addColumnGroupRow();
- columnGroupRows++;
- createCategory("Column group row " + columnGroupRows,
- "Column groups");
-
- createBooleanAction("Header Visible",
- "Column group row " + columnGroupRows, true,
- new Command<Grid, Boolean>() {
-
- @Override
- public void execute(Grid grid,
- Boolean value, Object columnIndex) {
- row.setHeaderVisible(value);
- }
- }, row);
-
- createBooleanAction("Footer Visible",
- "Column group row " + columnGroupRows, false,
- new Command<Grid, Boolean>() {
-
- @Override
- public void execute(Grid grid,
- Boolean value, Object columnIndex) {
- row.setFooterVisible(value);
- }
- }, row);
-
- for (int i = 0; i < COLUMNS; i++) {
- final int columnIndex = i;
- createClickAction("Group Column " + columnIndex
- + " & " + (columnIndex + 1),
- "Column group row " + columnGroupRows,
- new Command<Grid, Integer>() {
-
- @Override
- public void execute(Grid c,
- Integer value, Object data) {
- final ColumnGroup group = row
- .addGroup(
- "Column" + value,
- "Column"
- + (value + 1));
-
- group.setHeaderCaption("Column "
- + value + " & "
- + (value + 1));
-
- group.setFooterCaption("Column "
- + value + " & "
- + (value + 1));
- }
- }, i, row);
- }
- }
- }, null, null);
-
- }
-
protected void createRowActions() {
createCategory("Body rows", null);