@Override public Grid<ModelData> initGrid(ListStore<ModelData> store) { List<ColumnConfig> columns = new ArrayList<ColumnConfig>(); columns.add(configColumn(AdminUserBeanDesc.login, 380)); ColumnConfig roleColumn = configColumn(AdminUserBeanDesc.role, 400); roleColumn.setRenderer( new GridCellRenderer<ModelData>() { public Object render( ModelData model, String property, com.extjs.gxt.ui.client.widget.grid.ColumnData config, int rowIndex, int colIndex, ListStore<ModelData> store, Grid<ModelData> grid) { Object obj = model.get(AdminUserBeanDesc.role.getName()); String label = ""; try { label = (String) ((BeanModel) obj).get("label"); } catch (Exception e) { log.log( java.util.logging.Level.INFO, "can't cast obj:" + obj + "|class:" + (null != obj ? obj.getClass() : "null") + "|to RoleBean"); } return getSortedGroupLabel(label); } }); columns.add(roleColumn); columns.add(configColumn(AdminUserBeanDesc.lastName, 110)); columns.add(configColumn(AdminUserBeanDesc.firstName, 110)); ColumnConfig typeColumn = configColumn(AdminUserBeanDesc.userType, 60); typeColumn.setAlignment(HorizontalAlignment.CENTER); typeColumn.setRenderer( new GridCellRenderer<ModelData>() { public Object render( ModelData model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<ModelData> store, Grid<ModelData> grid) { Type type = Type.valueOf((String) model.get(property)); return TypeDecorator.decorate(type); } }); columns.add(typeColumn); ColumnConfig activeColumn = configColumn(AdminUserBeanDesc.active, 100); activeColumn.setAlignment(HorizontalAlignment.CENTER); CheckBoxImageRender.getInstance().render(activeColumn); columns.add(activeColumn); // columns.add(configCheckColumn(AdminUserBeanDesc.active, 55)); ColumnConfig creationDateColumn = configColumn(AdminUserBeanDesc.creationDate, 120); creationDateColumn.setRenderer( new GridCellRenderer<ModelData>() { public Object render( ModelData model, String property, com.extjs.gxt.ui.client.widget.grid.ColumnData config, int rowIndex, int colIndex, ListStore<ModelData> store, Grid<ModelData> grid) { return DateTimeFormat.getFormat("yyyy-MM-dd HH:mm:ss") .format((Date) model.get(AdminUserBeanDesc.creationDate.getName())); } }); columns.add(creationDateColumn); columns.add(configColumn(AdminUserBeanDesc.authenticationLogin, 100)); final ColumnModel cm = new ColumnModel(columns); GroupingView gridview = new GroupingView() { // for RoleBean grouping @Override protected String getGroup( Object value, ModelData m, int rowIndex, int colIndex, ListStore<ModelData> ds) { if (value instanceof RoleBean) { // return ((RoleBean) value).getLabel(); return getSortedGroupLabel(((RoleBean) value).getLabel()); } else { return value == null ? "" : value.toString(); } } }; gridview.setShowGroupedColumn(false); gridview.setForceFit(true); gridview.setGroupRenderer( new GridGroupRenderer() { public String render(GroupColumnData data) { String f = cm.getColumnById(data.field).getHeader(); String l = data.models.size() == 1 ? I18nUtils.getMessages().user_groupTextTpl_member() : I18nUtils.getMessages().user_groupTextTpl_members(); String label = ""; if (null != data && null != data.gvalue) { label = data.gvalue.toString(); } return f + ": " + getSortedGroupLabel(label) + " (" + data.models.size() + " " + l + ")"; } }); Grid<ModelData> grid = new Grid<ModelData>(store, cm); grid.setView(gridview); grid.setAutoExpandColumn(AdminUserBeanDesc.login.getName()); grid.getSelectionModel().setSelectionMode(SelectionMode.SINGLE); return grid; }
@Override public Grid<ModelData> initGrid(ListStore<ModelData> store) { List<ColumnConfig> columns = new ArrayList<ColumnConfig>(); ColumnConfig referenceColumn = configColumn(ProjectBeanDesc.reference, 100); referenceColumn.setRenderer( new GridCellRenderer<ModelData>() { public Object render( ModelData model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<ModelData> store, Grid<ModelData> grid) { boolean reference = (Boolean) model.get(property); Image image = new Image(Icons.INSTANCE.star()); return reference ? image : ""; } }); columns.add(referenceColumn); columns.add(configColumn(ProjectBeanDesc.label, 100)); columns.add(configColumn(ProjectBeanDesc.description, 100)); ColumnConfig createDateColumn = configColumn(ProjectBeanDesc.creationDate, 120); createDateColumn.setDateTimeFormat(DateTimeFormat.getFormat("yyyy-MM-dd HH:mm:ss")); columns.add(createDateColumn); ColumnConfig activeColumn = configColumn(ProjectBeanDesc.active, 100); activeColumn.setAlignment(HorizontalAlignment.CENTER); CheckBoxImageRender.getInstance().render(activeColumn); columns.add(activeColumn); ColumnConfig projectTypeColumn = configColumn(ProjectBeanDesc.projectType, 60); projectTypeColumn.setAlignment(HorizontalAlignment.CENTER); projectTypeColumn.setRenderer( new GridCellRenderer<ModelData>() { public Object render( ModelData model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<ModelData> store, Grid<ModelData> grid) { Type type = Type.valueOf((String) model.get(property)); return TypeDecorator.decorate(type); } }); columns.add(projectTypeColumn); columns.add(configColumn(ProjectBeanDesc.url, 100)); ColumnConfig warningColumn = configColumn(ProjectBeanDesc.warning, 100); warningColumn.setRenderer(new WarningInfoRenderer()); columns.add(warningColumn); ColumnModel cm = new ColumnModel(columns); Grid<ModelData> grid = new Grid<ModelData>(store, cm); grid.setAutoExpandColumn(ProjectBeanDesc.label.getName()); grid.getSelectionModel().setSelectionMode(SelectionMode.SINGLE); return grid; }