diff --git a/config/alfresco/web-client-config-dialogs.xml b/config/alfresco/web-client-config-dialogs.xml index 9e0b5b47ea..261aa65ce9 100644 --- a/config/alfresco/web-client-config-dialogs.xml +++ b/config/alfresco/web-client-config-dialogs.xml @@ -93,7 +93,8 @@ + title-id="manage_task_title" description-id="manage_task_desc" + actions-config-id="manage_task_actions" /> + + + + diff --git a/source/java/org/alfresco/web/app/AlfrescoNavigationHandler.java b/source/java/org/alfresco/web/app/AlfrescoNavigationHandler.java index 236e3cf13f..c201aa5ec1 100644 --- a/source/java/org/alfresco/web/app/AlfrescoNavigationHandler.java +++ b/source/java/org/alfresco/web/app/AlfrescoNavigationHandler.java @@ -29,8 +29,10 @@ import org.alfresco.config.ConfigService; import org.alfresco.web.app.servlet.ExternalAccessServlet; import org.alfresco.web.bean.NavigationBean; import org.alfresco.web.bean.dialog.DialogManager; +import org.alfresco.web.bean.dialog.DialogState; import org.alfresco.web.bean.repository.Node; import org.alfresco.web.bean.wizard.WizardManager; +import org.alfresco.web.bean.wizard.WizardState; import org.alfresco.web.config.DialogsConfigElement; import org.alfresco.web.config.NavigationConfigElement; import org.alfresco.web.config.NavigationElementReader; @@ -589,16 +591,51 @@ public class AlfrescoNavigationHandler extends NavigationHandler // or any overridden outcome that may be present if (getViewStack(context).empty() == false) { - String newViewId = (String)getViewStack(context).pop(); - // is there an overidden outcome? String overriddenOutcome = getOutcomeOverride(outcome); if (overriddenOutcome == null) { // there isn't an overidden outcome so go back to the previous view if (logger.isDebugEnabled()) - logger.debug("Closing " + closingItem + ", going back to view id: " + newViewId); - + logger.debug("Closing " + closingItem + ", going back to previous page"); + + // if the top of the stack is not a dialog or wizard just get the + // view id and navigate back to it. + + // if the top of the stack is a dialog or wizard retrieve the state + // and setup the appropriate manager with that state, then get the + // appropriate container page and navigate to it. + + Object topOfStack = getViewStack(context).pop(); + + if (logger.isDebugEnabled()) + logger.debug("Popped item from the top of the view stack: " + topOfStack); + + String newViewId = null; + + if (topOfStack instanceof String) + { + newViewId = (String)topOfStack; + } + else if (topOfStack instanceof DialogState) + { + // restore the dialog state and get the dialog container viewId + Application.getDialogManager().restoreState((DialogState)topOfStack); + newViewId = getDialogContainer(context); + } + else if (topOfStack instanceof WizardState) + { + // restore the wizard state and get the wizard container viewId + Application.getWizardManager().restoreState((WizardState)topOfStack); + newViewId = getWizardContainer(context); + } + else + { + if (logger.isWarnEnabled()) + logger.warn("Invalid object found on view stack: " + topOfStack); + } + + // go to the appropraite page goToView(context, newViewId); } else @@ -656,33 +693,66 @@ public class AlfrescoNavigationHandler extends NavigationHandler * * @param context FacesContext */ + @SuppressWarnings("unchecked") protected void addCurrentViewToStack(FacesContext context) { - // if we are opening a wizard or dialog push the current view - // id on to the stack, but only if it is different than the - // current view at the top (you can't launch a dialog from - // the same page 2 times in a row!) + // if the current viewId is either the dialog or wizard container page + // we need to save the state of the current dialog or wizard to the stack - // TODO: This wouldn't happen if we could be sure a dialog is - // ALWAYS exited properly, look into a way of ensuring - // dialogs get closed if a user navigates away from the page, - // would a PhaseListener help in any way?? + // If the current view is a normal page and it is not the same as the + // view currently at the top of the stack (you can't launch a dialog from + // the same page 2 times in a row so it must mean the user navigated away + // from the first dialog) just add the viewId to the stack + // work out what to add to the stack String viewId = context.getViewRoot().getViewId(); - - if (getViewStack(context).empty() || - viewId.equals(getViewStack(context).peek()) == false) + String dialogContainer = getDialogContainer(context); + String wizardContainer = getWizardContainer(context); + Object objectForStack = null; + if (viewId.equals(dialogContainer)) { - getViewStack(context).push(viewId); - - if (logger.isDebugEnabled()) - logger.debug("Pushed current view to stack: " + viewId); + DialogManager dlgMgr = Application.getDialogManager(); + objectForStack = dlgMgr.getState(); + } + else if (viewId.equals(wizardContainer)) + { + WizardManager wizMgr = Application.getWizardManager(); + objectForStack = wizMgr.getState(); } else { - if (getViewStack(context).empty() == false && logger.isDebugEnabled()) + objectForStack = viewId; + } + + // if the stack is currently empty add the item + Stack stack = getViewStack(context); + if (stack.empty()) + { + stack.push(objectForStack); + + if (logger.isDebugEnabled()) + logger.debug("Pushed item to view stack: " + objectForStack); + } + else + { + // if the item to go on to the stack and the top of + // stack are both Strings and equals to each other + // don't add anything to the stack to stop it + // growing unecessarily + Object topOfStack = stack.peek(); + if (objectForStack instanceof String && + topOfStack instanceof String && + topOfStack.equals(objectForStack)) { - logger.debug("current view is already top the view stack!"); + if (logger.isDebugEnabled()) + logger.debug("current view is already top of the view stack!"); + } + else + { + stack.push(objectForStack); + + if (logger.isDebugEnabled()) + logger.debug("Pushed item to view stack: " + objectForStack); } } } @@ -725,13 +795,13 @@ public class AlfrescoNavigationHandler extends NavigationHandler * the users session, will never be null */ @SuppressWarnings("unchecked") - private Stack getViewStack(FacesContext context) + private Stack getViewStack(FacesContext context) { - Stack viewStack = (Stack)context.getExternalContext().getSessionMap().get(VIEW_STACK); + Stack viewStack = (Stack)context.getExternalContext().getSessionMap().get(VIEW_STACK); if (viewStack == null) { - viewStack = new Stack(); + viewStack = new Stack(); context.getExternalContext().getSessionMap().put(VIEW_STACK, viewStack); } diff --git a/source/java/org/alfresco/web/bean/dialog/BaseDialogBean.java b/source/java/org/alfresco/web/bean/dialog/BaseDialogBean.java index fa3b203b6f..7cf566edf5 100644 --- a/source/java/org/alfresco/web/bean/dialog/BaseDialogBean.java +++ b/source/java/org/alfresco/web/bean/dialog/BaseDialogBean.java @@ -58,6 +58,11 @@ public abstract class BaseDialogBean implements IDialogBean this.isFinished = false; } + public void restored() + { + // do nothing by default, subclasses can override if necessary + } + public String cancel() { return getDefaultCancelOutcome(); diff --git a/source/java/org/alfresco/web/bean/dialog/DialogManager.java b/source/java/org/alfresco/web/bean/dialog/DialogManager.java index c47c6d8c62..7c56f24859 100644 --- a/source/java/org/alfresco/web/bean/dialog/DialogManager.java +++ b/source/java/org/alfresco/web/bean/dialog/DialogManager.java @@ -20,11 +20,10 @@ import org.alfresco.web.ui.common.component.UIActionLink; * * @author gavinc */ -public class DialogManager +public final class DialogManager { - protected IDialogBean currentDialog; - protected DialogConfig currentDialogConfig; - protected Map currentDialogParams; + private DialogState currentDialogState; + private Map paramsToApply; /** * Action handler used to setup parameters for the dialog being launched @@ -38,7 +37,7 @@ public class DialogManager if (component instanceof UIActionLink) { // store the parameters - this.currentDialogParams = ((UIActionLink)component).getParameterMap(); + this.paramsToApply = ((UIActionLink)component).getParameterMap(); } } @@ -49,22 +48,48 @@ public class DialogManager */ public void setCurrentDialog(DialogConfig config) { - this.currentDialogConfig = config; - - String beanName = this.currentDialogConfig.getManagedBean(); - this.currentDialog = (IDialogBean)FacesHelper.getManagedBean( + String beanName = config.getManagedBean(); + IDialogBean dialog = (IDialogBean)FacesHelper.getManagedBean( FacesContext.getCurrentInstance(), beanName); - if (this.currentDialog == null) + if (dialog == null) { throw new AlfrescoRuntimeException("Failed to find managed bean '" + beanName + "'"); } // initialise the managed bean - this.currentDialog.init(this.currentDialogParams); + dialog.init(this.paramsToApply); // reset the current parameters so subsequent dialogs don't get them - this.currentDialogParams = null; + this.paramsToApply = null; + + // create the DialogState object + this.currentDialogState = new DialogState(config, dialog); + } + + /** + * Returns the state of the currently active dialog + * + * @return Current dialog's state + */ + public DialogState getState() + { + return this.currentDialogState; + } + + /** + * Restores the dialog represented by the given DialogState object. + * NOTE: The dialog's restored() method is also called during this + * method. + * + * @param state The DialogState for the dialog to restore + */ + public void restoreState(DialogState state) + { + this.currentDialogState = state; + + // retrieve the dialog and call it's restored() method + this.currentDialogState.getDialog().restored(); } /** @@ -74,7 +99,7 @@ public class DialogManager */ public DialogConfig getCurrentDialog() { - return this.currentDialogConfig; + return this.currentDialogState.getConfig(); } /** @@ -84,7 +109,7 @@ public class DialogManager */ public IDialogBean getBean() { - return this.currentDialog; + return this.currentDialogState.getDialog(); } /** @@ -94,7 +119,7 @@ public class DialogManager */ public String getIcon() { - return this.currentDialogConfig.getIcon(); + return this.currentDialogState.getConfig().getIcon(); } /** @@ -105,7 +130,7 @@ public class DialogManager public String getErrorMessage() { return Application.getMessage(FacesContext.getCurrentInstance(), - this.currentDialogConfig.getErrorMessageId()); + this.currentDialogState.getConfig().getErrorMessageId()); } /** @@ -115,7 +140,7 @@ public class DialogManager */ public String getTitle() { - String title = this.currentDialogConfig.getTitleId(); + String title = this.currentDialogState.getConfig().getTitleId(); if (title != null) { @@ -123,7 +148,7 @@ public class DialogManager } else { - title = this.currentDialogConfig.getTitle(); + title = this.currentDialogState.getConfig().getTitle(); } return title; @@ -136,7 +161,7 @@ public class DialogManager */ public String getDescription() { - String desc = this.currentDialogConfig.getDescriptionId(); + String desc = this.currentDialogState.getConfig().getDescriptionId(); if (desc != null) { @@ -144,7 +169,7 @@ public class DialogManager } else { - desc = this.currentDialogConfig.getDescription(); + desc = this.currentDialogState.getConfig().getDescription(); } return desc; @@ -158,7 +183,7 @@ public class DialogManager */ public String getActions() { - return this.currentDialogConfig.getActionsConfigId(); + return this.currentDialogState.getConfig().getActionsConfigId(); } /** @@ -168,7 +193,7 @@ public class DialogManager */ public String getPage() { - return this.currentDialogConfig.getPage(); + return this.currentDialogState.getConfig().getPage(); } /** @@ -178,7 +203,7 @@ public class DialogManager */ public boolean isOKButtonVisible() { - return this.currentDialogConfig.isOKButtonVisible(); + return this.currentDialogState.getConfig().isOKButtonVisible(); } /** @@ -191,10 +216,10 @@ public class DialogManager List buttons = null; // get a list of buttons to display from the configuration - List cfgButtons = this.currentDialogConfig.getButtons(); + List cfgButtons = this.currentDialogState.getConfig().getButtons(); // get a list of buttons added dynamically by the dialog - List dynButtons = this.currentDialog.getAdditionalButtons(); + List dynButtons = this.currentDialogState.getDialog().getAdditionalButtons(); if (cfgButtons != null && dynButtons != null) { @@ -223,7 +248,7 @@ public class DialogManager */ public String getCancelButtonLabel() { - return this.currentDialog.getCancelButtonLabel(); + return this.currentDialogState.getDialog().getCancelButtonLabel(); } /** @@ -233,7 +258,7 @@ public class DialogManager */ public String getFinishButtonLabel() { - return this.currentDialog.getFinishButtonLabel(); + return this.currentDialogState.getDialog().getFinishButtonLabel(); } /** @@ -243,7 +268,7 @@ public class DialogManager */ public boolean getFinishButtonDisabled() { - return this.currentDialog.getFinishButtonDisabled(); + return this.currentDialogState.getDialog().getFinishButtonDisabled(); } /** @@ -253,7 +278,7 @@ public class DialogManager */ public String finish() { - return this.currentDialog.finish(); + return this.currentDialogState.getDialog().finish(); } /** @@ -263,6 +288,6 @@ public class DialogManager */ public String cancel() { - return this.currentDialog.cancel(); + return this.currentDialogState.getDialog().cancel(); } } diff --git a/source/java/org/alfresco/web/bean/dialog/DialogState.java b/source/java/org/alfresco/web/bean/dialog/DialogState.java new file mode 100644 index 0000000000..aee2a53ab2 --- /dev/null +++ b/source/java/org/alfresco/web/bean/dialog/DialogState.java @@ -0,0 +1,53 @@ +package org.alfresco.web.bean.dialog; + +import org.alfresco.web.app.AlfrescoNavigationHandler; +import org.alfresco.web.config.DialogsConfigElement.DialogConfig; + +/** + * Object responsible for holding the current state of an active dialog. + * + * @author gavinc + */ +public final class DialogState +{ + private DialogConfig config; + private IDialogBean dialog; + + /** + * Default constructor + * + * @param config The configuration for the dialog + * @param dialog The dialog bean instance + */ + public DialogState(DialogConfig config, IDialogBean dialog) + { + this.config = config; + this.dialog = dialog; + } + + /** + * Returns the configuration for the dialog + * + * @return The dialog configuration + */ + public DialogConfig getConfig() + { + return config; + } + + /** + * Returns the bean representing the dialog instance + * + * @return The dialog bean instance + */ + public IDialogBean getDialog() + { + return dialog; + } + + @Override + public String toString() + { + return AlfrescoNavigationHandler.DIALOG_PREFIX + this.config.getName(); + } +} diff --git a/source/java/org/alfresco/web/bean/dialog/IDialogBean.java b/source/java/org/alfresco/web/bean/dialog/IDialogBean.java index fe2e9b59dc..9d2ab19c98 100644 --- a/source/java/org/alfresco/web/bean/dialog/IDialogBean.java +++ b/source/java/org/alfresco/web/bean/dialog/IDialogBean.java @@ -19,6 +19,11 @@ public interface IDialogBean */ public void init(Map parameters); + /** + * Called when the dialog is restored after a nested dialog is closed + */ + public void restored(); + /** * Method handler called when the cancel button of the dialog is pressed * diff --git a/source/java/org/alfresco/web/bean/wizard/WizardManager.java b/source/java/org/alfresco/web/bean/wizard/WizardManager.java index a967648627..13362cc6e2 100644 --- a/source/java/org/alfresco/web/bean/wizard/WizardManager.java +++ b/source/java/org/alfresco/web/bean/wizard/WizardManager.java @@ -12,6 +12,7 @@ import javax.faces.event.ActionEvent; import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.web.app.Application; import org.alfresco.web.app.servlet.FacesHelper; +import org.alfresco.web.bean.dialog.DialogState; import org.alfresco.web.config.WizardsConfigElement.ConditionalPageConfig; import org.alfresco.web.config.WizardsConfigElement.PageConfig; import org.alfresco.web.config.WizardsConfigElement.StepConfig; @@ -26,16 +27,12 @@ import org.apache.commons.logging.LogFactory; * * @author gavinc */ -public class WizardManager +public final class WizardManager { private static Log logger = LogFactory.getLog(WizardManager.class); - protected int currentStep = 1; - protected PageConfig currentPageCfg; - protected WizardConfig currentWizardConfig; - protected IWizardBean currentWizard; - protected List steps; - protected Map currentWizardParams; + private WizardState currentWizardState; + private Map paramsToApply; /** * Action handler used to setup parameters for the wizard being launched @@ -49,7 +46,7 @@ public class WizardManager if (component instanceof UIActionLink) { // store the parameters - this.currentWizardParams = ((UIActionLink)component).getParameterMap(); + this.paramsToApply = ((UIActionLink)component).getParameterMap(); } } @@ -60,31 +57,53 @@ public class WizardManager */ public void setCurrentWizard(WizardConfig config) { - this.currentStep = 1; - this.currentWizardConfig = config; - - String beanName = this.currentWizardConfig.getManagedBean(); - this.currentWizard = (IWizardBean)FacesHelper.getManagedBean( + String beanName = config.getManagedBean(); + IWizardBean wizard = (IWizardBean)FacesHelper.getManagedBean( FacesContext.getCurrentInstance(), beanName); - if (this.currentWizard == null) + if (wizard == null) { throw new AlfrescoRuntimeException("Failed to find managed bean '" + beanName + "'"); } // initialise the managed bean - this.currentWizard.init(this.currentWizardParams); + wizard.init(this.paramsToApply); // reset the current parameters so subsequent wizards don't get them - this.currentWizardParams = null; + this.paramsToApply = null; - // get the steps for the wizard - this.steps = this.currentWizardConfig.getStepsAsList(); + // create the WizardState object + this.currentWizardState = new WizardState(config, wizard); // setup the first step determineCurrentPage(); } + /** + * Returns the state of the currently active wizard + * + * @return Current wizard's state + */ + public WizardState getState() + { + return this.currentWizardState; + } + + /** + * Restores the wizard represented by the given WizardState object. + * NOTE: The wizard's restored() method is also called during this + * method. + * + * @param state The WizardState for the wizard to restore + */ + public void restoreState(WizardState state) + { + this.currentWizardState = state; + + // retrieve the wizard and call it's restored() method + this.currentWizardState.getWizard().restored(); + } + /** * Returns the config for the current wizard * @@ -92,7 +111,7 @@ public class WizardManager */ public WizardConfig getCurrentWizard() { - return this.currentWizardConfig; + return this.currentWizardState.getConfig(); } /** @@ -102,7 +121,7 @@ public class WizardManager */ public IWizardBean getBean() { - return this.currentWizard; + return this.currentWizardState.getWizard(); } /** @@ -112,7 +131,7 @@ public class WizardManager */ public String getIcon() { - return this.currentWizardConfig.getIcon(); + return this.currentWizardState.getConfig().getIcon(); } /** @@ -123,7 +142,7 @@ public class WizardManager public String getErrorMessage() { return Application.getMessage(FacesContext.getCurrentInstance(), - this.currentWizardConfig.getErrorMessageId()); + this.currentWizardState.getConfig().getErrorMessageId()); } /** @@ -133,7 +152,7 @@ public class WizardManager */ public String getTitle() { - String title = this.currentWizardConfig.getTitleId(); + String title = this.currentWizardState.getConfig().getTitleId(); if (title != null) { @@ -141,7 +160,7 @@ public class WizardManager } else { - title = this.currentWizardConfig.getTitle(); + title = this.currentWizardState.getConfig().getTitle(); } return title; @@ -154,7 +173,7 @@ public class WizardManager */ public String getDescription() { - String desc = this.currentWizardConfig.getDescriptionId(); + String desc = this.currentWizardState.getConfig().getDescriptionId(); if (desc != null) { @@ -162,7 +181,7 @@ public class WizardManager } else { - desc = this.currentWizardConfig.getDescription(); + desc = this.currentWizardState.getConfig().getDescription(); } return desc; @@ -175,7 +194,7 @@ public class WizardManager */ public int getCurrentStep() { - return this.currentStep; + return this.currentWizardState.getCurrentStep(); } /** @@ -185,7 +204,7 @@ public class WizardManager */ public String getCurrentStepAsString() { - return Integer.toString(this.currentStep); + return Integer.toString(this.currentWizardState.getCurrentStep()); } /** @@ -197,7 +216,8 @@ public class WizardManager */ public String getCurrentStepName() { - return ((StepConfig)this.steps.get(this.currentStep-1)).getName(); + return ((StepConfig)this.currentWizardState.getSteps().get( + this.currentWizardState.getCurrentStep()-1)).getName(); } /** @@ -207,12 +227,12 @@ public class WizardManager */ public List getStepItems() { - List items = new ArrayList(this.steps.size()); + List items = new ArrayList(this.currentWizardState.getSteps().size()); - for (int x = 0; x < this.steps.size(); x++) + for (int x = 0; x < this.currentWizardState.getSteps().size(); x++) { String uiStepNumber = Integer.toString(x + 1); - StepConfig stepCfg = this.steps.get(x); + StepConfig stepCfg = this.currentWizardState.getSteps().get(x); UIListItem item = new UIListItem(); item.setValue(uiStepNumber); @@ -255,7 +275,7 @@ public class WizardManager */ public String getPage() { - return this.currentPageCfg.getPath(); + return this.currentWizardState.getCurrentPageCfg().getPath(); } /** @@ -265,7 +285,7 @@ public class WizardManager */ public String getStepTitle() { - String title = this.currentPageCfg.getTitleId(); + String title = this.currentWizardState.getCurrentPageCfg().getTitleId(); if (title != null) { @@ -273,7 +293,7 @@ public class WizardManager } else { - title = this.currentPageCfg.getTitle(); + title = this.currentWizardState.getCurrentPageCfg().getTitle(); } return title; @@ -286,7 +306,7 @@ public class WizardManager */ public String getStepDescription() { - String desc = this.currentPageCfg.getDescriptionId(); + String desc = this.currentWizardState.getCurrentPageCfg().getDescriptionId(); if (desc != null) { @@ -294,7 +314,7 @@ public class WizardManager } else { - desc = this.currentPageCfg.getDescription(); + desc = this.currentWizardState.getCurrentPageCfg().getDescription(); } return desc; @@ -307,7 +327,7 @@ public class WizardManager */ public String getStepInstructions() { - String instruction = this.currentPageCfg.getInstructionId(); + String instruction = this.currentWizardState.getCurrentPageCfg().getInstructionId(); if (instruction != null) { @@ -315,7 +335,7 @@ public class WizardManager } else { - instruction = this.currentPageCfg.getInstruction(); + instruction = this.currentWizardState.getCurrentPageCfg().getInstruction(); } return instruction; @@ -328,7 +348,7 @@ public class WizardManager */ public String getNextButtonLabel() { - return this.currentWizard.getNextButtonLabel(); + return this.currentWizardState.getWizard().getNextButtonLabel(); } /** @@ -338,13 +358,13 @@ public class WizardManager */ public boolean getNextButtonDisabled() { - if (this.currentStep == this.steps.size()) + if (this.currentWizardState.getCurrentStep() == this.currentWizardState.getSteps().size()) { return true; } else { - return this.currentWizard.getNextButtonDisabled(); + return this.currentWizardState.getWizard().getNextButtonDisabled(); } } @@ -355,7 +375,7 @@ public class WizardManager */ public String getBackButtonLabel() { - return this.currentWizard.getBackButtonLabel(); + return this.currentWizardState.getWizard().getBackButtonLabel(); } /** @@ -365,7 +385,7 @@ public class WizardManager */ public boolean getBackButtonDisabled() { - if (this.currentStep == 1) + if (this.currentWizardState.getCurrentStep() == 1) { return true; } @@ -382,7 +402,7 @@ public class WizardManager */ public String getCancelButtonLabel() { - return this.currentWizard.getCancelButtonLabel(); + return this.currentWizardState.getWizard().getCancelButtonLabel(); } /** @@ -392,7 +412,7 @@ public class WizardManager */ public String getFinishButtonLabel() { - return this.currentWizard.getFinishButtonLabel(); + return this.currentWizardState.getWizard().getFinishButtonLabel(); } /** @@ -402,13 +422,13 @@ public class WizardManager */ public boolean getFinishButtonDisabled() { - if (this.currentStep == this.steps.size()) + if (this.currentWizardState.getCurrentStep() == this.currentWizardState.getSteps().size()) { return false; } else { - return this.currentWizard.getFinishButtonDisabled(); + return this.currentWizardState.getWizard().getFinishButtonDisabled(); } } @@ -419,13 +439,16 @@ public class WizardManager */ public void next() { - this.currentStep++; + // calculate next step number and update wizard state + int currentStep = this.currentWizardState.getCurrentStep(); + currentStep++; + this.currentWizardState.setCurrentStep(currentStep); if (logger.isDebugEnabled()) - logger.debug("next called, current step is now: " + this.currentStep); + logger.debug("next called, current step is now: " + this.currentWizardState.getCurrentStep()); // tell the wizard the next button has been pressed - this.currentWizard.next(); + this.currentWizardState.getWizard().next(); determineCurrentPage(); } @@ -437,13 +460,16 @@ public class WizardManager */ public void back() { - this.currentStep--; + // calculate next step number and update wizard state + int currentStep = this.currentWizardState.getCurrentStep(); + currentStep--; + this.currentWizardState.setCurrentStep(currentStep); if (logger.isDebugEnabled()) - logger.debug("back called, current step is now: " + this.currentStep); + logger.debug("back called, current step is now: " + this.currentWizardState.getCurrentStep()); // tell the wizard the back button has been pressed - this.currentWizard.back(); + this.currentWizardState.getWizard().back(); determineCurrentPage(); } @@ -455,7 +481,7 @@ public class WizardManager */ public String finish() { - return this.currentWizard.finish(); + return this.currentWizardState.getWizard().finish(); } /** @@ -465,7 +491,7 @@ public class WizardManager */ public String cancel() { - return this.currentWizard.cancel(); + return this.currentWizardState.getWizard().cancel(); } /** @@ -473,10 +499,14 @@ public class WizardManager */ protected void determineCurrentPage() { - this.currentPageCfg = null; + // 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.steps.get(this.currentStep-1); + StepConfig stepCfg = this.currentWizardState.getSteps().get( + this.currentWizardState.getCurrentStep()-1); // is the step conditional? if (stepCfg.hasConditionalPages()) @@ -497,25 +527,28 @@ public class WizardManager Object obj = vb.getValue(context); if (obj instanceof Boolean && ((Boolean)obj).booleanValue()) { - this.currentPageCfg = pageCfg; + currentPageCfg = pageCfg; break; } } } // if none of the conditions passed use the default page - if (this.currentPageCfg == null) + if (currentPageCfg == null) { - this.currentPageCfg = stepCfg.getDefaultPage(); + currentPageCfg = stepCfg.getDefaultPage(); } - if (this.currentPageCfg == null) + 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.currentPageCfg); + logger.debug("Config for current page: " + this.currentWizardState.getCurrentPageCfg()); } } diff --git a/source/java/org/alfresco/web/bean/wizard/WizardState.java b/source/java/org/alfresco/web/bean/wizard/WizardState.java new file mode 100644 index 0000000000..d006e8f342 --- /dev/null +++ b/source/java/org/alfresco/web/bean/wizard/WizardState.java @@ -0,0 +1,113 @@ +package org.alfresco.web.bean.wizard; + +import java.util.List; + +import org.alfresco.web.app.AlfrescoNavigationHandler; +import org.alfresco.web.config.WizardsConfigElement.PageConfig; +import org.alfresco.web.config.WizardsConfigElement.StepConfig; +import org.alfresco.web.config.WizardsConfigElement.WizardConfig; + +/** + * Object responsible for holding the current state of an active wizard. + * + * @author gavinc + */ +public final class WizardState +{ + private int currentStep = 1; + private PageConfig currentPageCfg; + private WizardConfig config; + private IWizardBean wizard; + private List steps; + + /** + * Default constructor + * + * @param config The configuration for the wizard + * @param wizard The wizard bean instance + */ + public WizardState(WizardConfig config, IWizardBean wizard) + { + this.config = config; + this.wizard = wizard; + + this.steps = this.config.getStepsAsList(); + } + + /** + * Sets the configuration for the current page of the wizard + * + * @param currentPageCfg The configuration + */ + public void setCurrentPageCfg(PageConfig currentPageCfg) + { + this.currentPageCfg = currentPageCfg; + } + + /** + * Sets the current step the wizard is on + * + * @param currentStep The current step number + */ + public void setCurrentStep(int currentStep) + { + this.currentStep = currentStep; + } + + /** + * Returns the wizard bean instance + * + * @return The wizard bean instance + */ + public IWizardBean getWizard() + { + return this.wizard; + } + + /** + * Returns the configuration for the current wizard + * + * @return The wizard configuration + */ + public WizardConfig getConfig() + { + return this.config; + } + + /** + * Returns the configuration for the current page of the wizard + * + * @return The current page configuration + */ + public PageConfig getCurrentPageCfg() + { + return currentPageCfg; + } + + /** + * The current step the wizard is on + * + * @return The current wizard step + */ + public int getCurrentStep() + { + return currentStep; + } + + /** + * Returns the list of steps the wizard has + * + * @return List of wizard steps + */ + public List getSteps() + { + return steps; + } + + @Override + public String toString() + { + return AlfrescoNavigationHandler.WIZARD_PREFIX + this.config.getName() + + "[" + this.currentStep + "]"; + } +} diff --git a/source/java/org/alfresco/web/bean/workflow/ManageTaskDialog.java b/source/java/org/alfresco/web/bean/workflow/ManageTaskDialog.java index 78c838bf4b..fc425c1e0d 100644 --- a/source/java/org/alfresco/web/bean/workflow/ManageTaskDialog.java +++ b/source/java/org/alfresco/web/bean/workflow/ManageTaskDialog.java @@ -121,7 +121,18 @@ public class ManageTaskDialog extends BaseDialogBean this.task.id + "': " + this.workflowPackage ); } } - + + @Override + public void restored() + { + // reset the workflow package rich list so everything gets re-evaluated + if (this.packageItemsRichList != null) + { + this.packageItemsRichList.setValue(null); + this.packageItemsRichList = null; + } + } + @Override protected String finishImpl(FacesContext context, String outcome) throws Exception diff --git a/source/java/org/alfresco/web/bean/workflow/StartWorkflowWizard.java b/source/java/org/alfresco/web/bean/workflow/StartWorkflowWizard.java index b99d77ad54..95ee4ecb77 100644 --- a/source/java/org/alfresco/web/bean/workflow/StartWorkflowWizard.java +++ b/source/java/org/alfresco/web/bean/workflow/StartWorkflowWizard.java @@ -85,6 +85,7 @@ public class StartWorkflowWizard extends BaseWizardBean if (this.packageItemsRichList != null) { this.packageItemsRichList.setValue(null); + this.packageItemsRichList = null; } // TODO: Does this need to be in a read-only transaction?? @@ -105,6 +106,17 @@ public class StartWorkflowWizard extends BaseWizardBean } } + @Override + public void restored() + { + // reset the workflow package rich list so everything gets re-evaluated + if (this.packageItemsRichList != null) + { + this.packageItemsRichList.setValue(null); + this.packageItemsRichList = null; + } + } + @Override protected String finishImpl(FacesContext context, String outcome) throws Exception