final PropertyList propertyList) {
Log.debug("Building list-of-simples field for " + propertyList + "...");
EnhancedVLayout vLayout = new EnhancedVLayout();
final DynamicForm listGrid = new DynamicForm();
vLayout.addMember(listGrid);
final SelectItem membersItem = new SelectItem(propertyList.getName());
membersItem.setShowTitle(false);
membersItem.setMultiple(true);
membersItem.setMultipleAppearance(MultipleAppearance.GRID);
membersItem.setWidth(220);
membersItem.setHeight(60);
LinkedHashMap<String, String> memberValueToIndexMap = buildValueMap(propertyList);
membersItem.setValueMap(memberValueToIndexMap);
listGrid.setItems(membersItem);
if (!isReadOnly(propertyDefinitionList, propertyList)) {
// List is not read-only - add footer with New and Delete buttons to allow user to add or remove members.
ToolStrip footer = new ToolStrip();
footer.setPadding(5);
footer.setWidth100();
footer.setMembersMargin(15);
vLayout.addMember(footer);
final IButton deleteButton = new EnhancedIButton(MSG.common_button_delete());
deleteButton.setIcon(Window.getImgURL(ImageManager.getRemoveIcon()));
deleteButton.setTooltip(MSG.view_configEdit_tooltip_1());
deleteButton.setDisabled(true);
deleteButton.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler() {
public void onClick(ClickEvent clickEvent) {
final String[] selectedValues = membersItem.getValues();
final String noun = (selectedValues.length == 1) ? MSG.common_label_item() : MSG
.common_label_items();
String message = MSG.view_configEdit_confirm_3(Integer.toString(selectedValues.length), noun);
if (propertyList.getList().size() <= propertyDefinitionList.getMin()) {
SC.say("You cannot delete this entry because the minimum size bounds has been met: "
+ propertyDefinitionList.getMin());
} else {
SC.ask(message, new BooleanCallback() {
public void execute(Boolean confirmed) {
if (confirmed) {
for (int i = selectedValues.length - 1; i >= 0; i--) {
String selectedValue = selectedValues[i];
int index = Integer.valueOf(selectedValue);
propertyList.getList().remove(index);
// Rebuild the select item options.
LinkedHashMap<String, String> memberValueToIndexMap = buildValueMap(propertyList);
membersItem.setValueMap(memberValueToIndexMap);
deleteButton.disable();
firePropertyChangedEvent(propertyList, propertyDefinitionList, true);
CoreGUI.getMessageCenter().notify(
new Message(MSG.view_configEdit_msg_3(
Integer.toString(selectedValues.length), noun), EnumSet
.of(Message.Option.Transient)));
}
}
}
});
}
}
});
footer.addMember(deleteButton);
membersItem.addChangedHandler(new ChangedHandler() {
@Override
public void onChanged(ChangedEvent changedEvent) {
String[] selectedValues = membersItem.getValues();
int count = selectedValues.length;
deleteButton.setDisabled(count < 1);
}
});
final IButton newButton = new EnhancedIButton(MSG.common_button_new());
newButton.setIcon(Window.getImgURL(ImageManager.getAddIcon()));
newButton.setTooltip(MSG.view_configEdit_tooltip_2());
newButton.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler() {
public void onClick(ClickEvent clickEvent) {
if (propertyList.getList().size() >= propertyDefinitionList.getMax()) {
SC.say(MSG.view_configEdit_maxBoundsExceeded(String.valueOf(propertyDefinitionList.getMax())));
} else {
final Window popup = createPopup(MSG.view_configEdit_addItem(), 400, 150);
VLayout vLayout = new VLayout();
vLayout.setMargin(10);
HTMLFlow description = new HTMLFlow(propertyDefinitionList.getDescription());
vLayout.addMember(description);
final DynamicForm form = new DynamicForm();
PropertyDefinitionSimple memberPropertyDefinitionSimple = (PropertyDefinitionSimple) propertyDefinitionList
.getMemberDefinition();
final String propertyName = memberPropertyDefinitionSimple.getName();
final PropertySimple newMemberPropertySimple = new PropertySimple(propertyName, null);
FormItem simpleField = buildSimpleField(memberPropertyDefinitionSimple, newMemberPropertySimple);
simpleField.setTitle(memberPropertyDefinitionSimple.getDisplayName());
simpleField.setShowTitle(true);
simpleField.setAlign(Alignment.CENTER);
simpleField.setDisabled(false);
simpleField.setRequired(true);
simpleField.setEndRow(true);
SpacerItem spacer = new SpacerItem();
spacer.setHeight(9);
form.setItems(simpleField, spacer);
vLayout.addMember(form);
final IButton okButton = new EnhancedIButton(MSG.common_button_ok(), ButtonColor.BLUE);
okButton.disable();
okButton.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler() {
public void onClick(ClickEvent clickEvent) {
propertyList.add(newMemberPropertySimple);
// Rebuild the select item options.
LinkedHashMap<String, String> memberValueToIndexMap = buildValueMap(propertyList);
membersItem.setValueMap(memberValueToIndexMap);
firePropertyChangedEvent(propertyList, propertyDefinitionList, true);
CoreGUI.getMessageCenter().notify(
new Message(MSG.view_configEdit_msg_4(), EnumSet.of(Message.Option.Transient)));
popup.destroy();
}
});
form.addItemChangedHandler(new ItemChangedHandler() {
public void onItemChanged(ItemChangedEvent itemChangedEvent) {
Object newValue = itemChangedEvent.getNewValue();
newMemberPropertySimple.setValue(newValue);
// Only enable the OK button, allowing the user to add the property to the map, if the
// property is valid.
boolean isValid = form.validate();
okButton.setDisabled(!isValid);
}
});
final IButton cancelButton = new EnhancedIButton(MSG.common_button_cancel());