Coverage Report - org.kuali.student.core.workflow.ui.client.widgets.WorkflowUtilities
 
Classes in this File Line Coverage Branch Coverage Complexity
WorkflowUtilities
0%
0/183
0%
0/76
1.975
WorkflowUtilities$1
0%
0/6
N/A
1.975
WorkflowUtilities$10
0%
0/20
N/A
1.975
WorkflowUtilities$10$1
0%
0/8
0%
0/4
1.975
WorkflowUtilities$10$1$1
0%
0/12
0%
0/4
1.975
WorkflowUtilities$11
0%
0/8
0%
0/2
1.975
WorkflowUtilities$12
0%
0/24
N/A
1.975
WorkflowUtilities$12$1
0%
0/14
0%
0/10
1.975
WorkflowUtilities$12$1$1
0%
0/12
0%
0/4
1.975
WorkflowUtilities$13
0%
0/5
N/A
1.975
WorkflowUtilities$14
0%
0/3
N/A
1.975
WorkflowUtilities$14$1
0%
0/6
0%
0/2
1.975
WorkflowUtilities$15
0%
0/4
N/A
1.975
WorkflowUtilities$15$1
0%
0/10
0%
0/4
1.975
WorkflowUtilities$2
0%
0/4
N/A
1.975
WorkflowUtilities$2$1
0%
0/13
0%
0/4
1.975
WorkflowUtilities$3
0%
0/4
N/A
1.975
WorkflowUtilities$4
0%
0/5
N/A
1.975
WorkflowUtilities$5
0%
0/4
N/A
1.975
WorkflowUtilities$5$1
0%
0/10
0%
0/4
1.975
WorkflowUtilities$6
0%
0/16
N/A
1.975
WorkflowUtilities$6$1
0%
0/6
0%
0/2
1.975
WorkflowUtilities$6$1$1
0%
0/12
0%
0/4
1.975
WorkflowUtilities$7
0%
0/20
N/A
1.975
WorkflowUtilities$7$1
0%
0/8
0%
0/4
1.975
WorkflowUtilities$7$1$1
0%
0/12
0%
0/4
1.975
WorkflowUtilities$8
0%
0/20
N/A
1.975
WorkflowUtilities$8$1
0%
0/8
0%
0/4
1.975
WorkflowUtilities$8$1$1
0%
0/12
0%
0/4
1.975
WorkflowUtilities$9
0%
0/20
N/A
1.975
WorkflowUtilities$9$1
0%
0/8
0%
0/4
1.975
WorkflowUtilities$9$1$1
0%
0/12
0%
0/4
1.975
WorkflowUtilities$DecisionRationaleDetail
0%
0/21
0%
0/4
1.975
 
 1  
 /**
 2  
  * Copyright 2010 The Kuali Foundation Licensed under the
 3  
  * Educational Community License, Version 2.0 (the "License"); you may
 4  
  * not use this file except in compliance with the License. You may
 5  
  * obtain a copy of the License at
 6  
  * 
 7  
  * http://www.osedu.org/licenses/ECL-2.0
 8  
  *
 9  
  * Unless required by applicable law or agreed to in writing,
 10  
  * software distributed under the License is distributed on an "AS IS"
 11  
  * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 12  
  * or implied. See the License for the specific language governing
 13  
  * permissions and limitations under the License.
 14  
  */
 15  
 package org.kuali.student.core.workflow.ui.client.widgets;
 16  
 
 17  
 import java.util.ArrayList;
 18  
 import java.util.List;
 19  
 
 20  
 import org.kuali.student.common.ui.client.application.Application;
 21  
 import org.kuali.student.common.ui.client.application.KSAsyncCallback;
 22  
 import org.kuali.student.common.ui.client.configurable.mvc.LayoutController;
 23  
 import org.kuali.student.common.ui.client.configurable.mvc.SectionTitle;
 24  
 import org.kuali.student.common.ui.client.event.SaveActionEvent;
 25  
 import org.kuali.student.common.ui.client.mvc.Callback;
 26  
 import org.kuali.student.common.ui.client.mvc.DataModel;
 27  
 import org.kuali.student.common.ui.client.mvc.ModelChangeEvent;
 28  
 import org.kuali.student.common.ui.client.mvc.ModelChangeHandler;
 29  
 import org.kuali.student.common.ui.client.mvc.ModelRequestCallback;
 30  
 import org.kuali.student.common.ui.client.mvc.ModelChangeEvent.Action;
 31  
 import org.kuali.student.common.ui.client.service.CommentRpcService;
 32  
 import org.kuali.student.common.ui.client.service.CommentRpcServiceAsync;
 33  
 import org.kuali.student.common.ui.client.widgets.KSDropDown;
 34  
 import org.kuali.student.common.ui.client.widgets.KSLabel;
 35  
 import org.kuali.student.common.ui.client.widgets.KSLightBox;
 36  
 import org.kuali.student.common.ui.client.widgets.KSRichEditor;
 37  
 import org.kuali.student.common.ui.client.widgets.StylishDropDown;
 38  
 import org.kuali.student.common.ui.client.widgets.buttongroups.AcknowledgeCancelGroup;
 39  
 import org.kuali.student.common.ui.client.widgets.buttongroups.ConfirmApprovalCancelGroup;
 40  
 import org.kuali.student.common.ui.client.widgets.buttongroups.ConfirmCancelGroup;
 41  
 import org.kuali.student.common.ui.client.widgets.buttongroups.RejectCancelGroup;
 42  
 import org.kuali.student.common.ui.client.widgets.buttongroups.ButtonEnumerations.AcknowledgeCancelEnum;
 43  
 import org.kuali.student.common.ui.client.widgets.buttongroups.ButtonEnumerations.ConfirmApprovalCancelEnum;
 44  
 import org.kuali.student.common.ui.client.widgets.buttongroups.ButtonEnumerations.ConfirmCancelEnum;
 45  
 import org.kuali.student.common.ui.client.widgets.buttongroups.ButtonEnumerations.RejectCancelEnum;
 46  
 import org.kuali.student.common.ui.client.widgets.dialog.ConfirmationDialog;
 47  
 import org.kuali.student.common.ui.client.widgets.field.layout.element.AbbrPanel;
 48  
 import org.kuali.student.common.ui.client.widgets.list.impl.SimpleListItems;
 49  
 import org.kuali.student.common.ui.client.widgets.menus.KSMenuItemData;
 50  
 import org.kuali.student.common.ui.client.widgets.notification.KSNotification;
 51  
 import org.kuali.student.common.ui.client.widgets.notification.KSNotifier;
 52  
 import org.kuali.student.core.assembly.data.QueryPath;
 53  
 import org.kuali.student.core.comment.dto.CommentInfo;
 54  
 import org.kuali.student.core.dto.RichTextInfo;
 55  
 import org.kuali.student.core.dto.DtoConstants.DtoState;
 56  
 import org.kuali.student.core.validation.dto.ValidationResultInfo;
 57  
 import org.kuali.student.core.workflow.ui.client.WorkflowConstants;
 58  
 import org.kuali.student.core.workflow.ui.client.service.WorkflowRpcService;
 59  
 import org.kuali.student.core.workflow.ui.client.service.WorkflowRpcServiceAsync;
 60  
 
 61  
 import com.google.gwt.core.client.GWT;
 62  
 import com.google.gwt.event.dom.client.ClickEvent;
 63  
 import com.google.gwt.event.dom.client.ClickHandler;
 64  
 import com.google.gwt.user.client.Window;
 65  
 import com.google.gwt.user.client.rpc.AsyncCallback;
 66  
 import com.google.gwt.user.client.ui.VerticalPanel;
 67  
 import com.google.gwt.user.client.ui.Widget;
 68  
 
 69  0
 public class WorkflowUtilities{
 70  
 
 71  
         //TODO: This should come from the ReferenceModel like it does in CommentTool
 72  
     public static final String PROPOSAL_REF_TYPE_KEY = "referenceType.clu.proposal";
 73  
     
 74  0
         public static enum DecisionRationaleDetail {
 75  0
         APPROVE("kuali.comment.type.workflowDecisionRationale.approve", "Approved"),
 76  0
         REJECT("kuali.comment.type.workflowDecisionRationale.reject", "Rejected"),
 77  0
         RETURN_TO_PREVIOUS("kuali.comment.type.workflowDecisionRationale.return", "Sent for Revisions"),
 78  0
         WITHDRAW("kuali.comment.type.workflowDecisionRationale.withdraw", "Withdrawn"),
 79  0
         ACKNOWLEDGE("kuali.comment.type.workflowDecisionRationale.acknowledge", "Acknowledged"),
 80  0
         FYI("kuali.comment.type.workflowDecisionRationale.fyi", "FYI"),
 81  0
         CANCEL_WORKFLOW("kuali.comment.type.workflowDecisionRationale.cancelWorkflow", "Cancelled"),
 82  0
         BLANKET_APPROVE("kuali.comment.type.workflowDecisionRationale.blanketApprove", "Blanket Approved")
 83  
         ;
 84  
 
 85  0
         private String type = "";
 86  0
         private String label = "";
 87  
 
 88  0
         private DecisionRationaleDetail(String type, String label) {
 89  0
             this.type = type;
 90  0
             this.label = label;
 91  0
         }
 92  
 
 93  
         public String getType() {
 94  0
             return type;
 95  
         }
 96  
 
 97  
         public String getLabel() {
 98  0
             return label;
 99  
         }
 100  
 
 101  
         public static DecisionRationaleDetail getByType(String type) {
 102  0
             for (DecisionRationaleDetail detail : DecisionRationaleDetail.values()) {
 103  0
                 if (detail.getType().equals(type)) {
 104  0
                     return detail;
 105  
                 }
 106  
             }
 107  0
             return null;
 108  
         }
 109  
 
 110  
     }
 111  
 
 112  0
         DataModel dataModel=null;
 113  
         
 114  0
         boolean loaded=false;
 115  
     
 116  0
         private boolean workflowWidgetsEnabled = true;
 117  
         
 118  
         private KSMenuItemData wfApproveItem;
 119  
         private KSMenuItemData wfDisApproveItem;
 120  
         private KSMenuItemData wfAcknowledgeItem;
 121  
         private KSMenuItemData wfStartWorkflowItem;
 122  
     private KSMenuItemData wfCancelWorkflowItem;
 123  
         private KSMenuItemData wfFYIWorkflowItem;
 124  
         private KSMenuItemData wfWithdrawItem;
 125  
     private KSMenuItemData wfReturnToPreviousItem;
 126  
     private KSMenuItemData wfBlanketApproveItem;
 127  
         
 128  0
         private List<KSMenuItemData> items = new ArrayList<KSMenuItemData>();
 129  
             
 130  
     SaveActionEvent approveSaveActionEvent;
 131  
     SaveActionEvent startWorkflowSaveActionEvent;
 132  
     
 133  0
     WorkflowRpcServiceAsync workflowRpcServiceAsync = GWT.create(WorkflowRpcService.class);
 134  0
     private CommentRpcServiceAsync commentServiceAsync = GWT.create(CommentRpcService.class);
 135  
     
 136  
     private String modelName;
 137  
     private String proposalPath;
 138  0
     private String proposalId = "";
 139  0
     private String workflowId = "";
 140  0
     private String proposalName="";
 141  0
     private String workflowActions="";
 142  0
     private String proposalVersion="";
 143  
         
 144  0
         private List<StylishDropDown> workflowWidgets = new ArrayList<StylishDropDown>();
 145  
         private Callback<Boolean> submitCallback;
 146  0
         private ConfirmationDialog dialog = new ConfirmationDialog("Submit Proposal", "Are you sure you want to submit the proposal to workflow?", "Submit");
 147  
         private AbbrPanel required; 
 148  
         private KSLightBox submitSuccessDialog;
 149  
         private VerticalPanel dialogPanel;
 150  
     
 151  0
     private KSLabel workflowStatusLabel = new KSLabel("");
 152  
     
 153  
     private LayoutController parentController;
 154  
         
 155  0
         public WorkflowUtilities(LayoutController parentController, String proposalPath) {
 156  0
                 this.parentController = parentController;
 157  0
                 this.proposalPath = proposalPath;
 158  0
                 setupWFButtons();
 159  0
                 setupDialog();
 160  0
         }
 161  
         
 162  
         public void requestAndSetupModel() {
 163  
                 
 164  0
                 if(null==dataModel){
 165  
                         //Get the Model from the controller
 166  0
                         parentController.requestModel(modelName, new ModelRequestCallback<DataModel>() {
 167  
                         
 168  
                                 @Override
 169  
                                 public void onRequestFail(Throwable cause) {
 170  0
                                         Window.alert("Model Request Failed. "+cause.getMessage());
 171  0
                                 }
 172  
 
 173  
                                 @Override
 174  
                                 public void onModelReady(DataModel model) {
 175  
                                         //After we get the model update immediately
 176  0
                                         dataModel = model;
 177  0
                                         updateWorkflow(dataModel, false);
 178  0
                                 }
 179  
                         });                        
 180  
                 }else{
 181  
                         //If the model has been set don't waste time finding it again and don't register 
 182  
                         //another change listener, just update
 183  0
                         updateWorkflow(dataModel, false);
 184  
                 }
 185  0
         }
 186  
         
 187  
         private void setupWFButtons() {
 188  0
                 wfApproveItem = getApproveItem();
 189  0
                 wfDisApproveItem = getDisApproveItem();
 190  0
                 wfAcknowledgeItem = getAcknowledgeItem();
 191  0
                 wfStartWorkflowItem = getStartItem();
 192  0
                 wfCancelWorkflowItem = getCancelWorkflowItem();
 193  0
                 wfFYIWorkflowItem = getFYIWorkflowItem();
 194  0
                 wfWithdrawItem = getWithdrawItem();
 195  0
                 wfReturnToPreviousItem = getReturnToPreviousItem();
 196  0
                 wfBlanketApproveItem = getBlanketApproveItem();
 197  0
         }
 198  
         
 199  
         private void setupSubmitSuccessDialog(){
 200  0
                 if(submitSuccessDialog==null){
 201  0
                         submitSuccessDialog= new KSLightBox();
 202  0
                         submitSuccessDialog.setSize(580, 400);
 203  0
                         dialogPanel = new VerticalPanel();
 204  0
                         submitSuccessDialog.setWidget(dialogPanel);
 205  
                         
 206  
                 }
 207  
 
 208  0
         }
 209  
         
 210  
         private void setupDialog(){
 211  
 
 212  0
                 dialog.getConfirmButton().addClickHandler(new ClickHandler(){
 213  
 
 214  
                         @Override
 215  
                         public void onClick(ClickEvent event) {
 216  0
                                 dialog.getConfirmButton().setEnabled(false);
 217  0
                                 workflowRpcServiceAsync.submitDocumentWithId(workflowId, new KSAsyncCallback<Boolean>(){
 218  
                                         public void handleFailure(Throwable caught) {
 219  0
                                                 Window.alert("Error starting Proposal workflow");
 220  0
                                                 dialog.getConfirmButton().setEnabled(true);
 221  0
                                         }
 222  
                                         public void onSuccess(Boolean result) {
 223  0
                                                 if (result){
 224  0
                                                         updateWorkflow(dataModel, false);                                                
 225  0
                                                         dialog.hide();
 226  0
                                                         dialog.getConfirmButton().setEnabled(true);
 227  0
                                                         if(submitCallback != null){
 228  0
                                                                 submitCallback.exec(true);
 229  
                                                         }
 230  
                                                         //Notify the user that the document was submitted
 231  0
                                                         KSNotifier.add(new KSNotification("Proposal has been routed to workflow", false));
 232  
                                                 } else {
 233  0
                                                         Window.alert("Error starting Proposal workflow");
 234  
                                                 }
 235  0
                                         }
 236  
                                 });
 237  
                                 
 238  0
                         }
 239  
                 });
 240  0
         }
 241  
         
 242  
         public Widget getWorkflowActionsWidget(){
 243  
                 //InfoMessage infoContainer = new InfoMessage();
 244  0
                 StylishDropDown workflowActionsDropDown = new StylishDropDown("Workflow Actions");
 245  0
                 workflowActionsDropDown.makeAButtonWhenOneItem(true);
 246  0
                 workflowActionsDropDown.addStyleName("KS-Workflow-DropDown");
 247  0
                 workflowWidgets.add(workflowActionsDropDown);
 248  0
                 workflowActionsDropDown.setVisible(false);
 249  0
                 refresh();
 250  
 /*                infoContainer.add(workflowActionsDropDown);
 251  
                 infoContainer.showWarnStyling(false);
 252  
                 infoContainer.setVisible(true);*/
 253  
                 //workflowActionsDropDown
 254  0
                 return workflowActionsDropDown;
 255  
         }
 256  
         
 257  
         public void enableWorkflowActionsWidgets(boolean enable){
 258  0
                 workflowWidgetsEnabled = enable;
 259  0
                 updateWorkflowActionsWidget();
 260  0
         }
 261  
         
 262  
         public void doValidationCheck(Callback<List<ValidationResultInfo>> callback){
 263  0
                 dataModel.validateNextState(callback);
 264  0
         }
 265  
         
 266  
         public KSLabel getWorkflowStatusLabel(){
 267  0
                 return workflowStatusLabel;
 268  
         }
 269  
         
 270  
         /*
 271  
          * This updates the workflowId, proposalName, and proposalId when workflowId has changed and returns true if it has.
 272  
          */
 273  
         private boolean updateWorkflowIdFromModel(final DataModel model){
 274  0
                 if(model!=null){
 275  0
                         String modelWorkflowId = model.get(QueryPath.parse(proposalPath + "/workflowId")); 
 276  
                         
 277  
                         //If proposalId in model has been set or changed, get new workflowId and update workfow widget
 278  0
                         if (modelWorkflowId != null && !modelWorkflowId.isEmpty() && !modelWorkflowId.equals(workflowId)){
 279  0
                                 workflowId = modelWorkflowId; 
 280  0
                                 proposalId = model.get(QueryPath.parse(proposalPath + "/id"));
 281  0
                                 proposalName = model.get(QueryPath.parse(proposalPath + "/name"));
 282  0
                                 proposalVersion = model.get(QueryPath.parse(proposalPath + "/metaInfo/versionInd"));
 283  0
                                 return true;
 284  
                         }
 285  
                 }
 286  
                 
 287  0
                 return false;
 288  
         }
 289  
         
 290  
         /*
 291  
          * This updates the proposal version number when it has changed and returns true if it has.
 292  
          */
 293  
         private boolean updateProposalVersionNumber(final DataModel model){
 294  0
                 if(model!=null){
 295  0
                         String modelProposalVersion = model.get(QueryPath.parse(proposalPath + "/metaInfo/versionInd"));
 296  0
                         if (modelProposalVersion != null && !modelProposalVersion.isEmpty() && !modelProposalVersion.equals(proposalVersion)){
 297  0
                                 proposalVersion = modelProposalVersion;
 298  0
                                 return true;
 299  
                         }
 300  
                 }
 301  
                 
 302  0
                 return false;
 303  
         }
 304  
         
 305  
         /*
 306  
          * This method makes workflow service calls to update workflow document status and and items
 307  
          * to display in workflow drop down. NOTE: This method should be called only when needed to reduce
 308  
          * number of KEW service calls needed. 
 309  
          */
 310  
         private void updateWorkflow(DataModel model, boolean workflowActionTaken){
 311  
                 //Only update doc status and action drop down if new proposal loaded
 312  0
                 if (updateWorkflowIdFromModel(model) || updateProposalVersionNumber(model) || workflowActionTaken){                        
 313  
                         //Determine which workflow actions are displayed in the drop down
 314  0
                         workflowRpcServiceAsync.getActionsRequested(workflowId, new KSAsyncCallback<String>(){
 315  
                 
 316  
                                 public void onSuccess(String result) {
 317  0
                                         workflowActions = result;
 318  0
                                         updateWorkflowActionsWidget();
 319  0
                                 }
 320  
                         });
 321  
                 
 322  0
                         workflowRpcServiceAsync.getDocumentStatus(workflowId, new KSAsyncCallback<String>(){
 323  
                                 @Override
 324  
                                 public void handleFailure(Throwable caught) {
 325  0
                                         workflowStatusLabel.setText("Status: Unknown");
 326  0
                                 }
 327  
 
 328  
                                 @Override
 329  
                                 public void onSuccess(String result) {
 330  0
                                         setWorkflowStatus(result);
 331  0
                                 }                                                
 332  
                         });
 333  0
                 } else if (workflowId == null || workflowId.isEmpty()){
 334  0
                         workflowStatusLabel.setText("Status: Draft");                        
 335  
                 }
 336  0
         }
 337  
         
 338  
         private void updateWorkflowActionsWidget(){
 339  0
                 items.clear();
 340  
 
 341  
                 //Display all workflow actions if workflowWidgetsEnabled, otherwise just display
 342  
                 //the cancel option.
 343  0
                 if (workflowWidgetsEnabled){
 344  0
                         if(workflowActions.contains("S")){
 345  0
                                 items.add(wfStartWorkflowItem);
 346  
                         }
 347  0
             if(workflowActions.contains("C")){
 348  0
                 items.add(wfCancelWorkflowItem);
 349  
             }
 350  0
                         if(workflowActions.contains("A")){
 351  0
                                 items.add(wfApproveItem);
 352  0
                                 items.add(wfDisApproveItem);
 353  
                         }
 354  0
                         if(workflowActions.contains("K")){
 355  0
                                 items.add(wfAcknowledgeItem);
 356  
                         }
 357  0
                         if(workflowActions.contains("F")){
 358  0
                                 items.add(wfFYIWorkflowItem);
 359  
                         }
 360  0
             if(workflowActions.contains("R")){
 361  0
                 items.add(wfReturnToPreviousItem);
 362  
             }
 363  0
             if(workflowActions.contains("B")){
 364  0
                 items.add(wfBlanketApproveItem);
 365  
             }
 366  0
             if(workflowActions.contains("W")){
 367  0
                 items.add(wfWithdrawItem);
 368  
             }
 369  
                 } else {
 370  0
             if(workflowActions.contains("C")){
 371  0
                 items.add(wfCancelWorkflowItem);
 372  
             }
 373  0
             if(workflowActions.contains("W")){
 374  0
                 items.add(wfWithdrawItem);
 375  
             }
 376  
                 }
 377  0
                 for(StylishDropDown widget: workflowWidgets){
 378  
                         
 379  0
                         widget.setItems(items);
 380  0
                         widget.setEnabled(true);
 381  0
                         if(items.isEmpty()){
 382  0
                                 widget.setVisible(false);
 383  
                         }
 384  
                         else{
 385  0
                                 widget.setVisible(true);
 386  
                         }
 387  
                 }                
 388  0
         }
 389  
         
 390  
         private KSMenuItemData getFYIWorkflowItem() {
 391  
                 KSMenuItemData wfFYIWorkflowItem;
 392  0
                 final KSRichEditor rationaleEditor = new KSRichEditor();
 393  0
                 wfFYIWorkflowItem = new KSMenuItemData("FYI Proposal", new ClickHandler(){
 394  
                 public void onClick(ClickEvent event) {           
 395  0
                         addRationale(rationaleEditor,DecisionRationaleDetail.FYI.getType());
 396  0
                                 workflowRpcServiceAsync.fyiDocumentWithId(workflowId, new KSAsyncCallback<Boolean>(){
 397  
                                         public void handleFailure(Throwable caught) {
 398  0
                                                 Window.alert("Error FYIing Proposal");
 399  0
                                         }
 400  
                                         public void onSuccess(
 401  
                                                         Boolean result) {
 402  0
                                                 if(result){
 403  0
                                                         updateWorkflow(dataModel, true);
 404  0
                                                         if(submitCallback != null){
 405  0
                                                                 submitCallback.exec(true);
 406  
                                                         }
 407  
                                                         //Notify the user that the document was FYIed
 408  0
                                                         KSNotifier.add(new KSNotification("Proposal was FYIed", false));
 409  
                                                 }else{
 410  0
                                                         Window.alert("Error FYIing Proposal");
 411  
                                                 }
 412  0
                                         }
 413  
                                         
 414  
                                 });
 415  0
                 }        
 416  
             });
 417  0
                 return wfFYIWorkflowItem;
 418  
         }
 419  
 
 420  
         private KSMenuItemData getAcknowledgeItem() {
 421  
                 KSMenuItemData wfAcknowledgeItem;
 422  0
                 wfAcknowledgeItem = new KSMenuItemData("Acknowledge Proposal", new ClickHandler(){
 423  
                 public void onClick(ClickEvent event) {
 424  0
                         setupSubmitSuccessDialog();
 425  0
                                 final KSRichEditor rationaleEditor = new KSRichEditor();
 426  0
                                 AcknowledgeCancelGroup approvalButton = new AcknowledgeCancelGroup(new Callback<AcknowledgeCancelEnum>(){
 427  
 
 428  
                                         @Override
 429  
                                         public void exec(AcknowledgeCancelEnum result) {
 430  0
                                                 if(!result.name().equals("CANCEL")){
 431  0
                                                         addRationale(rationaleEditor,DecisionRationaleDetail.ACKNOWLEDGE.getType());
 432  0
                                                         workflowRpcServiceAsync.acknowledgeDocumentWithId(workflowId, new KSAsyncCallback<Boolean>(){
 433  
                                                                 public void handleFailure(Throwable caught) {
 434  0
                                                                         submitSuccessDialog.hide();
 435  0
                                                                         Window.alert("Error acknowledging Proposal");
 436  0
                                                                 }
 437  
                                                                 public void onSuccess(Boolean result) {
 438  0
                                                                         submitSuccessDialog.hide();
 439  0
                                                                         if(result){
 440  0
                                                                                 updateWorkflow(dataModel, true);
 441  0
                                                                                 if(submitCallback != null){
 442  0
                                                                                         submitCallback.exec(true);
 443  
                                                                                 }
 444  
                                                                                 //Notify the user that the document was acknowledged
 445  0
                                                                                 KSNotifier.add(new KSNotification("Proposal was acknowledged", false));
 446  
                                                                         }else{
 447  0
                                                                                 Window.alert("Error acknowledging Proposal");
 448  
                                                                         }
 449  0
                                                                 }
 450  
                                                         });
 451  
                                                 }
 452  
                                                 else{
 453  0
                                                         submitSuccessDialog.hide();
 454  
                                                 }
 455  0
                                         }
 456  
                                 });
 457  
                                 
 458  0
                                 SectionTitle headerTitle = SectionTitle.generateH3Title("Acknowledge Proposal");
 459  0
                                 SectionTitle dialogLabel = SectionTitle.generateH4Title("You are acknowledging the " + proposalName +" proposal");
 460  0
                                 SectionTitle fieldLabel = SectionTitle.generateH4Title("Decision Rationale");
 461  0
                                 rationaleEditor.addStyleName("KS-Comment-Create-Editor");
 462  0
                                 dialogPanel.clear();
 463  0
                                 dialogPanel.add(headerTitle);        
 464  0
                                 dialogPanel.add(dialogLabel);
 465  0
                                 dialogPanel.add(fieldLabel);
 466  0
                                 dialogPanel.add(rationaleEditor);
 467  0
                                 dialogPanel.add(approvalButton);
 468  0
                                 submitSuccessDialog.show();
 469  0
                 }        
 470  
             });
 471  0
                 return wfAcknowledgeItem;
 472  
         }
 473  
 
 474  
         private KSMenuItemData getDisApproveItem() {
 475  
                 KSMenuItemData wfDisApproveItem;
 476  0
                 wfDisApproveItem = new KSMenuItemData("Reject Proposal", new ClickHandler(){
 477  
                 public void onClick(ClickEvent event) {   
 478  0
                         setupSubmitSuccessDialog();
 479  0
                                 final KSRichEditor rationaleEditor = new KSRichEditor();
 480  0
                                 RejectCancelGroup disapprovalButton = new RejectCancelGroup(new Callback<RejectCancelEnum>(){
 481  
 
 482  
                                         @Override
 483  
                                         public void exec(RejectCancelEnum result) {
 484  0
                                                 if(!result.name().equals("CANCEL")){
 485  0
                                                         if(rationaleEditor.getText().trim().equals("")){
 486  0
                                                                 required.setText("Please enter the decision rationale");
 487  
                                                         }
 488  
                                                         else{
 489  0
                                                                 addRationale(rationaleEditor,DecisionRationaleDetail.REJECT.getType());
 490  0
                                                                 workflowRpcServiceAsync.disapproveDocumentWithId(workflowId, new KSAsyncCallback<Boolean>(){
 491  
                                                                         public void handleFailure(Throwable caught) {
 492  0
                                                                                 submitSuccessDialog.hide();
 493  0
                                                                                 Window.alert("Error rejecting Proposal");
 494  0
                                                                         }
 495  
                                                                         public void onSuccess(Boolean result) {
 496  0
                                                                                 submitSuccessDialog.hide();
 497  0
                                                                                 if(submitCallback != null){
 498  0
                                                                                         submitCallback.exec(result);
 499  
                                                                                 }
 500  0
                                                                                 if(result){
 501  0
                                                                                         KSNotifier.add(new KSNotification("Proposal was rejected", false));
 502  0
                                                                                         updateWorkflow(dataModel, true);
 503  
                                                                                 }else{
 504  0
                                                                                         Window.alert("Error rejecting Proposal");
 505  
                                                                                 }
 506  0
                                                                         }
 507  
                                                                         
 508  
                                                                 });
 509  
                                                         }
 510  
 
 511  
                                         }
 512  
                                         else{
 513  0
                                                 submitSuccessDialog.hide();
 514  
                                         }
 515  0
                                         }
 516  
                                 });
 517  0
                                 SectionTitle headerTitle = SectionTitle.generateH3Title("Reject Proposal");
 518  0
                                 SectionTitle dialogLabel = SectionTitle.generateH4Title("You are rejecting the " + proposalName +" proposal");
 519  0
                                 SectionTitle fieldLabel = SectionTitle.generateH4Title("Decision Rationale");
 520  0
                                 required = new AbbrPanel("Required", "ks-form-module-elements-required", " * ");
 521  0
                                 required.setVisible(true);
 522  
 //                                final KSRichEditor rationaleEditor = new KSRichEditor();
 523  
 //                                rationaleEditor.addStyleName("ks-textarea-width");
 524  
 //                                rationaleEditor.addStyleName("ks-textarea-large-height");
 525  0
                                 rationaleEditor.addStyleName("KS-Comment-Create-Editor");
 526  0
                                 dialogPanel.clear();
 527  0
                                 dialogPanel.add(headerTitle);        
 528  0
                                 dialogPanel.add(dialogLabel);
 529  0
                                 dialogPanel.add(fieldLabel);
 530  0
                                 dialogPanel.add(required);
 531  0
                                 dialogPanel.add(rationaleEditor);
 532  0
                                 dialogPanel.add(disapprovalButton);
 533  0
                                 submitSuccessDialog.setWidget(dialogPanel);
 534  0
                                 submitSuccessDialog.show();
 535  0
                 }        
 536  
             });
 537  0
                 return wfDisApproveItem;
 538  
         }
 539  
 
 540  
         private KSMenuItemData getApproveItem() {
 541  
                 KSMenuItemData wfApproveItem;
 542  
 
 543  0
                 wfApproveItem= new KSMenuItemData("Approve Proposal", new ClickHandler(){
 544  
                         public void onClick(ClickEvent event) {
 545  0
                                 setupSubmitSuccessDialog();
 546  0
                                 final KSRichEditor rationaleEditor = new KSRichEditor();
 547  0
                                 ConfirmApprovalCancelGroup approvalButton = new ConfirmApprovalCancelGroup(new Callback<ConfirmApprovalCancelEnum>(){
 548  
 
 549  
                                         @Override
 550  
                                         public void exec(ConfirmApprovalCancelEnum result) {
 551  0
                                                 if(!result.name().equals("CANCEL")){
 552  0
                                                         if(rationaleEditor.getText().trim().equals("")){
 553  0
                                                                 required.setText("Please enter the decision rationale");
 554  
                                                         }
 555  
                                                         else{
 556  0
                                                                 addRationale(rationaleEditor,DecisionRationaleDetail.APPROVE.getType());
 557  
                                                                 
 558  0
                                                                 workflowRpcServiceAsync.approveDocumentWithId(workflowId, new KSAsyncCallback<Boolean>(){
 559  
                                                                 public void handleFailure(Throwable caught) {
 560  0
                                                                         submitSuccessDialog.hide();
 561  0
                                                                         Window.alert("Error approving Proposal");
 562  0
                                                                 }
 563  
                                                                 public void onSuccess(Boolean result) {
 564  0
                                                                         submitSuccessDialog.hide();
 565  0
                                                                         if (result){
 566  0
                                                                                 updateWorkflow(dataModel, true);
 567  0
                                                                                 if(submitCallback != null){
 568  0
                                                                                         submitCallback.exec(result);
 569  
                                                                                 }
 570  
                                                                                 //Notify the user that the document was approved
 571  0
                                                                                 KSNotifier.add(new KSNotification("Proposal was approved", false));
 572  
                                                                         } else {
 573  0
                                                                                 Window.alert("Error approving Proposal");
 574  
                                                                         }
 575  0
                                                                 }
 576  
                                                         });
 577  
                                                         }
 578  
 
 579  
                                         }
 580  
                                         else{
 581  0
                                                 submitSuccessDialog.hide();
 582  
                                         }
 583  0
                                         }
 584  
                                 });
 585  
                                 
 586  0
                                 SectionTitle headerTitle = SectionTitle.generateH3Title("Approve Proposal");
 587  0
                                 SectionTitle dialogLabel = SectionTitle.generateH4Title("You are approving the " + proposalName +" proposal");
 588  0
                                 SectionTitle fieldLabel = SectionTitle.generateH4Title("Decision Rationale");
 589  0
                                 required = new AbbrPanel("Required", "ks-form-module-elements-required", " * ");
 590  0
                                 required.setVisible(true);
 591  0
                                 rationaleEditor.addStyleName("KS-Comment-Create-Editor");
 592  0
                                 dialogPanel.clear();
 593  0
                                 dialogPanel.add(headerTitle);        
 594  0
                                 dialogPanel.add(dialogLabel);
 595  0
                                 dialogPanel.add(fieldLabel);
 596  0
                                 dialogPanel.add(required);
 597  0
                                 dialogPanel.add(rationaleEditor);
 598  0
                                 dialogPanel.add(approvalButton);
 599  0
                                 dialogPanel.setSize("580px", "400px");
 600  
 //                                submitSuccessDialog.setWidget(dialogPanel);
 601  0
                                 submitSuccessDialog.show();
 602  0
                         }        
 603  
                 });
 604  0
                 return wfApproveItem;
 605  
         }
 606  
 
 607  
     private KSMenuItemData getWithdrawItem() {
 608  
         KSMenuItemData wfWithdrawItem;
 609  
 
 610  0
         wfWithdrawItem = new KSMenuItemData("Withdraw Proposal", new ClickHandler() {
 611  
             public void onClick(ClickEvent event) {
 612  0
                 setupSubmitSuccessDialog();
 613  0
                 final KSRichEditor rationaleEditor = new KSRichEditor();
 614  0
                 ConfirmCancelGroup withdrawButton = new ConfirmCancelGroup(new Callback<ConfirmCancelEnum>() {
 615  
 
 616  
                     @Override
 617  
                     public void exec(ConfirmCancelEnum result) {
 618  0
                         if (!result.name().equals("CANCEL")) {
 619  0
                             if (rationaleEditor.getText().trim().equals("")) {
 620  0
                                 required.setText("Please enter the decision rationale");
 621  
                             } else {
 622  0
                                 addRationale(rationaleEditor, DecisionRationaleDetail.WITHDRAW.getType());
 623  
 
 624  0
                                 workflowRpcServiceAsync.withdrawDocumentWithId(workflowId, new KSAsyncCallback<Boolean>() {
 625  
                                     public void handleFailure(Throwable caught) {
 626  0
                                         submitSuccessDialog.hide();
 627  0
                                         Window.alert("Error withdrawing Proposal");
 628  0
                                     }
 629  
 
 630  
                                     public void onSuccess(Boolean result) {
 631  0
                                         submitSuccessDialog.hide();
 632  0
                                         if (result) {
 633  0
                                             updateWorkflow(dataModel, true);
 634  0
                                             if (submitCallback != null) {
 635  0
                                                 submitCallback.exec(result);
 636  
                                             }
 637  
                                             // Notify the user that the document was approved
 638  0
                                             KSNotifier.add(new KSNotification("Proposal will be withdrawn", false));
 639  
                                         } else {
 640  0
                                             Window.alert("Error withdrawing Proposal");
 641  
                                         }
 642  0
                                     }
 643  
                                 });
 644  
                             }
 645  
 
 646  
                         } else {
 647  0
                             submitSuccessDialog.hide();
 648  
                         }
 649  0
                     }
 650  
                 });
 651  
 
 652  0
                 SectionTitle headerTitle = SectionTitle.generateH3Title("Withdraw Proposal");
 653  0
                 SectionTitle dialogLabel = SectionTitle.generateH4Title("You are withdrawing the " + proposalName + " proposal");
 654  0
                 SectionTitle fieldLabel = SectionTitle.generateH4Title("Decision Rationale");
 655  0
                 required = new AbbrPanel("Required", "ks-form-module-elements-required", " * ");
 656  0
                 required.setVisible(true);
 657  0
                 rationaleEditor.addStyleName("KS-Comment-Create-Editor");
 658  0
                 dialogPanel.clear();
 659  0
                 dialogPanel.add(headerTitle);
 660  0
                 dialogPanel.add(dialogLabel);
 661  0
                 dialogPanel.add(fieldLabel);
 662  0
                 dialogPanel.add(required);
 663  0
                 dialogPanel.add(rationaleEditor);
 664  0
                 dialogPanel.add(withdrawButton);
 665  0
                 dialogPanel.setSize("580px", "400px");
 666  
                 // submitSuccessDialog.setWidget(dialogPanel);
 667  0
                 submitSuccessDialog.show();
 668  0
             }
 669  
         });
 670  0
         return wfWithdrawItem;
 671  
     }
 672  
 
 673  
     private KSMenuItemData getBlanketApproveItem() {
 674  
         KSMenuItemData wfBlanketApproveItem;
 675  
 
 676  0
         wfBlanketApproveItem = new KSMenuItemData("Blanket Approve Proposal", new ClickHandler() {
 677  
             public void onClick(ClickEvent event) {
 678  0
                 setupSubmitSuccessDialog();
 679  0
                 final KSRichEditor rationaleEditor = new KSRichEditor();
 680  0
                 ConfirmCancelGroup blanketApprovalButton = new ConfirmCancelGroup(new Callback<ConfirmCancelEnum>() {
 681  
 
 682  
                     @Override
 683  
                     public void exec(ConfirmCancelEnum result) {
 684  0
                         if (!result.name().equals("CANCEL")) {
 685  0
                             if (rationaleEditor.getText().trim().equals("")) {
 686  0
                                 required.setText("Please enter the decision rationale");
 687  
                             } else {
 688  0
                                 addRationale(rationaleEditor, DecisionRationaleDetail.BLANKET_APPROVE.getType());
 689  
 
 690  0
                                 workflowRpcServiceAsync.blanketApproveDocumentWithId(workflowId, new KSAsyncCallback<Boolean>() {
 691  
                                     public void handleFailure(Throwable caught) {
 692  0
                                         submitSuccessDialog.hide();
 693  0
                                         Window.alert("Error blanket approving Proposal");
 694  0
                                     }
 695  
 
 696  
                                     public void onSuccess(Boolean result) {
 697  0
                                         submitSuccessDialog.hide();
 698  0
                                         if (result) {
 699  0
                                             updateWorkflow(dataModel, true);
 700  0
                                             if (submitCallback != null) {
 701  0
                                                 submitCallback.exec(result);
 702  
                                             }
 703  
                                             // Notify the user that the document was approved
 704  0
                                             KSNotifier.add(new KSNotification("Proposal will be blanket approved", false));
 705  
                                         } else {
 706  0
                                             Window.alert("Error blanket approving Proposal");
 707  
                                         }
 708  0
                                     }
 709  
                                 });
 710  
                             }
 711  
                         } else {
 712  0
                             submitSuccessDialog.hide();
 713  
                         }
 714  0
                     }
 715  
                 });
 716  
 
 717  0
                 SectionTitle headerTitle = SectionTitle.generateH3Title("Blanket Approve Proposal");
 718  0
                 SectionTitle dialogLabel = SectionTitle.generateH4Title("You are blanket approving the " + proposalName + " proposal");
 719  0
                 SectionTitle fieldLabel = SectionTitle.generateH4Title("Decision Rationale");
 720  0
                 required = new AbbrPanel("Required", "ks-form-module-elements-required", " * ");
 721  0
                 required.setVisible(true);
 722  0
                 rationaleEditor.addStyleName("KS-Comment-Create-Editor");
 723  0
                 dialogPanel.clear();
 724  0
                 dialogPanel.add(headerTitle);
 725  0
                 dialogPanel.add(dialogLabel);
 726  0
                 dialogPanel.add(fieldLabel);
 727  0
                 dialogPanel.add(required);
 728  0
                 dialogPanel.add(rationaleEditor);
 729  0
                 dialogPanel.add(blanketApprovalButton);
 730  0
                 dialogPanel.setSize("580px", "400px");
 731  
                 // submitSuccessDialog.setWidget(dialogPanel);
 732  0
                 submitSuccessDialog.show();
 733  0
             }
 734  
         });
 735  0
         return wfBlanketApproveItem;
 736  
     }
 737  
 
 738  
     protected KSDropDown setUpReturnToPreviousDropDown(String workflowId) {
 739  
 //        nodeNameList.clear();
 740  0
         final KSDropDown nodeNameDropDown = new KSDropDown();
 741  0
         nodeNameDropDown.setBlankFirstItem(true);
 742  0
         workflowRpcServiceAsync.getPreviousRouteNodeNames(workflowId, new KSAsyncCallback<List<String>>() {
 743  
             public void handleFailure(Throwable caught) {
 744  0
                 Window.alert("Error getting previous node names for Proposal");
 745  0
             }
 746  
 
 747  
             public void onSuccess(List<String> result) {
 748  0
                 SimpleListItems nodeNameList = new SimpleListItems();
 749  0
                 for (String nodeName : result) {
 750  0
                     nodeNameList.addItem(nodeName, nodeName);
 751  
                 }
 752  0
                 nodeNameDropDown.setListItems(nodeNameList);
 753  0
             }
 754  
         });
 755  0
         nodeNameDropDown.setInitialized(true);
 756  0
         return nodeNameDropDown;
 757  
     }
 758  
 
 759  
     private KSMenuItemData getReturnToPreviousItem() {
 760  
         KSMenuItemData wfReturnToPreviousItem;
 761  
 
 762  0
         wfReturnToPreviousItem = new KSMenuItemData("Return Proposal to Previous Node", new ClickHandler() {
 763  
             public void onClick(ClickEvent event) {
 764  0
                 setupSubmitSuccessDialog();
 765  0
                 final KSRichEditor rationaleEditor = new KSRichEditor();
 766  0
                 final KSDropDown nodeNameDropDown = setUpReturnToPreviousDropDown(workflowId);
 767  0
                 ConfirmCancelGroup returnButton = new ConfirmCancelGroup(new Callback<ConfirmCancelEnum>() {
 768  
 
 769  
                     @Override
 770  
                     public void exec(ConfirmCancelEnum result) {
 771  0
                         if (!result.name().equals("CANCEL")) {
 772  0
                             if ((rationaleEditor.getText().trim().equals("")) && (nodeNameDropDown.getSelectedItem().trim().equals(""))) {
 773  0
                                 required.setText("Please enter the decision rationale and select a node name to return to");
 774  0
                             } else if (rationaleEditor.getText().trim().equals("")) {
 775  0
                                 required.setText("Please enter the decision rationale");
 776  0
                             } else if (nodeNameDropDown.getSelectedItem().trim().equals("")) {
 777  0
                                 required.setText("Please select a node name to return to");
 778  
                             } else {
 779  0
                                 addRationale(rationaleEditor, DecisionRationaleDetail.RETURN_TO_PREVIOUS.getType());
 780  0
                                 String nodeName = nodeNameDropDown.getSelectedItem().trim();
 781  0
                                 workflowRpcServiceAsync.returnDocumentWithId(workflowId, nodeName, new KSAsyncCallback<Boolean>() {
 782  
                                     public void handleFailure(Throwable caught) {
 783  0
                                         submitSuccessDialog.hide();
 784  0
                                         Window.alert("Error returning the Proposal to a previous node");
 785  0
                                     }
 786  
 
 787  
                                     public void onSuccess(Boolean result) {
 788  0
                                         submitSuccessDialog.hide();
 789  0
                                         if (result) {
 790  0
                                             updateWorkflow(dataModel, true);
 791  0
                                             if (submitCallback != null) {
 792  0
                                                 submitCallback.exec(result);
 793  
                                             }
 794  
                                             // Notify the user that the document was approved
 795  0
                                             KSNotifier.add(new KSNotification("Proposal was returned", false));
 796  
                                         } else {
 797  0
                                             Window.alert("Error returning the Proposal to a previous node");
 798  
                                         }
 799  0
                                     }
 800  
                                 });
 801  0
                             }
 802  
 
 803  
                         } else {
 804  0
                             submitSuccessDialog.hide();
 805  
                         }
 806  0
                     }
 807  
                 });
 808  
 
 809  0
                 SectionTitle headerTitle = SectionTitle.generateH3Title("Return Proposal to Previous Node");
 810  0
                 SectionTitle dialogLabel = SectionTitle.generateH4Title("You are returning the " + proposalName + " proposal to a previous node");
 811  0
                 SectionTitle nnFieldLabel = SectionTitle.generateH4Title("Workflow Node Name");
 812  0
                 SectionTitle drFieldLabel = SectionTitle.generateH4Title("Decision Rationale");
 813  0
                 required = new AbbrPanel("Required", "ks-form-module-elements-required", " * ");
 814  0
                 required.setVisible(true);
 815  0
                 rationaleEditor.addStyleName("KS-Comment-Create-Editor");
 816  0
                 dialogPanel.clear();
 817  0
                 dialogPanel.add(headerTitle);
 818  0
                 dialogPanel.add(dialogLabel);
 819  0
                 dialogPanel.add(nnFieldLabel);
 820  0
                 dialogPanel.add(nodeNameDropDown);
 821  0
                 dialogPanel.add(drFieldLabel);
 822  0
                 dialogPanel.add(required);
 823  0
                 dialogPanel.add(rationaleEditor);
 824  0
                 dialogPanel.add(returnButton);
 825  0
                 dialogPanel.setSize("580px", "400px");
 826  
                 // submitSuccessDialog.setWidget(dialogPanel);
 827  0
                 submitSuccessDialog.show();
 828  0
             }
 829  
         });
 830  0
         return wfReturnToPreviousItem;
 831  
         }
 832  
 
 833  
     private void addRationale(KSRichEditor rationaleEditor, String rationaleType) {
 834  0
         CommentInfo newDecisionRationale = new CommentInfo();
 835  0
         RichTextInfo text = new RichTextInfo();
 836  0
         text.setFormatted(rationaleEditor.getHTML());
 837  0
         text.setPlain(rationaleEditor.getText());
 838  0
         newDecisionRationale.setReferenceTypeKey(PROPOSAL_REF_TYPE_KEY);
 839  0
         newDecisionRationale.setReferenceId(proposalId);
 840  0
         newDecisionRationale.setState(DtoState.ACTIVE.toString());
 841  0
         newDecisionRationale.setCommentText(text);
 842  0
         newDecisionRationale.setType(rationaleType);
 843  
 
 844  
         try {
 845  0
             commentServiceAsync.addComment(proposalId, PROPOSAL_REF_TYPE_KEY, newDecisionRationale, new KSAsyncCallback<CommentInfo>() {
 846  
 
 847  
                 @Override
 848  
                 public void handleFailure(Throwable caught) {
 849  0
                     GWT.log("Add Comment Failed", caught);
 850  0
                 }
 851  
 
 852  
                 @Override
 853  
                 public void onSuccess(CommentInfo result) {
 854  0
                     System.out.println("Rationale Added successfully");
 855  0
                 }
 856  
             });
 857  0
         } catch (Exception e) {
 858  0
             GWT.log("Add Comment Failed", e);
 859  0
         }
 860  0
     }
 861  
 
 862  
     private KSMenuItemData getStartItem() {
 863  
         KSMenuItemData wfStartWorkflowItem;
 864  0
             wfStartWorkflowItem = new KSMenuItemData("Submit Proposal", new ClickHandler(){
 865  
                     public void onClick(ClickEvent event) {
 866  
                 //Make sure the entire data model is valid before submit
 867  0
                                 dataModel.validateNextState(new Callback<List<ValidationResultInfo>>() {
 868  
                     @Override
 869  
                     public void exec(List<ValidationResultInfo> result) {
 870  
                             
 871  0
                             boolean isValid = ((LayoutController)parentController).isValid(result, false);
 872  0
                             if(isValid){
 873  0
                                             dialog.show();
 874  
                             }
 875  
                             else{
 876  0
                                     Window.alert("Unable to submit to workflow.  Please check sections for missing fields.");
 877  
                             }                            
 878  0
                     }
 879  
                 });
 880  0
                     }
 881  
 
 882  
             });
 883  0
                 return wfStartWorkflowItem;
 884  
         }
 885  
 
 886  
     private KSMenuItemData getCancelWorkflowItem() {
 887  
         KSMenuItemData wfCancelWorkflowItem;
 888  0
         final KSRichEditor rationaleEditor = new KSRichEditor();
 889  0
         wfCancelWorkflowItem = new KSMenuItemData("Cancel Proposal", new ClickHandler() {
 890  
             public void onClick(ClickEvent event) {
 891  0
                 addRationale(rationaleEditor, DecisionRationaleDetail.CANCEL_WORKFLOW.getType());
 892  0
                 workflowRpcServiceAsync.cancelDocumentWithId(workflowId, new KSAsyncCallback<Boolean>() {
 893  
                     public void handleFailure(Throwable caught) {
 894  0
                         Window.alert("Error Cancelling Proposal");
 895  0
                     }
 896  
 
 897  
                     public void onSuccess(Boolean result) {
 898  0
                         if (result) {
 899  0
                             updateWorkflow(dataModel, true);
 900  0
                             if (submitCallback != null) {
 901  0
                                 submitCallback.exec(true);
 902  
                             }
 903  
                             // Notify the user that the document was FYIed
 904  0
                             KSNotifier.add(new KSNotification("Proposal will be Cancelled", false));
 905  
                         } else {
 906  0
                             Window.alert("Error Cancelling Proposal");
 907  
                         }
 908  0
                     }
 909  
 
 910  
                 });
 911  0
             }
 912  
         });
 913  0
         return wfCancelWorkflowItem;
 914  
     }
 915  
 
 916  
         private void setWorkflowStatus(String statusCd){
 917  0
                 String statusTranslation = "";
 918  0
                 if (WorkflowConstants.ROUTE_HEADER_SAVED_CD.equals(statusCd)){
 919  0
                         statusTranslation = getLabel(WorkflowConstants.ROUTE_HEADER_SAVED_LABEL_KEY);
 920  0
                 } else  if (WorkflowConstants.ROUTE_HEADER_INITIATED_CD.equals(statusCd)){
 921  0
                         statusTranslation = getLabel(WorkflowConstants.ROUTE_HEADER_INITIATED_LABEL_KEY);
 922  0
                 } else if (WorkflowConstants.ROUTE_HEADER_ENROUTE_CD.equals(statusCd)){
 923  0
                         statusTranslation = getLabel(WorkflowConstants.ROUTE_HEADER_ENROUTE_LABEL_KEY);
 924  0
                 } else if (WorkflowConstants.ROUTE_HEADER_APPROVED_CD.equals(statusCd)){
 925  0
                         statusTranslation = getLabel(WorkflowConstants.ROUTE_HEADER_APPROVED_LABEL_KEY);
 926  0
                 } else if (WorkflowConstants.ROUTE_HEADER_CANCEL_CD.equals(statusCd)){
 927  0
                         statusTranslation = getLabel(WorkflowConstants.ROUTE_HEADER_CANCEL_LABEL_KEY);
 928  0
                 } else if (WorkflowConstants.ROUTE_HEADER_EXCEPTION_CD.equals(statusCd)){
 929  0
                         statusTranslation = getLabel(WorkflowConstants.ROUTE_HEADER_EXCEPTION_LABEL_KEY);
 930  0
                 } else if (WorkflowConstants.ROUTE_HEADER_DISAPPROVED_CD.equals(statusCd)){
 931  0
                         statusTranslation = getLabel(WorkflowConstants.ROUTE_HEADER_DISAPPROVED_LABEL_KEY);
 932  0
                 } else if (WorkflowConstants.ROUTE_HEADER_FINAL_CD.equals(statusCd)){
 933  0
                         statusTranslation = getLabel(WorkflowConstants.ROUTE_HEADER_FINAL_LABEL_KEY);
 934  0
                 } else if (WorkflowConstants.ROUTE_HEADER_DISAPPROVE_CANCEL_CD.equals(statusCd)){
 935  0
                         statusTranslation = getLabel(WorkflowConstants.ROUTE_HEADER_DISAPPROVE_CANCEL_LABEL_KEY);
 936  0
                 } else if (WorkflowConstants.ROUTE_HEADER_PROCESSED_CD.equals(statusCd)){
 937  0
                         statusTranslation = getLabel(WorkflowConstants.ROUTE_HEADER_PROCESSED_LABEL_KEY);
 938  
                 } else {
 939  0
                         statusTranslation = statusCd;
 940  
                 }
 941  
                 
 942  0
                 workflowStatusLabel.setText("Status: " + statusTranslation);        
 943  0
         }
 944  
         
 945  
         /**
 946  
          * Use to set the modelName to use when this widget requests the data model.
 947  
          * 
 948  
          * @param modelName
 949  
          */
 950  
         public void setModelName(String modelName) {
 951  0
                 this.modelName = modelName;
 952  0
         }
 953  
         
 954  
         /**
 955  
          * Use to set the data model path to retrieve the propsal data to use for this workflow. 
 956  
          * @param idPath
 957  
          */
 958  
         public void setProposalPath(String proposalPath) {
 959  0
                 this.proposalPath = proposalPath;
 960  0
         }
 961  
                 
 962  
         public void setWorkflowRpcService(WorkflowRpcServiceAsync workflowRpcServiceAsync){
 963  0
                 this.workflowRpcServiceAsync = workflowRpcServiceAsync;
 964  0
         }
 965  
 
 966  
         public void refresh(){
 967  0
                 updateWorkflow(dataModel, false);
 968  0
         }
 969  
         
 970  
     private String getLabel(String labelKey) {
 971  0
         return Application.getApplicationContext().getUILabel("common", null, null, labelKey);
 972  
     }
 973  
     
 974  
     public void getDataIdFromWorkflowId(String workflowId, AsyncCallback<String> callback){
 975  0
             workflowRpcServiceAsync.getDataIdFromWorkflowId(workflowId, callback);
 976  0
     }
 977  
 
 978  
         public void addSubmitCallback(Callback<Boolean> callback) {
 979  0
                 this.submitCallback = callback;
 980  
                 
 981  0
         }
 982  
 }