{
public void execute(Event<UIMembershipTypeForm> event) throws Exception
{
UIMembershipTypeForm uiForm = event.getSource();
UIMembershipManagement uiMembershipManagement = uiForm.getParent();
OrganizationService service = uiForm.getApplicationComponent(OrganizationService.class);
String msTypeName = uiForm.getUIStringInput(MEMBERSHIP_TYPE_NAME).getValue();
MembershipType mt = service.getMembershipTypeHandler().findMembershipType(msTypeName);
if (uiForm.getMembershipTypeName() == null)
{
//For create new membershipType case
if (mt != null)
{
UIApplication uiApp = event.getRequestContext().getUIApplication();
uiApp.addMessage(new ApplicationMessage("UIMembershipTypeForm.msg.SameName", null));
return;
}
mt = service.getMembershipTypeHandler().createMembershipTypeInstance();
uiForm.invokeSetBindingBean(mt);
service.getMembershipTypeHandler().createMembershipType(mt, true);
uiMembershipManagement.addOptions(mt);
}
else
{
//For edit a membershipType case
if (mt == null)
{
UIApplication uiApp = event.getRequestContext().getUIApplication();
uiApp.addMessage(new ApplicationMessage("UIMembershipTypeForm.msg.MembershipNotExist",
new String[]{msTypeName}));
}
else
{
uiForm.invokeSetBindingBean(mt);
service.getMembershipTypeHandler().saveMembershipType(mt, true);
}
}
uiMembershipManagement.getChild(UIListMembershipType.class).loadData();
uiForm.getUIStringInput(MEMBERSHIP_TYPE_NAME).setEditable(UIFormStringInput.ENABLE);