1 17 package org.alfresco.web.bean.wizard; 18 19 import java.io.Serializable ; 20 import java.text.MessageFormat ; 21 import java.util.Map ; 22 23 import javax.faces.context.FacesContext; 24 import javax.transaction.UserTransaction ; 25 26 import org.alfresco.service.cmr.action.Action; 27 import org.alfresco.web.app.Application; 28 import org.alfresco.web.bean.repository.Repository; 29 import org.alfresco.web.ui.common.Utils; 30 import org.apache.commons.logging.Log; 31 import org.apache.commons.logging.LogFactory; 32 33 38 public class NewActionWizard extends BaseActionWizard 39 { 40 private static Log logger = LogFactory.getLog(NewActionWizard.class); 41 42 private static final String ERROR = "error_action"; 43 44 private static final String WIZARD_TITLE_ID = "create_action_title"; 46 private static final String WIZARD_DESC_ID = "create_action_desc"; 47 private static final String STEP1_TITLE_ID = "create_action_step1_title"; 48 private static final String STEP2_TITLE_ID = "create_action_step2_title"; 49 private static final String FINISH_INSTRUCTION_ID = "create_action_finish_instruction"; 50 51 56 public String finish() 57 { 58 String outcome = FINISH_OUTCOME; 59 60 UserTransaction tx = null; 61 62 try 63 { 64 tx = Repository.getUserTransaction(FacesContext.getCurrentInstance()); 65 tx.begin(); 66 67 Map <String , Serializable > actionParams = buildActionParams(); 69 70 Action action = this.actionService.createAction(getAction()); 72 action.setParameterValues(actionParams); 73 74 this.actionService.executeAction(action, this.browseBean.getDocument().getNodeRef()); 76 77 if (logger.isDebugEnabled()) 78 { 79 logger.debug("Executed action '" + this.action + 80 "' with action params of " + 81 this.currentActionProperties); 82 } 83 84 this.browseBean.getDocument().reset(); 87 88 tx.commit(); 90 } 91 catch (Throwable e) 92 { 93 try { if (tx != null) {tx.rollback();} } catch (Exception ex) {} 95 Utils.addErrorMessage(MessageFormat.format(Application.getMessage( 96 FacesContext.getCurrentInstance(), ERROR), e.getMessage()), e); 97 outcome = null; 98 } 99 100 return outcome; 101 } 102 103 106 public String getWizardDescription() 107 { 108 return Application.getMessage(FacesContext.getCurrentInstance(), WIZARD_DESC_ID); 109 } 110 111 114 public String getWizardTitle() 115 { 116 return Application.getMessage(FacesContext.getCurrentInstance(), WIZARD_TITLE_ID); 117 } 118 119 122 public String getStepDescription() 123 { 124 return ""; 125 } 126 127 130 public String getStepTitle() 131 { 132 String stepTitle = null; 133 134 switch (this.currentStep) 135 { 136 case 1: 137 { 138 stepTitle = Application.getMessage(FacesContext.getCurrentInstance(), STEP1_TITLE_ID); 139 break; 140 } 141 case 2: 142 { 143 stepTitle = Application.getMessage(FacesContext.getCurrentInstance(), STEP2_TITLE_ID); 144 break; 145 } 146 case 3: 147 { 148 stepTitle = Application.getMessage(FacesContext.getCurrentInstance(), SUMMARY_TITLE_ID); 149 break; 150 } 151 default: 152 { 153 stepTitle = ""; 154 } 155 } 156 157 return stepTitle; 158 } 159 160 163 public String getStepInstructions() 164 { 165 String stepInstruction = null; 166 167 switch (this.currentStep) 168 { 169 case 3: 170 { 171 stepInstruction = Application.getMessage(FacesContext.getCurrentInstance(), FINISH_INSTRUCTION_ID); 172 break; 173 } 174 default: 175 { 176 stepInstruction = Application.getMessage(FacesContext.getCurrentInstance(), DEFAULT_INSTRUCTION_ID); 177 } 178 } 179 180 return stepInstruction; 181 } 182 183 186 public void init() 187 { 188 super.init(); 189 } 190 191 194 public String getSummary() 195 { 196 String summaryAction = this.actionService.getActionDefinition( 197 this.action).getTitle(); 198 199 return buildSummary( 200 new String [] {"Action"}, 201 new String [] {summaryAction}); 202 } 203 204 207 protected String determineOutcomeForStep(int step) 208 { 209 String outcome = null; 210 211 switch(step) 212 { 213 case 1: 214 { 215 outcome = "action"; 216 break; 217 } 218 case 2: 219 { 220 outcome = this.action; 221 break; 222 } 223 case 3: 224 { 225 outcome = "summary"; 226 break; 227 } 228 default: 229 { 230 outcome = CANCEL_OUTCOME; 231 } 232 } 233 234 return outcome; 235 } 236 } 237 | Popular Tags |