summaryrefslogtreecommitdiffstats
path: root/client/src
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2014-11-26 23:02:23 +0200
committerArtur Signell <artur@vaadin.com>2014-12-01 13:11:00 +0000
commit67c3d0534594585a9631ac3f00258c133a54d975 (patch)
treef3f87691c04612d049e02920572cce56ae43e036 /client/src
parent1edeb7c4a8f3a31915e895e2314d26d0f7534189 (diff)
downloadvaadin-framework-67c3d0534594585a9631ac3f00258c133a54d975.tar.gz
vaadin-framework-67c3d0534594585a9631ac3f00258c133a54d975.zip
Allow setting style names for header and footer cells (#7225)
Change-Id: Ieb8f5b36466a2d579e9c82f16613f6bc8952c831
Diffstat (limited to 'client/src')
-rw-r--r--client/src/com/vaadin/client/ui/grid/Grid.java23
-rw-r--r--client/src/com/vaadin/client/ui/grid/GridConnector.java1
-rw-r--r--client/src/com/vaadin/client/ui/grid/GridStaticSection.java24
3 files changed, 45 insertions, 3 deletions
diff --git a/client/src/com/vaadin/client/ui/grid/Grid.java b/client/src/com/vaadin/client/ui/grid/Grid.java
index 851d11bd86..c0edfd9eb8 100644
--- a/client/src/com/vaadin/client/ui/grid/Grid.java
+++ b/client/src/com/vaadin/client/ui/grid/Grid.java
@@ -88,6 +88,7 @@ import com.vaadin.shared.ui.grid.Range;
import com.vaadin.shared.ui.grid.ScrollDestination;
import com.vaadin.shared.ui.grid.SortDirection;
import com.vaadin.shared.ui.grid.SortEventOriginator;
+import com.vaadin.shared.util.SharedUtil;
/**
* A data grid view that supports columns and lazy loading of data rows from a
@@ -1338,6 +1339,7 @@ public class Grid<T> extends ResizeComposite implements
private GridStaticSection<?> section;
private RowContainer container;
+ private static final String CUSTOM_STYLE_PROPERTY_NAME = "customStyle";
public StaticSectionUpdater(GridStaticSection<?> section,
RowContainer container) {
@@ -1364,19 +1366,34 @@ public class Grid<T> extends ResizeComposite implements
// Assign colspan to cell before rendering
cell.setColSpan(metadata.getColspan());
+ TableCellElement element = cell.getElement();
switch (metadata.getType()) {
case TEXT:
- cell.getElement().setInnerText(metadata.getText());
+ element.setInnerText(metadata.getText());
break;
case HTML:
- cell.getElement().setInnerHTML(metadata.getHtml());
+ element.setInnerHTML(metadata.getHtml());
break;
case WIDGET:
preDetach(row, Arrays.asList(cell));
- cell.getElement().setInnerHTML("");
+ element.setInnerHTML("");
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);
+ }
cellFocusHandler.updateFocusedCellStyle(cell, container);
}
diff --git a/client/src/com/vaadin/client/ui/grid/GridConnector.java b/client/src/com/vaadin/client/ui/grid/GridConnector.java
index 00acf94de3..feb46af0c1 100644
--- a/client/src/com/vaadin/client/ui/grid/GridConnector.java
+++ b/client/src/com/vaadin/client/ui/grid/GridConnector.java
@@ -526,6 +526,7 @@ public class GridConnector extends AbstractHasComponentsConnector implements
throw new IllegalStateException("unexpected cell type: "
+ cellState.type);
}
+ cell.setStyleName(cellState.styleName);
}
/**
diff --git a/client/src/com/vaadin/client/ui/grid/GridStaticSection.java b/client/src/com/vaadin/client/ui/grid/GridStaticSection.java
index 79aef4601f..a85001f58c 100644
--- a/client/src/com/vaadin/client/ui/grid/GridStaticSection.java
+++ b/client/src/com/vaadin/client/ui/grid/GridStaticSection.java
@@ -49,6 +49,8 @@ abstract class GridStaticSection<ROWTYPE extends GridStaticSection.StaticRow<?>>
private GridStaticCellType type = GridStaticCellType.TEXT;
+ private String styleName = null;
+
/**
* Sets the text displayed in this cell.
*
@@ -176,6 +178,28 @@ abstract class GridStaticSection<ROWTYPE extends GridStaticSection.StaticRow<?>>
public GridStaticCellType getType() {
return type;
}
+
+ /**
+ * Returns the custom style name for this cell.
+ *
+ * @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 cell.
+ *
+ * @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();
+
+ }
+
}
/**