Skip to content

Commit

Permalink
Added default renderers that wrap text content (fixes #10)
Browse files Browse the repository at this point in the history
Change-Id: I10ebfb9b19cc3146cccc553646b91e959ceac0c9
  • Loading branch information
tomivirkki committed Jun 29, 2015
1 parent 5c7e134 commit 228f4e3
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 40 deletions.
Expand Up @@ -5,6 +5,7 @@

import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.query.client.js.JsUtils;
import com.google.gwt.safehtml.shared.SafeHtmlUtils;
import com.vaadin.client.widgets.Grid.Column;
import com.vaadin.components.common.js.JS;
import com.vaadin.components.common.js.JS.Setter;
Expand All @@ -14,6 +15,7 @@
import com.vaadin.components.grid.config.JSColumn;
import com.vaadin.components.grid.config.JSStaticCell;
import com.vaadin.components.grid.data.DataItemContainer;
import com.vaadin.components.grid.data.GridDomTableDataSource;
import com.vaadin.shared.ui.grid.GridConstants;

public final class GridColumn extends Column<Object, Object> {
Expand All @@ -32,6 +34,17 @@ public static GridColumn addColumn(JSColumn jsColumn,
private GridColumn(JSColumn jsColumn, GridComponent gridComponent) {
this.jsColumn = jsColumn;
this.gridComponent = gridComponent;

// Default renderer
setRenderer((cell, data) -> {
String innerHTML = JS.isUndefinedOrNull(data) ? "" : data
.toString();
innerHTML = gridComponent.getDataSource() instanceof GridDomTableDataSource ? innerHTML
: SafeHtmlUtils.htmlEscape(innerHTML);
cell.getElement().setInnerHTML(
"<span style='overflow: hidden; text-overflow: ellipsis;'>"
+ innerHTML + "</span>");
});
}

private JSStaticCell getDefaultHeaderCellReference() {
Expand Down
Expand Up @@ -4,7 +4,6 @@

import java.util.List;

import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.dom.client.Element;
import com.google.gwt.query.client.Function;
import com.google.gwt.query.client.GQuery;
Expand Down Expand Up @@ -138,16 +137,6 @@ private void configureColumnsFromDom(GQuery columns) {
jsSortOrder.setColumn(i);
sortOrders.add(jsSortOrder);
}
column.setRenderer(JsUtils.wrapFunction(new Function() {
@Override
public void f() {
JavaScriptObject cell = arguments(0);
Element element = JsUtils.prop(cell, "element");
Object data = JsUtils.prop(cell, "data");
element.setInnerHTML(data != null ? String.valueOf(data)
: "");
}
}));

String headerHtml = JSValidate.String.attr($th, "header-text",
$th.html(), $th.html());
Expand Down
Expand Up @@ -52,16 +52,20 @@ public JSStaticCell obtainJSStaticCell(StaticCell cell) {
bind(jsCell, cell, "colspan",
v -> cell.setColspan(((Double) v).intValue()));
bind(jsCell, cell, "className", v -> cell.setStyleName((String) v));
bind(jsCell, cell, "content", v -> {
if (v == null) {
cell.setHtml(null);
} else if (JS.isPrimitiveType(v) || v instanceof Number) {
cell.setHtml(String.valueOf(v));
} else if (JsUtils.isElement(v)) {
cell.setWidget(new SimplePanel((Element) v) {
bind(jsCell,
cell,
"content",
v -> {
if (v == null) {
cell.setHtml(null);
} else if (JS.isPrimitiveType(v) || v instanceof Number) {
cell.setHtml("<span style='overflow: hidden;text-overflow: ellipsis;'>"
+ String.valueOf(v) + "</span>");
} else if (JsUtils.isElement(v)) {
cell.setWidget(new SimplePanel((Element) v) {
});
}
});
}
});

cells.put(cell, jsCell);
}
Expand Down
24 changes: 4 additions & 20 deletions vaadin-components-gwt/src/main/webapp/vaadin-grid/vaadin-grid.html
Expand Up @@ -85,26 +85,14 @@
}

.v-grid-cell {
display: inline-block;
text-align: left;
display: -webkit-inline-flex;
display: inline-flex;
-webkit-align-items: center;
align-items: center;
box-sizing: border-box;
overflow: hidden;
text-overflow: ellipsis;
background: #fff;
}

.v-grid-cell:before {
content: "";
height: 100%;
}

.v-grid-cell.v-grid *,
.v-grid-cell.v-grid:before,
.v-grid-cell.v-grid:after {
display: inline-block;
vertical-align: middle;
}

:host > div {
position: relative;
outline: none;
Expand Down Expand Up @@ -372,10 +360,6 @@
-webkit-transform: scale(0.8);
transform: scale(0.8);
transition: all 180ms cubic-bezier(0.75,.0,0.25,1);

/* The following is a Firefox specific property
that intentionally disables the splash to avoid a bug */
-moz-appearance: scrollbar;
}

input[type="checkbox"] + label:active:before {
Expand Down

0 comments on commit 228f4e3

Please sign in to comment.