/** * sets the css for a row in a grid. the top row will get the header style and other rows get * either the even or odd style. * * @param grid * @param row * @param selected */ private void setGridRowStyle(Grid grid, int row, boolean selected) { String style = ""; if (row > 0) { if (selected) { style = SELECTED_ROW_CSS; } else { if (row % 2 == 0) { style = EVEN_ROW_CSS; } else { style = ODD_ROW_CSS; } } } else { style = GRID_HEADER_CSS; } for (int i = 0; i < grid.getColumnCount(); i++) { grid.getCellFormatter().setStyleName(row, i, style); } }
private void updateRecords() { records.clear(); if (displayFields.isEmpty()) { records.setWidget(new HTML("")); return; } List<StructureHolder> holders = oneToMany.getSelected(); if (holders.isEmpty()) { records.setWidget(new HTML("")); return; } List<String> descs = holders.get(0).getStructure().extractDescriptions(); Grid grid = new Grid(holders.size() + 1, displayFields.size()); grid.setCellSpacing(0); grid.setCellPadding(8); grid.addStyleName("page_assessment_classScheme_grid"); int row = 0; int column = 0; for (Integer value : displayFields) { try { grid.setHTML( row, column, "<span class=\"page_assessment_classScheme_grid_th\">" + descs.get(value) + "</span>"); } catch (IndexOutOfBoundsException e) { grid.setHTML(row, column, "<span class=\"page_assessment_classScheme_grid_th\">-</span>"); } finally { column++; } } row++; for (StructureHolder holder : holders) { final ArrayList<String> raw = new ArrayList<String>(), pretty = new ArrayList<String>(); final Structure<Object> structure = holder.getStructure(); final Map<String, String> map = new LinkedHashMap<String, String>(); for (Object obj : structure.getClassificationInfo()) { ClassificationInfo info = (ClassificationInfo) obj; map.put(info.getDescription(), info.getData()); raw.add(info.getData()); } try { structure.getDisplayableData(raw, pretty, 0); } catch (Exception e) { continue; } column = 0; for (Integer value : displayFields) { try { grid.setHTML( row, column, "<span class=\"page_assessment_classScheme_content\">" + pretty.get(value) + "</span>"); } catch (IndexOutOfBoundsException e) { grid.setHTML(row, column, "<span class=\"page_assessment_classScheme_content\">-</span>"); } finally { column++; } } row++; } for (int i = 0; i < grid.getColumnCount(); i++) grid.getColumnFormatter().setWidth(i, "150px"); records.setWidget(grid); }