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;
}
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);
}
Aggregations