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); }
/** * Creates the root element. * * @param currentFolder the current folder * @param applicationCategories the application categories * @param language the language * @return the element * @throws Exception the exception */ private Element createRootElement( String currentFolder, List<ApplicationCategory> applicationCategories, String language, String host) throws Exception { Document document = null; DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); document = builder.newDocument(); if (applicationCategories.isEmpty()) { Locale locale = null; if (language == null) { locale = Locale.ENGLISH; } else { locale = new Locale(language); } ResourceBundle resourceBundle = ResourceBundle.getBundle(FCK_RESOURCE_BUNDLE_FILE, locale); String message = ""; try { message = resourceBundle.getString("fckeditor.no-gadget"); } catch (MissingResourceException e) { message = "fckeditor.no-gadget"; } Element rootElement = document.createElement("Message"); document.appendChild(rootElement); rootElement.setAttribute("number", "555"); rootElement.setAttribute("text", message); rootElement.setAttribute("type", "Error"); return rootElement; } Element rootElement = document.createElement("Connector"); document.appendChild(rootElement); rootElement.setAttribute("resourceType", "Gadget"); Element currentFolderElement = document.createElement("CurrentFolder"); if (currentFolder == null || currentFolder.equals("/")) { currentFolderElement.setAttribute("name", applicationCategories.get(0).getName()); Element foldersElement = createFolderElement(document, applicationCategories); rootElement.appendChild(foldersElement); } else { PortalContainer container = PortalContainer.getInstance(); RequestLifeCycle.begin(container); try { ApplicationCategory applicationCategory = applicationRegistryService.getApplicationCategory( currentFolder.substring(1, currentFolder.length() - 1)); currentFolderElement.setAttribute("name", applicationCategory.getDisplayName()); Element filesElement = createFileElement(document, applicationCategory, host); rootElement.appendChild(filesElement); } finally { RequestLifeCycle.end(); } } rootElement.appendChild(currentFolderElement); return rootElement; }
/** * Creates the folder element. * * @param document the document * @param applicationCategories the application categories * @return the element * @throws Exception the exception */ private Element createFolderElement( Document document, List<ApplicationCategory> applicationCategories) throws Exception { Element folders = document.createElement("Folders"); for (ApplicationCategory applicationCategory : applicationCategories) { Element folder = document.createElement("Folder"); folder.setAttribute("name", applicationCategory.getDisplayName()); folders.appendChild(folder); } return folders; }
@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()); } } }
private List<Application> filterApps(ApplicationCategory applicationCategory) { List<Application> applications = new ArrayList<Application>(); if (applicationCategory.getApplications() == null) { return applications; } for (Application app : applicationCategory.getApplications()) { if (hasPermission(app.getAccessPermissions())) { applications.add(app); } } applicationCategory.setApplications(applications); return applications; }
private Application getApplication(String id) throws Exception { List<ApplicationCategory> pCategories = getApplicationCategories(); for (ApplicationCategory pCategory : pCategories) { List<Application> applications = pCategory.getApplications(); for (Application application : applications) { if (application.getId().equals(id)) { return application; } } } return null; }
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); }
private void initApplicationCategories() throws Exception { ApplicationRegistryService prService = getApplicationComponent(ApplicationRegistryService.class); String remoteUser = WebuiRequestContext.getCurrentInstance().getRemoteUser(); if (remoteUser == null || remoteUser.equals("")) return; List<ApplicationCategory> appCategories = prService.getApplicationCategories(new ApplicationCategoryComparator()); Iterator<ApplicationCategory> cateItr = appCategories.iterator(); while (cateItr.hasNext()) { ApplicationCategory cate = cateItr.next(); if (!hasPermission(cate.getAccessPermissions()) || filterApps(cate).size() < 1) { cateItr.remove(); } else { Collections.sort(cate.getApplications(), new ApplicationComparator()); } } listAppCategories = appCategories; }
public int compare(ApplicationCategory cat1, ApplicationCategory cat2) { return cat1.getDisplayName().compareToIgnoreCase(cat2.getDisplayName()); }