public void setValues(final UIPortlet uiPortlet) throws Exception { uiPortlet_ = uiPortlet; invokeGetBindingBean(uiPortlet_); String icon = uiPortlet.getIcon(); if (icon == null || icon.length() < 0) { icon = "PortletIcon"; } getChild(UIFormInputIconSelector.class).setSelectedIcon(icon); getChild(UIFormInputThemeSelector.class) .getChild(UIItemThemeSelector.class) .setSelectedTheme(uiPortlet.getSuitedTheme(null)); if (hasEditMode()) { uiPortlet.setCurrentPortletMode(PortletMode.EDIT); } else { Map<String, String> portletPreferenceMaps = new HashMap<String, String>(); org.gatein.pc.api.Portlet portlet = uiPortlet.getProducedOfferedPortlet(); Set<String> keySet = portlet.getInfo().getPreferences().getKeys(); for (String key : keySet) { PreferenceInfo preferenceInfo = portlet.getInfo().getPreferences().getPreference(key); if (!preferenceInfo.isReadOnly()) { String ppValue = (preferenceInfo.getDefaultValue().size() > 0) ? preferenceInfo.getDefaultValue().get(0) : ""; portletPreferenceMaps.put(key, ppValue); } } Portlet pp = uiPortlet.getPreferences(); if (pp != null) { for (Preference pref : pp) { if (!pref.isReadOnly()) { portletPreferenceMaps.put( pref.getName(), (pref.getValues().size() > 0) ? pref.getValues().get(0) : ""); } } } if (portletPreferenceMaps.size() > 0) { Set<String> ppKeySet = portletPreferenceMaps.keySet(); UIFormInputSet uiPortletPrefSet = getChildById(FIELD_PORTLET_PREF); uiPortletPrefSet.getChildren().clear(); for (String ppKey : ppKeySet) { String ppValue = portletPreferenceMaps.get(ppKey); UIFormStringInput preferenceStringInput = new UIFormStringInput(ppKey, null, ppValue); preferenceStringInput.setLabel(ppKey); preferenceStringInput.addValidator(MandatoryValidator.class); uiPortletPrefSet.addUIFormInput(preferenceStringInput); } uiPortletPrefSet.setRendered(true); setSelectedTab(FIELD_PORTLET_PREF); return; } setSelectedTab("PortletSetting"); } }
@SuppressWarnings("unchecked") public UIPortletForm() throws Exception { super("UIPortletForm"); UIFormInputSet uiPortletPrefSet = new UIFormInputSet(FIELD_PORTLET_PREF).setRendered(false); addUIFormInput(uiPortletPrefSet); UIFormInputSet uiSettingSet = new UIFormInputSet("PortletSetting"); uiSettingSet .addUIFormInput(new UIFormInputInfo("displayName", "displayName", null)) .addUIFormInput( new UIFormStringInput("title", "title", null) .addValidator(StringLengthValidator.class, 3, 60) .addValidator(NotHTMLTagValidator.class, "UIPortletForm.msg.InvalidPortletTitle")) .addUIFormInput( new UIFormStringInput("width", "width", null) .addValidator( ExpressionValidator.class, "(^([1-9]\\d*)px$)?", "UIPortletForm.msg.InvalidWidthHeight")) .addUIFormInput( new UIFormStringInput("height", "height", null) .addValidator( ExpressionValidator.class, "(^([1-9]\\d*)px$)?", "UIPortletForm.msg.InvalidWidthHeight")) .addUIFormInput(new UICheckBoxInput("showInfoBar", "showInfoBar", false)) .addUIFormInput(new UICheckBoxInput("showPortletMode", "showPortletMode", false)) .addUIFormInput(new UICheckBoxInput("showWindowState", "showWindowState", false)) .addUIFormInput( new UIFormTextAreaInput("description", "description", null) .addValidator( NotHTMLTagValidator.class, "UIPortletForm.msg.InvalidPortletDescription")); addUIFormInput(uiSettingSet); UIFormInputIconSelector uiIconSelector = new UIFormInputIconSelector("Icon", "icon"); addUIFormInput(uiIconSelector); UIFormInputThemeSelector uiThemeSelector = new UIFormInputThemeSelector(FIELD_THEME, null); SkinService skinService = getApplicationComponent(SkinService.class); uiThemeSelector.getChild(UIItemThemeSelector.class).setValues(skinService.getPortletThemes()); addUIFormInput(uiThemeSelector); UIListPermissionSelector uiListPermissionSelector = createUIComponent(UIListPermissionSelector.class, null, null); uiListPermissionSelector.configure("UIAccessPermission", "accessPermissions"); uiListPermissionSelector.addValidator(EmptyIteratorValidator.class); UIFormInputSet uiPermissionSet = createUIComponent(UIFormInputSet.class, "PortletPermission", null); uiPermissionSet.addChild(uiListPermissionSelector); addUIFormInput(uiPermissionSet); }
public void invokeSetBindingBean(Object bean) throws Exception { String ownerType = getUIFormSelectBox("ownerType").getValue(); String ownerId = getUIStringInput("ownerId").getValue(); // As ownerId is now normalized, we have to maker sure that owenerId of 'group' type starts with // a '/' if (PortalConfig.GROUP_TYPE.equals(ownerType) && ownerId.charAt(0) != '/') { ownerId = "/" + ownerId; } Page page = (Page) bean; page.setPageId(getUIStringInput("pageId").getValue()); page.setOwnerType(ownerType); page.setOwnerId(ownerId); page.setName(getUIStringInput("name").getValue()); String title = getUIStringInput("title").getValue(); if (title == null || title.trim().length() < 1) title = page.getName(); page.setTitle(title); if (!page.isShowMaxWindow()) { page.setShowMaxWindow((Boolean) getUIFormCheckBoxInput("showMaxWindow").getValue()); } if (!PortalConfig.USER_TYPE.equals(page.getOwnerType())) { page.setAccessPermissions( uiPermissionSetting.getChild(UIListPermissionSelector.class).getValue()); page.setEditPermission(uiPermissionSetting.getChild(UIPermissionSelector.class).getValue()); } UserACL userACL = getApplicationComponent(UserACL.class); userACL.hasPermission(page); UIFormInputItemSelector uiTemplate = getChildById("Template"); if (uiTemplate != null) { SelectItemOption<?> itemOption = uiTemplate.getSelectedItemOption(); if (itemOption != null) { page.setFactoryId(itemOption.getIcon()); // page.setTemplate((String)itemOption.getValue()); if (page.getFactoryId().equals(Page.DESKTOP_PAGE)) page.setShowMaxWindow(true); } } UIPageTemplateOptions uiConfigOptions = getChild(UIPageTemplateOptions.class); if (uiConfigOptions == null) return; Page selectedPage = uiConfigOptions.createPageFromSelectedOption(page.getOwnerType(), page.getOwnerId()); if (selectedPage == null) return; page.setChildren(selectedPage.getChildren()); page.setFactoryId(selectedPage.getFactoryId()); if (Page.DESKTOP_PAGE.equals(page.getFactoryId())) page.setShowMaxWindow(true); }
@SuppressWarnings("unchecked") public void setValues(UIPage uiPage) throws Exception { uiPage_ = uiPage; Page page = (Page) PortalDataMapper.buildModelObject(uiPage); if (uiPage.getOwnerType().equals(PortalConfig.USER_TYPE)) { removeChildById("PermissionSetting"); } else if (getChildById("PermissionSetting") == null) { addUIComponentInput(uiPermissionSetting); } uiPermissionSetting.getChild(UIPermissionSelector.class).setEditable(true); invokeGetBindingBean(page); getUIStringInput("name").setEditable(false); getUIStringInput("pageId").setValue(uiPage.getPageId()); getUIStringInput("title").setValue(uiPage.getTitle()); getUIFormCheckBoxInput("showMaxWindow").setValue(uiPage.isShowMaxWindow()); getUIFormSelectBox(OWNER_TYPE).setEnable(false).setValue(uiPage.getOwnerType()); removeChild(UIPageTemplateOptions.class); UIFormInputItemSelector uiTemplate = getChild(UIFormInputItemSelector.class); if (uiTemplate == null) return; if (page.getFactoryId() == null || page.getFactoryId().trim().length() < 1) { uiTemplate.setValue("Default"); return; } uiTemplate.setValue(uiPage.getFactoryId()); }
public void mapField(UIFormInputSet uiFormInputSet, Object bean) throws Exception { List<UIComponent> children = uiFormInputSet.getChildren(); for (UIComponent uichild : children) { if (uichild instanceof UIFormInput) { invokeGetBindingField((UIFormInput) uichild, bean); } } }
public void mapBean(Object bean, UIFormInputSet uiFormInputSet) throws Exception { List<UIComponent> children = uiFormInputSet.getChildren(); for (UIComponent uichild : children) { if (uichild instanceof UIFormInput) { invokeSetBindingField(bean, (UIFormInput) uichild); } } }
public void execute(Event<UIPageForm> event) throws Exception { UIPageForm uiForm = event.getSource(); UIFormSelectBox uiSelectBox = uiForm.getUIFormSelectBox(OWNER_TYPE); String ownerType = uiSelectBox.getValue(); PortalRequestContext prContext = Util.getPortalRequestContext(); UIFormInputSet uiSettingSet = uiForm.getChildById("PageSetting"); uiForm.setSelectedTab("PageSetting"); List<UIComponent> list = uiSettingSet.getChildren(); if (PortalConfig.USER_TYPE.equals(ownerType)) { uiForm.removeChildById("PermissionSetting"); list.remove(2); list.add(2, uiForm.ownerIdInput); uiForm.ownerIdInput.setValue(prContext.getRemoteUser()); } else { if (uiForm.getChildById("PermissionSetting") == null) { uiForm.addUIComponentInput(uiForm.uiPermissionSetting); } if (PortalConfig.PORTAL_TYPE.equals(ownerType)) { list.remove(2); list.add(2, uiForm.ownerIdInput); uiForm.ownerIdInput.setValue(prContext.getPortalOwner()); uiForm .findFirstComponentOfType(UIListPermissionSelector.class) .setValue(Util.getUIPortal().getAccessPermissions()); uiForm .findFirstComponentOfType(UIPermissionSelector.class) .setValue(Util.getUIPortal().getEditPermission()); } else { list.remove(2); list.add(2, uiForm.groupIdSelectBox); String groupIdSelected = uiForm.groupIdSelectBox.getValue(); groupIdSelected = groupIdSelected.startsWith("/") ? groupIdSelected : "/" + groupIdSelected; String permission = "*:" + groupIdSelected; uiForm .findFirstComponentOfType(UIListPermissionSelector.class) .setValue(new String[] {permission}); UserACL userACL = uiForm.getApplicationComponent(UserACL.class); permission = userACL.getMakableMT() + ":" + groupIdSelected; uiForm.findFirstComponentOfType(UIPermissionSelector.class).setValue(permission); } } prContext.addUIComponentToUpdateByAjax(uiForm.getParent()); }
private void savePreferences() throws Exception { UIFormInputSet uiPortletPrefSet = getChildById(FIELD_PORTLET_PREF); List<UIFormStringInput> uiFormInputs = new ArrayList<UIFormStringInput>(3); uiPortletPrefSet.findComponentOfType(uiFormInputs, UIFormStringInput.class); if (uiFormInputs.size() < 1) { return; } PropertyChange[] propertyChanges = new PropertyChange[uiFormInputs.size()]; for (int i = 0; i < uiFormInputs.size(); i++) { String name = uiFormInputs.get(i).getName(); String value = uiFormInputs.get(i).getValue(); propertyChanges[i] = PropertyChange.newUpdate(name, value); } // Now save it uiPortlet_.update(propertyChanges); }
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); }
@SuppressWarnings("unchecked") public UIPageForm(InitParams initParams) throws Exception { super("UIPageForm"); PortalRequestContext pcontext = Util.getPortalRequestContext(); UserPortalConfigService configService = getApplicationComponent(UserPortalConfigService.class); List<SelectItemOption<String>> ownerTypes = new ArrayList<SelectItemOption<String>>(); ownerTypes.add(new SelectItemOption<String>(PortalConfig.USER_TYPE)); UserPortalConfig userPortalConfig = configService.getUserPortalConfig(pcontext.getPortalOwner(), pcontext.getRemoteUser()); ExoContainer container = ExoContainerContext.getCurrentContainer(); UserACL acl = (UserACL) container.getComponentInstanceOfType(UserACL.class); if (acl.hasEditPermission(userPortalConfig.getPortalConfig())) { ownerTypes.add(new SelectItemOption<String>(PortalConfig.PORTAL_TYPE)); } ownerIdInput = new UIFormStringInput(OWNER_ID, OWNER_ID, null); ownerIdInput.setEditable(false).setValue(pcontext.getRemoteUser()); UIFormSelectBox uiSelectBoxOwnerType = new UIFormSelectBox(OWNER_TYPE, OWNER_TYPE, ownerTypes); uiSelectBoxOwnerType.setOnChange("ChangeOwnerType"); UIFormInputSet uiSettingSet = new UIFormInputSet("PageSetting"); uiSettingSet .addUIFormInput(new UIFormStringInput("pageId", "pageId", null).setEditable(false)) .addUIFormInput(uiSelectBoxOwnerType) .addUIFormInput(ownerIdInput) .addUIFormInput( new UIFormStringInput("name", "name", null) .addValidator(StringLengthValidator.class, 3, 30) .addValidator(IdentifierValidator.class) .addValidator(MandatoryValidator.class)) .addUIFormInput( new UIFormStringInput("title", "title", null) .addValidator(StringLengthValidator.class, 3, 120)) .addUIFormInput(new UIFormCheckBoxInput("showMaxWindow", "showMaxWindow", false)); addUIFormInput(uiSettingSet); setSelectedTab(uiSettingSet.getId()); // WebuiRequestContext context = WebuiRequestContext.getCurrentInstance(); // Param param = initParams.getParam("PageTemplate"); // List<SelectItemCategory> itemCategories = // (List<SelectItemCategory>)param.getMapGroovyObject(context); // UIFormInputItemSelector uiTemplate = new UIFormInputItemSelector("Template", "template"); // uiTemplate.setItemCategories(itemCategories); // addUIFormInput(uiTemplate); uiPermissionSetting = createUIComponent(UIFormInputSet.class, "PermissionSetting", null); UIListPermissionSelector uiListPermissionSelector = createUIComponent(UIListPermissionSelector.class, null, null); uiListPermissionSelector.configure("UIListPermissionSelector", "accessPermissions"); uiListPermissionSelector.addValidator(EmptyIteratorValidator.class); uiPermissionSetting.addChild(uiListPermissionSelector); uiPermissionSetting.setSelectedComponent(uiListPermissionSelector.getId()); UIPermissionSelector uiEditPermission = createUIComponent(UIPermissionSelector.class, null, null); uiEditPermission.setRendered(false); uiEditPermission.addValidator( org.exoplatform.webui.organization.UIPermissionSelector.MandatoryValidator.class); uiEditPermission.setEditable(false); uiEditPermission.configure("UIPermissionSelector", "editPermission"); uiPermissionSetting.addChild(uiEditPermission); // TODO: This following line is fixed for bug PORTAL-2127 uiListPermissionSelector .getChild(UIFormPopupWindow.class) .setId("UIPageFormPopupGroupMembershipSelector"); List<String> groups = configService.getMakableNavigations(pcontext.getRemoteUser(), true); if (groups.size() > 0) { Collections.sort(groups); ownerTypes.add(new SelectItemOption<String>(PortalConfig.GROUP_TYPE)); List<SelectItemOption<String>> groupsItem = new ArrayList<SelectItemOption<String>>(); for (String group : groups) { groupsItem.add(new SelectItemOption<String>(group)); } groupIdSelectBox = new UIFormSelectBox(OWNER_ID, OWNER_ID, groupsItem); groupIdSelectBox.setOnChange("ChangeOwnerId"); groupIdSelectBox.setParent(uiSettingSet); } setActions(new String[] {"Save", "Close"}); }