Search in sources :

Example 1 with Metadata

use of org.kie.workbench.common.stunner.core.diagram.Metadata in project kie-wb-common by kiegroup.

the class DMNMarshaller method unmarshall.

@Override
public Graph unmarshall(final Metadata metadata, final InputStream input) throws IOException {
    org.kie.dmn.model.v1_1.Definitions dmnXml = marshaller.unmarshal(new InputStreamReader(input));
    Map<String, Entry<org.kie.dmn.model.v1_1.DRGElement, Node>> elems = dmnXml.getDrgElement().stream().collect(Collectors.toMap(org.kie.dmn.model.v1_1.DRGElement::getId, dmn -> new SimpleEntry<>(dmn, dmnToStunner(dmn))));
    Optional<org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DMNDiagram> dmnDDDiagram = findDMNDiagram(dmnXml);
    for (Entry<org.kie.dmn.model.v1_1.DRGElement, Node> kv : elems.values()) {
        org.kie.dmn.model.v1_1.DRGElement elem = kv.getKey();
        Node currentNode = kv.getValue();
        ddExtAugmentStunner(dmnDDDiagram, currentNode);
        // DMN spec table 2: Requirements connection rules
        if (elem instanceof org.kie.dmn.model.v1_1.Decision) {
            org.kie.dmn.model.v1_1.Decision decision = (org.kie.dmn.model.v1_1.Decision) elem;
            for (org.kie.dmn.model.v1_1.InformationRequirement ir : decision.getInformationRequirement()) {
                if (ir.getRequiredInput() != null) {
                    String reqInputID = getId(ir.getRequiredInput());
                    Node requiredNode = elems.get(reqInputID).getValue();
                    Edge myEdge = factoryManager.newElement(UUID.uuid(), org.kie.workbench.common.dmn.api.definition.v1_1.InformationRequirement.class).asEdge();
                    connectEdge(myEdge, requiredNode, currentNode);
                    setConnectionMagnets(myEdge);
                }
                if (ir.getRequiredDecision() != null) {
                    String reqInputID = getId(ir.getRequiredDecision());
                    Node requiredNode = elems.get(reqInputID).getValue();
                    Edge myEdge = factoryManager.newElement(UUID.uuid(), org.kie.workbench.common.dmn.api.definition.v1_1.InformationRequirement.class).asEdge();
                    connectEdge(myEdge, requiredNode, currentNode);
                    setConnectionMagnets(myEdge);
                }
            }
            for (org.kie.dmn.model.v1_1.KnowledgeRequirement kr : decision.getKnowledgeRequirement()) {
                String reqInputID = getId(kr.getRequiredKnowledge());
                Node requiredNode = elems.get(reqInputID).getValue();
                Edge myEdge = factoryManager.newElement(UUID.uuid(), org.kie.workbench.common.dmn.api.definition.v1_1.KnowledgeRequirement.class).asEdge();
                connectEdge(myEdge, requiredNode, currentNode);
                setConnectionMagnets(myEdge);
            }
            for (org.kie.dmn.model.v1_1.AuthorityRequirement kr : decision.getAuthorityRequirement()) {
                String reqInputID = getId(kr.getRequiredAuthority());
                Node requiredNode = elems.get(reqInputID).getValue();
                Edge myEdge = factoryManager.newElement(UUID.uuid(), org.kie.workbench.common.dmn.api.definition.v1_1.AuthorityRequirement.class).asEdge();
                connectEdge(myEdge, requiredNode, currentNode);
                setConnectionMagnets(myEdge);
            }
        } else if (elem instanceof org.kie.dmn.model.v1_1.BusinessKnowledgeModel) {
            org.kie.dmn.model.v1_1.BusinessKnowledgeModel bkm = (org.kie.dmn.model.v1_1.BusinessKnowledgeModel) elem;
            for (org.kie.dmn.model.v1_1.KnowledgeRequirement kr : bkm.getKnowledgeRequirement()) {
                String reqInputID = getId(kr.getRequiredKnowledge());
                Node requiredNode = elems.get(reqInputID).getValue();
                Edge myEdge = factoryManager.newElement(UUID.uuid(), org.kie.workbench.common.dmn.api.definition.v1_1.KnowledgeRequirement.class).asEdge();
                connectEdge(myEdge, requiredNode, currentNode);
                setConnectionMagnets(myEdge);
            }
            for (org.kie.dmn.model.v1_1.AuthorityRequirement kr : bkm.getAuthorityRequirement()) {
                String reqInputID = getId(kr.getRequiredAuthority());
                Node requiredNode = elems.get(reqInputID).getValue();
                Edge myEdge = factoryManager.newElement(UUID.uuid(), org.kie.workbench.common.dmn.api.definition.v1_1.AuthorityRequirement.class).asEdge();
                connectEdge(myEdge, requiredNode, currentNode);
                setConnectionMagnets(myEdge);
            }
        } else if (elem instanceof org.kie.dmn.model.v1_1.KnowledgeSource) {
            org.kie.dmn.model.v1_1.KnowledgeSource ks = (org.kie.dmn.model.v1_1.KnowledgeSource) elem;
            for (org.kie.dmn.model.v1_1.AuthorityRequirement ir : ks.getAuthorityRequirement()) {
                if (ir.getRequiredInput() != null) {
                    String reqInputID = getId(ir.getRequiredInput());
                    Node requiredNode = elems.get(reqInputID).getValue();
                    Edge myEdge = factoryManager.newElement(UUID.uuid(), org.kie.workbench.common.dmn.api.definition.v1_1.AuthorityRequirement.class).asEdge();
                    connectEdge(myEdge, requiredNode, currentNode);
                    setConnectionMagnets(myEdge);
                }
                if (ir.getRequiredDecision() != null) {
                    String reqInputID = getId(ir.getRequiredDecision());
                    Node requiredNode = elems.get(reqInputID).getValue();
                    Edge myEdge = factoryManager.newElement(UUID.uuid(), org.kie.workbench.common.dmn.api.definition.v1_1.AuthorityRequirement.class).asEdge();
                    connectEdge(myEdge, requiredNode, currentNode);
                    setConnectionMagnets(myEdge);
                }
                if (ir.getRequiredAuthority() != null) {
                    String reqInputID = getId(ir.getRequiredAuthority());
                    Node requiredNode = elems.get(reqInputID).getValue();
                    Edge myEdge = factoryManager.newElement(UUID.uuid(), org.kie.workbench.common.dmn.api.definition.v1_1.AuthorityRequirement.class).asEdge();
                    connectEdge(myEdge, requiredNode, currentNode);
                    setConnectionMagnets(myEdge);
                }
            }
        }
    }
    Map<String, Node<View<TextAnnotation>, ?>> textAnnotations = dmnXml.getArtifact().stream().filter(org.kie.dmn.model.v1_1.TextAnnotation.class::isInstance).map(org.kie.dmn.model.v1_1.TextAnnotation.class::cast).collect(Collectors.toMap(org.kie.dmn.model.v1_1.TextAnnotation::getId, textAnnotationConverter::nodeFromDMN));
    textAnnotations.values().forEach(n -> ddExtAugmentStunner(dmnDDDiagram, n));
    List<org.kie.dmn.model.v1_1.Association> associations = dmnXml.getArtifact().stream().filter(org.kie.dmn.model.v1_1.Association.class::isInstance).map(org.kie.dmn.model.v1_1.Association.class::cast).collect(Collectors.toList());
    for (org.kie.dmn.model.v1_1.Association a : associations) {
        String sourceId = getId(a.getSourceRef());
        Node sourceNode = Optional.ofNullable(elems.get(sourceId)).map(Entry::getValue).orElse(textAnnotations.get(sourceId));
        String targetId = getId(a.getTargetRef());
        Node targetNode = Optional.ofNullable(elems.get(targetId)).map(Entry::getValue).orElse(textAnnotations.get(targetId));
        @SuppressWarnings("unchecked") Edge<View<Association>, ?> myEdge = (Edge<View<Association>, ?>) factoryManager.newElement(UUID.uuid(), Association.class).asEdge();
        Id id = new Id(a.getId());
        Description description = new Description(a.getDescription());
        Association definition = new Association(id, description);
        myEdge.getContent().setDefinition(definition);
        connectEdge(myEdge, sourceNode, targetNode);
        setConnectionMagnets(myEdge);
    }
    Graph graph = factoryManager.newDiagram("prova", BindableAdapterUtils.getDefinitionSetId(DMNDefinitionSet.class), metadata).getGraph();
    elems.values().stream().map(kv -> kv.getValue()).forEach(graph::addNode);
    textAnnotations.values().forEach(graph::addNode);
    @SuppressWarnings("unchecked") Node<View<DMNDiagram>, ?> dmnDiagramRoot = findDMNDiagramRoot(graph);
    Definitions definitionsStunnerPojo = DefinitionsConverter.wbFromDMN(dmnXml);
    dmnDiagramRoot.getContent().getDefinition().setDefinitions(definitionsStunnerPojo);
    elems.values().stream().map(kv -> kv.getValue()).forEach(node -> connectRootWithChild(dmnDiagramRoot, node));
    textAnnotations.values().stream().forEach(node -> connectRootWithChild(dmnDiagramRoot, node));
    return graph;
}
Also used : Arrays(java.util.Arrays) DecisionConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.DecisionConverter) Edge(org.kie.workbench.common.stunner.core.graph.Edge) KnowledgeSource(org.kie.workbench.common.dmn.api.definition.v1_1.KnowledgeSource) UUID(org.kie.workbench.common.stunner.core.util.UUID) EdgeImpl(org.kie.workbench.common.stunner.core.graph.impl.EdgeImpl) Definitions(org.kie.workbench.common.dmn.api.definition.v1_1.Definitions) TextAnnotationConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.TextAnnotationConverter) Bounds(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.org.omg.spec.CMMN_20151109_DC.Bounds) Map(java.util.Map) DMNDiagram(org.kie.workbench.common.dmn.api.definition.v1_1.DMNDiagram) ServerMarshalling(org.jboss.errai.marshalling.server.ServerMarshalling) BgColour(org.kie.workbench.common.dmn.api.property.background.BgColour) FactoryManager(org.kie.workbench.common.stunner.core.api.FactoryManager) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Height(org.kie.workbench.common.dmn.api.property.dimensions.Height) InputData(org.kie.workbench.common.dmn.api.definition.v1_1.InputData) DiagramMarshaller(org.kie.workbench.common.stunner.core.definition.service.DiagramMarshaller) BusinessKnowledgeModelConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.BusinessKnowledgeModelConverter) Child(org.kie.workbench.common.stunner.core.graph.content.relationship.Child) FontSet(org.kie.workbench.common.dmn.api.property.font.FontSet) Collectors(java.util.stream.Collectors) BorderColour(org.kie.workbench.common.dmn.api.property.background.BorderColour) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.v1_1.BusinessKnowledgeModel) List(java.util.List) Stream(java.util.stream.Stream) DDExtensionsRegister(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DDExtensionsRegister) Entry(java.util.Map.Entry) DMNMarshallerFactory(org.kie.dmn.backend.marshalling.v1_1.DMNMarshallerFactory) Optional(java.util.Optional) DMNShape(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DMNShape) ApplicationScoped(javax.enterprise.context.ApplicationScoped) Decision(org.kie.workbench.common.dmn.api.definition.v1_1.Decision) Node(org.kie.workbench.common.stunner.core.graph.Node) Width(org.kie.workbench.common.dmn.api.property.dimensions.Width) DMNDefinitionSet(org.kie.workbench.common.dmn.api.DMNDefinitionSet) RectangleDimensionsSet(org.kie.workbench.common.dmn.api.property.dimensions.RectangleDimensionsSet) DefinitionsConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.DefinitionsConverter) HashMap(java.util.HashMap) DiagramMetadataMarshaller(org.kie.workbench.common.stunner.core.definition.service.DiagramMetadataMarshaller) View(org.kie.workbench.common.stunner.core.graph.content.view.View) ColorUtils(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.ColorUtils) Inject(javax.inject.Inject) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) Bound(org.kie.workbench.common.stunner.core.graph.content.Bounds.Bound) DRGElement(org.kie.workbench.common.dmn.api.definition.v1_1.DRGElement) Description(org.kie.workbench.common.dmn.api.property.dmn.Description) StreamSupport(java.util.stream.StreamSupport) SimpleEntry(java.util.AbstractMap.SimpleEntry) BindableAdapterUtils(org.kie.workbench.common.stunner.core.definition.adapter.binding.BindableAdapterUtils) TextAnnotation(org.kie.workbench.common.dmn.api.definition.v1_1.TextAnnotation) XMLEncoderDiagramMetadataMarshaller(org.kie.workbench.common.stunner.core.backend.service.XMLEncoderDiagramMetadataMarshaller) BorderSize(org.kie.workbench.common.dmn.api.property.background.BorderSize) AssociationConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.AssociationConverter) BoundImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl) IOException(java.io.IOException) InputStreamReader(java.io.InputStreamReader) Association(org.kie.workbench.common.dmn.api.definition.v1_1.Association) BackgroundSet(org.kie.workbench.common.dmn.api.property.background.BackgroundSet) FontSetPropertyConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.FontSetPropertyConverter) InputDataConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.InputDataConverter) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) Consumer(java.util.function.Consumer) KnowledgeSourceConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.KnowledgeSourceConverter) Graph(org.kie.workbench.common.stunner.core.graph.Graph) MagnetConnection(org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection) DMNElement(org.kie.workbench.common.dmn.api.definition.v1_1.DMNElement) InputStream(java.io.InputStream) Node(org.kie.workbench.common.stunner.core.graph.Node) KnowledgeSource(org.kie.workbench.common.dmn.api.definition.v1_1.KnowledgeSource) DMNDiagram(org.kie.workbench.common.dmn.api.definition.v1_1.DMNDiagram) SimpleEntry(java.util.AbstractMap.SimpleEntry) Graph(org.kie.workbench.common.stunner.core.graph.Graph) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) DRGElement(org.kie.workbench.common.dmn.api.definition.v1_1.DRGElement) Description(org.kie.workbench.common.dmn.api.property.dmn.Description) Entry(java.util.Map.Entry) SimpleEntry(java.util.AbstractMap.SimpleEntry) Association(org.kie.workbench.common.dmn.api.definition.v1_1.Association) TextAnnotation(org.kie.workbench.common.dmn.api.definition.v1_1.TextAnnotation) InputStreamReader(java.io.InputStreamReader) Definitions(org.kie.workbench.common.dmn.api.definition.v1_1.Definitions) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Decision(org.kie.workbench.common.dmn.api.definition.v1_1.Decision) BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.v1_1.BusinessKnowledgeModel) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 2 with Metadata

use of org.kie.workbench.common.stunner.core.diagram.Metadata in project kie-wb-common by kiegroup.

the class AbstractProjectDiagramEditor method open.

@SuppressWarnings("unchecked")
protected void open(final ProjectDiagram diagram) {
    showLoadingViews();
    setOriginalHash(diagram.hashCode());
    final Metadata metadata = diagram.getMetadata();
    sessionManager.getSessionFactory(metadata, ClientFullSession.class).newSession(metadata, s -> {
        final AbstractClientFullSession session = (AbstractClientFullSession) s;
        presenter = sessionPresenterFactory.newPresenterEditor();
        getView().setWidget(presenter.getView());
        presenter.withToolbar(false).withPalette(true).displayNotifications(type -> true).open(diagram, session, new SessionPresenter.SessionPresenterCallback<AbstractClientFullSession, Diagram>() {

            @Override
            public void afterSessionOpened() {
            }

            @Override
            public void afterCanvasInitialized() {
            }

            @Override
            public void onSuccess() {
                bindCommands();
                updateTitle(diagram.getMetadata().getTitle());
                hideLoadingViews();
                setOriginalHash(getCurrentDiagramHash());
            }

            @Override
            public void onError(final ClientRuntimeError error) {
                onLoadError(error);
            }
        });
    });
}
Also used : CopySelectionSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.CopySelectionSessionCommand) ClearStatesSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.ClearStatesSessionCommand) ValidationUtils(org.kie.workbench.common.stunner.core.validation.impl.ValidationUtils) StunnerProjectClientConstants(org.kie.workbench.common.stunner.project.client.resources.i18n.StunnerProjectClientConstants) ChangeTitleWidgetEvent(org.uberfire.client.workbench.events.ChangeTitleWidgetEvent) ClientResourceType(org.uberfire.client.workbench.type.ClientResourceType) PathPlaceRequest(org.uberfire.mvp.impl.PathPlaceRequest) ClientRuntimeError(org.kie.workbench.common.stunner.core.client.service.ClientRuntimeError) AbstractClientFullSession(org.kie.workbench.common.stunner.core.client.session.impl.AbstractClientFullSession) KieEditorView(org.kie.workbench.common.widgets.metadata.client.KieEditorView) SessionPresenter(org.kie.workbench.common.stunner.client.widgets.presenters.session.SessionPresenter) ClientTranslationService(org.kie.workbench.common.stunner.core.client.i18n.ClientTranslationService) SessionCommandFactory(org.kie.workbench.common.stunner.core.client.session.command.impl.SessionCommandFactory) DiagramElementViolation(org.kie.workbench.common.stunner.core.validation.DiagramElementViolation) ProjectDiagram(org.kie.workbench.common.stunner.project.diagram.ProjectDiagram) ProjectMessagesListener(org.kie.workbench.common.stunner.project.client.screens.ProjectMessagesListener) Map(java.util.Map) Observes(javax.enterprise.event.Observes) PlaceGainFocusEvent(org.uberfire.client.workbench.events.PlaceGainFocusEvent) IsWidget(com.google.gwt.user.client.ui.IsWidget) UberView(org.uberfire.client.mvp.UberView) ClientFullSession(org.kie.workbench.common.stunner.core.client.session.ClientFullSession) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) ExportToPdfSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.ExportToPdfSessionCommand) OnSessionErrorEvent(org.kie.workbench.common.stunner.core.client.session.event.OnSessionErrorEvent) Collection(java.util.Collection) Violation(org.kie.workbench.common.stunner.core.validation.Violation) ClientProjectDiagramService(org.kie.workbench.common.stunner.project.client.service.ClientProjectDiagramService) YesNoCancelPopup(org.uberfire.ext.widgets.common.client.common.popups.YesNoCancelPopup) Menus(org.uberfire.workbench.model.menu.Menus) ClearSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.ClearSessionCommand) ClientSession(org.kie.workbench.common.stunner.core.client.session.ClientSession) Logger(java.util.logging.Logger) DeleteSelectionSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.DeleteSelectionSessionCommand) PlaceRequest(org.uberfire.mvp.PlaceRequest) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) Objects(java.util.Objects) LogConfiguration(com.google.gwt.logging.client.LogConfiguration) PasteSelectionSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.PasteSelectionSessionCommand) RedoSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.RedoSessionCommand) CutSelectionSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.CutSelectionSessionCommand) KieEditor(org.kie.workbench.common.widgets.metadata.client.KieEditor) ObservablePath(org.uberfire.backend.vfs.ObservablePath) UndoSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.UndoSessionCommand) ExportToPngSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.ExportToPngSessionCommand) PostConstruct(javax.annotation.PostConstruct) ExportToBpmnSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.ExportToBpmnSessionCommand) ValidateSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.ValidateSessionCommand) CanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.CanvasHandler) ErrorPopupPresenter(org.uberfire.client.workbench.widgets.common.ErrorPopupPresenter) HashMap(java.util.HashMap) SavePopUpPresenter(org.uberfire.ext.editor.commons.client.file.popups.SavePopUpPresenter) PlaceManager(org.uberfire.client.mvp.PlaceManager) VisitGraphSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.VisitGraphSessionCommand) Shape(org.kie.workbench.common.stunner.core.client.shape.Shape) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) Inject(javax.inject.Inject) AbstractPlaceEvent(org.uberfire.client.workbench.events.AbstractPlaceEvent) MenuItem(org.uberfire.workbench.model.menu.MenuItem) ClientSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.ClientSessionCommand) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) DiagramClientErrorHandler(org.kie.workbench.common.stunner.core.client.error.DiagramClientErrorHandler) CommonConstants(org.kie.workbench.common.widgets.client.resources.i18n.CommonConstants) SessionPresenterFactory(org.kie.workbench.common.stunner.client.widgets.presenters.session.SessionPresenterFactory) AbstractClientReadOnlySession(org.kie.workbench.common.stunner.core.client.session.impl.AbstractClientReadOnlySession) SessionManager(org.kie.workbench.common.stunner.core.client.api.SessionManager) ServiceCallback(org.kie.workbench.common.stunner.core.client.service.ServiceCallback) Command(org.uberfire.mvp.Command) FINE(java.util.logging.Level.FINE) Event(javax.enterprise.event.Event) PlaceHiddenEvent(org.uberfire.client.workbench.events.PlaceHiddenEvent) OnDiagramFocusEvent(org.kie.workbench.common.stunner.project.client.editor.event.OnDiagramFocusEvent) ExportToJpgSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.ExportToJpgSessionCommand) HashUtil(org.kie.workbench.common.stunner.core.util.HashUtil) OnDiagramLoseFocusEvent(org.kie.workbench.common.stunner.project.client.editor.event.OnDiagramLoseFocusEvent) FileMenuBuilder(org.kie.workbench.common.widgets.client.menu.FileMenuBuilder) SwitchGridSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.SwitchGridSessionCommand) AbstractClientFullSession(org.kie.workbench.common.stunner.core.client.session.impl.AbstractClientFullSession) ClientFullSession(org.kie.workbench.common.stunner.core.client.session.ClientFullSession) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) ClientRuntimeError(org.kie.workbench.common.stunner.core.client.service.ClientRuntimeError) AbstractClientFullSession(org.kie.workbench.common.stunner.core.client.session.impl.AbstractClientFullSession) SessionPresenter(org.kie.workbench.common.stunner.client.widgets.presenters.session.SessionPresenter) ProjectDiagram(org.kie.workbench.common.stunner.project.diagram.ProjectDiagram) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram)

Example 3 with Metadata

use of org.kie.workbench.common.stunner.core.diagram.Metadata in project kie-wb-common by kiegroup.

the class ExpandedPaletteDefinitionBuilder method createItem.

@Override
protected DefaultPaletteItem createItem(final Object definition, final String categoryId, final Metadata metadata, final Function<String, DefaultPaletteItem> itemSupplier) {
    final DefinitionAdapter<Object> definitionAdapter = getDefinitionManager().adapters().forDefinition();
    final String id = definitionAdapter.getId(definition);
    DefaultPaletteCategory result = null;
    DefaultPaletteCategory category = (DefaultPaletteCategory) itemSupplier.apply(categoryId);
    if (null == category) {
        final int catPriority = getItemPriority(categoryId);
        final String catDefId = categoryDefinitionIdProvider.apply(categoryId);
        final String catTitle = categoryMessageProvider.getTitle(categoryId);
        final String catDesc = categoryMessageProvider.getDescription(categoryId);
        final Glyph categoryGlyph = categoryGlyphProvider.apply(categoryId);
        category = new CategoryBuilder().setPriority(catPriority).setItemId(categoryId).setDefinitionId(catDefId).setTitle(catTitle).setDescription(catDesc).setTooltip(catTitle).setGlyph(categoryGlyph).build();
        result = category;
    }
    final MorphDefinition morphDefinition = morphDefinitionProvider.apply(definition);
    final boolean hasMorphBase = null != morphDefinition;
    String morphDefault = null;
    DefaultPaletteGroup group = null;
    if (hasMorphBase) {
        final String morphBaseId = morphDefinition.getBase();
        if (groupFilter.test(morphBaseId)) {
            morphDefault = morphDefinition.getDefault();
            final Optional<DefaultPaletteItem> groupOp = category.getItems().stream().filter(g -> g.getId().equals(morphBaseId)).findFirst();
            if (!groupOp.isPresent()) {
                final int groupPriority = getItemPriority(morphBaseId);
                final String groupTitle = groupMessageProvider.getTitle(morphBaseId);
                final String groupDesc = groupMessageProvider.getDescription(morphBaseId);
                group = new GroupBuilder().setPriority(groupPriority).setItemId(morphBaseId).setDefinitionId(morphDefault).setTitle(groupTitle).setDescription(groupDesc).build();
                category.getItems().add(group);
            } else {
                group = (DefaultPaletteGroup) groupOp.get();
            }
        }
    } else {
        // item has no morph base, but might belong to a custom group
        final String customGroupId = customGroupIdProvider != null ? customGroupIdProvider.apply(id) : null;
        if (customGroupId != null && groupFilter.test(customGroupId)) {
            final Optional<DefaultPaletteItem> groupOp = category.getItems().stream().filter(g -> g.getId().equals(customGroupId)).findFirst();
            if (!groupOp.isPresent()) {
                final int groupPriority = getItemPriority(customGroupId);
                final String groupTitle = customGroupMessageProvider.getTitle(customGroupId);
                final String groupDesc = groupMessageProvider.getDescription(customGroupId);
                group = new GroupBuilder().setPriority(groupPriority).setItemId(customGroupId).setTitle(groupTitle).setDescription(groupDesc).build();
                category.getItems().add(group);
            } else {
                group = (DefaultPaletteGroup) groupOp.get();
            }
        }
    }
    final int itemPriority = getItemPriority(id);
    final String title = definitionAdapter.getTitle(definition);
    final String description = definitionAdapter.getDescription(definition);
    final DefaultPaletteItem item = new ItemBuilder().setPriority(itemPriority).setItemId(id).setDefinitionId(id).setTitle(title).setDescription(description).build();
    if (null != group) {
        if (null != morphDefault && morphDefault.equals(id)) {
            group.getItems().add(0, item);
        } else {
            group.getItems().add(item);
        }
    } else {
        category.getItems().add(item);
    }
    return result;
}
Also used : Default(javax.enterprise.inject.Default) DefinitionUtils(org.kie.workbench.common.stunner.core.util.DefinitionUtils) StunnerTranslationService(org.kie.workbench.common.stunner.core.i18n.StunnerTranslationService) Predicate(java.util.function.Predicate) GroupBuilder(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinitionBuilders.GroupBuilder) ItemBuilder(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinitionBuilders.ItemBuilder) Function(java.util.function.Function) ClientFactoryService(org.kie.workbench.common.stunner.core.client.service.ClientFactoryService) MorphDefinition(org.kie.workbench.common.stunner.core.definition.morph.MorphDefinition) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) Inject(javax.inject.Inject) DefinitionAdapter(org.kie.workbench.common.stunner.core.definition.adapter.DefinitionAdapter) DefaultMorphGroupMessageProvider(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinitionProviders.DefaultMorphGroupMessageProvider) Glyph(org.kie.workbench.common.stunner.core.definition.shape.Glyph) Dependent(javax.enterprise.context.Dependent) Optional(java.util.Optional) DefaultMessageProvider(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinitionProviders.DefaultMessageProvider) CategoryBuilder(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinitionBuilders.CategoryBuilder) MorphDefinition(org.kie.workbench.common.stunner.core.definition.morph.MorphDefinition) GroupBuilder(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinitionBuilders.GroupBuilder) ItemBuilder(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinitionBuilders.ItemBuilder) CategoryBuilder(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinitionBuilders.CategoryBuilder) Glyph(org.kie.workbench.common.stunner.core.definition.shape.Glyph)

Example 4 with Metadata

use of org.kie.workbench.common.stunner.core.diagram.Metadata in project kie-wb-common by kiegroup.

the class StunnerClientLogger method logSessionInfo.

public static void logSessionInfo(final AbstractClientSession session) {
    log("************ Session Info ****************");
    if (null != session) {
        log("Session = " + session.toString());
        log("Canvas = " + session.getCanvas().toString());
        if (null != session.getCanvasHandler()) {
            final CanvasHandler canvasHandler = session.getCanvasHandler();
            log("CanvasHandler = " + canvasHandler.toString());
            final Diagram diagram = canvasHandler.getDiagram();
            if (null != diagram) {
                log("Diagram name = " + diagram.getName());
                log("Graph uuid = " + (null != diagram.getGraph() ? diagram.getGraph().getUUID() : "null"));
                final Metadata metadata = diagram.getMetadata();
                if (null != metadata) {
                    log("Metadata defSetId = " + metadata.getDefinitionSetId());
                    log("Metadata shapeSetId = " + metadata.getShapeSetId());
                    log("Metadata canvas root = " + metadata.getCanvasRootUUID());
                    log("Metadata title = " + metadata.getTitle());
                } else {
                    log("Metadata = null");
                }
            } else {
                log("Diagram = null");
            }
        } else {
            log("CanvasHandler = null");
        }
        if (session instanceof ClientFullSession) {
            logFullSessionInfo((ClientFullSession) session);
        }
    } else {
        log("Session is null");
    }
    log("******************************************");
}
Also used : AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) CanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.CanvasHandler) ClientFullSession(org.kie.workbench.common.stunner.core.client.session.ClientFullSession) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram)

Example 5 with Metadata

use of org.kie.workbench.common.stunner.core.diagram.Metadata in project kie-wb-common by kiegroup.

the class MapSelectionControlTest method setup.

@Before
@SuppressWarnings("unchecked")
public void setup() throws Exception {
    ShapeViewExtStub shapeView = new ShapeViewExtStub(shapeEventHandler, hasControlPoints);
    when(element.getUUID()).thenReturn(ELEMENT_UUID);
    when(element.getContent()).thenReturn(new ViewImpl<>(definition, BoundsImpl.build(0, 0, 10, 10)));
    when(canvasHandler.getDiagram()).thenReturn(diagram);
    when(diagram.getMetadata()).thenReturn(metadata);
    when(metadata.getCanvasRootUUID()).thenReturn(ROOT_UUID);
    when(canvasHandler.getCanvas()).thenReturn(canvas);
    when(canvas.getLayer()).thenReturn(layer);
    when(canvas.getShape(eq(ELEMENT_UUID))).thenReturn(shape);
    when(canvas.getShapes()).thenReturn(Collections.singletonList(shape));
    when(shape.getUUID()).thenReturn(ELEMENT_UUID);
    when(shape.getShapeView()).thenReturn(shapeView);
    when(shapeEventHandler.supports(eq(ViewEventType.MOUSE_CLICK))).thenReturn(true);
    this.tested = new MapSelectionControl(e -> elementSelectedEvent.fire((CanvasSelectionEvent) e), e -> clearSelectionEvent.fire((CanvasClearSelectionEvent) e));
    this.tested.setReadonly(false);
}
Also used : CanvasClearSelectionEvent(org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasClearSelectionEvent) HasEventHandlers(org.kie.workbench.common.stunner.core.client.shape.view.HasEventHandlers) ViewHandler(org.kie.workbench.common.stunner.core.client.shape.view.event.ViewHandler) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) HasControlPoints(org.kie.workbench.common.stunner.core.client.shape.view.HasControlPoints) AbstractCanvas(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvas) ViewImpl(org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl) Shape(org.kie.workbench.common.stunner.core.client.shape.Shape) Layer(org.kie.workbench.common.stunner.core.client.canvas.Layer) CanvasSelectionEvent(org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasSelectionEvent) ArgumentCaptor(org.mockito.ArgumentCaptor) Matchers.eq(org.mockito.Matchers.eq) CanvasShapeRemovedEvent(org.kie.workbench.common.stunner.core.client.canvas.event.registration.CanvasShapeRemovedEvent) ShapeState(org.kie.workbench.common.stunner.core.client.shape.ShapeState) Element(org.kie.workbench.common.stunner.core.graph.Element) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Before(org.junit.Before) ViewEventType(org.kie.workbench.common.stunner.core.client.shape.view.event.ViewEventType) BoundsImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl) Mockito.atLeastOnce(org.mockito.Mockito.atLeastOnce) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) MouseClickHandler(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickHandler) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) ShapeView(org.kie.workbench.common.stunner.core.client.shape.view.ShapeView) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) Mockito.verify(org.mockito.Mockito.verify) Matchers.any(org.mockito.Matchers.any) MouseClickEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent) Mockito.never(org.mockito.Mockito.never) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) Assert.assertFalse(org.junit.Assert.assertFalse) ShapeViewExtStub(org.kie.workbench.common.stunner.core.client.shape.ShapeViewExtStub) EventSourceMock(org.uberfire.mocks.EventSourceMock) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) ShapeViewExtStub(org.kie.workbench.common.stunner.core.client.shape.ShapeViewExtStub) Before(org.junit.Before)

Aggregations

Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)175 Graph (org.kie.workbench.common.stunner.core.graph.Graph)158 Test (org.junit.Test)156 Matchers.anyString (org.mockito.Matchers.anyString)53 View (org.kie.workbench.common.stunner.core.graph.content.view.View)32 AssignmentsInfo (org.kie.workbench.common.stunner.bpmn.definition.property.dataio.AssignmentsInfo)30 ItemAwareElement (org.eclipse.bpmn2.ItemAwareElement)28 RootElement (org.eclipse.bpmn2.RootElement)28 DataIOSet (org.kie.workbench.common.stunner.bpmn.definition.property.dataio.DataIOSet)28 Element (org.kie.workbench.common.stunner.core.graph.Element)27 FlowElement (org.eclipse.bpmn2.FlowElement)26 Diagram (org.kie.workbench.common.stunner.core.diagram.Diagram)16 UserTask (org.kie.workbench.common.stunner.bpmn.definition.UserTask)14 Edge (org.kie.workbench.common.stunner.core.graph.Edge)14 BPMNGeneralSet (org.kie.workbench.common.stunner.bpmn.definition.property.general.BPMNGeneralSet)11 StartErrorEvent (org.kie.workbench.common.stunner.bpmn.definition.StartErrorEvent)10 MessageRef (org.kie.workbench.common.stunner.bpmn.definition.property.event.message.MessageRef)10 StartSignalEvent (org.kie.workbench.common.stunner.bpmn.definition.StartSignalEvent)9 StartTimerEvent (org.kie.workbench.common.stunner.bpmn.definition.StartTimerEvent)9 Node (org.kie.workbench.common.stunner.core.graph.Node)9