footerStrip.setPadding(5);
footerStrip.setMembersMargin(10);
layout.addMember(footerStrip);
// footer OK button
final IButton okButton = new EnhancedIButton(MSG.common_button_ok(), ButtonColor.BLUE);
if (!propertyIsReadOnly) {
// if its read-only, allow the ok button to be enabled to just let the user close the window
// otherwise, disable it now and we will enable it after we know things are ready to be saved
okButton.setDisabled(true);
}
okButton.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler() {
public void onClick(ClickEvent clickEvent) {
if (!propertyIsReadOnly) {
boolean valuesHomogeneous = true;
boolean isValid = true;
String firstValue = data[0].getAttribute(FIELD_VALUE);
int i = 0;
for (ListGridRecord valueItem : data) {
String value = valueItem.getAttribute(FIELD_VALUE);
if (valuesHomogeneous) {
if ((value != null && !value.equals(firstValue)) || (value == null && firstValue != null)) {
valuesHomogeneous = false;
}
}
isValid = isValid && memberValuesGrid.validateRow(i);
Configuration config = (Configuration) valueItem.getAttributeAsObject(ATTR_CONFIG_OBJ);
PropertySimple memberPropertySimple = (PropertySimple) getProperty(config,
aggregatePropertySimple, index);
memberPropertySimple.setValue(value);
memberPropertySimple.setErrorMessage(null);
}
String aggregateStaticItemName = aggregateValueItem.getAttribute(RHQ_STATIC_ITEM_NAME_ATTRIBUTE);
FormItem aggregateStaticItem = aggregateValueItem.getForm().getField(aggregateStaticItemName);
String aggregateUnsetItemName = aggregateValueItem.getAttribute(RHQ_UNSET_ITEM_NAME_ATTRIBUTE);
FormItem aggregateUnsetItem = aggregateValueItem.getForm().getField(aggregateUnsetItemName);
aggregateUnsetItem.setDisabled(!valuesHomogeneous);
if (valuesHomogeneous) {
// Update the value of the aggregate property and set its override flag to true.
aggregatePropertySimple.setValue(firstValue);
aggregatePropertySimple.setOverride(true);
boolean isUnset = (firstValue == null);
aggregateUnsetItem.setValue(isUnset);
// Set the aggregate value item's value to the homogeneous value, unhide it, and enable it
// unless it's unset.
setValue(aggregateValueItem, firstValue);
aggregateValueItem.show();
aggregateValueItem.setDisabled(isUnset);
aggregateStaticItem.hide();
} else {
aggregatePropertySimple.setValue(null);
aggregatePropertySimple.setOverride(false);
aggregateValueItem.hide();
aggregateStaticItem.show();
}
CoreGUI.getMessageCenter().notify(
new Message(MSG.view_groupConfigEdit_saveReminder(), Severity.Info));
// this has the potential to send another message to the message center
firePropertyChangedEvent(aggregatePropertySimple, propertyDefinitionSimple, isValid);
}
popup.destroy();
}
});
footerStrip.addMember(okButton);
// track errors in grid - enable/disable OK button accordingly
// I tried many ways to get this to work right - this is what I came up with
memberValuesGrid.addRowEditorExitHandler(new RowEditorExitHandler() {
public void onRowEditorExit(RowEditorExitEvent event) {
memberValuesGrid.validateRow(event.getRowNum());
if (memberValuesGrid.hasErrors()) {
okButton.disable();
} else {
okButton.enable();
}
}
});
// if the data can be changed, add some additional widgets; if not, make the value grid read only
if (propertyIsReadOnly) {
memberValuesGrid.setCanEdit(false);
} else {
// put a cancel button in the footer strip to allow the user to exit without saving changes
final IButton cancelButton = new EnhancedIButton(MSG.common_button_cancel());
cancelButton.focus();
cancelButton.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler() {
public void onClick(ClickEvent clickEvent) {
popup.destroy();
}
});
footerStrip.addMember(cancelButton);