@Override public void execute(Event<UICategorySelector> event) throws Exception { UICategorySelector selector = event.getSource(); ApplicationRegistryService appRegService = selector.getApplicationComponent(ApplicationRegistryService.class); List<ApplicationCategory> categories = appRegService.getApplicationCategories(); UICheckBoxInput chkInput; for (ApplicationCategory category : categories) { chkInput = selector.getUIInput("category_" + category.getName()); if (chkInput != null && chkInput.isChecked()) { selector.addSelectedCategory("category_" + category.getName()); } } }
public void execute(Event<UICategorySelector> event) throws Exception { UICategorySelector selector = event.getSource(); ApplicationRegistryService appRegService = selector.getApplicationComponent(ApplicationRegistryService.class); List<ApplicationCategory> categories = appRegService.getApplicationCategories(); categories = categories != null ? categories : new ArrayList<ApplicationCategory>(); for (ApplicationCategory category : categories) { if (selector.getSelectedCategories().contains("category_" + category.getName())) { Application newApp = cloneApplication(selector.getApplication()); UIApplicationRegistryPortlet.setPermissionToAdminGroup(newApp); appRegService.save(category, newApp); } } selector.clearSelectedCategories(); UIContainer appInfo = selector.getParent(); appInfo.getChild(UICategorySelector.class).setRendered(false); UIApplicationRegistryPortlet uiPortlet = appInfo.getAncestorOfType(UIApplicationRegistryPortlet.class); UIApplicationOrganizer uiOrganizer = uiPortlet.getChild(UIApplicationOrganizer.class); UIGadgetManagement uiGadgetManagement = uiPortlet.getChild(UIGadgetManagement.class); uiOrganizer.reload(); if (uiGadgetManagement != null) { uiGadgetManagement.setSelectedGadget(selector.getApplication().getApplicationName()); } event.getRequestContext().addUIComponentToUpdateByAjax(appInfo); }
public void init() throws Exception { UIFormTableIteratorInputSet uiTableInputSet = createUIComponent(UIFormTableIteratorInputSet.class, null, null); uiTableInputSet.setName(getClass().getSimpleName()); uiTableInputSet.setId(getClass().getSimpleName()); uiTableInputSet.setColumns(TABLE_COLUMNS); addChild(uiTableInputSet); UIFormInputSet uiInputSet; UICheckBoxInput checkBoxInput; UIFormInputInfo uiInfo; HTMLEntityEncoder encoder = HTMLEntityEncoder.getInstance(); // ApplicationRegistryService appRegService = getApplicationComponent(ApplicationRegistryService.class); List<ApplicationCategory> categories = getAllCategories(); List<UIFormInputSet> uiInputSetList = new ArrayList<UIFormInputSet>(); for (ApplicationCategory category : categories) { uiInputSet = new UIFormInputSet(category.getName()); boolean defaultValue = false; if (application != null) { String definitionName = application.getDisplayName().replace(' ', '_'); defaultValue = appRegService.getApplication(category.getName(), definitionName) != null; } checkBoxInput = new UICheckBoxInput("category_" + category.getName(), null, defaultValue); checkBoxInput.setOnChange("SelectBox"); uiInfo = new UIFormInputInfo("categoryName", null, encoder.encode(category.getDisplayName(true))); uiInputSet.addChild(checkBoxInput); uiInputSet.addChild(uiInfo); uiTableInputSet.addChild(uiInputSet); uiInputSetList.add(uiInputSet); } UIFormPageIterator uiIterator = uiTableInputSet.getChild(UIFormPageIterator.class); SerializablePageList<UIFormInputSet> pageList = new SerializablePageList<UIFormInputSet>(UIFormInputSet.class, uiInputSetList, 5); uiIterator.setPageList(pageList); }