use of org.kie.workbench.common.forms.jbpm.client.rendering.documents.control.preview.handlers.DocumentPreviewStateActionsHandlerImpl in project kie-wb-common by kiegroup.
the class DocumentUpload method doUpload.
@Override
public void doUpload(final Document document, File file) {
if (!enabled) {
return;
}
DocumentData documentData = new DocumentData(document.getId(), document.getName(), document.getSize(), document.getUrl(), (long) document.getLastModified());
DocumentPreview preview = render(documentData);
DocumentPreviewStateActionsHandlerImpl handler = new DocumentPreviewStateActionsHandlerImpl(DocumentPreviewState.PENDING);
DocumentPreviewStateAction abortAction = new DocumentPreviewStateAction(translationService.getTranslation(Constants.DocumentUploadViewImplAbort), () -> uploader.remove(document.getId(), () -> doRemove(preview)));
handler.addStateActions(DocumentPreviewState.UPLOADING, Collections.singletonList(abortAction));
DocumentPreviewStateAction removeAction = new DocumentPreviewStateAction(translationService.getTranslation(Constants.DocumentUploadViewImplRemove), () -> uploader.remove(document.getId(), () -> doRemove(preview)));
handler.addStateActions(DocumentPreviewState.PENDING, Collections.singletonList(removeAction));
handler.addStateActions(DocumentPreviewState.UPLOADED, Collections.singletonList(removeAction));
final Command startUploadCallback = () -> handler.notifyStateChange(DocumentPreviewState.UPLOADING);
final ParameterizedCommand<Boolean> onFinishUpload = success -> {
if (success) {
handler.notifyStateChange(DocumentPreviewState.UPLOADED);
} else {
handler.notifyStateChange(DocumentPreviewState.ERROR);
}
};
DocumentPreviewStateAction retryAction = new DocumentPreviewStateAction(translationService.getTranslation(Constants.DocumentUploadViewImplRetry), () -> {
uploader.remove(document.getId(), () -> uploader.upload(document.getId(), file, startUploadCallback, onFinishUpload));
});
handler.addStateActions(DocumentPreviewState.ERROR, Arrays.asList(removeAction, retryAction));
preview.setStateHandler(handler);
uploader.upload(document.getId(), file, startUploadCallback, onFinishUpload);
ValueChangeEvent.fire(DocumentUpload.this, getValue());
}
use of org.kie.workbench.common.forms.jbpm.client.rendering.documents.control.preview.handlers.DocumentPreviewStateActionsHandlerImpl in project kie-wb-common by kiegroup.
the class DocumentUpload method setValue.
@Override
public void setValue(List<DocumentData> value, boolean fireEvents) {
if (value == null) {
value = new ArrayList<>();
}
if (getValue().containsAll(value)) {
return;
}
this.clear();
value.forEach(documentData -> {
DocumentPreview preview = render(documentData);
DocumentPreviewStateActionsHandlerImpl handler = new DocumentPreviewStateActionsHandlerImpl(DocumentPreviewState.STORED);
DocumentPreviewStateAction action = new DocumentPreviewStateAction(translationService.getTranslation(Constants.DocumentUploadViewImplRemove), () -> doRemove(preview));
handler.addStateActions(DocumentPreviewState.STORED, Collections.singletonList(action));
preview.setStateHandler(handler);
});
if (fireEvents) {
ValueChangeEvent.fire(this, value);
}
}
Aggregations