use of org.kie.workbench.common.stunner.core.definition.adapter.DefinitionId in project kie-wb-common by kiegroup.
the class AbstractElementFactory method computeLabels.
public static <T> String[] computeLabels(final DefinitionAdapter<T> adapter, final T definition) {
final Set<String> target = new HashSet<>();
final DefinitionId id = adapter.getId(definition);
target.add(id.value());
if (id.isDynamic()) {
target.add(id.type());
}
String[] labels = adapter.getLabels(definition);
if (null != labels) {
for (String label : labels) {
target.add(label);
}
}
return target.toArray(new String[target.size()]);
}
use of org.kie.workbench.common.stunner.core.definition.adapter.DefinitionId in project kie-wb-common by kiegroup.
the class BackendDefinitionAdapter method getId.
@Override
public DefinitionId getId(final T definition) {
final String definitionId = getDefinitionId(definition.getClass());
final Id idAnn = getClassAnnotation(definition.getClass(), Id.class);
if (null != idAnn) {
try {
final String value = BindableAdapterUtils.getDynamicDefinitionId(definitionId, getAnnotatedFieldValue(definition, Id.class));
return DefinitionId.build(value, definitionId.length());
} catch (Exception e) {
LOG.error("Error obtaining annotated id for Definition " + definition.getClass().getName());
}
}
return DefinitionId.build(definitionId);
}
use of org.kie.workbench.common.stunner.core.definition.adapter.DefinitionId in project kie-wb-common by kiegroup.
the class BindableDefinitionAdapterImplTest method testGetId.
@Test
public void testGetId() {
DefinitionId id = tested.getId(BEAN1);
assertTrue(id.isDynamic());
assertEquals(BEAN1.getClass().getName(), id.value());
}
use of org.kie.workbench.common.stunner.core.definition.adapter.DefinitionId in project kie-wb-common by kiegroup.
the class CloneConnectorCommand method initialize.
@Override
@SuppressWarnings("unchecked")
protected CloneConnectorCommand initialize(final GraphCommandExecutionContext context) {
super.initialize(context);
this.sourceNode = (Node<? extends View<?>, Edge>) getNode(context, sourceNodeUUID);
this.targetNode = (Node<? extends View<?>, Edge>) getNode(context, targetNodeUUID);
if (!(candidate.getContent() instanceof ViewConnector)) {
throw new IllegalArgumentException("Candidate: " + candidate.getTargetNode() + " content should be a ViewConnector");
}
// clone candidate
ViewConnector edgeContent = (ViewConnector) candidate.getContent();
final Object bean = edgeContent.getDefinition();
final DefinitionId definitionId = context.getDefinitionManager().adapters().forDefinition().getId(bean);
clone = context.getFactoryManager().newElement(UUID.uuid(), definitionId.value()).asEdge();
// Cloning the candidate content with properties
Object clonedDefinition = context.getDefinitionManager().cloneManager().clone(edgeContent.getDefinition(), ClonePolicy.ALL);
ViewConnector clonedContent = (ViewConnector) clone.getContent();
clonedContent.setDefinition(clonedDefinition);
// Magnet being moved on node
ViewConnector connectionContent = (ViewConnector) candidate.getContent();
this.sourceConnection = (Connection) connectionContent.getSourceConnection().orElse(null);
this.targetConnection = (Connection) connectionContent.getTargetConnection().orElse(null);
commands.add(new AddConnectorCommand(sourceNode, clone, sourceConnection));
commands.add(new SetConnectionTargetNodeCommand(targetNode, clone, targetConnection));
// Add the candidate into index, so child commands can find it.
getMutableIndex(context).addEdge(clone);
return this;
}
use of org.kie.workbench.common.stunner.core.definition.adapter.DefinitionId in project kie-wb-common by kiegroup.
the class CloneNodeCommand method initialize.
@Override
@SuppressWarnings("unchecked")
protected AbstractCompositeCommand<GraphCommandExecutionContext, RuleViolation> initialize(GraphCommandExecutionContext context) {
// getting the node parent
Optional<String> parentUUID = getParentUUID();
if (!parentUUID.isPresent()) {
throw new IllegalStateException("Parent not found for node " + candidate);
}
final Object bean = candidate.getContent().getDefinition();
final DefinitionId definitionId = context.getDefinitionManager().adapters().forDefinition().getId(bean);
clone = (Node<View, Edge>) context.getFactoryManager().newElement(UUID.uuid(), definitionId.value()).asNode();
cloneNodeContentWithProperties(context);
// creating node commands to be executed
createNodeCommands(clone, parentUUID.get(), position);
return this;
}
Aggregations