KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > web > bean > wizard > NewActionWizard


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.web.bean.wizard;
18
19 import java.io.Serializable JavaDoc;
20 import java.text.MessageFormat JavaDoc;
21 import java.util.Map JavaDoc;
22
23 import javax.faces.context.FacesContext;
24 import javax.transaction.UserTransaction JavaDoc;
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 /**
34  * Handler class used by the New Action Wizard
35  *
36  * @author Kevin Roast
37  */

38 public class NewActionWizard extends BaseActionWizard
39 {
40    private static Log logger = LogFactory.getLog(NewActionWizard.class);
41    
42    private static final String JavaDoc ERROR = "error_action";
43    
44    // TODO: retrieve these from the config service
45
private static final String JavaDoc WIZARD_TITLE_ID = "create_action_title";
46    private static final String JavaDoc WIZARD_DESC_ID = "create_action_desc";
47    private static final String JavaDoc STEP1_TITLE_ID = "create_action_step1_title";
48    private static final String JavaDoc STEP2_TITLE_ID = "create_action_step2_title";
49    private static final String JavaDoc FINISH_INSTRUCTION_ID = "create_action_finish_instruction";
50    
51    /**
52     * Deals with the finish button being pressed
53     *
54     * @return outcome
55     */

56    public String JavaDoc finish()
57    {
58       String JavaDoc outcome = FINISH_OUTCOME;
59       
60       UserTransaction JavaDoc tx = null;
61       
62       try
63       {
64          tx = Repository.getUserTransaction(FacesContext.getCurrentInstance());
65          tx.begin();
66          
67          // build the action params map based on the selected action instance
68
Map JavaDoc<String JavaDoc, Serializable JavaDoc> actionParams = buildActionParams();
69          
70          // build the action to execute
71
Action action = this.actionService.createAction(getAction());
72          action.setParameterValues(actionParams);
73          
74          // execute the action on the current document node
75
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          // reset the current document properties/aspects in case we have changed them
85
// during the execution of the custom action
86
this.browseBean.getDocument().reset();
87          
88          // commit the transaction
89
tx.commit();
90       }
91       catch (Throwable JavaDoc e)
92       {
93          // rollback the transaction
94
try { if (tx != null) {tx.rollback();} } catch (Exception JavaDoc 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    /**
104     * @see org.alfresco.web.bean.wizard.AbstractWizardBean#getWizardDescription()
105     */

106    public String JavaDoc getWizardDescription()
107    {
108       return Application.getMessage(FacesContext.getCurrentInstance(), WIZARD_DESC_ID);
109    }
110
111    /**
112     * @see org.alfresco.web.bean.wizard.AbstractWizardBean#getWizardTitle()
113     */

114    public String JavaDoc getWizardTitle()
115    {
116       return Application.getMessage(FacesContext.getCurrentInstance(), WIZARD_TITLE_ID);
117    }
118    
119    /**
120     * @see org.alfresco.web.bean.wizard.AbstractWizardBean#getStepDescription()
121     */

122    public String JavaDoc getStepDescription()
123    {
124       return "";
125    }
126
127    /**
128     * @see org.alfresco.web.bean.wizard.AbstractWizardBean#getStepTitle()
129     */

130    public String JavaDoc getStepTitle()
131    {
132       String JavaDoc 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    /**
161     * @see org.alfresco.web.bean.wizard.AbstractWizardBean#getStepInstructions()
162     */

163    public String JavaDoc getStepInstructions()
164    {
165       String JavaDoc 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    /**
184     * Initialises the wizard
185     */

186    public void init()
187    {
188       super.init();
189    }
190
191    /**
192     * @return Returns the summary data for the wizard.
193     */

194    public String JavaDoc getSummary()
195    {
196       String JavaDoc summaryAction = this.actionService.getActionDefinition(
197             this.action).getTitle();
198       
199       return buildSummary(
200             new String JavaDoc[] {"Action"},
201             new String JavaDoc[] {summaryAction});
202    }
203    
204    /**
205     * @see org.alfresco.web.bean.wizard.AbstractWizardBean#determineOutcomeForStep(int)
206     */

207    protected String JavaDoc determineOutcomeForStep(int step)
208    {
209       String JavaDoc 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