/** * Creates and configure the column model for the grid contained in this component. * * @param enabled <code>true</code> to enable the delete column, <code>false</code> to disable it. * @return A new array of column configs. */ private ColumnConfig[] createColumnModel(final boolean enabled) { final boolean canRemove = enabled && userCanPerformChangeType(ValueEventChangeType.REMOVE); // Creating columns final ColumnConfig lastEditDateColumn = new ColumnConfig("lastEditDate", I18N.CONSTANTS.reportLastEditDate(), 60); final ColumnConfig nameColumn = new ColumnConfig("name", I18N.CONSTANTS.reportName(), 100); final ColumnConfig editorNameColumn = new ColumnConfig("editorName", I18N.CONSTANTS.reportEditor(), 100); final ColumnConfig deleteColumn = new ColumnConfig("delete", "", 10); // Date column specificities lastEditDateColumn.setDateTimeFormat(DateUtils.DATE_SHORT); // Name column specificities nameColumn.setRenderer( new GridCellRenderer<ReportReference>() { @Override public Object render( final ReportReference model, String property, ColumnData config, int rowIndex, int colIndex, ListStore store, Grid grid) { final Anchor anchor = new Anchor((String) model.get(property)); anchor.addStyleName("flexibility-link"); anchor.addClickHandler( new ClickHandler() { @Override public void onClick(ClickEvent event) { eventBus.navigateRequest(createPageRequest(model.getId())); } }); return anchor; } }); // Delete column specificities deleteColumn.setSortable(false); deleteColumn.setRenderer( new GridCellRenderer<ReportReference>() { @Override public Object render( final ReportReference model, String property, ColumnData config, int rowIndex, int colIndex, final ListStore store, Grid grid) { if (!canRemove) { return "-"; } final Image image = IconImageBundle.ICONS.remove().createImage(); image.setTitle(I18N.CONSTANTS.remove()); image.addStyleName("flexibility-action"); // Action image.addClickHandler( new ClickHandler() { @Override public void onClick(ClickEvent event) { N10N.confirmation( I18N.CONSTANTS.remove(), I18N.MESSAGES.reportRemoveConfirm(model.getName()), new ConfirmCallback() { @Override public void onAction() { // TODO: Delete the report if (Log.isDebugEnabled()) { Log.debug("Removing '" + model.getName() + "' report..."); } dispatch.execute( new Delete(ProjectReportDTO.ENTITY_NAME, model.getId()), new CommandResultHandler<VoidResult>() { @Override public void onCommandSuccess(final VoidResult result) { store.remove(model); N10N.validNotif("OK", "OK"); } @Override public void onCommandFailure(final Throwable caught) { N10N.warn("ERROR", "ERROR"); } }); } }); } }); return image; } }); return new ColumnConfig[] {lastEditDateColumn, nameColumn, editorNameColumn, deleteColumn}; }