diff options
7 files changed, 147 insertions, 24 deletions
diff --git a/client/src/com/vaadin/client/ui/grid/Grid.java b/client/src/com/vaadin/client/ui/grid/Grid.java index c0edfd9eb8..98afc08033 100644 --- a/client/src/com/vaadin/client/ui/grid/Grid.java +++ b/client/src/com/vaadin/client/ui/grid/Grid.java @@ -1354,6 +1354,8 @@ public class Grid<T> extends ResizeComposite implements .getRow()); final List<GridColumn<?, T>> columns = getVisibleColumns(); + setCustomStyleName(row.getElement(), staticRow.getStyleName()); + for (FlyweightCell cell : cellsToUpdate) { final StaticCell metadata = staticRow.getCell(columns.get(cell .getColumn())); @@ -1380,25 +1382,28 @@ public class Grid<T> extends ResizeComposite implements postAttach(row, Arrays.asList(cell)); break; } - String oldStyleName = element - .getPropertyString(CUSTOM_STYLE_PROPERTY_NAME); - String newStyleName = metadata.getStyleName(); - - if (!SharedUtil.equals(oldStyleName, newStyleName)) { - if (oldStyleName != null) { - element.removeClassName(oldStyleName); - } - if (newStyleName != null) { - element.addClassName(newStyleName); - } - element.setPropertyString(CUSTOM_STYLE_PROPERTY_NAME, - newStyleName); - } + setCustomStyleName(element, metadata.getStyleName()); cellFocusHandler.updateFocusedCellStyle(cell, container); } } + private void setCustomStyleName(Element element, String styleName) { + String oldStyleName = element + .getPropertyString(CUSTOM_STYLE_PROPERTY_NAME); + + if (!SharedUtil.equals(oldStyleName, styleName)) { + if (oldStyleName != null) { + element.removeClassName(oldStyleName); + } + if (styleName != null) { + element.addClassName(styleName); + } + element.setPropertyString(CUSTOM_STYLE_PROPERTY_NAME, styleName); + } + + } + private void addSortingIndicatorsToHeaderRow(HeaderRow headerRow, FlyweightCell cell) { diff --git a/client/src/com/vaadin/client/ui/grid/GridConnector.java b/client/src/com/vaadin/client/ui/grid/GridConnector.java index feb46af0c1..2388516a2d 100644 --- a/client/src/com/vaadin/client/ui/grid/GridConnector.java +++ b/client/src/com/vaadin/client/ui/grid/GridConnector.java @@ -502,6 +502,8 @@ public class GridConnector extends AbstractHasComponentsConnector implements if (section instanceof GridHeader && rowState.defaultRow) { ((GridHeader) section).setDefaultRow((HeaderRow) row); } + + row.setStyleName(rowState.styleName); } section.setVisible(state.visible); diff --git a/client/src/com/vaadin/client/ui/grid/GridStaticSection.java b/client/src/com/vaadin/client/ui/grid/GridStaticSection.java index a85001f58c..c26287f095 100644 --- a/client/src/com/vaadin/client/ui/grid/GridStaticSection.java +++ b/client/src/com/vaadin/client/ui/grid/GridStaticSection.java @@ -220,6 +220,11 @@ abstract class GridStaticSection<ROWTYPE extends GridStaticSection.StaticRow<?>> private Map<Set<GridColumn<?, ?>>, CELLTYPE> cellGroups = new HashMap<Set<GridColumn<?, ?>>, CELLTYPE>(); /** + * A custom style name for the row or null if none is set. + */ + private String styleName = null; + + /** * Returns the cell on given GridColumn. If the column is merged * returned cell is the cell for the whole group. * @@ -381,6 +386,27 @@ abstract class GridStaticSection<ROWTYPE extends GridStaticSection.StaticRow<?>> protected void setSection(GridStaticSection<?> section) { this.section = section; } + + /** + * Returns the custom style name for this row. + * + * @return the style name or null if no style name has been set + */ + public String getStyleName() { + return styleName; + } + + /** + * Sets a custom style name for this row. + * + * @param styleName + * the style name to set or null to not use any style name + */ + public void setStyleName(String styleName) { + this.styleName = styleName; + section.requestSectionRefresh(); + } + } private Grid<?> grid; diff --git a/server/src/com/vaadin/ui/Grid.java b/server/src/com/vaadin/ui/Grid.java index c617917555..04b0e65a1e 100644 --- a/server/src/com/vaadin/ui/Grid.java +++ b/server/src/com/vaadin/ui/Grid.java @@ -357,6 +357,27 @@ public class Grid extends AbstractComponent implements SelectionChangeNotifier, } return null; } + + /** + * Returns the custom style name for this row. + * + * @return the style name or null if no style name has been set + */ + public String getStyleName() { + return getRowState().styleName; + } + + /** + * Sets a custom style name for this row. + * + * @param styleName + * the style name to set or null to not use any style + * name + */ + public void setStyleName(String styleName) { + getRowState().styleName = styleName; + } + } /** @@ -485,7 +506,8 @@ public class Grid extends AbstractComponent implements SelectionChangeNotifier, * Sets a custom style name for this cell. * * @param styleName - * the style name to set + * the style name to set or null to not use any style + * name */ public void setStyleName(String styleName) { cellState.styleName = styleName; diff --git a/shared/src/com/vaadin/shared/ui/grid/GridStaticSectionState.java b/shared/src/com/vaadin/shared/ui/grid/GridStaticSectionState.java index 39d84510f6..88539913d1 100644 --- a/shared/src/com/vaadin/shared/ui/grid/GridStaticSectionState.java +++ b/shared/src/com/vaadin/shared/ui/grid/GridStaticSectionState.java @@ -55,6 +55,11 @@ public class GridStaticSectionState implements Serializable { * Map from column id set to cell state for merged state. */ public Map<Set<String>, CellState> cellGroups = new HashMap<Set<String>, CellState>(); + + /** + * The style name for the row. Null if none. + */ + public String styleName = null; } public List<RowState> rows = new ArrayList<RowState>(); diff --git a/uitest/src/com/vaadin/tests/components/grid/GridHeaderStyleNames.java b/uitest/src/com/vaadin/tests/components/grid/GridHeaderStyleNames.java index 923e964ebb..7c9eb66012 100644 --- a/uitest/src/com/vaadin/tests/components/grid/GridHeaderStyleNames.java +++ b/uitest/src/com/vaadin/tests/components/grid/GridHeaderStyleNames.java @@ -34,6 +34,8 @@ public class GridHeaderStyleNames extends AbstractTestUIWithLog { private HeaderCell ageHeaderCell; private HeaderCell mergedCityCountryCell; private FooterCell ageFooterCell; + private HeaderRow headerRow; + private FooterRow footerRow; @Override protected void setup(VaadinRequest request) { @@ -43,12 +45,12 @@ public class GridHeaderStyleNames extends AbstractTestUIWithLog { ageHeaderCell = grid.getDefaultHeaderRow().getCell("age"); - HeaderRow row = grid.prependHeaderRow(); - mergedCityCountryCell = row.join("city", "country"); + headerRow = grid.prependHeaderRow(); + mergedCityCountryCell = headerRow.join("city", "country"); mergedCityCountryCell.setText("Merged cell"); addComponent(grid); - FooterRow footerRow = grid.appendFooterRow(); + footerRow = grid.appendFooterRow(); ageFooterCell = footerRow.getCell("age"); getPage() @@ -56,12 +58,16 @@ public class GridHeaderStyleNames extends AbstractTestUIWithLog { .add(".age {background-image: linear-gradient(to bottom,green 2%, #efefef 98%) !important;}"); getPage() .getStyles() - .add(".valo .v-grid-header .v-grid-cell.city-country {background-image: linear-gradient(to bottom,yellow 2%, #efefef 98%);}"); + .add(".valo .v-grid-header .v-grid-cell.city-country {background-image: linear-gradient(to bottom,yellow 2%, #efefef 98%) !important;}"); getPage() .getStyles() - .add(".valo .v-grid-footer .v-grid-cell.age-footer {background-image: linear-gradient(to bottom,blue 2%, #efefef 98%);}"); + .add(".valo .v-grid-footer .v-grid-cell.age-footer {background-image: linear-gradient(to bottom,blue 2%, #efefef 98%) !important;}"); + getPage() + .getStyles() + .add(".valo .v-grid .v-grid-row.custom-row > * {background-image: linear-gradient(to bottom,purple 2%, #efefef 98%);}"); - setStyles(true); + setCellStyles(true); + setRowStyles(true); Button b = new Button("Toggle styles"); b.addClickListener(new ClickListener() { @@ -69,14 +75,15 @@ public class GridHeaderStyleNames extends AbstractTestUIWithLog { @Override public void buttonClick(ClickEvent event) { - setStyles(!stylesOn); + setCellStyles(!stylesOn); + setRowStyles(!stylesOn); stylesOn = !stylesOn; } }); addComponent(b); } - protected void setStyles(boolean set) { + protected void setCellStyles(boolean set) { if (set) { ageHeaderCell.setStyleName("age"); ageFooterCell.setStyleName("age-footer"); @@ -89,4 +96,14 @@ public class GridHeaderStyleNames extends AbstractTestUIWithLog { } + protected void setRowStyles(boolean set) { + if (set) { + headerRow.setStyleName("custom-row"); + footerRow.setStyleName("custom-row"); + } else { + headerRow.setStyleName(null); + footerRow.setStyleName(null); + } + + } } diff --git a/uitest/src/com/vaadin/tests/components/grid/GridHeaderStyleNamesTest.java b/uitest/src/com/vaadin/tests/components/grid/GridHeaderStyleNamesTest.java index 5b3b29d284..d8cb8b0d0c 100644 --- a/uitest/src/com/vaadin/tests/components/grid/GridHeaderStyleNamesTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/GridHeaderStyleNamesTest.java @@ -45,7 +45,7 @@ public class GridHeaderStyleNamesTest extends SingleBrowserTest { } @Test - public void styleNamesCanBeAddedAndRemoved() { + public void cellStyleNamesCanBeAddedAndRemoved() { ButtonElement toggleStyles = $(ButtonElement.class).caption( "Toggle styles").first(); @@ -56,6 +56,19 @@ public class GridHeaderStyleNamesTest extends SingleBrowserTest { assertStylesSet(true); } + @Test + public void rowStyleNamesCanBeAddedAndRemoved() { + ButtonElement toggleStyles = $(ButtonElement.class).caption( + "Toggle styles").first(); + + assertRowStylesSet(true); + toggleStyles.click(); + assertRowStylesSet(false); + toggleStyles.click(); + assertRowStylesSet(true); + + } + private void assertStylesSet(boolean set) { if (set) { assertHasStyleName( @@ -90,10 +103,43 @@ public class GridHeaderStyleNamesTest extends SingleBrowserTest { } + private void assertRowStylesSet(boolean set) { + if (set) { + assertHasStyleName( + "Footer row should have the assigned 'custom-row' class name", + getFooterRow(), "custom-row"); + assertHasStyleName( + "Header row should have the assigned 'custom-row' class name", + getHeaderRow(), "custom-row"); + } else { + assertHasNotStyleName( + "Footer row should not have the removed 'custom-row' class name", + getFooterRow(), "custom-row"); + assertHasNotStyleName( + "Header row should not have the removed 'custom-row' class name", + getHeaderRow(), "custom-row"); + } + assertHasStyleName( + "The default v-grid-row style name should not be removed from the header row", + getHeaderRow(), "v-grid-row"); + assertHasStyleName( + "The default v-grid-row style name should not be removed from the footer row", + getFooterRow(), "v-grid-row"); + + } + private WebElement getAgeHeaderCell() { return grid.getHeaderCell(1, 2); } + private WebElement getFooterRow() { + return grid.getFooterRow(0); + } + + private WebElement getHeaderRow() { + return grid.getHeaderRow(0); + } + private void assertHasStyleName(String message, WebElement element, String stylename) { if (!hasCssClass(element, stylename)) { |