Search in sources :

Example 1 with File

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();
    }));
}
Also used : JSITInvocable(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITInvocable) Arrays(java.util.Arrays) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) PMMLDocumentMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata) JSITDMNElement(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDMNElement) Promises(org.uberfire.client.promise.Promises) JSITInputData(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITInputData) BuiltInTypeUtils.isBuiltInType(org.kie.workbench.common.dmn.api.editors.types.BuiltInTypeUtils.isBuiltInType) HashMap(java.util.HashMap) JSITDecision(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecision) Promise(elemental2.promise.Promise) ClientRuntimeError(org.kie.workbench.common.stunner.core.client.service.ClientRuntimeError) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) Inject(javax.inject.Inject) Js(jsinterop.base.Js) Map(java.util.Map) JSITDRGElement(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDRGElement) JSITDefinitions(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions) ServiceCallback(org.kie.workbench.common.stunner.core.client.service.ServiceCallback) DMNMarshallerImportsHelper(org.kie.workbench.common.dmn.api.marshalling.DMNMarshallerImportsHelper) JSITItemDefinition(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITItemDefinition) StringUtils.isEmpty(org.kie.workbench.common.stunner.core.util.StringUtils.isEmpty) DMNIncludedNode(org.kie.workbench.common.dmn.api.editors.included.DMNIncludedNode) PMMLIncludedModel(org.kie.workbench.common.dmn.api.editors.included.PMMLIncludedModel) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) JSITInformationItem(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITInformationItem) ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) Objects(java.util.Objects) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) FileUtils(org.kie.workbench.common.stunner.core.util.FileUtils) List(java.util.List) ImportedItemDefinitionPropertyConverter(org.kie.workbench.common.dmn.client.marshaller.converters.ImportedItemDefinitionPropertyConverter) JSITImport(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITImport) DMNImportTypes(org.kie.workbench.common.dmn.api.editors.included.DMNImportTypes) ImportedItemDefinitionPropertyConverter.withNamespace(org.kie.workbench.common.dmn.client.marshaller.converters.ImportedItemDefinitionPropertyConverter.withNamespace) Optional(java.util.Optional) DMNIncludedModel(org.kie.workbench.common.dmn.api.editors.included.DMNIncludedModel) IncludedModel(org.kie.workbench.common.dmn.api.editors.included.IncludedModel) QName(javax.xml.namespace.QName) Comparator(java.util.Comparator) Collections(java.util.Collections) PMMLIncludedModel(org.kie.workbench.common.dmn.api.editors.included.PMMLIncludedModel) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) JSITDefinitions(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions) ArrayList(java.util.ArrayList) ClientRuntimeError(org.kie.workbench.common.stunner.core.client.service.ClientRuntimeError) PMMLIncludedModel(org.kie.workbench.common.dmn.api.editors.included.PMMLIncludedModel) DMNIncludedModel(org.kie.workbench.common.dmn.api.editors.included.DMNIncludedModel) IncludedModel(org.kie.workbench.common.dmn.api.editors.included.IncludedModel) DMNIncludedModel(org.kie.workbench.common.dmn.api.editors.included.DMNIncludedModel)

Example 2 with File

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());
}
Also used : ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) ParameterizedCommand(org.uberfire.mvp.ParameterizedCommand) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) Arrays(java.util.Arrays) ManagedInstance(org.jboss.errai.ioc.client.api.ManagedInstance) Document(org.kie.workbench.common.forms.jbpm.client.rendering.documents.control.js.Document) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) HandlerRegistration(com.google.gwt.event.shared.HandlerRegistration) PreDestroy(javax.annotation.PreDestroy) DocumentData(org.kie.workbench.common.forms.jbpm.model.document.DocumentData) GwtEvent(com.google.gwt.event.shared.GwtEvent) IsWidget(com.google.gwt.user.client.ui.IsWidget) DocumentPreview(org.kie.workbench.common.forms.jbpm.client.rendering.documents.control.preview.DocumentPreview) Command(org.uberfire.mvp.Command) DocumentUploadManager(org.kie.workbench.common.forms.jbpm.client.rendering.documents.control.upload.DocumentUploadManager) TranslationService(org.jboss.errai.ui.client.local.spi.TranslationService) DocumentPreviewStateActionsHandlerImpl(org.kie.workbench.common.forms.jbpm.client.rendering.documents.control.preview.handlers.DocumentPreviewStateActionsHandlerImpl) Collection(java.util.Collection) File(elemental2.dom.File) DocumentPreviewStateAction(org.kie.workbench.common.forms.jbpm.client.rendering.documents.control.preview.DocumentPreviewStateAction) Collectors(java.util.stream.Collectors) Constants(org.kie.workbench.common.forms.jbpm.client.resources.i18n.Constants) List(java.util.List) Widget(com.google.gwt.user.client.ui.Widget) Dependent(javax.enterprise.context.Dependent) PostConstruct(javax.annotation.PostConstruct) DocumentPreviewState(org.kie.workbench.common.forms.jbpm.client.rendering.documents.control.preview.DocumentPreviewState) Collections(java.util.Collections) DocumentData(org.kie.workbench.common.forms.jbpm.model.document.DocumentData) DocumentPreview(org.kie.workbench.common.forms.jbpm.client.rendering.documents.control.preview.DocumentPreview) DocumentPreviewStateAction(org.kie.workbench.common.forms.jbpm.client.rendering.documents.control.preview.DocumentPreviewStateAction) ParameterizedCommand(org.uberfire.mvp.ParameterizedCommand) Command(org.uberfire.mvp.Command) DocumentPreviewStateActionsHandlerImpl(org.kie.workbench.common.forms.jbpm.client.rendering.documents.control.preview.handlers.DocumentPreviewStateActionsHandlerImpl)

Example 3 with File

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());
}
Also used : Icons(org.dominokit.domino.ui.icons.Icons) UiView(org.dominokit.domino.api.client.annotations.UiView) BreadcrumbPresenter(org.dominokit.domino.breadcrumb.client.presenters.BreadcrumbPresenter) ComponentView(org.dominokit.domino.componentcase.shared.extension.ComponentView) BreadcrumbView(org.dominokit.domino.breadcrumb.client.views.BreadcrumbView) Column(org.dominokit.domino.ui.column.Column) BlockHeader(org.dominokit.domino.ui.header.BlockHeader) Color(org.dominokit.domino.ui.style.Color) Row(org.dominokit.domino.ui.row.Row) Breadcrumb(org.dominokit.domino.ui.breadcrumbs.Breadcrumb) HTMLDivElement(elemental2.dom.HTMLDivElement) CodeResource(org.dominokit.domino.breadcrumb.client.views.CodeResource) Card(org.dominokit.domino.ui.cards.Card) Elements(org.jboss.gwt.elemento.core.Elements) Background(org.dominokit.domino.ui.style.Background) Row(org.dominokit.domino.ui.row.Row)

Example 4 with File

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());
}
Also used : Icons(org.dominokit.domino.ui.icons.Icons) UiView(org.dominokit.domino.api.client.annotations.UiView) BreadcrumbPresenter(org.dominokit.domino.breadcrumb.client.presenters.BreadcrumbPresenter) ComponentView(org.dominokit.domino.componentcase.shared.extension.ComponentView) BreadcrumbView(org.dominokit.domino.breadcrumb.client.views.BreadcrumbView) Column(org.dominokit.domino.ui.column.Column) BlockHeader(org.dominokit.domino.ui.header.BlockHeader) Color(org.dominokit.domino.ui.style.Color) Row(org.dominokit.domino.ui.row.Row) Breadcrumb(org.dominokit.domino.ui.breadcrumbs.Breadcrumb) HTMLDivElement(elemental2.dom.HTMLDivElement) CodeResource(org.dominokit.domino.breadcrumb.client.views.CodeResource) Card(org.dominokit.domino.ui.cards.Card) Elements(org.jboss.gwt.elemento.core.Elements) Background(org.dominokit.domino.ui.style.Background) Row(org.dominokit.domino.ui.row.Row)

Example 5 with File

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);
}
Also used : Document(org.kie.workbench.common.forms.jbpm.client.rendering.documents.control.js.Document) DocumentData(org.kie.workbench.common.forms.jbpm.model.document.DocumentData) DocumentPreviewStateActionsHandler(org.kie.workbench.common.forms.jbpm.client.rendering.documents.control.preview.DocumentPreviewStateActionsHandler) DocumentPreview(org.kie.workbench.common.forms.jbpm.client.rendering.documents.control.preview.DocumentPreview) DocumentPreviewStateAction(org.kie.workbench.common.forms.jbpm.client.rendering.documents.control.preview.DocumentPreviewStateAction) ParameterizedCommand(org.uberfire.mvp.ParameterizedCommand) Command(org.uberfire.mvp.Command) List(java.util.List) File(elemental2.dom.File) ParameterizedCommand(org.uberfire.mvp.ParameterizedCommand) Test(org.junit.Test)

Aggregations

List (java.util.List)3 File (elemental2.dom.File)2 HTMLDivElement (elemental2.dom.HTMLDivElement)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 Collectors (java.util.stream.Collectors)2 Inject (javax.inject.Inject)2 UiView (org.dominokit.domino.api.client.annotations.UiView)2 BreadcrumbPresenter (org.dominokit.domino.breadcrumb.client.presenters.BreadcrumbPresenter)2 BreadcrumbView (org.dominokit.domino.breadcrumb.client.views.BreadcrumbView)2 CodeResource (org.dominokit.domino.breadcrumb.client.views.CodeResource)2 ComponentView (org.dominokit.domino.componentcase.shared.extension.ComponentView)2 Breadcrumb (org.dominokit.domino.ui.breadcrumbs.Breadcrumb)2 Card (org.dominokit.domino.ui.cards.Card)2 Column (org.dominokit.domino.ui.column.Column)2 BlockHeader (org.dominokit.domino.ui.header.BlockHeader)2 Icons (org.dominokit.domino.ui.icons.Icons)2 Row (org.dominokit.domino.ui.row.Row)2 Background (org.dominokit.domino.ui.style.Background)2