use of org.kie.workbench.common.stunner.core.client.shape.factory.ShapeFactory in project kie-wb-common by kiegroup.
the class AbstractToolboxAction method getGlyph.
@Override
public Glyph getGlyph(final AbstractCanvasHandler canvasHandler, final String uuid) {
final String ssid = canvasHandler.getDiagram().getMetadata().getShapeSetId();
final ShapeFactory shapeFactory = canvasHandler.getShapeFactory(ssid);
return shapeFactory.getGlyph(getGlyphId(canvasHandler, uuid));
}
use of org.kie.workbench.common.stunner.core.client.shape.factory.ShapeFactory in project kie-wb-common by kiegroup.
the class CreateConnectorAction method showDragProxy.
@SuppressWarnings("unchecked")
private DragProxy<AbstractCanvasHandler, ConnectorDragProxy.Item, DragProxyCallback> showDragProxy(final AbstractCanvasHandler canvasHandler, final Edge<? extends ViewConnector<?>, Node> connector, final Node<? extends View<?>, Edge> sourceNode, final int x, final int y) {
// Built and show the drag proxy.
final String ssid = canvasHandler.getDiagram().getMetadata().getShapeSetId();
final ShapeFactory shapeFactory = canvasHandler.getShapeFactory(ssid);
final ConnectorDragProxy.Item connectorDragItem = new ConnectorDragProxy.Item() {
@Override
public Edge<? extends ViewConnector<?>, Node> getEdge() {
return connector;
}
@Override
public Node<? extends View<?>, Edge> getSourceNode() {
return sourceNode;
}
@Override
public ShapeFactory<?, ?> getShapeFactory() {
return shapeFactory;
}
};
return connectorDragProxyFactory.proxyFor(canvasHandler).show(connectorDragItem, x, y, new DragProxyCallback() {
@Override
public void onStart(final int x, final int y) {
start(canvasHandler);
}
@Override
public void onMove(final int x, final int y) {
final Node targetNode = graphBoundsIndexer.getAt(x, y);
final boolean allow = allow(x, y, connector, sourceNode, targetNode);
canvasHighlight.unhighLight();
if (null != targetNode && allow) {
canvasHighlight.highLight(targetNode);
} else if (null != targetNode) {
canvasHighlight.invalid(targetNode);
}
}
@Override
public void onComplete(final int x, final int y) {
final Node targetNode = graphBoundsIndexer.getAt(x, y);
accept(x, y, connector, sourceNode, targetNode);
}
});
}
use of org.kie.workbench.common.stunner.core.client.shape.factory.ShapeFactory in project kie-wb-common by kiegroup.
the class ConnectorDragProxyImpl method show.
@Override
@SuppressWarnings("unchecked")
public DragProxy<AbstractCanvasHandler, Item, DragProxyCallback> show(final Item item, final int x, final int y, final DragProxyCallback callback) {
// Source connector's shape - Obtain the shape for the source node.
final Node<View<?>, Edge> sourceNode = item.getSourceNode();
final Shape<?> sourceNodeShape = getCanvas().getShape(sourceNode.getUUID());
// Target connector's shape - Create a temporary shape view, that will act as the connector's target node.
final WiresShapeView transientShapeView = new WiresShapeView<>(new MultiPath().rect(0, 0, 1, 1).setFillAlpha(0).setStrokeAlpha(0));
getWiresManager().getMagnetManager().createMagnets(transientShapeView);
// Create the transient connector's shape and view.
final Edge<View<?>, Node> edge = item.getEdge();
final Shape<?> edgeShape = ((ShapeFactory<Object, ?>) item.getShapeFactory()).newShape(edge.getContent().getDefinition());
final EdgeShape connectorShape = (EdgeShape) edgeShape;
this.connectorShapeView = (WiresConnectorView<?>) edgeShape.getShapeView();
// Register and update shape's view as for edge bean's state.
getWiresManager().register(connectorShapeView);
connectorShape.applyProperties(edge, MutationContext.STATIC);
// Apply connector's connections for both source and target shapes.
// Using center connector strategy, so magnet index 0.
final MagnetConnection centerConnection = new MagnetConnection.Builder().atX(0).atY(0).magnet(0).build();
connectorShapeView.connect(sourceNodeShape.getShapeView(), centerConnection, transientShapeView, centerConnection);
// Optimize the index and show the drag proxy for the temporary shape view.
graphBoundsIndexer.build(canvasHandler.getDiagram().getGraph());
shapeViewDragProxyFactory.show(transientShapeView, x, y, new DragProxyCallback() {
@Override
public void onStart(final int x, final int y) {
callback.onStart(x, y);
// As using center magnet, update the connection.
connectorShapeView.updateForCenterConnection();
}
@Override
public void onMove(final int x, final int y) {
callback.onMove(x, y);
// As using center magnet, update the connection.
connectorShapeView.updateForCenterConnection();
}
@Override
public void onComplete(final int x, final int y) {
callback.onComplete(x, y);
deregisterTransientConnector();
getCanvas().draw();
}
});
return this;
}
use of org.kie.workbench.common.stunner.core.client.shape.factory.ShapeFactory in project kie-wb-common by kiegroup.
the class ObserverBuilderControlTest method setup.
@Before
@SuppressWarnings("unchecked")
public void setup() throws Exception {
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
ServiceCallback<Node<View<Object>, Edge>> callback = (ServiceCallback<Node<View<Object>, Edge>>) (invocationOnMock.getArguments()[2]);
view = new ViewImpl<>(new Object(), new BoundsImpl(new BoundImpl(0.0, 0.0), new BoundImpl(10.0, 20.0)));
Node<View<Object>, Edge> item = new NodeImpl<>("UUID");
item.setContent(view);
callback.onSuccess(item);
return null;
}
}).when(clientFactoryServices).newElement(anyString(), anyString(), any(ServiceCallback.class));
when(graphBoundsIndexer.setRootUUID(anyString())).thenReturn(graphBoundsIndexer);
AdapterManager adapters = mock(AdapterManager.class);
DefinitionAdapter definitionAdapter = mock(DefinitionAdapter.class);
DefinitionSetRuleAdapter rulesAdapter = mock(DefinitionSetRuleAdapter.class);
when(definitionAdapter.getId(any())).thenReturn("Object");
when(rulesAdapter.getRuleSet(any())).thenReturn(mock(RuleSet.class));
when(adapters.forDefinition()).thenReturn(definitionAdapter);
when(adapters.forRules()).thenReturn(rulesAdapter);
when(clientDefinitionManager.adapters()).thenReturn(adapters);
when(clientDefinitionManager.definitionSets()).thenReturn(mock(TypeDefinitionSetRegistry.class));
when(canvasCommandFactory.addNode(any(Node.class), anyString())).thenAnswer(new Answer<Command>() {
@Override
public Command answer(InvocationOnMock invocationOnMock) {
Node node = (Node) invocationOnMock.getArguments()[0];
String uid = (String) invocationOnMock.getArguments()[1];
return new AddCanvasNodeCommand(node, uid);
}
});
when(canvasCommandFactory.updatePosition(any(Node.class), any(Point2D.class))).thenAnswer(new Answer<Command>() {
@Override
public Command answer(InvocationOnMock invocationOnMock) {
Node node = (Node) invocationOnMock.getArguments()[0];
Point2D location = (Point2D) invocationOnMock.getArguments()[1];
return new UpdateElementPositionCommand(node, location);
}
});
when(canvasCommandFactory.draw()).thenReturn(mock(CanvasCommand.class));
ShapeSet shapeSet = mock(ShapeSet.class);
ShapeFactory shapeFactory = mock(ShapeFactory.class);
when(shapeFactory.newShape(any())).thenReturn(mock(ElementShape.class));
when(shapeSet.getShapeFactory()).thenReturn(shapeFactory);
when(shapeManager.getShapeSet(anyString())).thenReturn(shapeSet);
when(shapeManager.getDefaultShapeSet(anyString())).thenReturn(shapeSet);
tested = new ObserverBuilderControl(clientDefinitionManager, clientFactoryServices, graphUtils, ruleManager, canvasCommandFactory, graphBoundsIndexer, canvasLayoutUtils, mock(Event.class));
Diagram diagram = mock(Diagram.class);
Metadata metadata = mock(Metadata.class);
when(metadata.getCanvasRootUUID()).thenReturn("ID");
when(diagram.getMetadata()).thenReturn(metadata);
MutableIndex index = mock(MutableIndex.class);
Graph graph = mock(Graph.class);
DefinitionSet graphContent = mock(DefinitionSet.class);
when(graphContent.getBounds()).thenReturn(new BoundsImpl(new BoundImpl(10d, 10d), new BoundImpl(100d, 100d)));
when(graph.getContent()).thenReturn(graphContent);
when(index.getGraph()).thenReturn(graph);
when(graphIndexBuilder.build(any(Graph.class))).thenReturn(index);
canvasHandler = new CanvasHandlerImpl(clientDefinitionManager, canvasCommandFactory, clientFactoryServices, ruleManager, graphUtils, graphIndexBuilder, shapeManager, mock(TextPropertyProviderFactory.class), mock(Event.class), null, null, null);
canvasHandler.handle(mock(AbstractCanvas.class));
canvasHandler.draw(diagram, mock(ParameterizedCommand.class));
when(diagram.getGraph()).thenReturn(graph);
when(graph.nodes()).thenReturn(Collections.emptyList());
CanvasCommandManager commandManager = mock(CanvasCommandManager.class);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
Command command = (Command) invocationOnMock.getArguments()[1];
command.execute(invocationOnMock.getArguments()[0]);
return null;
}
}).when(commandManager).execute(any(), any(Command.class));
when(commandManagerProvider.getCommandManager()).thenReturn(commandManager);
tested.enable(canvasHandler);
tested.setCommandManagerProvider(commandManagerProvider);
}
use of org.kie.workbench.common.stunner.core.client.shape.factory.ShapeFactory in project kie-wb-common by kiegroup.
the class TreeExplorer method getGlyph.
private Glyph getGlyph(final String shapeSetId, final Element<org.kie.workbench.common.stunner.core.graph.content.view.View> element) {
final Object definition = element.getContent().getDefinition();
final String defId = definitionUtils.getDefinitionManager().adapters().forDefinition().getId(definition);
final ShapeFactory factory = shapeManager.getShapeSet(shapeSetId).getShapeFactory();
return factory.getGlyph(defId);
}
Aggregations