Currently supported: * Adding and removal of header and footer rows * Header is single-row by default * Footer is zero-row by default * Text captions * Showing and hiding the whole header or footer TODO: * Column spanning * HTML content * Widget content * Component content * Sorting/Indicators * Server side API * Shared state handling Change-Id: I9708f6f5dd7e9212e9ba5f1e462b55ca619c3df0tags/7.4.0.beta1
@@ -1682,7 +1682,7 @@ public class Grid<T> extends Composite implements | |||
GridStaticSection<?> section) { | |||
// Add or Remove rows on demand | |||
int rowDiff = section.getRowCount() - rows.getRowCount(); | |||
int rowDiff = section.getVisibleRowCount() - rows.getRowCount(); | |||
if (rowDiff > 0) { | |||
rows.insertRows(0, rowDiff); | |||
} else if (rowDiff < 0) { |
@@ -130,6 +130,8 @@ abstract class GridStaticSection<ROWTYPE extends GridStaticSection.StaticRow<?>> | |||
private List<ROWTYPE> rows = new ArrayList<ROWTYPE>(); | |||
private boolean visible = true; | |||
/** | |||
* Creates and returns a new instance of the row type. | |||
* | |||
@@ -142,6 +144,26 @@ abstract class GridStaticSection<ROWTYPE extends GridStaticSection.StaticRow<?>> | |||
*/ | |||
protected abstract void refreshGrid(); | |||
/** | |||
* Sets the visibility of the whole section. | |||
* | |||
* @param visible | |||
* true to show this section, false to hide | |||
*/ | |||
public void setVisible(boolean visible) { | |||
this.visible = visible; | |||
refreshGrid(); | |||
} | |||
/** | |||
* Returns the visibility of this section. | |||
* | |||
* @return true if visible, false otherwise. | |||
*/ | |||
public boolean isVisible() { | |||
return visible; | |||
} | |||
/** | |||
* Inserts a new row at the given position. | |||
* | |||
@@ -239,6 +261,10 @@ abstract class GridStaticSection<ROWTYPE extends GridStaticSection.StaticRow<?>> | |||
return rows; | |||
} | |||
protected int getVisibleRowCount() { | |||
return isVisible() ? getRowCount() : 0; | |||
} | |||
protected void addColumn(GridColumn<?, ?> column, int index) { | |||
for (ROWTYPE row : rows) { | |||
row.addCell(index); |
@@ -22,11 +22,28 @@ import org.junit.Test; | |||
public class GridFooterTest extends GridStaticSectionTest { | |||
@Test | |||
public void testFooterVisibility() throws Exception { | |||
public void testDefaultFooter() { | |||
openTestURL(); | |||
// Footer should have zero rows by default | |||
assertEquals(0, getGridFooterRowCells().size()); | |||
assertFooterCount(0); | |||
} | |||
@Test | |||
public void testFooterVisibility() throws Exception { | |||
openTestURL(); | |||
selectMenuPath("Component", "Footer", "Visible"); | |||
assertFooterCount(0); | |||
selectMenuPath("Component", "Footer", "Append row"); | |||
assertFooterCount(0); | |||
selectMenuPath("Component", "Footer", "Visible"); | |||
assertFooterCount(1); | |||
} | |||
@Test |
@@ -25,12 +25,29 @@ import com.vaadin.testbench.TestBenchElement; | |||
public class GridHeaderTest extends GridStaticSectionTest { | |||
@Test | |||
public void testDefaultHeader() throws Exception { | |||
openTestURL(); | |||
assertHeaderCount(1); | |||
assertHeaderTexts(0, 0); | |||
} | |||
@Test | |||
public void testHeaderVisibility() throws Exception { | |||
openTestURL(); | |||
// Column headers should be visible by default | |||
assertEquals(GridBasicFeatures.COLUMNS, getGridHeaderRowCells().size()); | |||
selectMenuPath("Component", "Header", "Visible"); | |||
assertHeaderCount(0); | |||
selectMenuPath("Component", "Header", "Append row"); | |||
assertHeaderCount(0); | |||
selectMenuPath("Component", "Header", "Visible"); | |||
assertHeaderCount(2); | |||
} | |||
@Test |
@@ -269,60 +269,76 @@ public class GridBasicClientFeatures extends | |||
private void createHeaderMenu() { | |||
final GridHeader header = grid.getHeader(); | |||
final String[] menuPath = { "Component", "Header" }; | |||
addMenuCommand("Visible", new ScheduledCommand() { | |||
@Override | |||
public void execute() { | |||
header.setVisible(!header.isVisible()); | |||
} | |||
}, menuPath); | |||
addMenuCommand("Prepend row", new ScheduledCommand() { | |||
@Override | |||
public void execute() { | |||
setHeaderTexts(header.prependRow()); | |||
} | |||
}, "Component", "Header"); | |||
}, menuPath); | |||
addMenuCommand("Append row", new ScheduledCommand() { | |||
@Override | |||
public void execute() { | |||
setHeaderTexts(header.appendRow()); | |||
} | |||
}, "Component", "Header"); | |||
}, menuPath); | |||
addMenuCommand("Remove top row", new ScheduledCommand() { | |||
@Override | |||
public void execute() { | |||
header.removeRow(0); | |||
} | |||
}, "Component", "Header"); | |||
}, menuPath); | |||
addMenuCommand("Remove bottom row", new ScheduledCommand() { | |||
@Override | |||
public void execute() { | |||
header.removeRow(header.getRowCount() - 1); | |||
} | |||
}, "Component", "Header"); | |||
}, menuPath); | |||
} | |||
private void createFooterMenu() { | |||
final GridFooter footer = grid.getFooter(); | |||
final String[] menuPath = { "Component", "Footer" }; | |||
addMenuCommand("Visible", new ScheduledCommand() { | |||
@Override | |||
public void execute() { | |||
footer.setVisible(!footer.isVisible()); | |||
} | |||
}, menuPath); | |||
addMenuCommand("Prepend row", new ScheduledCommand() { | |||
@Override | |||
public void execute() { | |||
setFooterTexts(footer.prependRow()); | |||
} | |||
}, "Component", "Footer"); | |||
}, menuPath); | |||
addMenuCommand("Append row", new ScheduledCommand() { | |||
@Override | |||
public void execute() { | |||
setFooterTexts(footer.appendRow()); | |||
} | |||
}, "Component", "Footer"); | |||
}, menuPath); | |||
addMenuCommand("Remove top row", new ScheduledCommand() { | |||
@Override | |||
public void execute() { | |||
footer.removeRow(0); | |||
} | |||
}, "Component", "Footer"); | |||
}, menuPath); | |||
addMenuCommand("Remove bottom row", new ScheduledCommand() { | |||
@Override | |||
public void execute() { | |||
footer.removeRow(footer.getRowCount() - 1); | |||
} | |||
}, "Component", "Footer"); | |||
}, menuPath); | |||
} | |||
/** |