Search in sources :

Example 6 with AbstractCanvasHandler

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;
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) BoundImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl) Node(org.kie.workbench.common.stunner.core.graph.Node) BoundsExceededViolation(org.kie.workbench.common.stunner.core.rule.violations.BoundsExceededViolation) CompositeCommand(org.kie.workbench.common.stunner.core.command.impl.CompositeCommand) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) Command(org.kie.workbench.common.stunner.core.command.Command) CompositeCommand(org.kie.workbench.common.stunner.core.command.impl.CompositeCommand) BoundsImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl) CommandResultImpl(org.kie.workbench.common.stunner.core.command.impl.CommandResultImpl)

Example 7 with AbstractCanvasHandler

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());
                }
            });
        }
    }
}
Also used : AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) CanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.CanvasHandler) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) CanvasSelectionEvent(org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasSelectionEvent) ClientRuntimeError(org.kie.workbench.common.stunner.core.client.service.ClientRuntimeError) ElementBuildRequestImpl(org.kie.workbench.common.stunner.core.client.canvas.controls.builder.request.ElementBuildRequestImpl)

Example 8 with AbstractCanvasHandler

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);
}
Also used : AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) AbstractCanvas(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvas) Element(org.kie.workbench.common.stunner.core.graph.Element)

Example 9 with AbstractCanvasHandler

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);
        })));
    });
}
Also used : NodeMouseClickHandler(com.ait.lienzo.client.core.event.NodeMouseClickHandler) CellEditorControlsView(org.kie.workbench.common.dmn.client.widgets.grid.controls.container.CellEditorControlsView) DMNGridData(org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridData) DefinitionUtils(org.kie.workbench.common.stunner.core.util.DefinitionUtils) ExpressionEditorDefinition(org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinition) HasCellEditorControls(org.kie.workbench.common.dmn.client.widgets.grid.controls.HasCellEditorControls) HasListSelectorControl(org.kie.workbench.common.dmn.client.widgets.grid.controls.list.HasListSelectorControl) ListSelectorView(org.kie.workbench.common.dmn.client.widgets.grid.controls.list.ListSelectorView) BaseExpressionGrid(org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid) DMNGridLayer(org.kie.workbench.common.dmn.client.widgets.layer.DMNGridLayer) GridColumn(org.uberfire.ext.wires.core.grids.client.model.GridColumn) ExpressionType(org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionType) GridSelectionManager(org.uberfire.ext.wires.core.grids.client.widget.layer.GridSelectionManager) ExpressionEditorDefinitions(org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinitions) Supplier(java.util.function.Supplier) BaseHeaderMetaData(org.uberfire.ext.wires.core.grids.client.model.impl.BaseHeaderMetaData) ArrayList(java.util.ArrayList) DMNGridRow(org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridRow) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) GridCellTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple) Expression(org.kie.workbench.common.dmn.api.definition.v1_1.Expression) SessionManager(org.kie.workbench.common.stunner.core.client.api.SessionManager) DMNGridPanel(org.kie.workbench.common.dmn.client.widgets.panel.DMNGridPanel) EventPropagationMode(com.ait.lienzo.shared.core.types.EventPropagationMode) SetCellValueCommand(org.kie.workbench.common.dmn.client.commands.general.SetCellValueCommand) TranslationService(org.jboss.errai.ui.client.local.spi.TranslationService) CanvasCommandFactory(org.kie.workbench.common.stunner.core.client.command.CanvasCommandFactory) GridCell(org.uberfire.ext.wires.core.grids.client.model.GridCell) GridDataCache(org.kie.workbench.common.dmn.client.widgets.grid.model.GridDataCache) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) SessionCommandManager(org.kie.workbench.common.stunner.core.client.command.SessionCommandManager) HasName(org.kie.workbench.common.dmn.api.definition.HasName) List(java.util.List) ExpressionCellValue(org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue) Optional(java.util.Optional) GridCellValueTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellValueTuple) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) Expression(org.kie.workbench.common.dmn.api.definition.v1_1.Expression) BaseExpressionGrid(org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid) ExpressionEditorDefinition(org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinition) SetCellValueCommand(org.kie.workbench.common.dmn.client.commands.general.SetCellValueCommand) ExpressionCellValue(org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue) GridCellValueTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellValueTuple)

Example 10 with AbstractCanvasHandler

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());
}
Also used : AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) EditExpressionEvent(org.kie.workbench.common.dmn.client.events.EditExpressionEvent) MouseClickEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent) Test(org.junit.Test)

Aggregations

AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)60 CanvasViolation (org.kie.workbench.common.stunner.core.client.command.CanvasViolation)37 Test (org.junit.Test)30 DMNGridRow (org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridRow)15 CompositeCommand (org.kie.workbench.common.stunner.core.command.impl.CompositeCommand)10 Node (org.kie.workbench.common.stunner.core.graph.Node)10 Command (org.kie.workbench.common.stunner.core.command.Command)9 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)9 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)9 List (org.kie.workbench.common.dmn.api.definition.v1_1.List)8 Edge (org.kie.workbench.common.stunner.core.graph.Edge)8 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)7 DecisionRule (org.kie.workbench.common.dmn.api.definition.v1_1.DecisionRule)6 CommandResult (org.kie.workbench.common.stunner.core.command.CommandResult)6 View (org.kie.workbench.common.stunner.core.graph.content.view.View)6 BaseGridRow (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow)6 Collectors (java.util.stream.Collectors)5 LiteralExpression (org.kie.workbench.common.dmn.api.definition.v1_1.LiteralExpression)5 CanvasSelectionEvent (org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasSelectionEvent)5 CanvasCommandFactory (org.kie.workbench.common.stunner.core.client.command.CanvasCommandFactory)5