use of org.kie.workbench.common.stunner.core.graph.Edge in project kie-wb-common by kiegroup.
the class DMNMarshallerTest method setup.
@Before
public void setup() throws Exception {
// Graph utils.
when(definitionManager.adapters()).thenReturn(adapterManager);
when(adapterManager.registry()).thenReturn(adapterRegistry);
definitionUtils = new DefinitionUtils(definitionManager, applicationFactoryManager);
testScopeModelFactory = new TestScopeModelFactory(new DMNDefinitionSet.DMNDefinitionSetBuilder().build());
// Definition manager.
final BackendDefinitionAdapter definitionAdapter = new BackendDefinitionAdapter(definitionUtils);
final BackendDefinitionSetAdapter definitionSetAdapter = new BackendDefinitionSetAdapter(definitionAdapter);
final BackendPropertySetAdapter propertySetAdapter = new BackendPropertySetAdapter();
final BackendPropertyAdapter propertyAdapter = new BackendPropertyAdapter();
when(adapterManager.forDefinitionSet()).thenReturn(definitionSetAdapter);
when(adapterManager.forDefinition()).thenReturn(definitionAdapter);
when(adapterManager.forPropertySet()).thenReturn(propertySetAdapter);
when(adapterManager.forProperty()).thenReturn(propertyAdapter);
when(adapterRegistry.getDefinitionSetAdapter(any(Class.class))).thenReturn(definitionSetAdapter);
when(adapterRegistry.getDefinitionAdapter(any(Class.class))).thenReturn(definitionAdapter);
when(adapterRegistry.getPropertySetAdapter(any(Class.class))).thenReturn(propertySetAdapter);
when(adapterRegistry.getPropertyAdapter(any(Class.class))).thenReturn(propertyAdapter);
commandManager = new GraphCommandManagerImpl(null, null, null);
commandFactory = new GraphCommandFactory();
connectionEdgeFactory = new EdgeFactoryImpl(definitionManager);
viewNodeFactory = new NodeFactoryImpl(definitionUtils);
dmnGraphFactory = new GraphFactoryImpl(definitionManager);
doAnswer(invocationOnMock -> {
String id = (String) invocationOnMock.getArguments()[0];
return testScopeModelFactory.build(id);
}).when(applicationFactoryManager).newDefinition(anyString());
doAnswer(invocationOnMock -> {
String uuid = (String) invocationOnMock.getArguments()[0];
String id = (String) invocationOnMock.getArguments()[1];
if (DMNDefinitionSet.class.getName().equals(id)) {
// Emulate DMNGraphFactoryImpl, that adds a DMNDiagram to new Graphs
// Please note this is different from the stunner jbpm test which this dmn test is based on
Graph graph = (Graph) dmnGraphFactory.build(uuid, DMN_DEF_SET_ID);
DMNDiagram model = new DMNDiagram.DMNDiagramBuilder().build();
Node node = viewNodeFactory.build(uuid, model);
graph.addNode(node);
return graph;
}
Object model = testScopeModelFactory.accepts(id) ? testScopeModelFactory.build(id) : null;
if (null != model) {
Class<? extends ElementFactory> element = BackendDefinitionAdapter.getGraphFactory(model.getClass());
if (element.isAssignableFrom(NodeFactory.class)) {
Node node = viewNodeFactory.build(uuid, model);
return node;
} else if (element.isAssignableFrom(EdgeFactory.class)) {
Edge edge = connectionEdgeFactory.build(uuid, model);
return edge;
}
}
return null;
}).when(applicationFactoryManager).newElement(anyString(), anyString());
doAnswer(invocationOnMock -> {
String uuid = (String) invocationOnMock.getArguments()[0];
Class type = (Class) invocationOnMock.getArguments()[1];
String id = BindableAdapterUtils.getGenericClassName(type);
if (DMNDefinitionSet.class.equals(type)) {
Graph graph = (Graph) dmnGraphFactory.build(uuid, DMN_DEF_SET_ID);
return graph;
}
Object model = testScopeModelFactory.accepts(id) ? testScopeModelFactory.build(id) : null;
if (null != model) {
Class<? extends ElementFactory> element = BackendDefinitionAdapter.getGraphFactory(model.getClass());
if (element.isAssignableFrom(NodeFactory.class)) {
Node node = viewNodeFactory.build(uuid, model);
return node;
} else if (element.isAssignableFrom(EdgeFactory.class)) {
Edge edge = connectionEdgeFactory.build(uuid, model);
return edge;
}
}
return null;
}).when(applicationFactoryManager).newElement(anyString(), any(Class.class));
doAnswer(invocationOnMock -> {
String uuid = (String) invocationOnMock.getArguments()[0];
String defSetId = (String) invocationOnMock.getArguments()[1];
final Graph graph = (Graph) applicationFactoryManager.newElement(uuid, defSetId);
final DiagramImpl result = new DiagramImpl(uuid, new MetadataImpl.MetadataImplBuilder(defSetId).build());
result.setGraph(graph);
return result;
}).when(applicationFactoryManager).newDiagram(anyString(), anyString(), any(Metadata.class));
MappingContextSingleton.loadDynamicMarshallers();
}
use of org.kie.workbench.common.stunner.core.graph.Edge in project kie-wb-common by kiegroup.
the class DMNEditBusinessKnowledgeModelToolboxAction method onMouseClick.
@Override
@SuppressWarnings("unchecked")
public ToolboxAction<AbstractCanvasHandler> onMouseClick(final AbstractCanvasHandler canvasHandler, final String uuid, final MouseClickEvent event) {
// Notice the toolbox factory ensure this action is only being included
// for BusinessKnowledgeModel definitions, next cast is safe.
final Node<View<? extends BusinessKnowledgeModel>, Edge> bkmNode = (Node<View<? extends BusinessKnowledgeModel>, Edge>) AbstractToolboxAction.getElement(canvasHandler, uuid).asNode();
final BusinessKnowledgeModel bkm = bkmNode.getContent().getDefinition();
editExpressionEvent.fire(new EditExpressionEvent(sessionManager.getCurrentSession(), uuid, bkm.getEncapsulatedLogic(), Optional.of(bkm)));
return this;
}
use of org.kie.workbench.common.stunner.core.graph.Edge in project kie-wb-common by kiegroup.
the class DMNEditDecisionToolboxAction method onMouseClick.
@Override
@SuppressWarnings("unchecked")
public ToolboxAction<AbstractCanvasHandler> onMouseClick(final AbstractCanvasHandler canvasHandler, final String uuid, final MouseClickEvent event) {
// Notice the toolbox factory ensure this action is only being included
// for Decision definitions, next cast is safe.
final Node<View<? extends Decision>, Edge> decisionNode = (Node<View<? extends Decision>, Edge>) AbstractToolboxAction.getElement(canvasHandler, uuid).asNode();
final Decision decision = decisionNode.getContent().getDefinition();
editExpressionEvent.fire(new EditExpressionEvent(sessionManager.getCurrentSession(), uuid, decision, Optional.of(decision)));
return this;
}
use of org.kie.workbench.common.stunner.core.graph.Edge in project kie-wb-common by kiegroup.
the class DMNFlowActionsToolboxFactory method getActions.
@Override
@SuppressWarnings("unchecked")
public Collection<ToolboxAction<AbstractCanvasHandler>> getActions(final AbstractCanvasHandler canvasHandler, final Element<?> element) {
final Set<ToolboxAction<AbstractCanvasHandler>> actions = new LinkedHashSet<>();
final Node<Definition<Object>, Edge> node = (Node<Definition<Object>, Edge>) element;
final Diagram diagram = canvasHandler.getDiagram();
final String defSetId = diagram.getMetadata().getDefinitionSetId();
// Look for the allowed connectors present in the Definition Set.
final Set<String> allowedConnectorIds = commonLookups.getAllowedConnectors(defSetId, node, 0, 10);
for (final String allowedConnectorId : allowedConnectorIds) {
// Append a new action for each connector.
actions.add(createConnectorActions.get().setEdgeId(allowedConnectorId));
// Append a new action for each candidate target node (as from the current connector).
commonLookups.getAllowedTargetDefinitions(defSetId, diagram.getGraph(), node, allowedConnectorId, 0, 10).forEach(def -> actions.add(createNodeActions.get().setEdgeId(allowedConnectorId).setNodeId(getDefinitionId(def))));
}
return actions;
}
use of org.kie.workbench.common.stunner.core.graph.Edge in project kie-wb-common by kiegroup.
the class AbstractEdgeBuilder method buildControlPoints.
private void buildControlPoints(BuilderContext context, T edge, GraphCommandFactory commandFactory) {
if (dockers.size() > 2) {
Counter indexCounter = new Counter(0);
ControlPoint[] controlPoints = dockers.subList(1, dockers.size() - 1).stream().sequential().map(docker -> (docker.length == 2 ? new Point2D(docker[0], docker[1]) : null)).filter(Objects::nonNull).map(point -> new ControlPointImpl(point, indexCounter.increment())).toArray(ControlPoint[]::new);
CommandResult<RuleViolation> addControlPointsResult = context.execute(commandFactory.addControlPoint(edge, controlPoints));
if (hasErrors(addControlPointsResult)) {
throw new RuntimeException("Error building BPMN graph. Command 'AddControlPointCommand' execution failed." + addControlPointsResult);
}
}
}
Aggregations