Search in sources :

Example 11 with MorphDefinition

use of org.kie.workbench.common.stunner.core.definition.morph.MorphDefinition in project kie-wb-common by kiegroup.

the class MorphActionsToolboxFactory method getActions.

@Override
@SuppressWarnings("unchecked")
public Collection<ToolboxAction<AbstractCanvasHandler>> getActions(final AbstractCanvasHandler canvasHandler, final Element<?> e) {
    final Set<ToolboxAction<AbstractCanvasHandler>> actions = new LinkedHashSet<>();
    if (null != e.asNode()) {
        final Element<? extends Definition<?>> element = (Element<? extends Definition<?>>) e;
        final Object definition = element.getContent().getDefinition();
        if (definitionUtils.hasMorphTargets(definition)) {
            final String id = getDefinitionManager().adapters().forDefinition().getId(definition).value();
            final MorphAdapter<Object> morphAdapter = getDefinitionManager().adapters().registry().getMorphAdapter(definition.getClass());
            final Iterable<MorphDefinition> morphDefinitions = morphAdapter.getMorphDefinitions(definition);
            if (null != morphDefinitions && morphDefinitions.iterator().hasNext()) {
                final Metadata metadata = canvasHandler.getDiagram().getMetadata();
                final Predicate<String> definitionsAllowedFilter = profileManager.isDefinitionIdAllowed(metadata);
                final Map<String, MorphDefinition> definitionMap = new LinkedHashMap<>();
                for (final MorphDefinition morphDefinition : morphDefinitions) {
                    final Iterable<String> morphTargets = morphAdapter.getTargets(definition, morphDefinition);
                    if (null != morphTargets && morphTargets.iterator().hasNext()) {
                        for (final String morphTarget : morphTargets) {
                            if (!id.equals(morphTarget) && definitionsAllowedFilter.test(morphTarget)) {
                                definitionMap.put(morphTarget, morphDefinition);
                            }
                        }
                    }
                }
                // Create a morph toolbox action for each target morph candidate.
                definitionMap.forEach((targetMorphId, morphDefinition) -> actions.add(morphNodeActions.get().setMorphDefinition(morphDefinition).setTargetDefinitionId(targetMorphId)));
            }
        }
    }
    return actions;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MorphDefinition(org.kie.workbench.common.stunner.core.definition.morph.MorphDefinition) Element(org.kie.workbench.common.stunner.core.graph.Element) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) MorphDefinition(org.kie.workbench.common.stunner.core.definition.morph.MorphDefinition) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) LinkedHashMap(java.util.LinkedHashMap)

Example 12 with MorphDefinition

use of org.kie.workbench.common.stunner.core.definition.morph.MorphDefinition in project kie-wb-common by kiegroup.

the class AbstractMorphAdapter method getTargets.

protected Iterable<String> getTargets(final Class<?> type, final String definitionId, final String baseId) {
    if (null != definitionId) {
        final List<String> result = new LinkedList<>();
        for (MorphDefinition morphDefinition : morphDefinitions) {
            final boolean acceptsDefinition = morphDefinition.accepts(definitionId) || (null != baseId && morphDefinition.accepts(baseId));
            if (acceptsDefinition) {
                final Iterable<String> t1 = morphDefinition.getTargets(definitionId);
                addAll(result, t1);
                if (null != baseId) {
                    final Iterable<String> t2 = morphDefinition.getTargets(baseId);
                    addAll(result, t2);
                }
            }
        }
        return result;
    }
    return null;
}
Also used : PropertyMorphDefinition(org.kie.workbench.common.stunner.core.definition.morph.PropertyMorphDefinition) MorphDefinition(org.kie.workbench.common.stunner.core.definition.morph.MorphDefinition) LinkedList(java.util.LinkedList)

Aggregations

MorphDefinition (org.kie.workbench.common.stunner.core.definition.morph.MorphDefinition)12 LinkedList (java.util.LinkedList)5 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)5 ArrayList (java.util.ArrayList)3 BPMNDefinitionSet (org.kie.workbench.common.stunner.bpmn.BPMNDefinitionSet)3 BPMNDiagramMarshaller (org.kie.workbench.common.stunner.bpmn.backend.BPMNDiagramMarshaller)3 BPMNGraphObjectBuilderFactory (org.kie.workbench.common.stunner.bpmn.backend.marshall.json.builder.BPMNGraphObjectBuilderFactory)3 Bpmn2OryxIdMappings (org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.Bpmn2OryxIdMappings)3 Bpmn2OryxManager (org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.Bpmn2OryxManager)3 AssignmentsTypeSerializer (org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.AssignmentsTypeSerializer)3 BooleanTypeSerializer (org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.BooleanTypeSerializer)3 Bpmn2OryxPropertyManager (org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.Bpmn2OryxPropertyManager)3 Bpmn2OryxPropertySerializer (org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.Bpmn2OryxPropertySerializer)3 ColorTypeSerializer (org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.ColorTypeSerializer)3 DoubleTypeSerializer (org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.DoubleTypeSerializer)3 EnumTypeSerializer (org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.EnumTypeSerializer)3 IntegerTypeSerializer (org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.IntegerTypeSerializer)3 ScriptTypeListTypeSerializer (org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.ScriptTypeListTypeSerializer)3 ScriptTypeTypeSerializer (org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.ScriptTypeTypeSerializer)3 StringTypeSerializer (org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.StringTypeSerializer)3