for (ListGridField listGridField : fields) {
listGridFieldsMap.put(listGridField.getName(), listGridField);
}
dataSourceFieldNamesSet.removeAll(listGridFieldsMap.keySet());
DataSourceField dataSourceIdField = getDataSource().getField(FIELD_ID);
boolean hideIdField = (!CoreGUI.isDebugMode() && !forceIdField);
if (dataSourceIdField != null && hideIdField) {
// setHidden() will not work on the DataSource field - use the listGrid.hideField() instead.
this.listGrid.hideField(FIELD_ID);
}
ListGridField listGridIdField = listGridFieldsMap.get(FIELD_ID);
if (listGridIdField != null) {
listGridIdField.setHidden(hideIdField);
}
if (!dataSourceFieldNamesSet.isEmpty()) {
ListGridField[] newFields = new ListGridField[fields.length + dataSourceFieldNamesSet.size()];
int destIndex = 0;
if (dataSourceFieldNamesSet.contains(FIELD_ID)) {
String datasourceFieldTitle = getDataSource().getField(FIELD_ID).getTitle();
String listGridFieldTitle = (datasourceFieldTitle != null) ? datasourceFieldTitle : MSG
.common_title_id();
listGridIdField = new ListGridField(FIELD_ID, listGridFieldTitle, 55);
// Override the DataSource id field metadata for consistent display across all Tables.
listGridIdField.setType(ListGridFieldType.INTEGER);
listGridIdField.setCanEdit(false);
listGridIdField.setHidden(hideIdField);
newFields[destIndex++] = listGridIdField;
dataSourceFieldNamesSet.remove(FIELD_ID);
}
System.arraycopy(fields, 0, newFields, destIndex, fields.length);
destIndex += fields.length;
for (String dataSourceFieldName : dataSourceFieldNamesSet) {
DataSourceField dataSourceField = getDataSource().getField(dataSourceFieldName);
ListGridField listGridField = new ListGridField(dataSourceField.getName());
this.listGrid.hideField(dataSourceFieldName);
listGridField.setHidden(true);
newFields[destIndex++] = listGridField;
}
this.listGrid.setFields(newFields);