Search in sources :

Example 1 with ItemConfig

use of org.alfresco.web.config.PropertySheetConfigElement.ItemConfig in project acs-community-packaging by Alfresco.

the class UIPropertySheet method encodeBegin.

/**
 * @see javax.faces.component.UIComponent#encodeBegin(javax.faces.context.FacesContext)
 */
@SuppressWarnings("unchecked")
public void encodeBegin(FacesContext context) throws IOException {
    int howManyChildren = getChildren().size();
    Boolean externalConfig = (Boolean) getAttributes().get("externalConfig");
    // generate a variable name to use if necessary
    if (this.variable == null) {
        this.variable = DEFAULT_VAR_NAME;
    }
    // force retrieval of node info
    Node node = getNode();
    if (howManyChildren == 0) {
        if (externalConfig != null && externalConfig.booleanValue()) {
            // configure the component using the config service
            if (logger.isDebugEnabled())
                logger.debug("Configuring property sheet using ConfigService");
            // get the properties to display
            ConfigService configSvc = Application.getConfigService(FacesContext.getCurrentInstance());
            Config configProps = null;
            if (getConfigArea() == null) {
                configProps = configSvc.getConfig(node);
            } else {
                // only look within the given area
                configProps = configSvc.getConfig(node, new ConfigLookupContext(getConfigArea()));
            }
            PropertySheetConfigElement itemsToDisplay = (PropertySheetConfigElement) configProps.getConfigElement("property-sheet");
            if (itemsToDisplay != null) {
                Collection<ItemConfig> itemsToRender = null;
                if (this.getMode().equalsIgnoreCase(EDIT_MODE)) {
                    itemsToRender = itemsToDisplay.getEditableItemsToShow().values();
                    if (logger.isDebugEnabled())
                        logger.debug("Items to render: " + itemsToDisplay.getEditableItemNamesToShow());
                } else {
                    itemsToRender = itemsToDisplay.getItemsToShow().values();
                    if (logger.isDebugEnabled())
                        logger.debug("Items to render: " + itemsToDisplay.getItemNamesToShow());
                }
                createComponentsFromConfig(context, itemsToRender);
            } else {
                if (logger.isDebugEnabled())
                    logger.debug("There are no items to render!");
            }
        } else {
            // show all the properties for the current node
            if (logger.isDebugEnabled())
                logger.debug("Configuring property sheet using node's current state");
            createComponentsFromNode(context, node);
        }
    }
    // put the node in the session if it is not there already
    Map sessionMap = getFacesContext().getExternalContext().getSessionMap();
    sessionMap.put(this.variable, node);
    if (logger.isDebugEnabled())
        logger.debug("Put node into session with key '" + this.variable + "': " + node);
    super.encodeBegin(context);
}
Also used : ItemConfig(org.alfresco.web.config.PropertySheetConfigElement.ItemConfig) ConfigLookupContext(org.springframework.extensions.config.ConfigLookupContext) ConfigService(org.springframework.extensions.config.ConfigService) PropertySheetConfigElement(org.alfresco.web.config.PropertySheetConfigElement) PropertyConfig(org.alfresco.web.config.PropertySheetConfigElement.PropertyConfig) SeparatorConfig(org.alfresco.web.config.PropertySheetConfigElement.SeparatorConfig) AssociationConfig(org.alfresco.web.config.PropertySheetConfigElement.AssociationConfig) ChildAssociationConfig(org.alfresco.web.config.PropertySheetConfigElement.ChildAssociationConfig) ItemConfig(org.alfresco.web.config.PropertySheetConfigElement.ItemConfig) Config(org.springframework.extensions.config.Config) Node(org.alfresco.web.bean.repository.Node) Map(java.util.Map)

Example 2 with ItemConfig

use of org.alfresco.web.config.PropertySheetConfigElement.ItemConfig in project acs-community-packaging by Alfresco.

the class UIPropertySheet method createComponentsFromConfig.

/**
 * Creates all the property components required to display the properties specified
 * in an external config file.
 *
 * @param context JSF context
 * @param items Collection of properties to render (driven from configuration)
 * @throws IOException
 */
@SuppressWarnings("unchecked")
private void createComponentsFromConfig(FacesContext context, Collection<ItemConfig> items) throws IOException {
    for (ItemConfig item : items) {
        String id = null;
        PropertySheetItem propSheetItem = null;
        // create the appropriate component
        if (item instanceof PropertyConfig) {
            id = PROP_ID_PREFIX + item.getName();
            propSheetItem = (PropertySheetItem) context.getApplication().createComponent(RepoConstants.ALFRESCO_FACES_PROPERTY);
        } else if (item instanceof AssociationConfig) {
            id = ASSOC_ID_PREFIX + item.getName();
            propSheetItem = (PropertySheetItem) context.getApplication().createComponent(RepoConstants.ALFRESCO_FACES_ASSOCIATION);
        } else if (item instanceof ChildAssociationConfig) {
            id = ASSOC_ID_PREFIX + item.getName();
            propSheetItem = (PropertySheetItem) context.getApplication().createComponent(RepoConstants.ALFRESCO_FACES_CHILD_ASSOCIATION);
        } else if (item instanceof SeparatorConfig) {
            id = SEP_ID_PREFIX + item.getName();
            propSheetItem = (PropertySheetItem) context.getApplication().createComponent(RepoConstants.ALFRESCO_FACES_SEPARATOR);
        }
        // now setup the common stuff across all component types
        if (propSheetItem != null) {
            FacesHelper.setupComponentId(context, propSheetItem, id);
            propSheetItem.setName(item.getName());
            propSheetItem.setConverter(item.getConverter());
            propSheetItem.setComponentGenerator(item.getComponentGenerator());
            propSheetItem.setIgnoreIfMissing(item.getIgnoreIfMissing());
            String displayLabel = item.getDisplayLabel();
            if (item.getDisplayLabelId() != null) {
                String label = Application.getMessage(context, item.getDisplayLabelId());
                if (label != null) {
                    displayLabel = label;
                }
            }
            propSheetItem.setDisplayLabel(displayLabel);
            // should be read only set it as such
            if (isReadOnly() || item.isReadOnly()) {
                propSheetItem.setReadOnly(true);
            }
            this.getChildren().add(propSheetItem);
            if (logger.isDebugEnabled())
                logger.debug("Created property sheet item component " + propSheetItem + "(" + propSheetItem.getClientId(context) + ") for '" + item.getName() + "' and added it to property sheet " + this);
        }
    }
}
Also used : ItemConfig(org.alfresco.web.config.PropertySheetConfigElement.ItemConfig) AssociationConfig(org.alfresco.web.config.PropertySheetConfigElement.AssociationConfig) ChildAssociationConfig(org.alfresco.web.config.PropertySheetConfigElement.ChildAssociationConfig) ChildAssociationConfig(org.alfresco.web.config.PropertySheetConfigElement.ChildAssociationConfig) SeparatorConfig(org.alfresco.web.config.PropertySheetConfigElement.SeparatorConfig) PropertyConfig(org.alfresco.web.config.PropertySheetConfigElement.PropertyConfig)

Aggregations

AssociationConfig (org.alfresco.web.config.PropertySheetConfigElement.AssociationConfig)2 ChildAssociationConfig (org.alfresco.web.config.PropertySheetConfigElement.ChildAssociationConfig)2 ItemConfig (org.alfresco.web.config.PropertySheetConfigElement.ItemConfig)2 PropertyConfig (org.alfresco.web.config.PropertySheetConfigElement.PropertyConfig)2 SeparatorConfig (org.alfresco.web.config.PropertySheetConfigElement.SeparatorConfig)2 Map (java.util.Map)1 Node (org.alfresco.web.bean.repository.Node)1 PropertySheetConfigElement (org.alfresco.web.config.PropertySheetConfigElement)1 Config (org.springframework.extensions.config.Config)1 ConfigLookupContext (org.springframework.extensions.config.ConfigLookupContext)1 ConfigService (org.springframework.extensions.config.ConfigService)1