Search in sources :

Example 1 with CommonDomainLookups

use of org.kie.workbench.common.stunner.core.lookup.domain.CommonDomainLookups in project kie-wb-common by kiegroup.

the class DMNFlowActionsToolboxFactory method getActions.

@Override
@SuppressWarnings("unchecked")
public Collection<ToolboxAction<AbstractCanvasHandler>> getActions(final AbstractCanvasHandler canvasHandler, final Element<?> element) {
    final Set<ToolboxAction<AbstractCanvasHandler>> actions = new LinkedHashSet<>();
    final Node<Definition<Object>, Edge> node = (Node<Definition<Object>, Edge>) element;
    final Diagram diagram = canvasHandler.getDiagram();
    final String defSetId = diagram.getMetadata().getDefinitionSetId();
    final CommonDomainLookups lookup = toolboxDomainLookups.get(defSetId);
    // Look for the allowed connectors present in the Definition Set.
    final Set<String> allowedConnectorIds = lookup.lookupTargetConnectors(node);
    for (final String allowedConnectorId : allowedConnectorIds) {
        // Append a new action for each connector.
        actions.add(createConnectorActions.get().setEdgeId(allowedConnectorId));
        // Append a new action for each candidate target node (as from the current connector).
        final Set<String> defIds = lookup.lookupTargetNodes(diagram.getGraph(), node, allowedConnectorId);
        defIds.forEach(definitionId -> actions.add(createNodeActions.get().setEdgeId(allowedConnectorId).setNodeId(definitionId)));
    }
    return actions;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ToolboxAction(org.kie.workbench.common.stunner.core.client.components.toolbox.actions.ToolboxAction) CreateNodeToolboxAction(org.kie.workbench.common.stunner.core.client.components.toolbox.actions.CreateNodeToolboxAction) CreateConnectorToolboxAction(org.kie.workbench.common.stunner.core.client.components.toolbox.actions.CreateConnectorToolboxAction) Node(org.kie.workbench.common.stunner.core.graph.Node) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) Edge(org.kie.workbench.common.stunner.core.graph.Edge) CommonDomainLookups(org.kie.workbench.common.stunner.core.lookup.domain.CommonDomainLookups) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram)

Example 2 with CommonDomainLookups

use of org.kie.workbench.common.stunner.core.lookup.domain.CommonDomainLookups in project kie-wb-common by kiegroup.

the class FlowActionsToolboxFactory method getActions.

@Override
@SuppressWarnings("unchecked")
public Collection<ToolboxAction<AbstractCanvasHandler>> getActions(final AbstractCanvasHandler canvasHandler, final Element<?> element) {
    final Diagram diagram = canvasHandler.getDiagram();
    final Metadata metadata = diagram.getMetadata();
    final String defSetId = metadata.getDefinitionSetId();
    final Annotation qualifier = definitionUtils.getQualifier(defSetId);
    final Node<Definition<Object>, Edge> node = (Node<Definition<Object>, Edge>) element;
    // Look for the default connector type and create a button for it.
    final CommonDomainLookups lookup = toolboxDomainLookups.get(defSetId);
    final Set<String> targetConnectors = lookup.lookupTargetConnectors(node);
    return Stream.concat(targetConnectors.stream().map(connectorDefId -> newCreateConnectorToolboxAction(qualifier).setEdgeId(connectorDefId)), targetConnectors.stream().flatMap(defaultConnectorId -> {
        final Predicate<String> definitionsAllowedFilter = profileManager.isDefinitionIdAllowed(metadata);
        final Set<String> targets = lookup.lookupTargetNodes(diagram.getGraph(), node, defaultConnectorId, definitionsAllowedFilter);
        final Set<String> morphTargets = lookup.lookupMorphBaseDefinitions(targets);
        return morphTargets.stream().map(defId -> newCreateNodeToolboxAction(qualifier).setEdgeId(defaultConnectorId).setNodeId(defId));
    })).collect(Collectors.toList());
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Annotation(java.lang.annotation.Annotation) CommonDomainLookups(org.kie.workbench.common.stunner.core.lookup.domain.CommonDomainLookups) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram)

Example 3 with CommonDomainLookups

use of org.kie.workbench.common.stunner.core.lookup.domain.CommonDomainLookups in project kie-wb-common by kiegroup.

the class AbstractAppendNodeShortcut method executeAction.

@Override
public void executeAction(final AbstractCanvasHandler canvasHandler, final String selectedNodeId) {
    final Node sourceNode = CanvasLayoutUtils.getElement(canvasHandler, selectedNodeId).asNode();
    final String definitionSetId = canvasHandler.getDiagram().getMetadata().getDefinitionSetId();
    final CommonDomainLookups commonDomainLookups = toolboxDomainLookups.get(definitionSetId);
    final Set<String> connectorDefinitionIds = commonDomainLookups.lookupTargetConnectors(sourceNode);
    for (final String connectorDefinitionId : connectorDefinitionIds) {
        final Set<String> targetNodesDefinitionIds = commonDomainLookups.lookupTargetNodes(canvasHandler.getDiagram().getGraph(), sourceNode, connectorDefinitionId);
        for (final String targetNodeDefinitionId : targetNodesDefinitionIds) {
            final Object definition = definitionsCacheRegistry.getDefinitionById(targetNodeDefinitionId);
            if (canAppendNodeOfDefinition(definition)) {
                generalCreateNodeAction.executeAction(canvasHandler, selectedNodeId, targetNodeDefinitionId, connectorDefinitionId);
                break;
            }
        }
    }
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) CommonDomainLookups(org.kie.workbench.common.stunner.core.lookup.domain.CommonDomainLookups)

Example 4 with CommonDomainLookups

use of org.kie.workbench.common.stunner.core.lookup.domain.CommonDomainLookups in project kie-wb-common by kiegroup.

the class ToolboxDomainLookups method get.

public CommonDomainLookups get(final String definitionSetId) {
    CommonDomainLookups lookup = domainLookups.get(definitionSetId);
    if (null == lookup) {
        lookup = domainLookupInstances.get();
        lookup.setDomain(definitionSetId);
        domainLookups.put(definitionSetId, lookup);
    }
    return lookup;
}
Also used : CommonDomainLookups(org.kie.workbench.common.stunner.core.lookup.domain.CommonDomainLookups)

Example 5 with CommonDomainLookups

use of org.kie.workbench.common.stunner.core.lookup.domain.CommonDomainLookups in project kie-wb-common by kiegroup.

the class ToolboxDomainLookupsTest method testGetCached.

@Test
public void testGetCached() {
    String dsId = "ds1";
    CommonDomainLookups lookups = tested.get(dsId);
    CommonDomainLookups lookups1 = tested.get(dsId);
    assertEquals(domainLookups, lookups);
    verify(domainLookups, times(1)).setDomain(eq(dsId));
}
Also used : CommonDomainLookups(org.kie.workbench.common.stunner.core.lookup.domain.CommonDomainLookups) Test(org.junit.Test)

Aggregations

CommonDomainLookups (org.kie.workbench.common.stunner.core.lookup.domain.CommonDomainLookups)5 Node (org.kie.workbench.common.stunner.core.graph.Node)3 Diagram (org.kie.workbench.common.stunner.core.diagram.Diagram)2 Edge (org.kie.workbench.common.stunner.core.graph.Edge)2 Definition (org.kie.workbench.common.stunner.core.graph.content.definition.Definition)2 Annotation (java.lang.annotation.Annotation)1 LinkedHashSet (java.util.LinkedHashSet)1 Test (org.junit.Test)1 CreateConnectorToolboxAction (org.kie.workbench.common.stunner.core.client.components.toolbox.actions.CreateConnectorToolboxAction)1 CreateNodeToolboxAction (org.kie.workbench.common.stunner.core.client.components.toolbox.actions.CreateNodeToolboxAction)1 ToolboxAction (org.kie.workbench.common.stunner.core.client.components.toolbox.actions.ToolboxAction)1 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)1