Search in sources :

Example 1 with UIDescription

use of org.alfresco.web.ui.common.component.description.UIDescription in project acs-community-packaging by Alfresco.

the class CreateSpaceWizard method getFolderTypes.

/**
 * Returns a list of UIListItem objects representing the folder types
 * and also constructs the list of descriptions for each type
 *
 * @return List of UIListItem components
 */
@SuppressWarnings("unchecked")
public List<UIListItem> getFolderTypes() {
    if ((this.folderTypes == null) || (Application.isDynamicConfig(FacesContext.getCurrentInstance()))) {
        FacesContext context = FacesContext.getCurrentInstance();
        this.folderTypes = new ArrayList<UIListItem>(2);
        this.folderTypeDescriptions = new ArrayList<UIDescription>(2);
        // add the well known 'container space' type to start with
        UIListItem defaultItem = new UIListItem();
        String defaultLabel = Application.getMessage(context, "container");
        defaultItem.setValue(ContentModel.TYPE_FOLDER.toString());
        defaultItem.setLabel(defaultLabel);
        defaultItem.setTooltip(defaultLabel);
        defaultItem.setImage(DEFAULT_SPACE_TYPE_ICON_PATH);
        this.folderTypes.add(defaultItem);
        UIDescription defaultDesc = new UIDescription();
        defaultDesc.setControlValue(ContentModel.TYPE_FOLDER.toString());
        defaultDesc.setText(Application.getMessage(context, "container_desc"));
        this.folderTypeDescriptions.add(defaultDesc);
        // add any configured content sub-types to the list
        Config wizardCfg = Application.getConfigService(FacesContext.getCurrentInstance()).getConfig("Space Wizards");
        if (wizardCfg != null) {
            ConfigElement typesCfg = wizardCfg.getConfigElement("folder-types");
            if (typesCfg != null) {
                for (ConfigElement child : typesCfg.getChildren()) {
                    QName idQName = Repository.resolveToQName(child.getAttribute("name"));
                    if (idQName != null) {
                        TypeDefinition typeDef = this.getDictionaryService().getType(idQName);
                        if (typeDef != null) {
                            if (this.getDictionaryService().isSubClass(typeDef.getName(), ContentModel.TYPE_FOLDER)) {
                                // try and get the label from config
                                String label = Utils.getDisplayLabel(context, child);
                                // if there wasn't a client based label try and get it from the dictionary
                                if (label == null) {
                                    label = typeDef.getTitle(this.getDictionaryService());
                                }
                                // finally use the localname if we still haven't found a label
                                if (label == null) {
                                    label = idQName.getLocalName();
                                }
                                // resolve a description string for the type
                                String description = Utils.getDescription(context, child);
                                // if we don't have a local description just use the label
                                if (description == null) {
                                    description = label;
                                }
                                // extract the icon to use from the config
                                String icon = child.getAttribute("icon");
                                if (icon == null || icon.length() == 0) {
                                    icon = DEFAULT_SPACE_TYPE_ICON_PATH;
                                }
                                UIListItem item = new UIListItem();
                                item.setValue(idQName.toString());
                                item.setLabel(label);
                                item.setTooltip(label);
                                item.setImage(icon);
                                this.folderTypes.add(item);
                                UIDescription desc = new UIDescription();
                                desc.setControlValue(idQName.toString());
                                desc.setText(description);
                                this.folderTypeDescriptions.add(desc);
                            } else {
                                logger.warn("Failed to add '" + child.getAttribute("name") + "' to the list of folder types as the type is not a subtype of cm:folder");
                            }
                        } else {
                            logger.warn("Failed to add '" + child.getAttribute("name") + "' to the list of folder types as the type is not recognised");
                        }
                    } else {
                        logger.warn("Failed to add '" + child.getAttribute("name") + "' to the list of folder types as the prefix can not be resolved");
                    }
                }
            } else {
                logger.warn("Could not find 'folder-types' configuration element");
            }
        } else {
            logger.warn("Could not find 'Space Wizards' configuration section");
        }
    }
    return this.folderTypes;
}
Also used : UIDescription(org.alfresco.web.ui.common.component.description.UIDescription) FacesContext(javax.faces.context.FacesContext) UIListItem(org.alfresco.web.ui.common.component.UIListItem) ConfigElement(org.springframework.extensions.config.ConfigElement) Config(org.springframework.extensions.config.Config) QName(org.alfresco.service.namespace.QName) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition)

Example 2 with UIDescription

use of org.alfresco.web.ui.common.component.description.UIDescription in project acs-community-packaging by Alfresco.

the class DashboardWizard method buildLayoutValueLists.

/**
 * Build the cached list of values for the layout page. The lists are used by the
 * image radio picker and dynamic description components.
 */
private void buildLayoutValueLists() {
    List<UIListItem> icons = new ArrayList<UIListItem>(4);
    List<UIDescription> descriptions = new ArrayList<UIDescription>(4);
    FacesContext context = FacesContext.getCurrentInstance();
    DashboardsConfigElement config = DashboardManager.getDashboardConfig();
    Iterator<LayoutDefinition> layoutItr = config.getLayouts().iterator();
    while (layoutItr.hasNext()) {
        LayoutDefinition layoutDef = layoutItr.next();
        // build UIListItem to represent the layout image
        String label = layoutDef.Label;
        if (label == null) {
            label = Application.getMessage(context, layoutDef.LabelId);
        }
        String desc = layoutDef.Description;
        if (desc == null) {
            desc = Application.getMessage(context, layoutDef.DescriptionId);
        }
        UIListItem item = new UIListItem();
        item.setLabel(label);
        item.setTooltip(desc);
        item.setValue(layoutDef.Id);
        item.setImage(layoutDef.Image);
        icons.add(item);
        // build UIDescription to represent the layout description text
        UIDescription description = new UIDescription();
        description.setControlValue(layoutDef.Id);
        description.setText(desc);
        descriptions.add(description);
    }
    this.layoutIcons = icons;
    this.layoutDescriptions = descriptions;
}
Also used : UIDescription(org.alfresco.web.ui.common.component.description.UIDescription) FacesContext(javax.faces.context.FacesContext) UIListItem(org.alfresco.web.ui.common.component.UIListItem) ArrayList(java.util.ArrayList) DashboardsConfigElement(org.alfresco.web.config.DashboardsConfigElement) LayoutDefinition(org.alfresco.web.config.DashboardsConfigElement.LayoutDefinition)

Aggregations

FacesContext (javax.faces.context.FacesContext)2 UIListItem (org.alfresco.web.ui.common.component.UIListItem)2 UIDescription (org.alfresco.web.ui.common.component.description.UIDescription)2 ArrayList (java.util.ArrayList)1 TypeDefinition (org.alfresco.service.cmr.dictionary.TypeDefinition)1 QName (org.alfresco.service.namespace.QName)1 DashboardsConfigElement (org.alfresco.web.config.DashboardsConfigElement)1 LayoutDefinition (org.alfresco.web.config.DashboardsConfigElement.LayoutDefinition)1 Config (org.springframework.extensions.config.Config)1 ConfigElement (org.springframework.extensions.config.ConfigElement)1