final int listMin = propertyDefinitionList.getMin();
final int listMax = propertyDefinitionList.getMax();
final Canvas errorPanel = buildListOfMapsGridErrorPanel(listMin, listMax);
final ListGrid summaryTable = new ListGrid();
listOfMapsGrids.put(propertyDefinitionList, summaryTable);
summaryTable.setAlternateRecordStyles(true);
summaryTable.setShowAllRecords(true);
summaryTable.setShowAllColumns(true);
summaryTable.setWidth100();
// [BZ 822173 - Table layout problem on configuration page.]
// setBodyOverflow(Overflow.VISIBLE) && setAutoFitFieldWidths(true) issue
//summaryTable.setBodyOverflow(VISIBLE);
//summaryTable.setOverflow(VISIBLE);
// Instead, use setAutoFitData...
summaryTable.setAutoFitData(Autofit.BOTH);
summaryTable.setAutoFitFieldWidths(true);
summaryTable.setAutoFitWidthApproach(AutoFitWidthApproach.BOTH);
summaryTable.setRecordEnabledProperty(null);
List<ListGridField> fieldsList = new ArrayList<ListGridField>();
final List<PropertyDefinition> propertyDefinitions = new ArrayList<PropertyDefinition>(
memberPropertyDefinitionMap.getOrderedPropertyDefinitions());
List<PropertyDefinition> summaryPropertyDefinitions = new ArrayList<PropertyDefinition>();
for (PropertyDefinition subDef : propertyDefinitions) {
if (subDef.isSummary()) {
summaryPropertyDefinitions.add(subDef);
}
}
if (summaryPropertyDefinitions.isEmpty()) {
// An extra "feature of the config system". If no fields are labeled summary, all are considered summary.
summaryPropertyDefinitions.addAll(propertyDefinitions);
}
for (PropertyDefinition summaryPropDef : summaryPropertyDefinitions) {
ListGridField field = createListGridField(summaryPropDef);
fieldsList.add(field);
}
boolean allSubDefsReadOnly = isAllReadOnly(propertyDefinitions);
ListGridField editField = new ListGridField("edit", 20);
editField.setType(ListGridFieldType.ICON);
final boolean mapReadOnly = this.readOnly || allSubDefsReadOnly;
String icon = (mapReadOnly) ? ImageManager.getViewIcon() : ImageManager.getEditIcon();
editField.setCellIcon(Window.getImgURL(icon));
editField.setCanEdit(false);
editField.setCanGroupBy(false);
editField.setCanSort(false);
editField.setCanHide(false);
editField.addRecordClickHandler(new RecordClickHandler() {
public void onRecordClick(RecordClickEvent recordClickEvent) {
PropertyMapListGridRecord record = (PropertyMapListGridRecord) recordClickEvent.getRecord();
PropertyMap memberPropertyMap = (PropertyMap) record.getPropertyMap();
Log.debug("Editing property map: " + memberPropertyMap);
displayMapEditor(summaryTable, errorPanel, record, propertyDefinitionList, propertyList,
memberPropertyDefinitionMap, memberPropertyMap, mapReadOnly);
}
});
fieldsList.add(editField);
boolean propertyReadOnly = (readOnly || (!allPropertiesWritable && propertyDefinitionList.isReadOnly()));
if (!propertyReadOnly) {
ListGridField removeField = new ListGridField("remove", 20);
removeField.setType(ListGridFieldType.ICON);
removeField.setCellIcon(Window.getImgURL(ImageManager.getRemoveIcon()));
removeField.setCanEdit(false);
removeField.setCanFilter(true);
removeField.setFilterEditorType(new SpacerItem());
removeField.setCanGroupBy(false);
removeField.setCanSort(false);
removeField.setCanHide(false);
removeField.addRecordClickHandler(new RecordClickHandler() {
public void onRecordClick(final RecordClickEvent recordClickEvent) {
Log.debug("You want to delete: " + recordClickEvent.getRecordNum());
SC.confirm(MSG.view_configEdit_confirm_2(), new BooleanCallback() {
public void execute(Boolean confirmed) {
if (confirmed) {
if (summaryTable.getRecordList().getLength() <= listMin) {
SC.say(MSG.view_configEdit_minBoundsExceeded(String.valueOf(listMin)));
} else {
PropertyMapListGridRecord recordToBeDeleted = (PropertyMapListGridRecord) recordClickEvent
.getRecord();
propertyList.getList().remove(recordToBeDeleted.getIndex());
ListGridRecord[] rows = buildSummaryRecords(propertyList, propertyDefinitions);
boolean listGridRecordCountValid = isListGridRecordCountValid(rows, listMin,
listMax);
if (errorPanel.isVisible() && listGridRecordCountValid) {
errorPanel.setVisible(false);
}
summaryTable.setData(rows);
firePropertyChangedEvent(propertyList, propertyDefinitionList,
listGridRecordCountValid);
}
}
}
});
}
});
editField.setEditorType(new ButtonItem("delete", MSG.common_button_delete()));
fieldsList.add(removeField);
}
summaryTable.setFields(fieldsList.toArray(new ListGridField[fieldsList.size()]));
// Now add rows containing the actual data (i.e. member property values).
ListGridRecord[] rows = buildSummaryRecords(propertyList, propertyDefinitions);
summaryTable.setData(rows);
VLayout summaryTableHolder = new EnhancedVLayout();
ToolStrip toolStrip = new ToolStrip();
toolStrip.setWidth100();
if (!propertyReadOnly) {
IButton addRowButton = new EnhancedIButton();
addRowButton.setWidth("40px");
addRowButton.setIcon(Window.getImgURL(ImageManager.getAddIcon()));
addRowButton.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler() {
public void onClick(ClickEvent clickEvent) {
if (propertyList.getList().size() >= listMax) {
SC.say(MSG.view_configEdit_maxBoundsExceeded(String.valueOf(propertyDefinitionList.getMax())));
return;
}
displayMapEditor(summaryTable, errorPanel, null, propertyDefinitionList, propertyList,
memberPropertyDefinitionMap, null, mapReadOnly);
}
});
toolStrip.addMember(addRowButton);
}
if (isListGridRecordCountValid(summaryTable.getRecords(), listMin, listMax)) {
errorPanel.setVisible(false);
} else {
errorPanel.setVisible(true);
}
summaryTableHolder.setMembers(summaryTable, toolStrip, errorPanel);