01: /**
02: * Wizard Framework
03: * Copyright 2004 - 2005 Andrew Pietsch
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, write to the Free Software
17: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: *
19: * $Id: Path.java,v 1.7 2005/05/16 23:07:00 pietschy Exp $
20: */package org.pietschy.wizard.models;
21:
22: import org.pietschy.wizard.WizardStep;
23:
24: import java.util.ArrayList;
25: import java.util.List;
26: import java.util.Set;
27:
28: /**
29: * Paths represent a sequence of {@link WizardStep}s.
30: */
31: public abstract class Path {
32: private ArrayList steps = new ArrayList();
33:
34: protected Path() {
35: }
36:
37: /**
38: * Gets the path that will follow this one.
39: * @return the next path.
40: */
41: protected abstract Path getNextPath(MultiPathModel model);
42:
43: /**
44: * Adds a wizard step to this path. Paths must contain at least one step, and the steps
45: * will be traversed in the order they are added.
46: * @param step the next {@link WizardStep} in the path.
47: */
48: public void addStep(WizardStep step) {
49: steps.add(step);
50: }
51:
52: public WizardStep firstStep() {
53: return (WizardStep) steps.get(0);
54: }
55:
56: public WizardStep nextStep(WizardStep currentStep) {
57: int index = steps.indexOf(currentStep);
58: return (WizardStep) steps.get(index + 1);
59: }
60:
61: public WizardStep previousStep(WizardStep currentStep) {
62: int index = steps.indexOf(currentStep);
63: return (WizardStep) steps.get(index - 1);
64: }
65:
66: public WizardStep lastStep() {
67: return (WizardStep) steps.get(steps.size() - 1);
68: }
69:
70: /**
71: * Checks if the specified step is the first step in the path.
72: * @param step the step to check
73: * @return <tt>true</tt> if the step is the first in the path, <tt>false</tt> otherwise.
74: */
75: public boolean isFirstStep(WizardStep step) {
76: return steps.indexOf(step) == 0;
77: }
78:
79: /**
80: * Checks if the specified step is the last step in the path.
81: * @param step the step to check
82: * @return <tt>true</tt> if the step is the last in the path, <tt>false</tt> otherwise.
83: */
84: public boolean isLastStep(WizardStep step) {
85: boolean lastStep = steps.lastIndexOf(step) == steps.size() - 1;
86: return lastStep;
87: }
88:
89: public ArrayList getSteps() {
90: return steps;
91: }
92:
93: public boolean contains(WizardStep step) {
94: return steps.contains(step);
95: }
96:
97: public abstract void acceptVisitor(PathVisitor visitor);
98: }
|