use of org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler in project kie-wb-common by kiegroup.
the class ResizeControlImpl method doResize.
@SuppressWarnings("unchecked")
private CommandResult<CanvasViolation> doResize(final Element<? extends View<?>> element, final Double x, final Double y, final double w, final double h) {
// Calculate the new graph element's bounds.
final Point2D current = (null != x && null != y) ? new Point2D(x, y) : GraphUtils.getPosition(element.getContent());
final BoundsImpl newBounds = new BoundsImpl(new BoundImpl(current.getX(), current.getY()), new BoundImpl(current.getX() + w, current.getY() + h));
// Check the new bound values that come from the user's action do not exceed graph ones.
if (!GraphUtils.checkBoundsExceeded(canvasHandler.getDiagram().getGraph(), newBounds)) {
final CanvasViolation cv = CanvasViolationImpl.Builder.build(new BoundsExceededViolation(newBounds).setUUID(canvasHandler.getUuid()));
return new CommandResultImpl<>(CommandResult.Type.ERROR, Collections.singleton(cv));
}
// Execute the update position and update property/ies command/s on the bean instance to achieve the new bounds.
final List<Command<AbstractCanvasHandler, CanvasViolation>> commands = getResizeCommands(element, w, h);
final CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation> commandBuilder = new CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation>();
if (null != commands) {
if (null != x && null != y) {
commandBuilder.addCommand(canvasCommandFactory.updatePosition((Node<View<?>, Edge>) element, new Point2D(x, y)));
}
commands.forEach(commandBuilder::addCommand);
}
final CommandResult<CanvasViolation> resizeResults = getCommandManager().execute(canvasHandler, commandBuilder.build());
// Update the view bounds on the node content after successful resize.
if (!CommandUtils.isError(resizeResults)) {
element.getContent().setBounds(newBounds);
}
return resizeResults;
}
use of org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler in project kie-wb-common by kiegroup.
the class ObserverBuilderControl method onBuildCanvasShape.
@SuppressWarnings("unchecked")
void onBuildCanvasShape(@Observes final BuildCanvasShapeEvent buildCanvasShapeEvent) {
checkNotNull("buildCanvasShapeEvent", buildCanvasShapeEvent);
if (null != canvasHandler) {
final CanvasHandler context = buildCanvasShapeEvent.getCanvasHandler();
if (null != context && context.equals(canvasHandler)) {
final Object definition = buildCanvasShapeEvent.getDefinition();
final double x = buildCanvasShapeEvent.getX();
final double y = buildCanvasShapeEvent.getY();
final double _x = x >= 0 ? x - canvasHandler.getAbstractCanvas().getAbsoluteX() : -1;
final double _y = y >= 0 ? y - canvasHandler.getAbstractCanvas().getAbsoluteY() : -1;
final ElementBuildRequest<AbstractCanvasHandler> request = new ElementBuildRequestImpl(_x, _y, definition);
ObserverBuilderControl.this.build(request, new BuildCallback() {
@Override
public void onSuccess(final String uuid) {
canvasHandler.getCanvas().draw();
canvasSelectionEvent.fire(new CanvasSelectionEvent(canvasHandler, uuid));
}
@Override
public void onError(final ClientRuntimeError error) {
LOGGER.log(Level.SEVERE, error.toString());
}
});
}
}
}
use of org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler in project kie-wb-common by kiegroup.
the class DiagramPresenterFactoryImpl method newViewer.
@Override
@SuppressWarnings("unchecked")
public DiagramViewer<Diagram, ?> newViewer(final Diagram diagram) {
final CanvasFactory<AbstractCanvas, AbstractCanvasHandler> canvasFactory = shapeManager.getCanvasFactory(diagram);
final AbstractCanvas canvas = canvasFactory.newCanvas();
final AbstractCanvasHandler canvasHandler = canvasFactory.newCanvasHandler();
final ZoomControl<AbstractCanvas> zoomControl = canvasFactory.newControl(ZoomControl.class);
final SelectionControl<AbstractCanvasHandler, Element> selectionControl = canvasFactory.newControl(SelectionControl.class);
return new DiagramViewerImpl<>(canvas, canvasHandler, viewInstances.get(), zoomControl, selectionControl, canvasControlDisposer);
}
use of org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler in project kie-wb-common by kiegroup.
the class UndefinedExpressionGrid method onExpressionTypeChanged.
void onExpressionTypeChanged(final ExpressionType type) {
final Optional<Expression> expression = expressionEditorDefinitionsSupplier.get().stream().filter(e -> e.getType().equals(type)).map(ExpressionEditorDefinition::getModelClass).findFirst().get();
final Optional<ExpressionEditorDefinition<Expression>> expressionEditorDefinition = expressionEditorDefinitionsSupplier.get().getExpressionEditorDefinition(expression);
expressionEditorDefinition.ifPresent(ed -> {
final Optional<BaseExpressionGrid> editor = ed.getEditor(parent, nodeUUID, hasExpression, expression, hasName, nesting);
final GridCellValueTuple gcv = new GridCellValueTuple<>(parent.getRowIndex(), parent.getColumnIndex(), parent.getGridWidget(), new ExpressionCellValue(editor));
sessionCommandManager.execute((AbstractCanvasHandler) sessionManager.getCurrentSession().getCanvasHandler(), new SetCellValueCommand(gcv, () -> uiModelMapper, () -> editor.ifPresent(e -> {
e.selectFirstCell();
synchroniseViewWhenExpressionEditorChanged(e);
})));
});
}
use of org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler in project kie-wb-common by kiegroup.
the class DMNEditBusinessKnowledgeModelToolboxActionTest method testAction.
@Test
public void testAction() {
final MouseClickEvent event = mock(MouseClickEvent.class);
ToolboxAction<AbstractCanvasHandler> cascade = tested.onMouseClick(canvasHandler, E_UUID, event);
assertEquals(tested, cascade);
final ArgumentCaptor<EditExpressionEvent> eventCaptor = ArgumentCaptor.forClass(EditExpressionEvent.class);
verify(editExpressionEvent, times(1)).fire(eventCaptor.capture());
final EditExpressionEvent editExprEvent = eventCaptor.getValue();
assertEquals(E_UUID, editExprEvent.getNodeUUID());
assertEquals(bkmFunction, editExprEvent.getHasExpression());
assertEquals(bkm, editExprEvent.getHasName().get());
assertEquals(session, editExprEvent.getSession());
}
Aggregations