001: package nl.hippo.cms.wizard;
002:
003: import java.util.HashMap;
004: import java.util.Iterator;
005:
006: import nl.hippo.cms.wizard.components.AbstractComponentContainer;
007: import nl.hippo.cms.wizard.components.Component;
008: import nl.hippo.cms.wizard.components.Configuration;
009: import nl.hippo.cms.wizard.engines.Engine;
010:
011: import org.springframework.web.context.WebApplicationContext;
012:
013: /**
014: * Root component for the wizard model. Holds an OrderedMap of Configurations which
015: * are displayed as tabs.
016: *
017: * @author a.bogaart@hippo.nl
018: *
019: */
020:
021: public class NewDocumentWizard extends AbstractComponentContainer
022: implements Wizard {
023:
024: public static final String TYPE = "wizard";
025:
026: private String resultAction = Constants.WIZARD_DEFAULT_RESULT_ACTION;
027:
028: /**
029: * Default Constructor
030: */
031: public NewDocumentWizard() throws Exception {
032: this (Constants.WIZARD_DEFAULT_ID);
033: }
034:
035: /**
036: * Configure Wizard with an id
037: *
038: * @param id
039: * @throws Exception
040: */
041: public NewDocumentWizard(String id) throws Exception {
042: super ();
043: Configuration conf = new Configuration(new HashMap());
044: conf.add(Constants.ID_ATTRIBUTE_NAME, id);
045: configure(conf);
046: }
047:
048: public void configure(Configuration config) throws Exception {
049: super .configure(config);
050: if (config.get(Constants.DEFAULT_RESULT_ACTION_ATTRIBUTE_NAME) != null) {
051: resultAction = config
052: .get(Constants.DEFAULT_RESULT_ACTION_ATTRIBUTE_NAME);
053: }
054: }
055:
056: /* (non-Javadoc)
057: * @see nl.hippo.cms.wizard.Wizard#getResultAction()
058: */
059: public String getResultAction() {
060: return resultAction;
061: }
062:
063: /* (non-Javadoc)
064: * @see nl.hippo.cms.wizard.Wizard#setResultAction(String resultAction)
065: */
066: public void setResultAction(String resultAction) {
067: this .resultAction = resultAction;
068: }
069:
070: //Override
071: /**
072: * Cforms stores the value of the current tab as an int, describing it's index in the OrderedMap.
073: * @return Component reference to current component in focus, or null if not found
074: */
075: public Component getCurrentComponent() {
076: Integer integer = new Integer(getCurrent());
077: int count = integer.intValue();
078: int forCount = 0;
079: Iterator it = components.values().iterator();
080: while (it.hasNext()) {
081: Engine engine = (Engine) it.next();
082: if (count == forCount) {
083: return engine;
084: }
085: forCount++;
086: }
087: return null;
088: }
089:
090: //@Override
091: /**
092: * We can't have an empty or null value as initial state since this will break the behaviour of the
093: * ResetOldResourceDropdown form event, so return 0 instead.
094: */
095: public String getCurrent() {
096: String current = super .getCurrent();
097: if (current == null || current.equals("")) {
098: return "0";
099: }
100: return current;
101: }
102:
103: //Override
104: /* (non-Javadoc)
105: * @see nl.hippo.cms.wizard.components.Component#fillResult(nl.hippo.cms.wizard.WizardResult, org.springframework.web.context.WebApplicationContext)
106: */
107: public void fillResult(WizardResult result,
108: WebApplicationContext model) throws Exception {
109: Engine currentEngine = (Engine) getCurrentComponent();
110: if (currentEngine == null) {
111: throw new Exception(
112: "No engine has been used, currentEngine is null.");
113: }
114: currentEngine.fillResult(result, model);
115: result.setResultAction(resultAction);
116: }
117:
118: /* (non-Javadoc)
119: * @see nl.hippo.cms.wizard.component.Component#getType()
120: */
121: public String getType() {
122: return TYPE;
123: }
124:
125: /**
126: * Different reset behaviour for the tabs, use super call to auto reset Resources but save tab state
127: */
128: //@Override
129: public void reset() {
130: String current = getCurrent();
131: super.reset();
132: setCurrent(current);
133: }
134: }
|