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