1 17 package org.alfresco.web.bean.wizard; 18 19 import javax.faces.context.FacesContext; 20 import javax.faces.event.ActionEvent; 21 22 import org.alfresco.service.cmr.model.FileFolderService; 23 import org.alfresco.service.cmr.repository.NodeService; 24 import org.alfresco.service.cmr.search.SearchService; 25 import org.alfresco.web.app.Application; 26 import org.alfresco.web.app.context.UIContextService; 27 import org.alfresco.web.bean.BrowseBean; 28 import org.alfresco.web.bean.NavigationBean; 29 import org.apache.commons.logging.Log; 30 import org.apache.commons.logging.LogFactory; 31 32 37 public abstract class AbstractWizardBean 38 { 39 private static Log logger = LogFactory.getLog(AbstractWizardBean.class); 40 41 42 private static final String MSG_NOT_SET = "value_not_set"; 43 44 protected static final String FINISH_OUTCOME = "finish"; 45 protected static final String CANCEL_OUTCOME = "cancel"; 46 protected static final String DEFAULT_INSTRUCTION_ID = "default_instruction"; 47 protected static final String SUMMARY_TITLE_ID = "summary"; 48 protected static final String SUMMARY_DESCRIPTION_ID = "summary_desc"; 49 50 protected int currentStep = 1; 52 protected boolean editMode = false; 53 protected NodeService nodeService; 54 protected FileFolderService fileFolderService; 55 protected SearchService searchService; 56 protected NavigationBean navigator; 57 protected BrowseBean browseBean; 58 59 62 public abstract String getWizardDescription(); 63 64 67 public abstract String getWizardTitle(); 68 69 72 public abstract String getStepTitle(); 73 74 77 public abstract String getStepDescription(); 78 79 82 public abstract String getStepInstructions(); 83 84 90 protected abstract String determineOutcomeForStep(int step); 91 92 97 public abstract String finish(); 98 99 103 public void startWizard(ActionEvent event) 104 { 105 UIContextService.getInstance(FacesContext.getCurrentInstance()).notifyBeans(); 108 109 this.editMode = false; 111 112 init(); 115 116 if (logger.isDebugEnabled()) 117 logger.debug("Started wizard : " + getWizardTitle()); 118 } 119 120 124 public void startWizardForEdit(ActionEvent event) 125 { 126 UIContextService.getInstance(FacesContext.getCurrentInstance()).notifyBeans(); 129 130 this.editMode = true; 132 133 init(); 136 populate(); 137 138 if (logger.isDebugEnabled()) 139 logger.debug("Started wizard : " + getWizardTitle() + " for editing"); 140 } 141 142 147 public boolean isInEditMode() 148 { 149 return this.editMode; 150 } 151 152 157 public String next() 158 { 159 this.currentStep++; 160 161 String outcome = determineOutcomeForStep(this.currentStep); 163 164 if (logger.isDebugEnabled()) 165 { 166 logger.debug("current step is now: " + this.currentStep); 167 logger.debug("Next outcome: " + outcome); 168 } 169 170 return outcome; 172 } 173 174 179 public String back() 180 { 181 this.currentStep--; 182 183 String outcome = determineOutcomeForStep(this.currentStep); 185 186 if (logger.isDebugEnabled()) 187 { 188 logger.debug("current step is now: " + this.currentStep); 189 logger.debug("Back outcome: " + outcome); 190 } 191 192 return outcome; 194 } 195 196 201 public String cancel() 202 { 203 init(); 205 206 return CANCEL_OUTCOME; 207 } 208 209 212 public void init() 213 { 214 this.currentStep = 1; 215 } 216 217 221 public void populate() 222 { 223 } 225 226 229 public NodeService getNodeService() 230 { 231 return this.nodeService; 232 } 233 234 237 public void setNodeService(NodeService nodeService) 238 { 239 this.nodeService = nodeService; 240 } 241 242 245 public void setFileFolderService(FileFolderService fileFolderService) 246 { 247 this.fileFolderService = fileFolderService; 248 } 249 250 253 public void setSearchService(SearchService searchService) 254 { 255 this.searchService = searchService; 256 } 257 258 261 public NavigationBean getNavigator() 262 { 263 return navigator; 264 } 265 266 269 public void setNavigator(NavigationBean navigator) 270 { 271 this.navigator = navigator; 272 } 273 274 277 public BrowseBean getBrowseBean() 278 { 279 return this.browseBean; 280 } 281 282 285 public void setBrowseBean(BrowseBean browseBean) 286 { 287 this.browseBean = browseBean; 288 } 289 290 298 protected String buildSummary(String [] labels, String [] values) 299 { 300 if (labels == null || values == null || labels.length != values.length) 301 { 302 throw new IllegalArgumentException ("Labels and Values passed to summary must be valid and of equal length."); 303 } 304 305 String msg = Application.getMessage(FacesContext.getCurrentInstance(), MSG_NOT_SET); 306 String notSetMsg = "<" + msg + ">"; 307 308 StringBuilder buf = new StringBuilder (256); 309 310 buf.append("<table cellspacing='4' cellpadding='2' border='0' class='summary'>"); 311 for (int i=0; i<labels.length; i++) 312 { 313 String value = values[i]; 314 buf.append("<tr><td valign='top'><b>"); 315 buf.append(labels[i]); 316 buf.append(":</b></td><td>"); 317 buf.append(value != null ? value : notSetMsg); 318 buf.append("</td></tr>"); 319 } 320 buf.append("</table>"); 321 322 return buf.toString(); 323 } 324 } 325 | Popular Tags |