Search in sources :

Example 1 with StepConfig

use of org.alfresco.web.config.WizardsConfigElement.StepConfig in project acs-community-packaging by Alfresco.

the class WizardManager method determineCurrentPage.

/**
 * Sets up the current page to show in the wizard
 */
protected void determineCurrentPage() {
    // reset the current page config in the state object
    this.currentWizardState.setCurrentPageCfg(null);
    PageConfig currentPageCfg = null;
    // get the config for the current step position
    StepConfig stepCfg = this.currentWizardState.getSteps().get(this.currentWizardState.getCurrentStep() - 1);
    // is the step conditional?
    if (stepCfg.hasConditionalPages()) {
        FacesContext context = FacesContext.getCurrentInstance();
        // test each conditional page in turn
        List<ConditionalPageConfig> pages = stepCfg.getConditionalPages();
        for (ConditionalPageConfig pageCfg : pages) {
            String condition = pageCfg.getCondition();
            if (logger.isDebugEnabled())
                logger.debug("Evaluating condition: " + condition);
            ValueBinding vb = context.getApplication().createValueBinding(condition);
            Object obj = vb.getValue(context);
            if (obj instanceof Boolean && ((Boolean) obj).booleanValue()) {
                currentPageCfg = pageCfg;
                break;
            }
        }
    }
    // if none of the conditions passed use the default page
    if (currentPageCfg == null) {
        currentPageCfg = stepCfg.getDefaultPage();
    }
    if (currentPageCfg == null) {
        throw new AlfrescoRuntimeException("Failed to determine page for step '" + stepCfg.getName() + "'. Make sure a default page is configured.");
    }
    // save the current page config in the state object
    this.currentWizardState.setCurrentPageCfg(currentPageCfg);
    if (logger.isDebugEnabled())
        logger.debug("Config for current page: " + this.currentWizardState.getCurrentPageCfg());
}
Also used : FacesContext(javax.faces.context.FacesContext) ConditionalPageConfig(org.alfresco.web.config.WizardsConfigElement.ConditionalPageConfig) PageConfig(org.alfresco.web.config.WizardsConfigElement.PageConfig) ConditionalPageConfig(org.alfresco.web.config.WizardsConfigElement.ConditionalPageConfig) ValueBinding(javax.faces.el.ValueBinding) StepConfig(org.alfresco.web.config.WizardsConfigElement.StepConfig) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 2 with StepConfig

use of org.alfresco.web.config.WizardsConfigElement.StepConfig in project acs-community-packaging by Alfresco.

the class WizardsElementReader method parseStep.

/**
 * Parses the given element which represents a step in a wizard
 *
 * @param step The Element representing the step
 * @return A StepConfig object
 */
protected StepConfig parseStep(Element step) {
    // get the name of the step and create the config object
    String stepName = step.attributeValue(ATTR_NAME);
    String stepTitle = step.attributeValue(ATTR_TITLE);
    String stepTitleId = step.attributeValue(ATTR_TITLE_ID);
    String stepDescription = step.attributeValue(ATTR_DESCRIPTION);
    String stepDescriptionId = step.attributeValue(ATTR_DESCRIPTION_ID);
    StepConfig stepCfg = new StepConfig(stepName, stepTitle, stepTitleId, stepDescription, stepDescriptionId);
    // find and parse the default page
    Element defaultPageElem = step.element(ELEMENT_PAGE);
    if (defaultPageElem != null) {
        String path = defaultPageElem.attributeValue(ATTR_PATH);
        String title = defaultPageElem.attributeValue(ATTR_TITLE);
        String titleId = defaultPageElem.attributeValue(ATTR_TITLE_ID);
        String description = defaultPageElem.attributeValue(ATTR_DESCRIPTION);
        String descriptionId = defaultPageElem.attributeValue(ATTR_DESCRIPTION_ID);
        String instruction = defaultPageElem.attributeValue(ATTR_INSTRUCTION);
        String instructionId = defaultPageElem.attributeValue(ATTR_INSTRUCTION_ID);
        // create and set the page config on the step
        stepCfg.setDefaultPage(new PageConfig(path, title, titleId, description, descriptionId, instruction, instructionId));
    }
    // find and parse any conditions that are present
    Iterator<Element> conditions = step.elementIterator(ELEMENT_CONDITION);
    while (conditions.hasNext()) {
        Element conditionElem = conditions.next();
        String ifAttr = conditionElem.attributeValue(ATTR_IF);
        Element conditionalPageElem = conditionElem.element(ELEMENT_PAGE);
        if (conditionalPageElem == null) {
            throw new ConfigException("A condition in step '" + stepCfg.getName() + "' does not have a containing <page> element");
        }
        String path = conditionalPageElem.attributeValue(ATTR_PATH);
        String title = conditionalPageElem.attributeValue(ATTR_TITLE);
        String titleId = conditionalPageElem.attributeValue(ATTR_TITLE_ID);
        String description = conditionalPageElem.attributeValue(ATTR_DESCRIPTION);
        String descriptionId = conditionalPageElem.attributeValue(ATTR_DESCRIPTION_ID);
        String instruction = conditionalPageElem.attributeValue(ATTR_INSTRUCTION);
        String instructionId = conditionalPageElem.attributeValue(ATTR_INSTRUCTION_ID);
        // create and add the page to the step
        stepCfg.addConditionalPage(new ConditionalPageConfig(path, ifAttr, title, titleId, description, descriptionId, instruction, instructionId));
    }
    return stepCfg;
}
Also used : ConditionalPageConfig(org.alfresco.web.config.WizardsConfigElement.ConditionalPageConfig) PageConfig(org.alfresco.web.config.WizardsConfigElement.PageConfig) ConfigElement(org.springframework.extensions.config.ConfigElement) Element(org.dom4j.Element) ConditionalPageConfig(org.alfresco.web.config.WizardsConfigElement.ConditionalPageConfig) StepConfig(org.alfresco.web.config.WizardsConfigElement.StepConfig) ConfigException(org.springframework.extensions.config.ConfigException)

Example 3 with StepConfig

use of org.alfresco.web.config.WizardsConfigElement.StepConfig in project acs-community-packaging by Alfresco.

the class WizardsElementReader method parse.

/**
 * @see org.springframework.extensions.config.xml.elementreader.ConfigElementReader#parse(org.dom4j.Element)
 */
public ConfigElement parse(Element element) {
    WizardsConfigElement configElement = null;
    if (element != null) {
        String elementName = element.getName();
        if (elementName.equals(ELEMENT_WIZARDS) == false) {
            throw new ConfigException("WizardsElementReader can only parse " + ELEMENT_WIZARDS + "elements, the element passed was '" + elementName + "'");
        }
        configElement = new WizardsConfigElement();
        // go through the items to show
        Iterator<Element> items = element.elementIterator(ELEMENT_WIZARD);
        while (items.hasNext()) {
            Element wizard = items.next();
            String name = wizard.attributeValue(ATTR_NAME);
            String bean = wizard.attributeValue(ATTR_MANAGED_BEAN);
            String icon = wizard.attributeValue(ATTR_ICON);
            String title = wizard.attributeValue(ATTR_TITLE);
            String titleId = wizard.attributeValue(ATTR_TITLE_ID);
            String subTitle = wizard.attributeValue(ATTR_SUBTITLE);
            String subTitleId = wizard.attributeValue(ATTR_SUBTITLE_ID);
            String description = wizard.attributeValue(ATTR_DESCRIPTION);
            String descriptionId = wizard.attributeValue(ATTR_DESCRIPTION_ID);
            String errorMsgId = wizard.attributeValue(ATTR_ERROR_MSG_ID);
            // create the wizard config object
            WizardsConfigElement.WizardConfig wizardCfg = new WizardsConfigElement.WizardConfig(name, bean, icon, title, titleId, subTitle, subTitleId, description, descriptionId, errorMsgId);
            Iterator<Element> steps = wizard.elementIterator(ELEMENT_STEP);
            while (steps.hasNext()) {
                StepConfig stepCfg = parseStep(steps.next());
                wizardCfg.addStep(stepCfg);
            }
            configElement.addWizard(wizardCfg);
        }
    }
    return configElement;
}
Also used : ConfigElement(org.springframework.extensions.config.ConfigElement) Element(org.dom4j.Element) StepConfig(org.alfresco.web.config.WizardsConfigElement.StepConfig) ConfigException(org.springframework.extensions.config.ConfigException)

Example 4 with StepConfig

use of org.alfresco.web.config.WizardsConfigElement.StepConfig in project acs-community-packaging by Alfresco.

the class WizardManager method getStepItems.

/**
 * Returns a list of UIListItems representing the steps of the wizard
 *
 * @return List of steps to display in UI
 */
public List<UIListItem> getStepItems() {
    List<UIListItem> items = new ArrayList<UIListItem>(this.currentWizardState.getSteps().size());
    for (int x = 0; x < this.currentWizardState.getSteps().size(); x++) {
        String uiStepNumber = Integer.toString(x + 1);
        StepConfig stepCfg = this.currentWizardState.getSteps().get(x);
        UIListItem item = new UIListItem();
        item.setValue(uiStepNumber);
        // get the title for the step
        String stepTitle = stepCfg.getTitleId();
        if (stepTitle != null) {
            stepTitle = Application.getMessage(FacesContext.getCurrentInstance(), stepTitle);
        } else {
            stepTitle = stepCfg.getTitle();
        }
        // get the tooltip for the step
        String stepTooltip = stepCfg.getDescriptionId();
        if (stepTooltip != null) {
            stepTooltip = Application.getMessage(FacesContext.getCurrentInstance(), stepTooltip);
        } else {
            stepTooltip = stepCfg.getDescription();
        }
        // set the label and tooltip
        item.setLabel(uiStepNumber + ". " + stepTitle);
        item.setTooltip(stepTooltip);
        items.add(item);
    }
    return items;
}
Also used : UIListItem(org.alfresco.web.ui.common.component.UIListItem) ArrayList(java.util.ArrayList) StepConfig(org.alfresco.web.config.WizardsConfigElement.StepConfig)

Aggregations

StepConfig (org.alfresco.web.config.WizardsConfigElement.StepConfig)4 ConditionalPageConfig (org.alfresco.web.config.WizardsConfigElement.ConditionalPageConfig)2 PageConfig (org.alfresco.web.config.WizardsConfigElement.PageConfig)2 Element (org.dom4j.Element)2 ConfigElement (org.springframework.extensions.config.ConfigElement)2 ConfigException (org.springframework.extensions.config.ConfigException)2 ArrayList (java.util.ArrayList)1 FacesContext (javax.faces.context.FacesContext)1 ValueBinding (javax.faces.el.ValueBinding)1 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1 UIListItem (org.alfresco.web.ui.common.component.UIListItem)1