protected void configureTable() {
List<ListGridField> fields = getDataSource().getListGridFields(this.resourceId == null);
setListGridFields(true, fields.toArray(new ListGridField[fields.size()])); // true = always show the ID field
addTableAction(MSG.common_button_delete(), MSG.common_msg_areYouSure(), ButtonColor.RED,
new AbstractTableAction(hasWritePerm ? TableActionEnablement.ANY : TableActionEnablement.NEVER) {
public void executeAction(ListGridRecord[] selection, Object actionValue) {
if (selection != null && selection.length > 0) {
int[] doomedIds = new int[selection.length];
int i = 0;
for (ListGridRecord selected : selection) {
doomedIds[i++] = selected.getAttributeAsInt(AbstractConfigurationHistoryDataSource.Field.ID);
if (selected.getAttribute(AbstractConfigurationHistoryDataSource.Field.GROUP_CONFIG_UPDATE_ID) != null) {
CoreGUI.getMessageCenter().notify(
new Message(MSG.view_configurationHistoryList_cannotDeleteGroupItems(),
Severity.Warning));
return; // abort
}
if (Boolean.parseBoolean(selected
.getAttribute(AbstractConfigurationHistoryDataSource.Field.CURRENT_CONFIG))) {
CoreGUI.getMessageCenter().notify(
new Message(MSG.view_configurationHistoryList_cannotDeleteCurrent(), Severity.Warning));
return; // abort
}
}
delete(doomedIds);
}
}
});
addTableAction(MSG.common_button_compare(), null, ButtonColor.BLUE, new AbstractTableAction(
TableActionEnablement.MULTIPLE) {
public void executeAction(ListGridRecord[] selection, Object actionValue) {
// The config updates do not have their Configurations fetched, so we need to reload the selected
// config updates, specifying that their Configurations should be fetched, in order to compare the
// Configurations.
List<Integer> updateIds = new ArrayList<Integer>();
for (ListGridRecord record : selection) {
int updateId = record.getAttributeAsInt(AbstractConfigurationHistoryDataSource.Field.ID);
updateIds.add(updateId);
}
Criteria criteria = new Criteria();
criteria.addCriteria(AbstractConfigurationHistoryDataSource.CriteriaField.IDS,
updateIds.toArray(new Integer[updateIds.size()]));
DSRequest requestProperties = new DSRequest();
requestProperties.setAttribute(
AbstractConfigurationHistoryDataSource.RequestProperty.FETCH_CONFIGURATION, true);
getDataSource().fetchData(criteria, new DSCallback() {
public void execute(DSResponse response, Object rawData, DSRequest request) {
ArrayList<AbstractResourceConfigurationUpdate> updatesWithConfigs = new ArrayList<AbstractResourceConfigurationUpdate>();
Record[] records = response.getData();
for (Record record : records) {
AbstractResourceConfigurationUpdate update = (AbstractResourceConfigurationUpdate) record
.getAttributeAsObject(AbstractConfigurationHistoryDataSource.Field.OBJECT);
updatesWithConfigs.add(update);
}
ConfigurationComparisonView.displayComparisonDialog(updatesWithConfigs);
}
}, requestProperties);
}
});
if (getResourceId() != null) {
addTableAction(MSG.view_configurationHistoryList_rollback(), MSG.common_msg_areYouSure(), ButtonColor.RED,
new AbstractTableAction(hasWritePerm ? TableActionEnablement.SINGLE : TableActionEnablement.NEVER) {
public void executeAction(ListGridRecord[] selection, Object actionValue) {
if (selection != null && selection.length == 1) {
ListGridRecord record = selection[0];
int configHistoryIdToRollbackTo = record
.getAttributeAsInt(AbstractConfigurationHistoryDataSource.Field.ID);