Search in sources :

Example 1 with UIListItems

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

the class UISidebar method encodeBegin.

@SuppressWarnings("unchecked")
@Override
public void encodeBegin(FacesContext context) throws IOException {
    if (!isRendered())
        return;
    ResponseWriter out = context.getResponseWriter();
    out.write("<div id='sidebar' class='sidebar'>");
    // render the start of the header panel
    String cxPath = context.getExternalContext().getRequestContextPath();
    out.write("<table cellspacing='0' cellpadding='0' style='background-color: #ffffff;' width='100%'>" + "<tr valign='top'><td width='20%'><table cellspacing='0' cellpadding='0' width='100%'>" + "<tr><td style='width: 5px; background-image: url(");
    out.write(cxPath);
    out.write("/images/parts/sidebar_top_grey_begin.gif)' valign='top'>" + "<img src=\"");
    out.write(cxPath);
    out.write("/images/parts/sidebar_grey_01.gif\" width='5' height='5' alt=''></td>" + "<td style='height: 24px; background-image: url(");
    out.write(cxPath);
    out.write("/images/parts/sidebar_top_grey_bg.gif)'>");
    // generate the required child components if not present
    if (this.getChildCount() == 1) {
        // create the mode list component
        UIModeList modeList = (UIModeList) context.getApplication().createComponent("org.alfresco.faces.ModeList");
        modeList.setId("sidebarPluginList");
        modeList.setValue(this.getActivePlugin());
        modeList.setIconColumnWidth(2);
        modeList.setMenu(true);
        modeList.setMenuImage("/images/icons/menu.gif");
        modeList.getAttributes().put("itemSpacing", 4);
        modeList.getAttributes().put("styleClass", "moreActionsMenu");
        modeList.getAttributes().put("selectedStyleClass", "statusListHighlight");
        MethodBinding listener = context.getApplication().createMethodBinding("#{SidebarBean.pluginChanged}", new Class[] { ActionEvent.class });
        modeList.setActionListener(listener);
        // create the child list items component
        UIListItems items = (UIListItems) context.getApplication().createComponent("org.alfresco.faces.ListItems");
        ValueBinding binding = context.getApplication().createValueBinding("#{SidebarBean.plugins}");
        items.setValueBinding("value", binding);
        // add the list items to the mode list component
        modeList.getChildren().add(items);
        // create the actions component
        UIActions actions = (UIActions) context.getApplication().createComponent("org.alfresco.faces.Actions");
        actions.setId("sidebarActions");
        actions.setShowLink(false);
        setupActionGroupId(context, actions);
        // add components to the sidebar
        this.getChildren().add(0, modeList);
        this.getChildren().add(1, actions);
    } else {
        // update the child UIActions component with the correct
        // action group id and clear it's current children
        UIActions actions = (UIActions) this.getChildren().get(1);
        actions.reset();
        setupActionGroupId(context, actions);
    }
}
Also used : ResponseWriter(javax.faces.context.ResponseWriter) ValueBinding(javax.faces.el.ValueBinding) UIListItems(org.alfresco.web.ui.common.component.UIListItems) UIModeList(org.alfresco.web.ui.common.component.UIModeList) MethodBinding(javax.faces.el.MethodBinding)

Example 2 with UIListItems

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

the class SpaceIconPickerGenerator method setupProperty.

@Override
@SuppressWarnings("unchecked")
protected void setupProperty(FacesContext context, UIPropertySheet propertySheet, PropertySheetItem item, PropertyDefinition propertyDef, UIComponent component) {
    // do the standard setup
    super.setupProperty(context, propertySheet, item, propertyDef, component);
    // list of icons the user can select from
    if (propertySheet.inEditMode()) {
        // create the list items child component
        UIListItems items = (UIListItems) context.getApplication().createComponent(RepoConstants.ALFRESCO_FACES_LIST_ITEMS);
        // setup the value binding for the list of icons, this needs
        // to be sensitive to the bean used for the property sheet
        // we therefore need to get the value binding expression and
        // extract the bean name and then add '.icons' to the end,
        // this means any page that uses this component must supply
        // a getIcons method that returns a List of UIListItem's
        ValueBinding binding = propertySheet.getValueBinding("value");
        String expression = binding.getExpressionString();
        String beanName = expression.substring(2, expression.indexOf(".") + 1);
        if (beanName.equals("DialogManager.") || beanName.equals("WizardManager.")) {
            // deal with the special dialog and wizard manager beans by
            // adding .bean
            beanName = beanName + "bean.";
        }
        String newExpression = "#{" + beanName + "icons}";
        ValueBinding vb = context.getApplication().createValueBinding(newExpression);
        items.setValueBinding("value", vb);
        // add the list items component to the image picker component
        component.getChildren().add(items);
    }
}
Also used : ValueBinding(javax.faces.el.ValueBinding) UIListItems(org.alfresco.web.ui.common.component.UIListItems)

Example 3 with UIListItems

use of org.alfresco.web.ui.common.component.UIListItems 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 4 with UIListItems

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

the class ModeListRenderer method encodeChildren.

/**
 * @see javax.faces.render.Renderer#encodeChildren(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
 */
public void encodeChildren(FacesContext context, UIComponent component) throws IOException {
    if (!component.isRendered()) {
        return;
    }
    UIModeList list = (UIModeList) component;
    ResponseWriter out = context.getResponseWriter();
    // get the child components
    for (Iterator i = list.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, list, item);
                    }
                }
            }
        } else if (child instanceof UIListItem && child.isRendered()) {
            // found a valid UIListItem child to render
            renderItem(context, out, list, (UIListItem) child);
        }
    }
}
Also used : ResponseWriter(javax.faces.context.ResponseWriter) UIListItem(org.alfresco.web.ui.common.component.UIListItem) Iterator(java.util.Iterator) UIComponent(javax.faces.component.UIComponent) UIListItems(org.alfresco.web.ui.common.component.UIListItems) UIModeList(org.alfresco.web.ui.common.component.UIModeList) Collection(java.util.Collection)

Example 5 with UIListItems

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

the class ModeListRenderer 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;
    }
    UIModeList list = (UIModeList) component;
    ResponseWriter out = context.getResponseWriter();
    Map attrs = list.getAttributes();
    if (!list.isMenu()) {
        // start outer table container the list items
        out.write("<table cellspacing='1' cellpadding='0'");
        outputAttribute(out, attrs.get("styleClass"), "class");
        outputAttribute(out, attrs.get("style"), "style");
        outputAttribute(out, attrs.get("width"), "width");
        out.write('>');
        // horizontal rendering outputs a single row with each item as a column cell
        if (list.isHorizontal()) {
            out.write("<tr>");
        }
        // output title row if present
        if (list.getLabel() != null) {
            // first column contains an icon if present, second column contains text
            if (!list.isHorizontal()) {
                out.write("<tr>");
            }
            out.write("<td><table cellpadding='0' style='width:100%;'");
            outputAttribute(out, attrs.get("itemSpacing"), "cellspacing");
            out.write("><tr>");
            // output icon column
            if (list.getIconColumnWidth() != 0) {
                out.write("<td style='width:");
                out.write(String.valueOf(list.getIconColumnWidth()));
                out.write("px'></td>");
            }
            // output title label
            out.write("<td><span");
            outputAttribute(out, attrs.get("labelStyle"), "style");
            outputAttribute(out, attrs.get("labelStyleClass"), "class");
            out.write('>');
            out.write(Utils.encode(list.getLabel()));
            out.write("</span></td></tr></table></td>");
            if (!list.isHorizontal()) {
                out.write("</tr>");
            }
        }
    } else {
        // render as a pop-up menu
        // TODO: show the image set for the individual item if available?
        out.write("<table cellspacing='0' cellpadding='0' style='white-space:nowrap'><tr>");
        String selectedImage = (String) attrs.get("selectedImage");
        if (selectedImage != null) {
            out.write("<td style='padding-right:4px'>");
            out.write(Utils.buildImageTag(context, selectedImage, null, "middle"));
            out.write("</td>");
        }
        String menuId = UIMenu.getNextMenuId(list, context);
        out.write("<td style='white-space: nowrap;'><a href='#' onclick=\"javascript:_toggleMenu(event, '");
        out.write(menuId);
        out.write("');return false;\">");
        // use default label if available
        String label = list.getLabel();
        if (label == null || label.length() == 0) {
            // else get the child components and walk to find the selected
            for (Iterator i = list.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 selected render as the label
                            if (item.getValue().equals(list.getValue())) {
                                label = item.getLabel();
                                break;
                            }
                        }
                    }
                } else if (child instanceof UIListItem && child.isRendered()) {
                    // found a valid UIListItem child to render
                    UIListItem item = (UIListItem) child;
                    // if selected render as the label
                    if (item.getValue().equals(list.getValue())) {
                        label = item.getLabel();
                        break;
                    }
                }
            }
        }
        // render the label
        if (label != null && label.length() != 0) {
            out.write("<span");
            outputAttribute(out, attrs.get("labelStyle"), "style");
            outputAttribute(out, attrs.get("labelStyleClass"), "class");
            out.write('>');
            out.write(Utils.encode(label));
            out.write("</span>&nbsp;");
        }
        // output image
        if (list.getMenuImage() != null) {
            out.write(Utils.buildImageTag(context, list.getMenuImage(), null, "-4px"));
        }
        out.write("</a></td></tr></table>");
        // output the hidden DIV section to contain the menu item table
        out.write("<div id='");
        out.write(menuId);
        out.write("' style='position:absolute;display:none;padding-left:2px;'>");
        // start outer table container the list items
        out.write("<table cellspacing='1' cellpadding='0'");
        outputAttribute(out, attrs.get("styleClass"), "class");
        outputAttribute(out, attrs.get("style"), "style");
        outputAttribute(out, attrs.get("width"), "width");
        out.write('>');
    }
}
Also used : ResponseWriter(javax.faces.context.ResponseWriter) UIListItem(org.alfresco.web.ui.common.component.UIListItem) Iterator(java.util.Iterator) UIComponent(javax.faces.component.UIComponent) UIListItems(org.alfresco.web.ui.common.component.UIListItems) UIModeList(org.alfresco.web.ui.common.component.UIModeList) Collection(java.util.Collection) Map(java.util.Map)

Aggregations

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