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