View Javadoc

1   package com.explosion.expfmodules.wizard.standard;
2   
3   import java.util.ArrayList;
4   import java.util.Collections;
5   import java.util.Comparator;
6   import java.util.Iterator;
7   import java.util.List;
8   import java.util.Map;
9   
10  import com.explosion.expfmodules.wizard.StepAction;
11  import com.explosion.expfmodules.wizard.StepDefinition;
12  import com.explosion.expfmodules.wizard.StepView;
13  import com.explosion.expfmodules.wizard.Wizard;
14  import com.explosion.utilities.GeneralConstants;
15  
16  
17  /* =============================================================================
18   *       
19   *     Copyright 2004 Stephen Cowx
20   *
21   *     Licensed under the Apache License, Version 2.0 (the "License");
22   *     you may not use this file except in compliance with the License.
23   *     You may obtain a copy of the License at
24   *
25   *     http://www.apache.org/licenses/LICENSE-2.0
26   *
27   *     Unless required by applicable law or agreed to in writing, software
28   *     distributed under the License is distributed on an "AS IS" BASIS,
29   *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
30   *     See the License for the specific language governing permissions and
31   *     limitations under the License.
32   * 
33   * =============================================================================
34   */
35  
36  /***
37   * @author Stephen Cowx
38   * Created on 22-Dec-2004
39   */
40  public class StandardStepDefinition implements StepDefinition
41  {
42  
43      private StepAction action;
44      private Map dataItems;
45      private String help;
46      private String id;
47      private String name;
48      private String notes;
49      private String icon;
50      private StepView view;
51      private Wizard wizard;
52      
53      /***
54       * Returns a reference to the wizard to which this step belongs
55       * @return
56       */
57      public Wizard getWizard()
58      {
59          return wizard;
60      }
61      
62      /***
63       * Sets the wizard
64       * @param wizard
65       */
66      public void setWizard(Wizard wizard)
67      {
68         this.wizard = wizard; 
69      }
70      
71      /***
72       * @see com.explosion.expfmodules.wizard.StepDefinition#getAction()
73       * @return
74       */   
75      public StepAction getAction()
76      {
77          return action;
78      }
79      
80      /***
81       * @see com.explosion.expfmodules.wizard.StepDefinition#setAction(com.explosion.expfmodules.wizard.StepAction)
82       * @param action
83       */
84      public void setAction(StepAction action)
85      {
86          this.action = action;
87      }
88      
89      /***
90       * @see com.explosion.expfmodules.wizard.StepDefinition#getDataItems()
91       * @return
92       */
93      public Map getDataItems()
94      {
95          return dataItems;
96      }
97      
98      /***
99       * Sets the data items
100      * @param dataItems
101      */
102     public void setDataItems(Map dataItems)
103     {
104         this.dataItems = dataItems;
105     }
106     
107     
108     /***
109      * Returns a collection of the dataItems in this step ordered according to their
110      * preferred display order
111      * @return
112      */
113     public List getOrderedDataItems()
114     {
115       List list = new ArrayList();
116       if (dataItems != null && dataItems.values() != null)
117       {
118       	for (Iterator it = dataItems.values().iterator(); it.hasNext();)
119         {
120 	      list.add(it.next());
121 	    }
122         Collections.sort(list, new PreferenceDataItemComparator());
123       }
124       return list;
125     }
126     
127     /***
128      * @see com.explosion.expfmodules.wizard.StepDefinition#getHelp()
129      * @return
130      */
131     public String getHelp()
132     {
133         return help;
134     }
135     
136     /***
137      * @param help
138      */
139     public void setHelp(String help)
140     {
141         this.help = help;
142     }
143     
144     /***
145      * @see com.explosion.expfmodules.wizard.StepDefinition#getId()
146      * @return
147      */
148     public String getId()
149     {
150         return this.id;
151     }
152     
153     /***
154      * @param id
155      */
156     public void setId(String id)
157     {
158         this.id = id;
159     }
160     
161     /***
162      * @see com.explosion.expfmodules.wizard.StepDefinition#getName()
163      * @return
164      */
165     public String getName()
166     {
167         return name;
168     }
169     
170     /***
171      * @param name
172      */
173     public void setName(String name)
174     {
175         this.name = name;
176     }
177     
178     /***
179      * @see com.explosion.expfmodules.wizard.StepDefinition#getView()
180      * @return
181      */
182     public StepView getView()
183     {
184         return view;
185     }
186     
187     /***
188      * @see com.explosion.expfmodules.wizard.StepDefinition#setView(com.explosion.expfmodules.wizard.StepView)
189      * @param view
190      */
191     public void setView(StepView view)
192     {
193         this.view = view;
194     }
195     
196     /***
197      * returns the icon for this step
198      * @return
199      */
200     public String getIcon()
201     {
202         return icon;
203     }
204     
205     /***
206      * Sets the Icon for this step
207      * @param icon
208      */
209     public void setIcon(String icon)
210     {
211         this.icon = icon;
212     }
213     
214     /***
215      * Returns the notes for this step
216      * @return
217      */
218     public String getNotes()
219     {
220         return notes;
221     }
222     
223     /***
224      * Sets the notes for this step
225      * @param notes
226      */
227     public void setNotes(String notes)
228     {
229         this.notes = notes;
230     }
231     
232     /***
233      * Displays information about this step definition
234      */
235     public String toString()
236     {
237     	StringBuffer string = new StringBuffer();
238     	string.append(GeneralConstants.LS);
239     	string.append(GeneralConstants.LS);
240     	string.append(GeneralConstants.LS);
241     	string.append(GeneralConstants.LS);
242     	
243     	return string.toString();
244     }
245 }
246 
247 class PreferenceDataItemComparator implements Comparator
248 {
249 	/***
250 	 * returns value appropriate depending on the sort order
251 	 */
252 	public int compare(Object arg0, Object arg1) {
253 		PreferenceDataItem item1 = (PreferenceDataItem) arg0;
254 		PreferenceDataItem item2 = (PreferenceDataItem) arg1;
255 		
256 		if (item1.getSortOrderNumber() > item1.getSortOrderNumber())
257 			return 1;
258 		else if (item1.getSortOrderNumber() < item1.getSortOrderNumber())
259 			return -1;
260 		else 
261 			return 0;
262 	}
263 }