Search in sources :

Example 1 with IHandler

use of org.alfresco.web.bean.actions.IHandler in project acs-community-packaging by Alfresco.

the class CreateCompositeRuleWizard method cancelAddCondition.

@Override
public void cancelAddCondition() {
    this.editCurrentCompositeCondition = false;
    this.rowIndex = -1;
    if (isAddingCompositeCondition()) {
        // don't clear when editing, since we are looking at a REFERENCE to an existing condition
        if (this.editingCondition == false) {
            this.currentConditionProperties.clear();
        }
        // reset the action drop down
        this.selectedCondition = null;
        // determine what page to go back to
        FacesContext context = FacesContext.getCurrentInstance();
        String currentViewId = context.getViewRoot().getViewId();
        IHandler handler = this.conditionHandlers.get(CompositeConditionHandler.NAME);
        String compositePage = handler.getJSPPath();
        if (currentViewId.equals(compositePage)) {
            this.returnViewId = getWizardContainerViewId(context);
        }
        goToPage(FacesContext.getCurrentInstance(), this.returnViewId);
    } else {
        super.cancelAddCondition();
        return;
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) IHandler(org.alfresco.web.bean.actions.IHandler)

Example 2 with IHandler

use of org.alfresco.web.bean.actions.IHandler in project acs-community-packaging by Alfresco.

the class CreateCompositeRuleWizard method addCondition.

/**
 * Adds the condition just setup by the user to the list of composite
 * conditions This gathers the composite conditions in the
 */
@Override
public void addCondition() {
    if (!isAddingCompositeCondition()) {
        super.addCondition();
        printConditionState();
        return;
    }
    if (logger.isDebugEnabled())
        logger.debug("Adding Condition to Composite Condition. ");
    FacesContext context = FacesContext.getCurrentInstance();
    // this is called from the actions page so there must be a handler
    // present so there's no need to check for null
    IHandler handler = this.conditionHandlers.get(this.selectedCondition);
    if (handler != null) {
        String summary = handler.generateSummary(context, this, this.currentConditionProperties);
        this.currentConditionProperties.put(PROP_CONDITION_SUMMARY, summary);
    } else {
        if (logger.isWarnEnabled())
            logger.warn("No Summary could be generated for rule condition " + this.selectedCondition);
        this.currentConditionProperties.put(PROP_CONDITION_SUMMARY, "ERROR - No Summary for " + this.selectedCondition);
    }
    if (editingCondition == false) {
        // this check is needed to prevent an condition when you are editing a composite, to prevent it from adding twice
        currentCompositeConditionPropertiesList.add(this.currentConditionProperties);
        if (logger.isDebugEnabled())
            logger.debug("\tAdded condition to Composite condition.");
    } else {
        if (logger.isDebugEnabled())
            logger.debug("\tEdited composite condition. ");
    }
    this.currentConditionProperties = new HashMap<String, Serializable>(3);
    // resetting it for composite condition
    // TODO: this is not persistent currently, which causes a minor bug
    this.currentConditionProperties.put(PROP_CONDITION_NAME, CompositeConditionHandler.NAME);
    this.currentConditionProperties.put(BaseConditionHandler.PROP_CONDITION_NOT, Boolean.FALSE);
    // reset the action drop down
    this.selectedCondition = null;
    // refresh the wizard
    printConditionState();
    goToPage(context, this.returnViewId);
}
Also used : FacesContext(javax.faces.context.FacesContext) Serializable(java.io.Serializable) IHandler(org.alfresco.web.bean.actions.IHandler)

Example 3 with IHandler

use of org.alfresco.web.bean.actions.IHandler in project acs-community-packaging by Alfresco.

the class CreateCompositeRuleWizard method finishAddingCompositeCondition.

public void finishAddingCompositeCondition() {
    if (logger.isDebugEnabled())
        logger.debug("Finishing Adding Composite Condition.");
    // reset the effective chosen condition to composite-condition
    this.selectedCondition = CompositeConditionHandler.NAME;
    FacesContext context = FacesContext.getCurrentInstance();
    returnViewId = getWizardContainerViewId(context);
    printConditionState();
    if (logger.isDebugEnabled())
        logger.debug("\tAdding Condition '" + selectedCondition + "'");
    IHandler handler = this.conditionHandlers.get(this.selectedCondition);
    // creating object temporarily so we can pass it to CompositeConditionHandler
    currentConditionProperties.put(CompositeConditionHandler.PROP_COMPOSITE_CONDITION, (Serializable) this.currentCompositeConditionPropertiesList);
    currentConditionProperties.put(PROP_CONDITION_NAME, this.selectedCondition);
    // this is called from the actions page so there must be a handler
    // present so there's no need to check for null
    String summary = handler.generateSummary(context, this, currentConditionProperties);
    if (summary != null) {
        currentConditionProperties.put(PROP_CONDITION_SUMMARY, summary);
    }
    if (logger.isDebugEnabled())
        logger.debug("Generated Summary - [" + summary + "] + selectedCondition " + this.selectedCondition);
    if (this.editCurrentCompositeCondition == true) {
        if (rowIndex != -1) {
            this.allConditionsPropertiesList.remove(rowIndex);
            this.allConditionsPropertiesList.add(rowIndex, currentConditionProperties);
        }
    } else {
        this.allConditionsPropertiesList.add(currentConditionProperties);
    }
    this.editCurrentCompositeCondition = false;
    this.rowIndex = -1;
    clearCompositeConditionMode();
    // refresh the wizard
    goToPage(context, this.returnViewId);
}
Also used : FacesContext(javax.faces.context.FacesContext) IHandler(org.alfresco.web.bean.actions.IHandler)

Example 4 with IHandler

use of org.alfresco.web.bean.actions.IHandler in project acs-community-packaging by Alfresco.

the class CreateRuleWizard method promptForConditionValues.

// ------------------------------------------------------------------------------
// Action event handlers
/**
 * Displays the settings page for the current condition being added (if required)
 */
public void promptForConditionValues() {
    // set the flag to show we are creating a new condition
    this.editingCondition = false;
    FacesContext context = FacesContext.getCurrentInstance();
    this.returnViewId = context.getViewRoot().getViewId();
    String viewId = null;
    this.currentConditionProperties = new HashMap<String, Serializable>(3);
    this.currentConditionProperties.put(PROP_CONDITION_NAME, this.selectedCondition);
    this.currentConditionProperties.put(BaseConditionHandler.PROP_CONDITION_NOT, Boolean.FALSE);
    // get the handler for the condition, if there isn't one we presume it
    // is a no-parameter condition
    IHandler handler = this.conditionHandlers.get(this.selectedCondition);
    if (handler != null) {
        if (logger.isDebugEnabled())
            logger.debug("Found Handler for selected condition - '" + this.selectedCondition + "'");
        // setup any UI defaults the condition may have and get the location of
        // the JSP used to collect the parameters
        handler.setupUIDefaults(this.currentConditionProperties);
        viewId = handler.getJSPPath();
        if (logger.isDebugEnabled())
            logger.debug("Handler returned JSP page- '" + viewId + "'  Handler Type " + handler.getClass().toString());
    } else {
        if (logger.isDebugEnabled())
            logger.debug("Did Not Find a handler for selected condition - '" + this.selectedCondition + "'");
        // just add the action to the list and use the title as the summary
        ActionConditionDefinition conditionDef = this.getActionService().getActionConditionDefinition(this.selectedCondition);
        this.currentConditionProperties.put(PROP_CONDITION_SUMMARY, conditionDef.getTitle());
        this.currentConditionProperties.put(BaseConditionHandler.PROP_CONDITION_NOT, Boolean.FALSE);
        // add the no params marker so we can disable the edit action
        this.currentConditionProperties.put(NO_PARAMS_MARKER, "no-params");
        this.allConditionsPropertiesList.add(this.currentConditionProperties);
        // come back to the same page we're on now as there are no params to collect
        viewId = this.returnViewId;
    }
    if (logger.isDebugEnabled())
        logger.debug("Currently creating '" + this.selectedCondition + "' condition");
    // go to the page to collect the settings
    goToPage(context, viewId);
}
Also used : FacesContext(javax.faces.context.FacesContext) Serializable(java.io.Serializable) IHandler(org.alfresco.web.bean.actions.IHandler) ActionConditionDefinition(org.alfresco.service.cmr.action.ActionConditionDefinition)

Example 5 with IHandler

use of org.alfresco.web.bean.actions.IHandler in project acs-community-packaging by Alfresco.

the class CreateRuleWizard method initialiseConditionHandlers.

/**
 * Initialises the condition handlers from the current configuration.
 */
protected void initialiseConditionHandlers() {
    if ((this.conditionHandlers == null) || (Application.isDynamicConfig(FacesContext.getCurrentInstance()))) {
        ConfigService svc = Application.getConfigService(FacesContext.getCurrentInstance());
        Config wizardCfg = svc.getConfig("Action Wizards");
        if (wizardCfg != null) {
            ConfigElement conditionHandlerCfg = wizardCfg.getConfigElement("condition-handlers");
            if (conditionHandlerCfg != null) {
                this.conditionHandlers = new HashMap<String, IHandler>(20);
                // instantiate each handler and store in the map
                for (ConfigElement child : conditionHandlerCfg.getChildren()) {
                    String conditionName = child.getAttribute("name");
                    String handlerClass = child.getAttribute("class");
                    if (conditionName != null && conditionName.length() > 0 && handlerClass != null && handlerClass.length() > 0) {
                        try {
                            @SuppressWarnings("unchecked") Class klass = Class.forName(handlerClass);
                            IHandler handler = (IHandler) klass.newInstance();
                            this.conditionHandlers.put(conditionName, handler);
                        } catch (Exception e) {
                            throw new AlfrescoRuntimeException("Failed to setup condition handler for '" + conditionName + "'", e);
                        }
                    }
                }
            } else {
                logger.warn("Could not find 'condition-handlers' configuration element");
            }
        } else {
            logger.warn("Could not find 'Action Wizards' configuration section");
        }
    }
}
Also used : ConfigService(org.springframework.extensions.config.ConfigService) ConfigElement(org.springframework.extensions.config.ConfigElement) Config(org.springframework.extensions.config.Config) IHandler(org.alfresco.web.bean.actions.IHandler) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) IOException(java.io.IOException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Aggregations

IHandler (org.alfresco.web.bean.actions.IHandler)10 Serializable (java.io.Serializable)5 FacesContext (javax.faces.context.FacesContext)5 HashMap (java.util.HashMap)2 Action (org.alfresco.service.cmr.action.Action)2 ActionCondition (org.alfresco.service.cmr.action.ActionCondition)2 ActionConditionDefinition (org.alfresco.service.cmr.action.ActionConditionDefinition)2 CompositeAction (org.alfresco.service.cmr.action.CompositeAction)2 CompositeActionCondition (org.alfresco.service.cmr.action.CompositeActionCondition)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1 ActionDefinition (org.alfresco.service.cmr.action.ActionDefinition)1 Config (org.springframework.extensions.config.Config)1 ConfigElement (org.springframework.extensions.config.ConfigElement)1 ConfigService (org.springframework.extensions.config.ConfigService)1