Search in sources :

Example 1 with HasInheritance

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

the class NodePropertyMorphBuilderImpl method getDefinitionToBuild.

@Override
@SuppressWarnings("unchecked")
protected String getDefinitionToBuild(final BuilderContext context) {
    final String defaultDefinitionId = propertyMorphDefinition.getDefault();
    final String definitionId = BindableAdapterUtils.getDefinitionId(definitionClass);
    Collection<MorphProperty> mps = new LinkedList<MorphProperty>();
    // TODO: Iterate over all morph properties.
    final Iterable<MorphProperty> mps1 = propertyMorphDefinition.getMorphProperties(definitionId);
    if (mps1 != null && mps1.iterator().hasNext()) {
        mps.add(mps1.iterator().next());
    }
    DefinitionAdapter<Object> definitionAdapter = context.getDefinitionManager().adapters().registry().getDefinitionAdapter(definitionClass);
    String baseId = ((HasInheritance) definitionAdapter).getBaseType(definitionClass);
    if (null != baseId) {
        final Iterable<MorphProperty> mps2 = propertyMorphDefinition.getMorphProperties(baseId);
        if (mps2 != null && mps2.iterator().hasNext()) {
            mps.add(mps2.iterator().next());
        }
    }
    final MorphProperty morphProperty = mps.iterator().next();
    final Object defaultDefinition = context.getFactoryManager().newDefinition(defaultDefinitionId);
    final DefinitionUtils definitionUtils = new DefinitionUtils(context.getDefinitionManager(), context.getFactoryManager());
    final Object mp = definitionUtils.getProperty(defaultDefinition, morphProperty.getProperty());
    final PropertyType propertyType = context.getDefinitionManager().adapters().forProperty().getType(mp);
    final String oryxId = context.getOryxManager().getMappingsManager().getOryxPropertyId(mp.getClass());
    final String pRawValue = properties.get(oryxId);
    final Object pValue = context.getOryxManager().getPropertyManager().parse(mp, propertyType, pRawValue);
    return morphProperty.getMorphTarget(pValue);
}
Also used : HasInheritance(org.kie.workbench.common.stunner.core.definition.adapter.binding.HasInheritance) MorphProperty(org.kie.workbench.common.stunner.core.definition.morph.MorphProperty) DefinitionUtils(org.kie.workbench.common.stunner.core.util.DefinitionUtils) PropertyType(org.kie.workbench.common.stunner.core.definition.property.PropertyType) LinkedList(java.util.LinkedList)

Aggregations

LinkedList (java.util.LinkedList)1 HasInheritance (org.kie.workbench.common.stunner.core.definition.adapter.binding.HasInheritance)1 MorphProperty (org.kie.workbench.common.stunner.core.definition.morph.MorphProperty)1 PropertyType (org.kie.workbench.common.stunner.core.definition.property.PropertyType)1 DefinitionUtils (org.kie.workbench.common.stunner.core.util.DefinitionUtils)1