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