Search in sources :

Example 1 with BindableMorphAdapter

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

the class BPMNGraphObjectBuilderFactory method builderFor.

@Override
@SuppressWarnings("all")
public GraphObjectBuilder<?, ?> builderFor(final String oryxId) {
    if (oryxId == null) {
        throw new NullPointerException();
    }
    final Class<?> defClass = oryxManager.getMappingsManager().getDefinition(oryxId);
    if (null != defClass) {
        final String defId = oryxManager.getMappingsManager().getDefinitionId(oryxId);
        if (ServiceTask.class.equals(defClass)) {
            return new ServiceTaskNodeBuilder(defId, workItemDefinitionRegistries);
        }
        MorphAdapter<Object> morphAdapter = definitionManager.adapters().registry().getMorphAdapter(defClass);
        BindablePropertyMorphDefinition propertyMorphDefinition = null;
        if (null != morphAdapter) {
            final Iterable<MorphDefinition> morphDefinitions = ((BindableMorphAdapter<Object>) morphAdapter).getMorphDefinitionsForType(defClass);
            if (null != morphDefinitions && morphDefinitions.iterator().hasNext()) {
                for (MorphDefinition morphDefinition : morphDefinitions) {
                    if (morphDefinition instanceof BindablePropertyMorphDefinition) {
                        propertyMorphDefinition = (BindablePropertyMorphDefinition) morphDefinition;
                        break;
                    }
                }
            }
        }
        if (null != propertyMorphDefinition) {
            // Specific handle for morphing based on class inheritance.
            return new NodePropertyMorphBuilderImpl(defClass, propertyMorphDefinition);
        } else {
            Class<? extends ElementFactory> elementFactory = BackendDefinitionAdapter.getGraphFactory(defClass);
            if (isNodeFactory(elementFactory)) {
                return new NodeBuilderImpl(defClass, defId);
            } else if (isEdgeFactory(elementFactory)) {
                return new EdgeBuilderImpl(defClass);
            } else {
                throw new RuntimeException("No graph element found for definition with class [" + defClass.getName() + "]");
            }
        }
    }
    throw new DefinitionNotFoundException("No definition found for oryx stencil with id [" + oryxId + "]", oryxId);
}
Also used : BindablePropertyMorphDefinition(org.kie.workbench.common.stunner.core.definition.morph.BindablePropertyMorphDefinition) MorphDefinition(org.kie.workbench.common.stunner.core.definition.morph.MorphDefinition) BindablePropertyMorphDefinition(org.kie.workbench.common.stunner.core.definition.morph.BindablePropertyMorphDefinition) BindableMorphAdapter(org.kie.workbench.common.stunner.core.definition.adapter.BindableMorphAdapter) DefinitionNotFoundException(org.kie.workbench.common.stunner.core.definition.exception.DefinitionNotFoundException)

Aggregations

BindableMorphAdapter (org.kie.workbench.common.stunner.core.definition.adapter.BindableMorphAdapter)1 DefinitionNotFoundException (org.kie.workbench.common.stunner.core.definition.exception.DefinitionNotFoundException)1 BindablePropertyMorphDefinition (org.kie.workbench.common.stunner.core.definition.morph.BindablePropertyMorphDefinition)1 MorphDefinition (org.kie.workbench.common.stunner.core.definition.morph.MorphDefinition)1