Search in sources :

Example 1 with UIImagePicker

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

the class ImagePickerRadioRenderer method encodeChildren.

/**
 * @see javax.faces.render.Renderer#encodeChildren(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
 */
@SuppressWarnings("unchecked")
public void encodeChildren(FacesContext context, UIComponent component) throws IOException {
    if (component.isRendered() == false) {
        return;
    }
    UIImagePicker imagePicker = (UIImagePicker) component;
    Map attrs = imagePicker.getAttributes();
    Integer cols = (Integer) attrs.get("columns");
    if (cols != null && cols instanceof Integer) {
        this.columns = cols.intValue();
    }
    // retrieve the onclick handler, if there is one
    String onclick = (String) attrs.get("onclick");
    ResponseWriter out = context.getResponseWriter();
    // determine whether the options should be pulled from config or
    // from the child components
    String configSection = (String) attrs.get("configSection");
    if (configSection != null && configSection.length() > 0) {
        // render all the icons from the list that appear in the given
        // config section
        ConfigService cfgService = Application.getConfigService(context);
        Config cfg = cfgService.getConfig(configSection);
        if (cfg != null) {
            ConfigElement iconsCfg = cfg.getConfigElement("icons");
            if (iconsCfg != null) {
                for (ConfigElement icon : iconsCfg.getChildren()) {
                    String iconName = icon.getAttribute("name");
                    String iconPath = icon.getAttribute("path");
                    if (iconName != null && iconPath != null) {
                        UIListItem item = new UIListItem();
                        item.setValue(iconName);
                        item.setImage(iconPath);
                        renderItem(context, out, imagePicker, item, onclick);
                    }
                }
            }
        }
    } else {
        try {
            // get the child components
            for (Iterator i = imagePicker.getChildren().iterator(); i.hasNext(); ) /**/
            {
                UIComponent child = (UIComponent) i.next();
                if (child instanceof UIListItems) {
                    // get the value of the list items component and iterate
                    // through it's collection
                    Object listItems = ((UIListItems) child).getValue();
                    if (listItems instanceof Collection) {
                        Iterator iter = ((Collection) listItems).iterator();
                        while (iter.hasNext()) {
                            UIListItem item = (UIListItem) iter.next();
                            if (item.isRendered()) {
                                renderItem(context, out, imagePicker, item, onclick);
                            }
                        }
                    }
                } else if (child instanceof UIListItem && child.isRendered() == true) {
                    // found a valid UIListItem child to render
                    UIListItem item = (UIListItem) child;
                    renderItem(context, out, imagePicker, item, onclick);
                }
            }
        } catch (PropertyNotFoundException pnfe) {
            // method specified in the value binding expression
            if (logger.isWarnEnabled())
                logger.warn("Failed to retrieve icons: " + pnfe.toString());
            out.write(Application.getMessage(context, "no_icons_found"));
        }
    }
    // if we are in the middle of a row, close it
    if (open) {
        out.write("</tr>\n");
    }
}
Also used : PropertyNotFoundException(javax.faces.el.PropertyNotFoundException) ConfigElement(org.springframework.extensions.config.ConfigElement) Config(org.springframework.extensions.config.Config) UIComponent(javax.faces.component.UIComponent) UIListItems(org.alfresco.web.ui.common.component.UIListItems) UIImagePicker(org.alfresco.web.ui.common.component.UIImagePicker) ConfigService(org.springframework.extensions.config.ConfigService) ResponseWriter(javax.faces.context.ResponseWriter) UIListItem(org.alfresco.web.ui.common.component.UIListItem) Iterator(java.util.Iterator) Collection(java.util.Collection) Map(java.util.Map)

Example 2 with UIImagePicker

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

the class ImagePickerRadioRenderer method encodeBegin.

/**
 * @see javax.faces.render.Renderer#encodeBegin(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
 */
public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
    if (component.isRendered() == false) {
        return;
    }
    // setup counters
    this.columns = 1;
    this.position = 0;
    this.open = false;
    this.imageSelected = false;
    ResponseWriter out = context.getResponseWriter();
    UIImagePicker imagePicker = (UIImagePicker) component;
    Map attrs = imagePicker.getAttributes();
    out.write("<table cellpadding='0'");
    outputAttribute(out, attrs.get("spacing"), "cellspacing");
    outputAttribute(out, attrs.get("styleClass"), "class");
    outputAttribute(out, attrs.get("style"), "style");
    out.write(">\n");
}
Also used : ResponseWriter(javax.faces.context.ResponseWriter) Map(java.util.Map) UIImagePicker(org.alfresco.web.ui.common.component.UIImagePicker)

Aggregations

Map (java.util.Map)2 ResponseWriter (javax.faces.context.ResponseWriter)2 UIImagePicker (org.alfresco.web.ui.common.component.UIImagePicker)2 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 UIComponent (javax.faces.component.UIComponent)1 PropertyNotFoundException (javax.faces.el.PropertyNotFoundException)1 UIListItem (org.alfresco.web.ui.common.component.UIListItem)1 UIListItems (org.alfresco.web.ui.common.component.UIListItems)1 Config (org.springframework.extensions.config.Config)1 ConfigElement (org.springframework.extensions.config.ConfigElement)1 ConfigService (org.springframework.extensions.config.ConfigService)1