View Javadoc

1   package com.sri.emo.wizard.completion;
2   
3   import com.sri.emo.wizard.PageMetadata;
4   import com.sri.emo.wizard.WizardException;
5   import com.sri.emo.wizard.defaults.EmoWizardPage;
6   
7   import java.io.Serializable;
8   import java.util.ArrayList;
9   import java.util.List;
10  
11  
12  /***
13   * Page Entry Data for Multiple Attribute Entry Pages.
14   *
15   * @author Michael Rimov
16   */
17  public class MultiEntryWizardPage extends EmoWizardPage {
18  
19  
20      /***
21  	 * 
22  	 */
23  	private static final long serialVersionUID = 1L;
24  	private int numEntries = 0;
25  
26      /***
27       * Default constructor.
28       *
29       * @param newId        Integer
30       * @param pageMetadata PageMetadata
31       */
32      public MultiEntryWizardPage(Integer newId, PageMetadata pageMetadata) {
33          super(newId, pageMetadata, null);
34      }
35  
36      protected MultiEntryMetadata getMultiMetadata() {
37          return (MultiEntryMetadata) this.getMetadata();
38      }
39  
40      /***
41       * Sets the data associated with the page.
42       *
43       * @param newData the new data for the page.
44       * @throws WizardException upon error.
45       * @todo Implement this com.sri.emo.wizard.WizardPage method
46       */
47      public void setData(Serializable newData) throws WizardException {
48          if (newData == null) {
49              super.setData(null);
50              return;
51          }
52  
53          List listToSet;
54          if (newData instanceof String) {
55              listToSet = new ArrayList(1);
56              listToSet.add(newData);
57          } else if (newData instanceof List) {
58              listToSet = (List) newData;
59          } else {
60              this.addError("Received type: " + newData.getClass().getName() + " and do not know how to process it.");
61              return;
62          }
63  
64  //        if (listToSet.size() < getNumEntries()) {
65  //            this.addError("Please fill out values for all boxes");
66  //        }
67  //
68  //        int counter = 1;
69  //        for (Iterator i = listToSet.iterator(); i.hasNext(); ) {
70  //            String val = (String) i.next();
71  //            if (val == null || val.trim().length() == 0) {
72  //                this.addError("Please enter a value for box number: " + counter);
73  //            }
74  //
75  //            counter++;
76  //        }
77  
78          super.setData((Serializable) listToSet);
79  
80      }
81  
82      public void setNumEntries(int newValue) {
83          numEntries = newValue;
84      }
85  
86      public int getNumEntries() {
87  
88          //
89          //Special case.  If numEntries is not set.
90          //
91          if (numEntries == 0) {
92  
93              //And min == max
94              Integer min = getMultiMetadata().getMinEntries();
95              Integer max = getMultiMetadata().getMaxEntries();
96  
97              if (min != null && max != null && min.intValue() == max.intValue()) {
98                  //Then return min/max value instead.
99                  return min.intValue();
100             }
101         }
102 
103         return numEntries;
104     }
105 
106 
107 }