use of elemental2.dom.File in project kie-wb-common by kiegroup.
the class DMNMarshallerImportsClientHelper method loadModels.
public void loadModels(final ServiceCallback<List<IncludedModel>> callback) {
final List<IncludedModel> models = new ArrayList<>();
dmnImportsContentService.getModelsURIs().then(items -> promises.all(Arrays.asList(items), file -> {
final String fileName = FileUtils.getFileName(file);
if (fileName.endsWith("." + DMNImportTypes.DMN.getFileExtension())) {
return dmnImportsContentService.loadFile(file).then(fileContent -> promises.create((success, failed) -> dmnImportsService.getWbDefinitions(fileContent, new ServiceCallback<Definitions>() {
@Override
public void onSuccess(final Definitions definitions) {
final String modelPackage = "";
final String namespace = definitions.getNamespace().getValue();
final String importType = DMNImportTypes.DMN.getDefaultNamespace();
final int drgElementCount = definitions.getDrgElement().size();
final int itemDefinitionCount = definitions.getItemDefinition().size();
models.add(new DMNIncludedModel(fileName, modelPackage, fileName, namespace, importType, drgElementCount, itemDefinitionCount));
success.onInvoke(promises.resolve());
}
@Override
public void onError(final ClientRuntimeError error) {
// Swallow. Since it must try to load other paths.
success.onInvoke(promises.resolve());
}
})));
}
if (fileName.endsWith("." + DMNImportTypes.PMML.getFileExtension())) {
return dmnImportsContentService.getPMMLDocumentMetadata(file).then(pmmlDocumentMetadata -> {
int modelCount = pmmlDocumentMetadata.getModels() != null ? pmmlDocumentMetadata.getModels().size() : 0;
models.add(new PMMLIncludedModel(fileName, "", fileName, DMNImportTypes.PMML.getDefaultNamespace(), modelCount));
return promises.resolve();
});
}
return promises.reject("Error: " + fileName + " is an invalid file. Only *.dmn and *.pmml are supported");
}).then(v -> {
callback.onSuccess(models);
return promises.resolve();
}));
}
use of elemental2.dom.File 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 elemental2.dom.File in project domino-ui-demo by DominoKit.
the class BreadcrumbViewImpl method breadcrumbWithBackground.
private void breadcrumbWithBackground() {
Row row = Row.create();
element.appendChild(row.addColumn(column.copy().addElement(Card.create("WITH MATERIAL DESIGN COLORS", "You can use material design colors").appendContent(Breadcrumb.create().setBackground(Background.PINK).addItem(" Home ", evt -> {
}).addItem(" Library ", evt -> {
}).asElement()).appendContent(Breadcrumb.create().setBackground(Background.CYAN).addItem(" Home ", evt -> {
}).addItem(" Library ", evt -> {
}).addItem(" Data ", evt -> {
}).asElement()).appendContent(Breadcrumb.create().setBackground(Background.TEAL).addItem(" Home ", evt -> {
}).addItem(" Library ", evt -> {
}).addItem(" Data ", evt -> {
}).addItem(" File ", evt -> {
}).asElement()).appendContent(Breadcrumb.create().setBackground(Background.ORANGE).addItem(" Home ", evt -> {
}).addItem(" Library ", evt -> {
}).addItem(" Data ", evt -> {
}).addItem(" File ", evt -> {
}).addItem(" Extensions ", evt -> {
}).asElement()).asElement())).asElement());
element.appendChild(row.addColumn(column.copy().addElement(Card.create("WITH ICONS & MATERIAL DESIGN COLORS").appendContent(Breadcrumb.create().setBackground(Background.PINK).addItem(Icons.ALL.home(), " Home ", evt -> {
}).addItem(Icons.ALL.library_books(), " Library ", evt -> {
}).asElement()).appendContent(Breadcrumb.create().setBackground(Background.CYAN).addItem(Icons.ALL.home(), " Home ", evt -> {
}).addItem(Icons.ALL.library_books(), " Library ", evt -> {
}).addItem(Icons.ALL.archive(), " Data ", evt -> {
}).asElement()).appendContent(Breadcrumb.create().setBackground(Background.TEAL).addItem(Icons.ALL.home(), " Home ", evt -> {
}).addItem(Icons.ALL.library_books(), " Library ", evt -> {
}).addItem(Icons.ALL.archive(), " Data ", evt -> {
}).addItem(Icons.ALL.attachment(), " File ", evt -> {
}).asElement()).appendContent(Breadcrumb.create().setBackground(Background.ORANGE).addItem(Icons.ALL.home(), " Home ", evt -> {
}).addItem(Icons.ALL.library_books(), " Library ", evt -> {
}).addItem(Icons.ALL.archive(), " Data ", evt -> {
}).addItem(Icons.ALL.attachment(), " File ", evt -> {
}).addItem(Icons.ALL.extension(), " Extensions ", evt -> {
}).asElement()).asElement())).asElement());
element.appendChild(Card.createCodeCard(CodeResource.INSTANCE.breadcrumbWithBackground()).asElement());
}
use of elemental2.dom.File in project domino-ui-demo by DominoKit.
the class BreadcrumbViewImpl method coloredBreadcrumb.
private void coloredBreadcrumb() {
Row row = Row.create();
element.appendChild(row.addColumn(column.copy().addElement(Card.create("WITH MATERIAL DESIGN COLORS", "You can use material design colors").appendContent(Breadcrumb.create().setColor(Color.PINK).addItem(" Home ", evt -> {
}).addItem(" Library ", evt -> {
}).asElement()).appendContent(Breadcrumb.create().setColor(Color.CYAN).addItem(" Home ", evt -> {
}).addItem(" Library ", evt -> {
}).addItem(" Data ", evt -> {
}).asElement()).appendContent(Breadcrumb.create().setColor(Color.TEAL).addItem(" Home ", evt -> {
}).addItem(" Library ", evt -> {
}).addItem(" Data ", evt -> {
}).addItem(" File ", evt -> {
}).asElement()).appendContent(Breadcrumb.create().setColor(Color.ORANGE).addItem(" Home ", evt -> {
}).addItem(" Library ", evt -> {
}).addItem(" Data ", evt -> {
}).addItem(" File ", evt -> {
}).addItem(" Extensions ", evt -> {
}).asElement()).asElement())).asElement());
element.appendChild(row.addColumn(column.copy().addElement(Card.create("WITH ICONS & MATERIAL DESIGN COLORS").appendContent(Breadcrumb.create().setColor(Color.PINK).addItem(Icons.ALL.home(), " Home ", evt -> {
}).addItem(Icons.ALL.library_books(), " Library ", evt -> {
}).asElement()).appendContent(Breadcrumb.create().setColor(Color.CYAN).addItem(Icons.ALL.home(), " Home ", evt -> {
}).addItem(Icons.ALL.library_books(), " Library ", evt -> {
}).addItem(Icons.ALL.archive(), " Data ", evt -> {
}).asElement()).appendContent(Breadcrumb.create().setColor(Color.TEAL).addItem(Icons.ALL.home(), " Home ", evt -> {
}).addItem(Icons.ALL.library_books(), " Library ", evt -> {
}).addItem(Icons.ALL.archive(), " Data ", evt -> {
}).addItem(Icons.ALL.attachment(), " File ", evt -> {
}).asElement()).appendContent(Breadcrumb.create().setColor(Color.ORANGE).addItem(Icons.ALL.home(), " Home ", evt -> {
}).addItem(Icons.ALL.library_books(), " Library ", evt -> {
}).addItem(Icons.ALL.archive(), " Data ", evt -> {
}).addItem(Icons.ALL.attachment(), " File ", evt -> {
}).addItem(Icons.ALL.extension(), " Extensions ", evt -> {
}).asElement()).asElement())).asElement());
element.appendChild(Card.createCodeCard(CodeResource.INSTANCE.coloredBreadcrumb()).asElement());
}
use of elemental2.dom.File in project kie-wb-common by kiegroup.
the class DocumentUploadTest method testDrop.
@Test
public void testDrop() {
Document doc = mock(Document.class);
when(doc.getId()).thenReturn(DOC_1);
when(doc.getName()).thenReturn(DOC_1);
when(doc.getSize()).thenReturn(1024);
when(doc.getLastModified()).thenReturn((double) System.currentTimeMillis());
File file = mock(File.class);
documentUpload.doUpload(doc, file);
verify(instance).get();
verify(view).addDocument(any());
List<DocumentPreview> previews = (List<DocumentPreview>) documentUpload.getCurrentPreviews();
Assertions.assertThat(previews).isNotNull().hasSize(1);
ArgumentCaptor<DocumentData> documentDataArgumentCaptor = ArgumentCaptor.forClass(DocumentData.class);
DocumentPreview preview = previews.get(0);
verify(preview).init(documentDataArgumentCaptor.capture());
DocumentData documentData = documentDataArgumentCaptor.getValue();
Assertions.assertThat(documentData).isNotNull().hasFieldOrPropertyWithValue("contentId", DOC_1).hasFieldOrPropertyWithValue("fileName", DOC_1).hasFieldOrPropertyWithValue("size", Long.valueOf(1024));
ArgumentCaptor<DocumentPreviewStateActionsHandler> handlerCaptor = ArgumentCaptor.forClass(DocumentPreviewStateActionsHandler.class);
verify(preview).setStateHandler(handlerCaptor.capture());
DocumentPreviewStateActionsHandler handler = handlerCaptor.getValue();
ArgumentCaptor<Command> startUploadCaptor = ArgumentCaptor.forClass(Command.class);
ArgumentCaptor<ParameterizedCommand> uploadResultCaptor = ArgumentCaptor.forClass(ParameterizedCommand.class);
verify(uploader).upload(eq(DOC_1), any(), startUploadCaptor.capture(), uploadResultCaptor.capture());
startUploadCaptor.getValue().execute();
verify(preview).setState(DocumentPreviewState.UPLOADING);
uploadResultCaptor.getValue().execute(false);
verify(preview).setState(DocumentPreviewState.ERROR);
DocumentPreviewStateAction action = ((List<DocumentPreviewStateAction>) handler.getCurrentStateActions()).get(1);
action.execute();
verify(uploader).remove(eq(DOC_1), any());
uploadResultCaptor.getValue().execute(true);
verify(preview).setState(DocumentPreviewState.UPLOADED);
}
Aggregations