Change-Id: Ib0c1701346dc6b8b9ef5b5290fc6ffaff68d9f96tags/7.2.0.beta1
@@ -298,6 +298,22 @@ public class Grid<T> extends Composite { | |||
private int findIndexOfColumn() { | |||
return grid.columns.indexOf(this); | |||
} | |||
/** | |||
* Sets the pixel width of the column. Use a negative value for the grid | |||
* to autosize column based on content and available space | |||
* | |||
* @param pixels | |||
* the width in pixels or negative for auto sizing | |||
*/ | |||
public void setWidth(int pixels) { | |||
if (grid != null) { | |||
int index = findIndexOfColumn(); | |||
ColumnConfiguration conf = grid.escalator | |||
.getColumnConfiguration(); | |||
conf.setColumnWidth(index, pixels); | |||
} | |||
} | |||
} | |||
/** |
@@ -181,6 +181,7 @@ public class GridConnector extends AbstractComponentConnector { | |||
column.setVisible(state.visible); | |||
column.setHeaderCaption(state.header); | |||
column.setFooterCaption(state.footer); | |||
column.setWidth(state.width); | |||
} | |||
/** |
@@ -134,8 +134,6 @@ public class GridColumn implements Serializable { | |||
/** | |||
* Sets the width (in pixels). | |||
* | |||
* FIXME Currently not implemented. | |||
* | |||
* @param pixelWidth | |||
* the new pixel width of the column | |||
* @throws IllegalStateException | |||
@@ -154,6 +152,17 @@ public class GridColumn implements Serializable { | |||
grid.markAsDirty(); | |||
} | |||
/** | |||
* Marks the column width as undefined meaning that the grid is free to | |||
* resize the column based on the cell contents and available space in the | |||
* grid. | |||
*/ | |||
public void setWidthUndefined() { | |||
checkColumnIsAttached(); | |||
state.width = -1; | |||
grid.markAsDirty(); | |||
} | |||
/** | |||
* Is this column visible in the grid. By default all columns are visible. | |||
* |
@@ -142,8 +142,40 @@ public class GridBasicFeatures extends AbstractComponentTest<Grid> { | |||
} | |||
}, null, c); | |||
} | |||
createCategory("Column" + c + " Width", "Column" + c); | |||
createClickAction("Auto", "Column" + c + " Width", | |||
new Command<Grid, Integer>() { | |||
@Override | |||
public void execute(Grid grid, Integer value, | |||
Object columnIndex) { | |||
Object propertyId = (new ArrayList(grid | |||
.getContainerDatasource() | |||
.getContainerPropertyIds()) | |||
.get((Integer) columnIndex)); | |||
GridColumn column = grid.getColumn(propertyId); | |||
column.setWidthUndefined(); | |||
} | |||
}, -1, c); | |||
for (int w = 50; w < 300; w += 50) { | |||
createClickAction(w + "px", "Column" + c + " Width", | |||
new Command<Grid, Integer>() { | |||
@Override | |||
public void execute(Grid grid, Integer value, | |||
Object columnIndex) { | |||
Object propertyId = (new ArrayList(grid | |||
.getContainerDatasource() | |||
.getContainerPropertyIds()) | |||
.get((Integer) columnIndex)); | |||
GridColumn column = grid.getColumn(propertyId); | |||
column.setWidth(value); | |||
} | |||
}, w, c); | |||
} | |||
} | |||
} | |||
protected void createColumnGroupActions() { |
@@ -188,17 +188,57 @@ public class GridBasicFeaturesTest extends MultiBrowserTest { | |||
// Freeze column 2 | |||
selectMenuPath("Component", "Columns", "Column2", "Freeze"); | |||
WebElement cell = getDriver() | |||
.findElement( | |||
By.xpath("//tbody[contains(@class, 'v-escalator-body')]/tr[1]/td[1]")); | |||
WebElement cell = getBodyCellByRowAndColumn(1, 1); | |||
assertTrue(cell.getAttribute("class").contains("frozen")); | |||
cell = getDriver() | |||
.findElement( | |||
By.xpath("//tbody[contains(@class, 'v-escalator-body')]/tr[1]/td[2]")); | |||
cell = getBodyCellByRowAndColumn(1, 2); | |||
assertTrue(cell.getAttribute("class").contains("frozen")); | |||
} | |||
@Test | |||
public void testColumnWidths() throws Exception { | |||
openTestURL(); | |||
// Default borders and margins implemented by escalator | |||
int cellBorder = 1 + 1; | |||
int cellMargin = 2 + 2; | |||
// Default column width is 100px | |||
WebElement cell = getBodyCellByRowAndColumn(1, 1); | |||
assertEquals((100 - cellBorder - cellMargin) + "px", | |||
cell.getCssValue("width")); | |||
// Set first column to be 200px wide | |||
selectMenuPath("Component", "Columns", "Column0", "Column0 Width", | |||
"200px"); | |||
cell = getBodyCellByRowAndColumn(1, 1); | |||
assertEquals((200 - cellBorder - cellMargin) + "px", | |||
cell.getCssValue("width")); | |||
// Set second column to be 150px wide | |||
selectMenuPath("Component", "Columns", "Column1", "Column1 Width", | |||
"150px"); | |||
cell = getBodyCellByRowAndColumn(1, 2); | |||
assertEquals((150 - cellBorder - cellMargin) + "px", | |||
cell.getCssValue("width")); | |||
// Set first column to be auto sized (defaults to 100px currently) | |||
selectMenuPath("Component", "Columns", "Column0", "Column0 Width", | |||
"Auto"); | |||
cell = getBodyCellByRowAndColumn(1, 1); | |||
assertEquals((100 - cellBorder - cellMargin) + "px", | |||
cell.getCssValue("width")); | |||
} | |||
private WebElement getBodyCellByRowAndColumn(int row, int column) { | |||
return getDriver().findElement( | |||
By.xpath("//tbody[contains(@class, 'v-escalator-body')]/tr[" | |||
+ row + "]/td[" + column + "]")); | |||
} | |||
private void selectSubMenu(String menuCaption) { | |||
selectMenu(menuCaption); | |||
new Actions(getDriver()).moveByOffset(100, 0).build().perform(); |