public void execute(Event<UICategoryForm> event) throws Exception
{
UICategoryForm uiForm = event.getSource();
WebuiRequestContext ctx = event.getRequestContext();
UIApplicationOrganizer uiOrganizer = uiForm.getParent();
ApplicationRegistryService service = uiForm.getApplicationComponent(ApplicationRegistryService.class);
ApplicationCategory category = uiForm.getCategory();
boolean isCreateNew = category == null;
if (isCreateNew)
{
category = new ApplicationCategory();
}
UIFormInputSet uiSetting = uiForm.getChildById(FIELD_SETTING);
UIFormInputSet uiPermission = uiForm.getChildById(FIELD_PERMISSION);
category.setName(uiSetting.getUIStringInput(FIELD_NAME).getValue());
String displayName = uiSetting.getUIStringInput(FIELD_DISPLAY_NAME).getValue();
if (displayName == null || displayName.length() < 1)
{
category.setDisplayName(category.getName());
}
else
{
category.setDisplayName(displayName);
}
category.setDescription(uiSetting.getUIFormTextAreaInput(FIELD_DESCRIPTION).getValue());
UIListPermissionSelector uiListPermissionSelector = uiPermission.getChild(UIListPermissionSelector.class);
ArrayList<String> pers = new ArrayList<String>();
if (uiListPermissionSelector.getValue() != null)
{
for (String per : uiListPermissionSelector.getValue())
{
pers.add(per);
}
}
category.setAccessPermissions(pers);
ApplicationCategory existCategory = service.getApplicationCategory(category.getName());
if (!isCreateNew)
{
if (existCategory == null)
{
uiOrganizer.reload();
UIApplication uiApp = ctx.getUIApplication();
uiApp.addMessage(new ApplicationMessage("category.msg.changeNotExist", null));
ctx.addUIComponentToUpdateByAjax(uiOrganizer);
return;
}
category.setModifiedDate(new Date());
}
else
{
if (existCategory != null)
{
UIApplication uiApp = event.getRequestContext().getUIApplication();
uiApp.addMessage(new ApplicationMessage("UICategoryForm.msg.SameName", null));
if (uiOrganizer.getCategory(category.getName()) == null)
{
uiOrganizer.initApplicationCategories();
}
return;
}
category.setModifiedDate(new Date());
category.setCreatedDate(new Date());
}
service.save(category);
uiForm.setValue(null);
uiOrganizer.reload();
uiOrganizer.setSelectedCategory(category.getName());
ctx.addUIComponentToUpdateByAjax(uiOrganizer);
}