Search in sources :

Example 1 with MorphProperty

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

the class AbstractMorphAdapter method getMorphProperties.

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

Example 2 with MorphProperty

use of org.kie.workbench.common.stunner.core.definition.morph.MorphProperty 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)2 MorphProperty (org.kie.workbench.common.stunner.core.definition.morph.MorphProperty)2 HasInheritance (org.kie.workbench.common.stunner.core.definition.adapter.binding.HasInheritance)1 MorphDefinition (org.kie.workbench.common.stunner.core.definition.morph.MorphDefinition)1 PropertyMorphDefinition (org.kie.workbench.common.stunner.core.definition.morph.PropertyMorphDefinition)1 PropertyType (org.kie.workbench.common.stunner.core.definition.property.PropertyType)1 DefinitionUtils (org.kie.workbench.common.stunner.core.util.DefinitionUtils)1