Coverage Report - org.kuali.student.core.document.ui.client.widgets.documenttool.DocumentTool
 
Classes in this File Line Coverage Branch Coverage Complexity
DocumentTool
0%
0/137
0%
0/10
1.723
DocumentTool$1
0%
0/3
N/A
1.723
DocumentTool$2
0%
0/4
0%
0/2
1.723
DocumentTool$3
0%
0/10
0%
0/2
1.723
DocumentTool$3$1
0%
0/10
N/A
1.723
DocumentTool$3$1$1
0%
0/4
N/A
1.723
DocumentTool$3$1$1$1
0%
0/56
0%
0/26
1.723
DocumentTool$4
0%
0/10
0%
0/6
1.723
DocumentTool$5
0%
0/3
N/A
1.723
DocumentTool$5$1
0%
0/3
N/A
1.723
DocumentTool$6
0%
0/14
0%
0/10
1.723
DocumentTool$7
0%
0/9
0%
0/4
1.723
DocumentTool$8
0%
0/1
N/A
1.723
DocumentTool$DocumentForm
0%
0/14
N/A
1.723
 
 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  
 
 16  
 package org.kuali.student.core.document.ui.client.widgets.documenttool;
 17  
 
 18  
 import java.util.List;
 19  
 import java.util.Map;
 20  
 
 21  
 import org.kuali.student.common.assembly.data.ConstraintMetadata;
 22  
 import org.kuali.student.common.assembly.data.Metadata;
 23  
 import org.kuali.student.common.assembly.data.QueryPath;
 24  
 import org.kuali.student.common.ui.client.application.KSAsyncCallback;
 25  
 import org.kuali.student.common.ui.client.configurable.mvc.DelayedToolView;
 26  
 import org.kuali.student.common.ui.client.configurable.mvc.FieldDescriptor;
 27  
 import org.kuali.student.common.ui.client.configurable.mvc.HasReferenceId;
 28  
 import org.kuali.student.common.ui.client.configurable.mvc.SectionTitle;
 29  
 import org.kuali.student.common.ui.client.configurable.mvc.binding.ModelWidgetBinding;
 30  
 import org.kuali.student.common.ui.client.configurable.mvc.multiplicity.MultiplicityConfiguration;
 31  
 import org.kuali.student.common.ui.client.configurable.mvc.multiplicity.MultiplicityFieldConfiguration;
 32  
 import org.kuali.student.common.ui.client.configurable.mvc.multiplicity.MultiplicityFieldWidgetInitializer;
 33  
 import org.kuali.student.common.ui.client.configurable.mvc.multiplicity.SwapCompositeCondition;
 34  
 import org.kuali.student.common.ui.client.configurable.mvc.multiplicity.SwapCompositeConditionFieldConfig;
 35  
 import org.kuali.student.common.ui.client.configurable.mvc.sections.InfoMessage;
 36  
 import org.kuali.student.common.ui.client.configurable.mvc.sections.MultiplicitySection;
 37  
 import org.kuali.student.common.ui.client.configurable.mvc.sections.VerticalSection;
 38  
 import org.kuali.student.common.ui.client.configurable.mvc.sections.WarnContainer;
 39  
 import org.kuali.student.common.ui.client.dto.FileStatus;
 40  
 import org.kuali.student.common.ui.client.dto.UploadStatus;
 41  
 import org.kuali.student.common.ui.client.dto.FileStatus.FileTransferStatus;
 42  
 import org.kuali.student.common.ui.client.dto.UploadStatus.UploadTransferStatus;
 43  
 import org.kuali.student.common.ui.client.mvc.Callback;
 44  
 import org.kuali.student.common.ui.client.mvc.DataModel;
 45  
 import org.kuali.student.common.ui.client.mvc.DataModelDefinition;
 46  
 import org.kuali.student.common.ui.client.theme.Theme;
 47  
 import org.kuali.student.common.ui.client.widgets.KSLabel;
 48  
 import org.kuali.student.common.ui.client.widgets.KSLightBox;
 49  
 import org.kuali.student.common.ui.client.widgets.KSTextArea;
 50  
 import org.kuali.student.common.ui.client.widgets.KSButtonAbstract.ButtonStyle;
 51  
 import org.kuali.student.common.ui.client.widgets.buttongroups.OkGroup;
 52  
 import org.kuali.student.common.ui.client.widgets.buttongroups.ButtonEnumerations.OkEnum;
 53  
 import org.kuali.student.common.ui.client.widgets.field.layout.element.MessageKeyInfo;
 54  
 import org.kuali.student.common.ui.client.widgets.layout.VerticalFlowPanel;
 55  
 import org.kuali.student.core.document.dto.RefDocRelationInfo;
 56  
 import org.kuali.student.core.document.ui.client.service.DocumentRpcService;
 57  
 import org.kuali.student.core.document.ui.client.service.DocumentRpcServiceAsync;
 58  
 import org.kuali.student.core.document.ui.client.service.UploadStatusRpcService;
 59  
 import org.kuali.student.core.document.ui.client.service.UploadStatusRpcServiceAsync;
 60  
 
 61  
 import com.google.gwt.core.client.GWT;
 62  
 import com.google.gwt.i18n.client.NumberFormat;
 63  
 import com.google.gwt.user.client.Timer;
 64  
 import com.google.gwt.user.client.ui.Composite;
 65  
 import com.google.gwt.user.client.ui.FileUpload;
 66  
 import com.google.gwt.user.client.ui.FlexTable;
 67  
 import com.google.gwt.user.client.ui.FormPanel;
 68  
 import com.google.gwt.user.client.ui.HTML;
 69  
 import com.google.gwt.user.client.ui.Image;
 70  
 import com.google.gwt.user.client.ui.Widget;
 71  
 import com.google.gwt.widgetideas.client.ProgressBar;
 72  
 import com.google.gwt.widgetideas.client.ProgressBar.TextFormatter;
 73  
 
 74  0
 public class DocumentTool extends DelayedToolView implements HasReferenceId{
 75  
 
 76  
         private String referenceId;
 77  
         private String referenceTypeKey;
 78  
         private String referenceType;
 79  
         private String referenceState;
 80  
         private String refObjectTypeKey;
 81  0
         private final String refDocRelationTypeKey = "kuali.org.DocRelation.allObjectTypes";
 82  
         
 83  
         private static final int POLL_INTERVAL = 2000;
 84  
 
 85  0
         private DocumentRpcServiceAsync documentServiceAsync = GWT.create(DocumentRpcService.class);
 86  0
         private VerticalFlowPanel layout = new VerticalFlowPanel();
 87  0
     private VerticalFlowPanel documentList = new VerticalFlowPanel();
 88  0
     private VerticalFlowPanel uploadList = new VerticalFlowPanel();
 89  
 //    private KSButton addMore = new KSButton("Add Another");
 90  0
     private KSLabel loadingDocuments = new KSLabel("Loading Documents...");
 91  0
     private FormPanel form = new FormPanel();
 92  0
     private Callback<String> deleteCallback = new Callback<String>(){
 93  
 
 94  
                 @Override
 95  
                 public void exec(String result) {
 96  0
                         refreshDocuments();
 97  0
                 }
 98  
 
 99  
     };
 100  
 
 101  0
     private KSLightBox progressWindow = new KSLightBox();
 102  0
     private VerticalFlowPanel progressPanel = new VerticalFlowPanel();
 103  0
     private KSLabel progressLabel = new KSLabel();
 104  0
     private ProgressBar progressBar = new ProgressBar();
 105  0
     private FlexTable fileProgressTable = new FlexTable();
 106  0
     private InfoMessage saveWarning = new InfoMessage("The document must be saved before Document files can be uploaded.", true);
 107  
     private Composite showAllLink;
 108  
 
 109  
     private DataModelDefinition modelDefinition;
 110  
 
 111  0
     private OkGroup progressButtons = new OkGroup(new Callback<OkEnum>(){
 112  
                 @Override
 113  
                 public void exec(OkEnum result) {
 114  0
                           if(result == OkEnum.Ok){
 115  0
                                   progressWindow.hide();
 116  
                           }
 117  0
                 }
 118  
     });
 119  0
     private UploadStatusRpcServiceAsync uploadStatusRpc = GWT.create(UploadStatusRpcService.class);
 120  
 
 121  0
         private OkGroup buttonPanel = new OkGroup(new Callback<OkEnum>(){
 122  
 
 123  
                 @Override
 124  
                 public void exec(OkEnum result) {
 125  0
                           if(result == OkEnum.Ok){
 126  0
                                   progressButtons.getButton(OkEnum.Ok).setEnabled(false);
 127  0
                                   progressLabel.setText("Starting upload...");
 128  
                                   //progressBar.setMin
 129  0
                                   progressBar.setProgress(0);
 130  0
                                   progressBar.setMaxProgress(0);
 131  0
                                   fileProgressTable.clear();
 132  0
                                   progressWindow.show();
 133  0
                                   uploadStatusRpc.getUploadId(new KSAsyncCallback<String>(){
 134  
 
 135  
                                         @Override
 136  
                                         public void handleFailure(Throwable caught) {
 137  0
                                                 progressLabel.setText("Could not contact server.");
 138  0
                                                 progressButtons.getButton(OkEnum.Ok).setEnabled(true);
 139  0
                                         }
 140  
 
 141  
                                         @Override
 142  
                                         public void onSuccess(final String result) {
 143  0
                                                 form.setAction(GWT.getModuleBaseURL()+"rpcservices/DocumentUpload?uploadId=" + result + "&referenceId=" + referenceId +"&refObjectTypeKey=" + refObjectTypeKey + "&refDocRelationTypeKey=" + refDocRelationTypeKey);
 144  0
                                                 form.submit();
 145  
 
 146  0
                                                 progressLabel.setText("Uploading...");
 147  0
                                                 Timer progressTimer = new Timer(){
 148  0
                                                         private boolean maxSet = false;
 149  
                                                         @Override
 150  
                                                         public void run() {
 151  0
                                                                 uploadStatusRpc.getUploadStatus(result, new KSAsyncCallback<UploadStatus>(){
 152  
 
 153  
                                                                         @Override
 154  
                                                                         public void handleFailure(Throwable caught) {
 155  0
                                                                                 progressLabel.setText("Unable to query upload status.");
 156  0
                                                                                 progressButtons.getButton(OkEnum.Ok).setEnabled(true);
 157  0
                                                                                 refreshDocuments();
 158  0
                                                                                 cancel();
 159  0
                                                                         }
 160  
 
 161  0
                                                                         private int currentFile = 0;
 162  
 
 163  
                                                                         @Override
 164  
                                                                         public void onSuccess(UploadStatus result) {
 165  0
                                                                                 if(!maxSet && result.getTotalSize() != null && result.getTotalSize() != 0){
 166  0
                                                                                         progressBar.setMaxProgress(((double)result.getTotalSize())/1024);
 167  0
                                                                                         maxSet = true;
 168  
                                                                                 }
 169  
 
 170  
                                                                                 //Individual file status
 171  0
                                                                                 fileProgressTable.clear();
 172  0
                                                                                 currentFile = 0;
 173  0
                                                                                 for(FileStatus fs: result.getFileStatusList()){
 174  0
                                                                                         addFileProgress(fs);
 175  0
                                                                                         currentFile++;
 176  
                                                                                 }
 177  
 
 178  0
                                                                                 if(result.getProgress() != null){
 179  0
                                                                                         progressBar.setProgress(((double)result.getProgress())/1024);
 180  
                                                                                 }
 181  
 
 182  0
                                                                                 if(result.getStatus() == UploadTransferStatus.UPLOAD_FINISHED){
 183  0
                                                                                         progressLabel.setText("Processing...");
 184  0
                                                                                         progressBar.setProgress(progressBar.getMaxProgress());
 185  
                                                                                 }
 186  0
                                                                                 else if(result.getStatus() == UploadTransferStatus.COMMIT_FINISHED){
 187  0
                                                                                         progressLabel.setText("File upload successful!");
 188  0
                                                                                         progressBar.setProgress(progressBar.getMaxProgress());
 189  0
                                                                                         progressButtons.getButton(OkEnum.Ok).setEnabled(true);
 190  0
                                                                                         resetUploadFormPanel();
 191  
 
 192  0
                                                                                         cancel();
 193  0
                                                                                         refreshDocuments();
 194  
 
 195  
                                                                                 }
 196  0
                                                                                 else if(result.getStatus() == UploadTransferStatus.ERROR){
 197  0
                                                                                         progressLabel.setText("Error uploading!");
 198  0
                                                                                         progressButtons.getButton(OkEnum.Ok).setEnabled(true);
 199  0
                                                                                         refreshDocuments();
 200  0
                                                                                         cancel();
 201  
                                                                                 }
 202  
 
 203  0
                                                                         }
 204  
 
 205  0
                                                                         NumberFormat nf = NumberFormat.getFormat("#.##");
 206  
 
 207  
                                                                         private void addFileProgress(FileStatus fs) {
 208  
 
 209  
                                                                                 HTML fileNameLabel;
 210  
                                                                                 //Name
 211  0
                                                                                 if(fs.getStatus() == FileTransferStatus.COMMIT_FINISHED){
 212  0
                                                                                         fileNameLabel = new HTML("<a href=\"" + GWT.getModuleBaseURL()+"rpcservices/DocumentUpload?docId=" + fs.getDocId() + "\"><b>" + fs.getFileName() + "</b></a>");
 213  
                                                                                 }
 214  
                                                                                 else{
 215  0
                                                                                         fileNameLabel = new HTML("<b>" + fs.getFileName() + "</b>");
 216  
                                                                                 }
 217  
 
 218  0
                                                                                 fileProgressTable.setWidget(currentFile, 0, fileNameLabel);
 219  
 
 220  
                                                                                 //Progress
 221  0
                                                                                 Long curProgress = (fs.getProgress())/1024;
 222  0
                                                                                 String curProgressString = "";
 223  0
                                                                                 if(curProgress < 1024){
 224  0
                                                                                         curProgressString = nf.format(curProgress) + "kb";
 225  
                                                                                 }
 226  
                                                                                 else{
 227  0
                                                                                         curProgressString = nf.format(curProgress/1024) + "mb";
 228  
                                                                                 }
 229  0
                                                                                 fileProgressTable.setWidget(currentFile, 1,  new KSLabel(curProgressString));
 230  
 
 231  
                                                                                 //Status
 232  0
                                                                                 String statusString = "";
 233  0
                                                                                 switch(fs.getStatus()){
 234  
                                                                                         case ERROR:
 235  0
                                                                                                 statusString = "Error!";
 236  0
                                                                                                 break;
 237  
                                                                                         case COMMIT_FINISHED:
 238  0
                                                                                                 statusString = "Finished";
 239  0
                                                                                                 break;
 240  
                                                                                         case FILE_ERROR:
 241  
                                                                                                 //Not used
 242  0
                                                                                                 break;
 243  
                                                                                         case IN_PROGRESS:
 244  0
                                                                                                 statusString = "Uploading...";
 245  0
                                                                                                 break;
 246  
                                                                                         case UPLOAD_FINISHED:
 247  0
                                                                                                 statusString = "Processing...";
 248  
                                                                                                 break;
 249  
                                                                                 }
 250  0
                                                                                 fileProgressTable.setWidget(currentFile, 2, new KSLabel(statusString));
 251  
 
 252  0
                                                                         }
 253  
 
 254  
 
 255  
                                                                 });
 256  0
                                                         }
 257  
                                                 };
 258  0
                                                 progressTimer.scheduleRepeating(POLL_INTERVAL);
 259  0
                                         }
 260  
                                   });
 261  
                           }
 262  0
                 }
 263  
         });
 264  
 
 265  
         public DocumentTool(String refObjectTypeKey, Enum<?> viewEnum, String viewName) {
 266  0
                 super(viewEnum, viewName);
 267  0
                 this.refObjectTypeKey = refObjectTypeKey;
 268  0
         }
 269  
 
 270  
         protected void isAuthorizedUploadDocuments() {
 271  0
         documentServiceAsync.isAuthorizedUploadDocuments(referenceId, referenceTypeKey, new KSAsyncCallback<Boolean>() {
 272  
 
 273  
                         @Override
 274  
             public void handleFailure(Throwable caught) {
 275  0
                                 GWT.log("Error checking permission for adding comments: ", caught);
 276  0
                                 throw new RuntimeException("Error checking Permissions: ", caught);
 277  
             }
 278  
 
 279  
                         @Override
 280  
             public void onSuccess(Boolean result) {
 281  0
                                 GWT.log("User is " + ((result) ? "" : "not ") + "authorized to add comment.", null);
 282  0
                                 if(referenceId != null && !(referenceId.isEmpty())){
 283  
                                         //buttonPanel.getButton(OkEnum.Ok).setEnabled(true);
 284  0
                                 processUi(result);
 285  
                                 }
 286  
                                 else{
 287  0
                                         saveWarning.setVisible(true);
 288  0
                                         buttonPanel.setVisible(false);
 289  0
                                         documentList.setVisible(false);
 290  
                                         //buttonPanel.getButton(OkEnum.Ok).setEnabled(false);
 291  
                                 }
 292  0
             }
 293  
 
 294  
                 });
 295  0
         }
 296  
 
 297  
     protected void processUi(Boolean result){
 298  0
        saveWarning.setVisible(false);
 299  0
            buttonPanel.setVisible(result);
 300  0
            documentList.setVisible(true);
 301  0
            refreshDocuments();
 302  0
     }
 303  
 
 304  
     private Metadata getMetaData(String fieldKey) {
 305  0
         return modelDefinition.getMetadata(QueryPath.concat(fieldKey));
 306  
     }
 307  
 
 308  
     protected String getLabel(String labelKey) {
 309  
         // Could have used gwt-message.xml to define labels but this ui is not using the
 310  
         // UI label framework.
 311  0
         return labelKey;
 312  
     }
 313  
 
 314  
     private MultiplicityConfiguration setupMultiplicityConfig(
 315  
             MultiplicityConfiguration.MultiplicityType multiplicityType,
 316  
             MultiplicityConfiguration.StyleType styleType,
 317  
             String path, String addItemlabelMessageKey,
 318  
             String itemLabelMessageKey,
 319  
             Map<SwapCompositeCondition, List<SwapCompositeConditionFieldConfig>> swappableFieldsDefinition,
 320  
             List<String> deletionParentKeys) {
 321  0
         QueryPath parentPath = QueryPath.concat(path);
 322  0
         MultiplicityConfiguration config = new MultiplicityConfiguration(multiplicityType,
 323  
                 styleType, getMetaData(parentPath.toString()));
 324  0
         config.setAddItemLabel(getLabel(addItemlabelMessageKey));
 325  0
         config.setItemLabel(getLabel(itemLabelMessageKey));
 326  0
         config.setUpdateable(true);
 327  
 
 328  0
         FieldDescriptor parentFd = buildMuliplicityParentFieldDescriptor(path, getLabel(itemLabelMessageKey), null);
 329  0
         config.setParent(parentFd);
 330  
 
 331  0
         MultiplicityFieldConfiguration fc = buildMultiplicityFD("fieldKey",
 332  
                 "", parentPath.toString());
 333  0
         MultiplicityFieldWidgetInitializer fieldWidgetInitializer = new MultiplicityFieldWidgetInitializer() {
 334  
             @Override
 335  
             public ModelWidgetBinding getModelWidgetBindingInstance() {
 336  0
                 return new ModelWidgetBinding<DocumentForm>() {
 337  
                     public void setModelValue(DocumentForm widget, DataModel model, String path) {
 338  
 
 339  0
                     }
 340  
                     public void setWidgetValue(DocumentForm widget, DataModel model, String path){
 341  
 
 342  0
                     }
 343  
                 };
 344  
             }
 345  
             @Override
 346  
             public Widget getNewWidget() {
 347  0
                 return new DocumentForm();
 348  
             }
 349  
         };
 350  0
         fc.setFieldWidgetInitializer(fieldWidgetInitializer);
 351  
 
 352  
         // make the initial number of item equal to 1
 353  0
         ConstraintMetadata min1 = new ConstraintMetadata();
 354  0
         min1.setMinOccurs(1);
 355  0
         Metadata metadata = new Metadata();
 356  0
         metadata = new Metadata();
 357  0
         metadata.getConstraints().add(min1);
 358  0
         config.setMetaData(metadata);
 359  0
         config.addFieldConfiguration(fc);
 360  0
         config.nextLine();
 361  0
         return config;
 362  
     }
 363  
 
 364  
     private FieldDescriptor buildMuliplicityParentFieldDescriptor(String fieldKey, String messageKey, String parentPath) {
 365  0
         QueryPath path = QueryPath.concat(parentPath, fieldKey);
 366  0
         Metadata meta = modelDefinition.getMetadata(path);
 367  0
         FieldDescriptor fd = new FieldDescriptor(path.toString(), generateMessageInfo(messageKey), meta);
 368  0
         return fd;
 369  
     }
 370  
 
 371  
     private MultiplicityFieldConfiguration buildMultiplicityFD(
 372  
             String fieldKey, String labelKey, String parentPath) {
 373  
 
 374  0
         QueryPath fieldPath = QueryPath.concat(parentPath, QueryPath.getWildCard(), fieldKey);
 375  0
         Metadata meta = modelDefinition.getMetadata(fieldPath);
 376  
 
 377  0
         MultiplicityFieldConfiguration fd = new MultiplicityFieldConfiguration(
 378  
                 fieldPath.toString(), generateMessageInfo(labelKey), meta, null);
 379  
 
 380  
 
 381  0
         return fd;
 382  
 
 383  
     }
 384  
 
 385  
     protected MessageKeyInfo generateMessageInfo(String labelKey) {
 386  0
         return new MessageKeyInfo("groupName", "type", "state", labelKey);
 387  
     }
 388  
 
 389  
     private Widget createUploadForm() {
 390  0
             VerticalSection verticalSection = new VerticalSection();
 391  0
             MultiplicityConfiguration uploadFileMultiplicityConfig = setupMultiplicityConfig(
 392  
                     MultiplicityConfiguration.MultiplicityType.GROUP,
 393  
                     MultiplicityConfiguration.StyleType.TOP_LEVEL_GROUP,
 394  
                     "path", "Include More Files",
 395  
                     "File Name",
 396  
                     null,
 397  
                     null);
 398  0
         MultiplicitySection ms = null;
 399  0
         ms = new MultiplicitySection(uploadFileMultiplicityConfig);
 400  0
         verticalSection.addSection(ms);
 401  0
         verticalSection.getLayout().setWidth("350");
 402  
 
 403  0
         return verticalSection;
 404  
         }
 405  
 
 406  
     @Override
 407  
     protected Widget createWidget() {
 408  0
         SectionTitle viewTitle = SectionTitle.generateH2Title(getTitle());
 409  0
         viewTitle.addStyleName("ks-layout-header");
 410  
 
 411  0
         layout.add(viewTitle);
 412  0
         layout.add(saveWarning);
 413  0
         saveWarning.setVisible(false);
 414  0
         buttonPanel.setButtonText(OkEnum.Ok, "Upload");
 415  0
         buttonPanel.getButton(OkEnum.Ok).setStyleName(ButtonStyle.SECONDARY.getStyle());
 416  
 
 417  0
         uploadList.add(createUploadForm());
 418  0
         form.setWidget(uploadList);
 419  0
         form.setMethod(FormPanel.METHOD_POST);
 420  0
         form.setEncoding(FormPanel.ENCODING_MULTIPART);
 421  
 
 422  0
         buttonPanel.setContent(form);
 423  0
         if (showAllLink != null) {
 424  0
             layout.add(showAllLink);
 425  
         }
 426  0
         layout.add(buttonPanel);
 427  0
         layout.add(documentList);
 428  0
         documentList.setVisible(false);
 429  0
         buttonPanel.setVisible(false);
 430  
 
 431  0
         SectionTitle sectionTitle = SectionTitle.generateH2Title("Upload Status");
 432  0
         progressPanel.add(sectionTitle);
 433  0
         progressPanel.add(progressLabel);
 434  0
         progressPanel.add(progressBar);
 435  0
         progressPanel.add(fileProgressTable);
 436  0
         progressBar.setWidth("400px");
 437  0
         progressBar.setTextFormatter(new TextFormatter() {
 438  
 
 439  
             @Override
 440  
             protected String getText(ProgressBar bar, double curProgress) {
 441  
                 String result;
 442  0
                 NumberFormat nf = NumberFormat.getFormat("#.##");
 443  0
                 if (curProgress == bar.getMaxProgress()) {
 444  0
                     result = "Total Uploaded: " + nf.format(curProgress) + "kb";
 445  0
                 } else if (curProgress == 0 || bar.getMaxProgress() == 0) {
 446  0
                     result = "";
 447  
                 } else {
 448  
                     String curProgressString;
 449  
                     String maxProgressString;
 450  
 
 451  0
                     if (curProgress < 1024) {
 452  0
                         curProgressString = nf.format(curProgress) + "kb";
 453  
                     } else {
 454  0
                         curProgressString = nf.format(curProgress / 1024) + "mb";
 455  
                     }
 456  
 
 457  0
                     if (bar.getMaxProgress() < 1024) {
 458  0
                         maxProgressString = nf.format(bar.getMaxProgress()) + "kb";
 459  
                     } else {
 460  0
                         maxProgressString = nf.format((bar.getMaxProgress()) / 1024) + "mb";
 461  
                     }
 462  0
                     result = curProgressString + " out of " + maxProgressString;
 463  
                 }
 464  0
                 return result;
 465  
             }
 466  
         });
 467  0
         progressBar.setHeight("30px");
 468  0
         progressPanel.add(progressButtons);
 469  0
         progressPanel.setWidth("500px");
 470  0
         progressWindow.setWidget(progressPanel);
 471  0
         progressWindow.setSize(520, 270);
 472  
 
 473  0
         return layout;
 474  
     }
 475  
 
 476  
     private void resetUploadFormPanel() {
 477  0
         uploadList.clear();
 478  0
         uploadList.add(createUploadForm());
 479  0
     }
 480  
 
 481  
         private static class DocumentForm extends Composite{
 482  0
                 private KSLabel file = new KSLabel("File Name");
 483  0
                 private KSLabel description = new KSLabel("Description");
 484  0
                 private FileUpload upload = new FileUpload();
 485  0
                 private KSTextArea documentDescription = new KSTextArea();
 486  0
                 private FlexTable tableLayout = new FlexTable();
 487  
 
 488  0
                 public DocumentForm(){
 489  0
                         tableLayout.setWidget(0, 0, file);
 490  0
                         tableLayout.setWidget(0, 1, upload);
 491  0
                         upload.setName("uploadFile");
 492  0
                         tableLayout.setWidget(1, 0, description);
 493  0
                         tableLayout.setWidget(1, 1, documentDescription);
 494  0
                         documentDescription.setName("documentDescription");
 495  0
                         this.initWidget(tableLayout);
 496  0
                 }
 497  
         }
 498  
 
 499  
         public String getReferenceId() {
 500  0
                 return referenceId;
 501  
         }
 502  
 
 503  
         public void setReferenceId(String referenceId) {
 504  0
                 this.referenceId = referenceId;
 505  0
         }
 506  
 
 507  
         public String getReferenceTypeKey() {
 508  0
                 return referenceTypeKey;
 509  
         }
 510  
 
 511  
         public void setReferenceTypeKey(String referenceTypeKey) {
 512  0
                 this.referenceTypeKey = referenceTypeKey;
 513  0
         }
 514  
 
 515  
         public String getReferenceType() {
 516  0
                 return referenceType;
 517  
         }
 518  
 
 519  
         public void setReferenceType(String referenceType) {
 520  0
                 this.referenceType = referenceType;
 521  0
         }
 522  
 
 523  
         public String getReferenceState() {
 524  0
                 return referenceState;
 525  
         }
 526  
 
 527  
         public void setReferenceState(String referenceState) {
 528  0
                 this.referenceState = referenceState;
 529  0
         }
 530  
 
 531  
     @Override
 532  
     public void setVisible(boolean visible) {
 533  0
         super.setVisible(visible);
 534  0
         if (showAllLink == null){
 535  0
             isAuthorizedUploadDocuments();
 536  
         }
 537  0
     }
 538  
 
 539  
         private void refreshDocuments(){
 540  0
                 documentList.clear();
 541  0
         if(referenceId != null && !(referenceId.isEmpty())){
 542  0
                 documentList.add(loadingDocuments);
 543  
                 try {
 544  0
                         documentServiceAsync.getRefDocIdsForRef(refObjectTypeKey, referenceId, new KSAsyncCallback<List<RefDocRelationInfo>>(){
 545  
 
 546  
                                         @Override
 547  
                                         public void handleFailure(Throwable caught) {
 548  0
                                                 GWT.log("getRefDocIdsForRef failed", caught);
 549  0
                                                 documentList.remove(loadingDocuments);
 550  
 
 551  0
                                         }
 552  
 
 553  
                                         @Override
 554  
                                         public void onSuccess(List<RefDocRelationInfo> result) {
 555  0
                                                 documentList.clear();
 556  0
                                                 if(result != null && !(result.isEmpty())){
 557  0
                                                     documentList.add(new DocumentList(refObjectTypeKey, result, deleteCallback));
 558  
                                                 }
 559  0
                                                 documentList.remove(loadingDocuments);
 560  0
                                         }
 561  
                                 });
 562  0
                         } catch (Exception e) {
 563  0
                                 GWT.log("getRefDocIdsForRef failed", e);
 564  0
                         }
 565  
         }
 566  0
         }
 567  
 
 568  
         @Override
 569  
         public Image getImage() {
 570  0
                 return Theme.INSTANCE.getCommonImages().getDocumentIcon();
 571  
         }
 572  
 
 573  
     public DataModelDefinition getModelDefinition() {
 574  0
         return modelDefinition;
 575  
     }
 576  
 
 577  
     public void setModelDefinition(DataModelDefinition modelDefinition) {
 578  0
         this.modelDefinition = modelDefinition;
 579  0
     }
 580  
 
 581  
     public void setShowAllLink(Composite showAllLink) {
 582  0
         this.showAllLink = showAllLink;
 583  0
     }
 584  
 
 585  
     public void showShowAllLink(boolean show) {
 586  0
         this.showAllLink.setVisible(show);
 587  0
         if (show) {
 588  0
             saveWarning.setVisible(false);
 589  0
             buttonPanel.setVisible(false);
 590  0
             documentList.setVisible(false);
 591  
         } else {
 592  0
             isAuthorizedUploadDocuments();
 593  
         }
 594  0
     }
 595  
 
 596  
     @Override
 597  
     public void showExport(boolean show) {
 598  
     // TODO Auto-generated method stub
 599  
 
 600  0
     }
 601  
 
 602  
 }