View Javadoc

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