table.setWidth(cm.getTotalWidth() + "px");
List<HeaderGroupConfig> configs = cm.getHeaderGroups();
FlexCellFormatter cf = table.getFlexCellFormatter();
RowFormatter rf = table.getRowFormatter();
rows = 0;
for (HeaderGroupConfig config : configs) {
rows = Math.max(rows, config.getRow() + 1);
}
rows += 1;
for (int i = 0; i < rows; i++) {
rf.setStyleName(i, "x-grid3-hd-row");
rf.getElement(i).setAttribute("role", "presentation");
}
int cols = cm.getColumnCount();
for (HeaderGroupConfig config : cm.getHeaderGroups()) {
int col = config.getColumn();
int row = config.getRow();
int rs = config.getRowspan();
int cs = config.getColspan();
Group group = createNewGroup(config);
group.render(DOM.createDiv());
boolean hide = true;
if (rows > 1) {
for (int i = col; i < (col + cs); i++) {
if (!cm.isHidden(i)) {
hide = false;
}
}
}
if (hide) {
continue;
}
table.setWidget(row, col, group);
cf.setStyleName(row, col, "x-grid3-header x-grid3-hd x-grid3-cell");
HorizontalAlignment align = config.getHorizontalAlignment();
if (align == HorizontalAlignment.RIGHT) {
cf.setHorizontalAlignment(row, col, HasHorizontalAlignment.ALIGN_RIGHT);
} else if (align == HorizontalAlignment.LEFT) {
cf.setHorizontalAlignment(row, col, HasHorizontalAlignment.ALIGN_LEFT);
} else {
cf.setHorizontalAlignment(row, col, HasHorizontalAlignment.ALIGN_CENTER);
}
int ncs = cs;
if (cs > 1) {
for (int i = col; i < (col + cs); i++) {
if (cm.isHidden(i)) {
ncs -= 1;
}
}
}
cf.setRowSpan(row, col, rs);
cf.setColSpan(row, col, ncs);
}
for (int i = 0; i < cols; i++) {
Head h = createNewHead(cm.getColumn(i));
if (cm.isHidden(i)) {
continue;
}
int rowspan = 1;
if (rows > 1) {
for (int j = rows - 2; j >= 0; j--) {
if (!cm.hasGroup(j, i)) {
rowspan += 1;
}
}
}
h.render(DOM.createDiv());
int row;
if (rowspan > 1) {
row = (rows - 1) - (rowspan - 1);
} else {
row = rows - 1;
}
h.row = row;
if (rowspan > 1) {
table.setWidget(row, i, h);
table.getFlexCellFormatter().setRowSpan(row, i, rowspan);
} else {
table.setWidget(row, i, h);
}
cf.setStyleName(row, i, "x-grid3-header x-grid3-hd x-grid3-cell x-grid3-td-" + cm.getColumnId(i));
cf.getElement(row, i).setAttribute("role", "presentation");
HorizontalAlignment align = cm.getColumnAlignment(i);
if (align == HorizontalAlignment.RIGHT) {
table.getCellFormatter().setHorizontalAlignment(row, i, HasHorizontalAlignment.ALIGN_RIGHT);
table.getCellFormatter().getElement(row, i).getFirstChildElement().getStyle().setPropertyPx("paddingRight", 16);