Search in sources :

Example 1 with DialogButtonConfig

use of org.alfresco.web.config.DialogsConfigElement.DialogButtonConfig in project acs-community-packaging by Alfresco.

the class UIDialogButtons method generateAdditionalButtons.

/**
 * If there are any additional buttons to add as defined by the dialog
 * configuration and the dialog at runtime they are generated in this
 * method.
 *
 * @param context Faces context
 */
@SuppressWarnings("unchecked")
protected void generateAdditionalButtons(FacesContext context) {
    // get potential list of additional buttons
    List<DialogButtonConfig> buttons = Application.getDialogManager().getAdditionalButtons();
    if (buttons != null && buttons.size() > 0) {
        if (logger.isDebugEnabled())
            logger.debug("Adding " + buttons.size() + " additional buttons: " + buttons);
        // add a spacing row to separate the additional buttons from the OK button
        addSpacingRow(context);
        for (DialogButtonConfig buttonCfg : buttons) {
            UICommand button = (UICommand) context.getApplication().createComponent(HtmlCommandButton.COMPONENT_TYPE);
            button.setRendererType(ComponentConstants.JAVAX_FACES_BUTTON);
            FacesHelper.setupComponentId(context, button, buttonCfg.getId());
            // setup the value of the button (the label)
            String label = buttonCfg.getLabel();
            if (label != null) {
                // see if the label represents a value binding
                if (label.startsWith(BINDING_EXPRESSION_START)) {
                    ValueBinding binding = context.getApplication().createValueBinding(label);
                    button.setValueBinding("value", binding);
                } else {
                    button.setValue(label);
                }
            } else {
                // NOTE: the config checks that a label or a label id
                // is present so we can assume there is an id
                // if there isn't a label
                String labelId = buttonCfg.getLabelId();
                label = Application.getMessage(context, labelId);
                button.setValue(label);
            }
            // setup the action binding, the config checks that an action
            // is present so no need to check for NullPointer. It also checks
            // it represents a method binding expression.
            String action = buttonCfg.getAction();
            MethodBinding methodBinding = context.getApplication().createMethodBinding(action, null);
            button.setAction(methodBinding);
            // setup the disabled attribute, check for null and
            // binding expressions
            String disabled = buttonCfg.getDisabled();
            if (disabled != null && disabled.length() > 0) {
                if (disabled.startsWith(BINDING_EXPRESSION_START)) {
                    ValueBinding binding = context.getApplication().createValueBinding(disabled);
                    button.setValueBinding("disabled", binding);
                } else {
                    button.getAttributes().put("disabled", Boolean.parseBoolean(disabled));
                }
            }
            // setup CSS class for the button
            String styleClass = (String) this.getAttributes().get("styleClass");
            if (styleClass != null) {
                button.getAttributes().put("styleClass", styleClass);
            }
            // setup the onclick handler for the button
            String onclick = buttonCfg.getOnclick();
            if (onclick != null && onclick.length() > 0) {
                button.getAttributes().put("onclick", onclick);
            }
            // add the button
            this.getChildren().add(button);
            if (logger.isDebugEnabled())
                logger.debug("Added button with id of: " + button.getId());
        }
        // add a spacing row to separate the additional buttons from the Cancel button
        addSpacingRow(context);
    }
}
Also used : ValueBinding(javax.faces.el.ValueBinding) DialogButtonConfig(org.alfresco.web.config.DialogsConfigElement.DialogButtonConfig) MethodBinding(javax.faces.el.MethodBinding) UICommand(javax.faces.component.UICommand)

Example 2 with DialogButtonConfig

use of org.alfresco.web.config.DialogsConfigElement.DialogButtonConfig in project acs-community-packaging by Alfresco.

the class ManageTaskDialog method getAdditionalButtons.

@Override
public List<DialogButtonConfig> getAdditionalButtons() {
    List<DialogButtonConfig> buttons = null;
    if (this.getWorkflowTask() != null) {
        // get the transitions available from this task and
        // show them in the dialog as additional buttons
        this.transitions = this.getWorkflowTask().path.node.transitions;
        boolean isPooledTask = isPooledTask();
        if (isPooledTask || this.transitions != null) {
            buttons = new ArrayList<DialogButtonConfig>(this.transitions.length + 1);
            if (isPooledTask) {
                if (this.taskNode.getProperties().get(ContentModel.PROP_OWNER) == null) {
                    buttons.add(new DialogButtonConfig("button_take_ownership", null, "take_ownership", "#{DialogManager.bean.takeOwnership}", "false", null));
                } else {
                    buttons.add(new DialogButtonConfig("button_return_to_pool", null, "return_ownership", "#{DialogManager.bean.returnOwnership}", "false", null));
                }
            }
            if (this.transitions != null) {
                Object hiddenTransitions = this.taskNode.getProperties().get(WorkflowModel.PROP_HIDDEN_TRANSITIONS);
                for (WorkflowTransition trans : this.transitions) {
                    if (hiddenTransitions == null || (hiddenTransitions instanceof String && ((String) hiddenTransitions).equals("")) || (hiddenTransitions instanceof String && !((String) hiddenTransitions).equals(trans.id)) || (hiddenTransitions instanceof List<?>) && !((List<?>) hiddenTransitions).contains(trans.id)) {
                        if (this.taskNode.getProperties().get(ContentModel.PROP_OWNER) != null) {
                            buttons.add(new DialogButtonConfig(ID_PREFIX + trans.title, trans.title, null, "#{DialogManager.bean.transition}", "false", null));
                        }
                    }
                }
            }
        }
    }
    return buttons;
}
Also used : DialogButtonConfig(org.alfresco.web.config.DialogsConfigElement.DialogButtonConfig) WorkflowTransition(org.alfresco.service.cmr.workflow.WorkflowTransition)

Example 3 with DialogButtonConfig

use of org.alfresco.web.config.DialogsConfigElement.DialogButtonConfig in project acs-community-packaging by Alfresco.

the class DialogsElementReader method parseButtons.

/**
 * Retrieve the configuration for additional buttons.
 *
 * @param dialog The dialog XML element
 * @return List of configured buttons
 */
@SuppressWarnings("unchecked")
protected List<DialogButtonConfig> parseButtons(Element dialog) {
    List<DialogButtonConfig> buttons = null;
    // iterate over any configured buttons
    Element buttonsConfig = dialog.element(ELEMENT_BUTTONS);
    if (buttonsConfig != null) {
        buttons = new ArrayList<DialogButtonConfig>(4);
        Iterator<Element> children = buttonsConfig.elementIterator(ELEMENT_BUTTON);
        while (children.hasNext()) {
            Element button = children.next();
            String id = button.attributeValue(ATTR_ID);
            String label = button.attributeValue(ATTR_LABEL);
            String labelId = button.attributeValue(ATTR_LABEL_ID);
            String action = button.attributeValue(ATTR_ACTION);
            String disabled = button.attributeValue(ATTR_DISABLED);
            String onclick = button.attributeValue(ATTR_ONCLICK);
            // create the button config object
            DialogButtonConfig btnCfg = new DialogButtonConfig(id, label, labelId, action, disabled, onclick);
            // add the button to the list
            buttons.add(btnCfg);
        }
    }
    return buttons;
}
Also used : ConfigElement(org.springframework.extensions.config.ConfigElement) Element(org.dom4j.Element) DialogButtonConfig(org.alfresco.web.config.DialogsConfigElement.DialogButtonConfig)

Example 4 with DialogButtonConfig

use of org.alfresco.web.config.DialogsConfigElement.DialogButtonConfig in project acs-community-packaging by Alfresco.

the class DialogsElementReader method parse.

/**
 * @see org.springframework.extensions.config.xml.elementreader.ConfigElementReader#parse(org.dom4j.Element)
 */
@SuppressWarnings("unchecked")
public ConfigElement parse(Element element) {
    DialogsConfigElement configElement = null;
    if (element != null) {
        String elementName = element.getName();
        if (elementName.equals(ELEMENT_DIALOGS) == false) {
            throw new ConfigException("DialogsElementReader can only parse " + ELEMENT_DIALOGS + "elements, the element passed was '" + elementName + "'");
        }
        configElement = new DialogsConfigElement();
        // go through the dialogs
        Iterator<Element> items = element.elementIterator(ELEMENT_DIALOG);
        while (items.hasNext()) {
            Element item = items.next();
            String name = item.attributeValue(ATTR_NAME);
            String page = item.attributeValue(ATTR_PAGE);
            String bean = item.attributeValue(ATTR_MANAGED_BEAN);
            String icon = item.attributeValue(ATTR_ICON);
            String title = item.attributeValue(ATTR_TITLE);
            String titleId = item.attributeValue(ATTR_TITLE_ID);
            String subTitle = item.attributeValue(ATTR_SUBTITLE);
            String subTitleId = item.attributeValue(ATTR_SUBTITLE_ID);
            String description = item.attributeValue(ATTR_DESCRIPTION);
            String descriptionId = item.attributeValue(ATTR_DESCRIPTION_ID);
            String errorMsgId = item.attributeValue(ATTR_ERROR_MSG_ID);
            String showOK = item.attributeValue(ATTR_SHOW_OK_BUTTON);
            boolean isOKButtonVisible = true;
            if (showOK != null) {
                isOKButtonVisible = Boolean.parseBoolean(showOK);
            }
            // action related config
            String actionsConfigId = item.attributeValue(ATTR_ACTIONS_CONFIG_ID);
            boolean useMenuForActions = false;
            String asMenu = item.attributeValue(ATTR_ACTIONS_AS_MENU);
            if (asMenu != null) {
                useMenuForActions = Boolean.parseBoolean(asMenu);
            }
            String actionsMenuLabel = item.attributeValue(ATTR_ACTIONS_MENU_LABEL);
            String actionsMenuLabelId = item.attributeValue(ATTR_ACTIONS_MENU_LABEL_ID);
            String moreActionsConfigId = item.attributeValue(ATTR_MORE_ACTIONS_CONFIG_ID);
            String moreActionsMenuLabel = item.attributeValue(ATTR_MORE_ACTIONS_MENU_LABEL);
            String moreActionsMenuLabelId = item.attributeValue(ATTR_MORE_ACTIONS_MENU_LABEL_ID);
            // parse any buttons that may be present
            List<DialogButtonConfig> buttons = parseButtons(item);
            // setup the attrbiutes object
            DialogsConfigElement.DialogAttributes attrs = new DialogsConfigElement.DialogAttributes(name, page, bean);
            attrs.setIcon(icon);
            attrs.setTitle(title);
            attrs.setTitleId(titleId);
            attrs.setSubTitle(subTitle);
            attrs.setSubTitleId(subTitleId);
            attrs.setDescription(description);
            attrs.setDescriptionId(descriptionId);
            attrs.setErrorMessageId(errorMsgId);
            attrs.setOKButtonVisible(isOKButtonVisible);
            attrs.setButtons(buttons);
            attrs.setActionsConfigId(actionsConfigId);
            attrs.setActionsAsMenu(useMenuForActions);
            attrs.setActionsMenuLabel(actionsMenuLabel);
            attrs.setActionsMenuLabelId(actionsMenuLabelId);
            attrs.setMoreActionsConfigId(moreActionsConfigId);
            attrs.setMoreActionsMenuLabel(moreActionsMenuLabel);
            attrs.setMoreActionsMenuLabelId(moreActionsMenuLabelId);
            // create and add the dialog config object
            DialogsConfigElement.DialogConfig cfg = new DialogsConfigElement.DialogConfig(attrs);
            configElement.addDialog(cfg);
        }
    }
    return configElement;
}
Also used : ConfigElement(org.springframework.extensions.config.ConfigElement) Element(org.dom4j.Element) DialogButtonConfig(org.alfresco.web.config.DialogsConfigElement.DialogButtonConfig) ConfigException(org.springframework.extensions.config.ConfigException)

Aggregations

DialogButtonConfig (org.alfresco.web.config.DialogsConfigElement.DialogButtonConfig)4 Element (org.dom4j.Element)2 ConfigElement (org.springframework.extensions.config.ConfigElement)2 UICommand (javax.faces.component.UICommand)1 MethodBinding (javax.faces.el.MethodBinding)1 ValueBinding (javax.faces.el.ValueBinding)1 WorkflowTransition (org.alfresco.service.cmr.workflow.WorkflowTransition)1 ConfigException (org.springframework.extensions.config.ConfigException)1