Search in sources :

Example 1 with CanvasHandler

use of org.kie.workbench.common.stunner.core.client.canvas.CanvasHandler in project kie-wb-common by kiegroup.

the class StunnerClientLogger method logSessionInfo.

public static void logSessionInfo(final AbstractClientSession session) {
    log("************ Session Info ****************");
    if (null != session) {
        log("Session = " + session.toString());
        log("Canvas = " + session.getCanvas().toString());
        if (null != session.getCanvasHandler()) {
            final CanvasHandler canvasHandler = session.getCanvasHandler();
            log("CanvasHandler = " + canvasHandler.toString());
            final Diagram diagram = canvasHandler.getDiagram();
            if (null != diagram) {
                log("Diagram name = " + diagram.getName());
                log("Graph uuid = " + (null != diagram.getGraph() ? diagram.getGraph().getUUID() : "null"));
                final Metadata metadata = diagram.getMetadata();
                if (null != metadata) {
                    log("Metadata defSetId = " + metadata.getDefinitionSetId());
                    log("Metadata shapeSetId = " + metadata.getShapeSetId());
                    log("Metadata canvas root = " + metadata.getCanvasRootUUID());
                    log("Metadata title = " + metadata.getTitle());
                } else {
                    log("Metadata = null");
                }
            } else {
                log("Diagram = null");
            }
        } else {
            log("CanvasHandler = null");
        }
        if (session instanceof ClientFullSession) {
            logFullSessionInfo((ClientFullSession) session);
        }
    } else {
        log("Session is null");
    }
    log("******************************************");
}
Also used : AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) CanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.CanvasHandler) ClientFullSession(org.kie.workbench.common.stunner.core.client.session.ClientFullSession) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram)

Example 2 with CanvasHandler

use of org.kie.workbench.common.stunner.core.client.canvas.CanvasHandler 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 3 with CanvasHandler

use of org.kie.workbench.common.stunner.core.client.canvas.CanvasHandler in project kie-wb-common by kiegroup.

the class CanvasLayoutUtils method getNext.

@SuppressWarnings("unchecked")
public Point2D getNext(final CanvasHandler canvasHandler, final Node<View<?>, Edge> root, final Node<View<?>, Edge> newNode) {
    final double[] rootBounds = getBoundCoordinates(root.getContent());
    final double[] rootSize = GraphUtils.getNodeSize(root.getContent());
    final double[] newNodeSize = GraphUtils.getNodeSize(newNode.getContent());
    Point2D[] offset = { new Point2D(PADDING_X, 0) };
    Point2D[] parentOffset = { new Point2D(0, 0) };
    double[] maxNodeY = { 0 };
    if (root.getOutEdges().size() > 0) {
        root.getOutEdges().stream().filter(e -> e.getContent() instanceof ViewConnector).filter(e -> null != e.getTargetNode() && !e.getTargetNode().equals(newNode)).forEach(n -> {
            final Node<View<?>, Edge> node = n.getTargetNode();
            final Point2D nodePos = GraphUtils.getPosition(node.getContent());
            final Point2D rootPos = GraphUtils.getPosition(root.getContent());
            if (nodePos.getY() > maxNodeY[0]) {
                maxNodeY[0] = nodePos.getY();
                final double[] nodeSize = GraphUtils.getNodeSize(node.getContent());
                offset[0].setY(maxNodeY[0] + nodeSize[1] - rootPos.getY());
            }
        });
        offset[0].setY(offset[0].getY() + parentOffset[0].getY() + PADDING_Y);
    } else {
        offset[0].setY(parentOffset[0].getY() - (newNodeSize[1] - rootSize[1]) / 2);
    }
    offset[0].setX(offset[0].getX() + PADDING_X);
    final Point2D offsetCoordinates = new Point2D(offset[0].getX(), offset[0].getY());
    final Point2D rootNodeCoordinates = new Point2D(rootBounds[0], rootBounds[1]);
    return getNext(canvasHandler, root, rootSize[0], rootSize[1], newNodeSize[0], newNodeSize[1], offsetCoordinates, rootNodeCoordinates);
}
Also used : Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Violation(org.kie.workbench.common.stunner.core.validation.Violation) GraphBoundsIndexer(org.kie.workbench.common.stunner.core.graph.processing.index.bounds.GraphBoundsIndexer) RuleSet(org.kie.workbench.common.stunner.core.rule.RuleSet) PortablePreconditions.checkNotNull(org.kie.soup.commons.validation.PortablePreconditions.checkNotNull) DefinitionSet(org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet) RuleContextBuilder(org.kie.workbench.common.stunner.core.rule.context.impl.RuleContextBuilder) View(org.kie.workbench.common.stunner.core.graph.content.view.View) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) GraphUtils(org.kie.workbench.common.stunner.core.graph.util.GraphUtils) Inject(javax.inject.Inject) NodeContainmentContext(org.kie.workbench.common.stunner.core.rule.context.NodeContainmentContext) Graph(org.kie.workbench.common.stunner.core.graph.Graph) RuleViolations(org.kie.workbench.common.stunner.core.rule.RuleViolations) Dependent(javax.enterprise.context.Dependent) Element(org.kie.workbench.common.stunner.core.graph.Element) DefinitionManager(org.kie.workbench.common.stunner.core.api.DefinitionManager) RuleManager(org.kie.workbench.common.stunner.core.rule.RuleManager) CanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.CanvasHandler) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Node(org.kie.workbench.common.stunner.core.graph.Node) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 4 with CanvasHandler

use of org.kie.workbench.common.stunner.core.client.canvas.CanvasHandler in project kie-wb-common by kiegroup.

the class ShowcaseDiagramService method save.

public void save(final AbstractClientFullSession session, final ServiceCallback<Diagram<Graph, Metadata>> diagramServiceCallback) {
    // Update diagram's image data as thumbnail.
    final String thumbData = toImageData(session);
    final CanvasHandler canvasHandler = session.getCanvasHandler();
    final Diagram diagram = canvasHandler.getDiagram();
    diagram.getMetadata().setThumbData(thumbData);
    save(diagram, diagramServiceCallback);
}
Also used : AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) CanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.CanvasHandler) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram)

Example 5 with CanvasHandler

use of org.kie.workbench.common.stunner.core.client.canvas.CanvasHandler in project kie-wb-common by kiegroup.

the class ShowcaseDiagramService method save.

// TODO: Move this to ClientFactoryServices, so shared for others as well.
public void save(final AbstractClientFullSession session, final ServiceCallback<Diagram<Graph, Metadata>> diagramServiceCallback) {
    // Update diagram's image data as thumbnail.
    final String thumbData = toImageData(session);
    final CanvasHandler canvasHandler = session.getCanvasHandler();
    final Diagram diagram = canvasHandler.getDiagram();
    diagram.getMetadata().setThumbData(thumbData);
    save(diagram, diagramServiceCallback);
}
Also used : AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) CanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.CanvasHandler) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram)

Aggregations

CanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.CanvasHandler)9 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)6 Diagram (org.kie.workbench.common.stunner.core.diagram.Diagram)5 ClientRuntimeError (org.kie.workbench.common.stunner.core.client.service.ClientRuntimeError)2 BoundingBox (com.ait.lienzo.client.core.types.BoundingBox)1 ArrayList (java.util.ArrayList)1 Dependent (javax.enterprise.context.Dependent)1 Inject (javax.inject.Inject)1 Test (org.junit.Test)1 PortablePreconditions.checkNotNull (org.kie.soup.commons.validation.PortablePreconditions.checkNotNull)1 DefinitionManager (org.kie.workbench.common.stunner.core.api.DefinitionManager)1 Layer (org.kie.workbench.common.stunner.core.client.canvas.Layer)1 ElementBuildRequestImpl (org.kie.workbench.common.stunner.core.client.canvas.controls.builder.request.ElementBuildRequestImpl)1 CanvasSelectionEvent (org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasSelectionEvent)1 ClientFullSession (org.kie.workbench.common.stunner.core.client.session.ClientFullSession)1 AbstractClientSession (org.kie.workbench.common.stunner.core.client.session.impl.AbstractClientSession)1 Shape (org.kie.workbench.common.stunner.core.client.shape.Shape)1 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)1 Edge (org.kie.workbench.common.stunner.core.graph.Edge)1 Element (org.kie.workbench.common.stunner.core.graph.Element)1