package com.nexirius.theteam.datamodel;
import com.nexirius.framework.application.DialogManager;
import com.nexirius.framework.datamodel.DataModel;
import com.nexirius.framework.datamodel.DataModelEnumeration;
import com.nexirius.framework.datamodel.DefaultDataModelCommand;
public class AddressListModel extends EditListModel {
public static final String FIELD_ADDRESS_LIST = "AddressList";
AddressListModel() {
super(FIELD_ADDRESS_LIST, new AddressArrayModel());
appendMethod(new DefaultDataModelCommand("setMainAddress"));
}
public String getMemberId() {
return ((MemberModel) getParentDataModel()).getInstanceName();
}
public DataModel addItem() {
AddressModel address = new AddressModel();
if (DialogManager.getPopupEditorAdaptor().popupEdit(address)) {
return address;
}
return null;
}
public boolean editItem(DataModel model) {
AddressModel a = (AddressModel) model;
if (DialogManager.getPopupEditorAdaptor().popupEdit(a)) {
return true;
}
return false;
}
public void setMainAddress() {
DataModel highlighted = getHighlightedItem();
if (highlighted != null) {
DataModelEnumeration en = getList().getEnumeration();
while (en.hasMore()) {
AddressModel address = (AddressModel) en.next();
address.setMainAddress(address == highlighted);
}
} else {
DialogManager.error("NothingHighlighted");
}
}
}