Merge from HEAD to WCM-DEV2.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3659 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Britt Park
2006-09-02 18:19:00 +00:00
parent 3b1d6b89f5
commit cc6af1a45c
100 changed files with 4941 additions and 1298 deletions

View File

@@ -26,16 +26,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<StepConfig> steps;
protected Map<String, String> currentWizardParams;
private WizardState currentWizardState;
private Map<String, String> paramsToApply;
/**
* Action handler used to setup parameters for the wizard being launched
@@ -49,7 +45,7 @@ public class WizardManager
if (component instanceof UIActionLink)
{
// store the parameters
this.currentWizardParams = ((UIActionLink)component).getParameterMap();
this.paramsToApply = ((UIActionLink)component).getParameterMap();
}
}
@@ -60,31 +56,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 +110,7 @@ public class WizardManager
*/
public WizardConfig getCurrentWizard()
{
return this.currentWizardConfig;
return this.currentWizardState.getConfig();
}
/**
@@ -102,7 +120,7 @@ public class WizardManager
*/
public IWizardBean getBean()
{
return this.currentWizard;
return this.currentWizardState.getWizard();
}
/**
@@ -112,7 +130,7 @@ public class WizardManager
*/
public String getIcon()
{
return this.currentWizardConfig.getIcon();
return this.currentWizardState.getConfig().getIcon();
}
/**
@@ -123,7 +141,7 @@ public class WizardManager
public String getErrorMessage()
{
return Application.getMessage(FacesContext.getCurrentInstance(),
this.currentWizardConfig.getErrorMessageId());
this.currentWizardState.getConfig().getErrorMessageId());
}
/**
@@ -133,15 +151,23 @@ public class WizardManager
*/
public String getTitle()
{
String title = this.currentWizardConfig.getTitleId();
// try and get the title directly from the wizard
String title = this.currentWizardState.getWizard().getTitle();
if (title != null)
if (title == null)
{
title = Application.getMessage(FacesContext.getCurrentInstance(), title);
}
else
{
title = this.currentWizardConfig.getTitle();
// try and get the title via a message bundle key
title = this.currentWizardState.getConfig().getTitleId();
if (title != null)
{
title = Application.getMessage(FacesContext.getCurrentInstance(), title);
}
else
{
// try and get the title from the configuration
title = this.currentWizardState.getConfig().getTitle();
}
}
return title;
@@ -154,15 +180,23 @@ public class WizardManager
*/
public String getDescription()
{
String desc = this.currentWizardConfig.getDescriptionId();
// try and get the description directly from the dialog
String desc = this.currentWizardState.getWizard().getDescription();
if (desc != null)
if (desc == null)
{
desc = Application.getMessage(FacesContext.getCurrentInstance(), desc);
}
else
{
desc = this.currentWizardConfig.getDescription();
// try and get the description via a message bundle key
desc = this.currentWizardState.getConfig().getDescriptionId();
if (desc != null)
{
desc = Application.getMessage(FacesContext.getCurrentInstance(), desc);
}
else
{
// try and get the description from the configuration
desc = this.currentWizardState.getConfig().getDescription();
}
}
return desc;
@@ -175,7 +209,7 @@ public class WizardManager
*/
public int getCurrentStep()
{
return this.currentStep;
return this.currentWizardState.getCurrentStep();
}
/**
@@ -185,7 +219,7 @@ public class WizardManager
*/
public String getCurrentStepAsString()
{
return Integer.toString(this.currentStep);
return Integer.toString(this.currentWizardState.getCurrentStep());
}
/**
@@ -197,7 +231,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 +242,12 @@ public class WizardManager
*/
public List<UIListItem> getStepItems()
{
List<UIListItem> items = new ArrayList<UIListItem>(this.steps.size());
List<UIListItem> items = new ArrayList<UIListItem>(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 +290,7 @@ public class WizardManager
*/
public String getPage()
{
return this.currentPageCfg.getPath();
return this.currentWizardState.getCurrentPageCfg().getPath();
}
/**
@@ -265,7 +300,7 @@ public class WizardManager
*/
public String getStepTitle()
{
String title = this.currentPageCfg.getTitleId();
String title = this.currentWizardState.getCurrentPageCfg().getTitleId();
if (title != null)
{
@@ -273,7 +308,7 @@ public class WizardManager
}
else
{
title = this.currentPageCfg.getTitle();
title = this.currentWizardState.getCurrentPageCfg().getTitle();
}
return title;
@@ -286,7 +321,7 @@ public class WizardManager
*/
public String getStepDescription()
{
String desc = this.currentPageCfg.getDescriptionId();
String desc = this.currentWizardState.getCurrentPageCfg().getDescriptionId();
if (desc != null)
{
@@ -294,7 +329,7 @@ public class WizardManager
}
else
{
desc = this.currentPageCfg.getDescription();
desc = this.currentWizardState.getCurrentPageCfg().getDescription();
}
return desc;
@@ -307,7 +342,7 @@ public class WizardManager
*/
public String getStepInstructions()
{
String instruction = this.currentPageCfg.getInstructionId();
String instruction = this.currentWizardState.getCurrentPageCfg().getInstructionId();
if (instruction != null)
{
@@ -315,7 +350,7 @@ public class WizardManager
}
else
{
instruction = this.currentPageCfg.getInstruction();
instruction = this.currentWizardState.getCurrentPageCfg().getInstruction();
}
return instruction;
@@ -328,7 +363,7 @@ public class WizardManager
*/
public String getNextButtonLabel()
{
return this.currentWizard.getNextButtonLabel();
return this.currentWizardState.getWizard().getNextButtonLabel();
}
/**
@@ -338,13 +373,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 +390,7 @@ public class WizardManager
*/
public String getBackButtonLabel()
{
return this.currentWizard.getBackButtonLabel();
return this.currentWizardState.getWizard().getBackButtonLabel();
}
/**
@@ -365,7 +400,7 @@ public class WizardManager
*/
public boolean getBackButtonDisabled()
{
if (this.currentStep == 1)
if (this.currentWizardState.getCurrentStep() == 1)
{
return true;
}
@@ -382,7 +417,7 @@ public class WizardManager
*/
public String getCancelButtonLabel()
{
return this.currentWizard.getCancelButtonLabel();
return this.currentWizardState.getWizard().getCancelButtonLabel();
}
/**
@@ -392,7 +427,7 @@ public class WizardManager
*/
public String getFinishButtonLabel()
{
return this.currentWizard.getFinishButtonLabel();
return this.currentWizardState.getWizard().getFinishButtonLabel();
}
/**
@@ -402,13 +437,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 +454,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 +475,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 +496,7 @@ public class WizardManager
*/
public String finish()
{
return this.currentWizard.finish();
return this.currentWizardState.getWizard().finish();
}
/**
@@ -465,7 +506,7 @@ public class WizardManager
*/
public String cancel()
{
return this.currentWizard.cancel();
return this.currentWizardState.getWizard().cancel();
}
/**
@@ -473,10 +514,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 +542,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());
}
}

View File

@@ -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<StepConfig> 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<StepConfig> getSteps()
{
return steps;
}
@Override
public String toString()
{
return AlfrescoNavigationHandler.WIZARD_PREFIX + this.config.getName() +
"[" + this.currentStep + "]";
}
}