Search in sources :

Example 1 with DefinitionId

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()]);
}
Also used : DefinitionId(org.kie.workbench.common.stunner.core.definition.adapter.DefinitionId) HashSet(java.util.HashSet)

Example 2 with DefinitionId

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);
}
Also used : DefinitionId(org.kie.workbench.common.stunner.core.definition.adapter.DefinitionId) Id(org.kie.workbench.common.stunner.core.definition.annotation.definition.Id)

Example 3 with 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());
}
Also used : DefinitionId(org.kie.workbench.common.stunner.core.definition.adapter.DefinitionId) Test(org.junit.Test)

Example 4 with DefinitionId

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;
}
Also used : DefinitionId(org.kie.workbench.common.stunner.core.definition.adapter.DefinitionId) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 5 with DefinitionId

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;
}
Also used : DefinitionId(org.kie.workbench.common.stunner.core.definition.adapter.DefinitionId) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Aggregations

DefinitionId (org.kie.workbench.common.stunner.core.definition.adapter.DefinitionId)5 Edge (org.kie.workbench.common.stunner.core.graph.Edge)2 HashSet (java.util.HashSet)1 Test (org.junit.Test)1 Id (org.kie.workbench.common.stunner.core.definition.annotation.definition.Id)1 View (org.kie.workbench.common.stunner.core.graph.content.view.View)1 ViewConnector (org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector)1