View Javadoc

1   package com.sri.emo.wizard.creation;
2   
3   import java.io.*;
4   import java.util.*;
5   
6   import com.jcorporate.expresso.core.db.*;
7   import com.jcorporate.expresso.core.dbobj.*;
8   import com.sri.emo.wizard.*;
9   import com.sri.emo.wizard.creation.model.*;
10  import com.sri.emo.wizard.defaults.*;
11  import com.sri.emo.wizard.expressoimpl.*;
12  
13  
14  /***
15   * <p>Title: </p>
16   *
17   * <p>Description: </p>
18   *
19   * <p>Copyright: Copyright (c) 2003</p>
20   *
21   * <p>Company: </p>
22   *
23   * @author not attributable
24   * @version 1.0
25   */
26  public class SearchListPage extends EmoWizardPage {
27      /***
28       * The prefix of all ids that this class culls from the parameters.  They are
29       * of the form of WIZ_DATA_ID + "_" + SomeNumber
30       */
31      public static final String PARAM_PREFIX = WizardController.WIZ_DATA_ID;
32  
33      SearchResultBean searchBean;
34      String nodeType;
35      Serializable sourcePageId;
36  
37      public SearchListPage(Integer newId, PageMetadata pageMetadata, ValidValue[] optionalMenu) {
38          super(newId, pageMetadata, null);
39          SearchResultBean bean = new SearchResultBean();
40          bean.setPageId(newId);
41          searchBean = new SearchResultBean();
42      }
43  
44      public void setData(final Serializable newData) throws WizardException {
45          System.out.println("SearchListPage.setData(" + newData + ")");
46          if (newData == null) {
47              super.setData(newData);
48              return;
49          }
50          if (!(newData instanceof Map)) {
51              throw new IllegalArgumentException(
52                      "Internal Error: Incoming data was: " +
53                      newData.getClass().getName() +
54                      " and we needed a java.util.Map");
55          }
56          searchBean.clearSelectedSearchResults();
57  
58          HashSet prunedData = null;
59          if (newData == null) {
60              prunedData = new HashSet();
61          } else {
62              final Map givenData = (Map) newData;
63              final String searchPrefix = PARAM_PREFIX + "_";
64  
65              prunedData = new HashSet(givenData.size());
66              for (Iterator i = givenData.keySet().iterator(); i.hasNext(); ) {
67                  String oneKey = (String) i.next();
68                  if (oneKey.startsWith(searchPrefix)) {
69                      System.out.println("data = " + givenData.get(oneKey));
70                      prunedData.add(givenData.get(oneKey));
71                      try {
72                          searchBean.setSelectedNode(Integer.parseInt((String)
73                                  givenData.get(oneKey)));
74                      } catch (NumberFormatException ex) {
75                          throw new IllegalArgumentException("Invalid integer found within the search list");
76                      } catch (DBException ex) {
77                          ex.printStackTrace();
78                      }
79                  }
80              }
81  
82              MinMaxPageMetadata metadata = (MinMaxPageMetadata) getMetadata();
83  
84              if (metadata.getMaxEntries() != null
85                  && metadata.getMaxEntries().intValue() < prunedData.size()) {
86                  this.addError("Please only choose a maximum of: " +
87                                metadata.getMaxEntries().toString() + " choices");
88              }
89          }
90          super.setData(prunedData);
91      }
92  
93      public SearchResultBean getSearchBean() {
94          return searchBean;
95      }
96  
97      public String getNodeType() {
98          return nodeType;
99      }
100 
101     public Serializable getSourcePageId() {
102         return sourcePageId;
103     }
104 
105     public void setSearchBean(SearchResultBean searchBean) {
106         this.searchBean = searchBean;
107     }
108 
109     /***
110      * setNodeType
111      *
112      * @param string String
113      */
114     public void setNodeType(String nodeType) {
115         this.nodeType = nodeType;
116     }
117 
118     public void setSourcePageId(Serializable sourcePageId) {
119         this.sourcePageId = sourcePageId;
120     }
121 }