Search in sources :

Example 1 with Point

use of org.eclipse.sapphire.ui.Point in project liferay-ide by liferay.

the class WorkflowDefinitionLayoutPersistenceService method _addConnectionToPersistenceCache.

private void _addConnectionToPersistenceCache(DiagramConnectionPart connPart) {
    ConnectionHashKey connKey = ConnectionHashKey.createKey(connPart);
    _connectionBendPoints.put(connKey, connPart.getBendpoints());
    if (connPart.getLabelPosition() != null) {
        _connectionLabelPositions.put(connKey, new Point(connPart.getLabelPosition()));
    } else {
        _connectionLabelPositions.put(connKey, new Point(-1, -1));
    }
}
Also used : ConnectionHashKey(org.eclipse.sapphire.ui.diagram.layout.ConnectionHashKey) Point(org.eclipse.sapphire.ui.Point)

Example 2 with Point

use of org.eclipse.sapphire.ui.Point in project liferay-ide by liferay.

the class WorkflowDefinitionLayoutPersistenceService method _handleConnectionBendpointChange.

private void _handleConnectionBendpointChange(Transition transition) {
    ConnectionService connService = _part().service(ConnectionService.class);
    DiagramConnectionPart connPart = _getConnectionPart(connService, transition);
    if (connPart != null) {
        List<Point> bendpoints = new ArrayList<>();
        WorkflowNode wfNode = transition.nearest(WorkflowNode.class);
        ElementHandle<WorkflowNodeMetadata> nodeMetadata = wfNode.getMetadata();
        WorkflowNodeMetadata metadata = nodeMetadata.content(false);
        TransitionMetadata transitionMetadata = _getTransitionMetadata(transition, metadata);
        for (ConnectionBendpoint bendpoint : transitionMetadata.getBendpoints()) {
            bendpoints.add(new Point(bendpoint.getX().content(), bendpoint.getY().content()));
        }
        connPart.resetBendpoints(bendpoints);
    }
}
Also used : ConnectionService(org.eclipse.sapphire.ui.diagram.ConnectionService) ConnectionBendpoint(com.liferay.ide.kaleo.core.model.ConnectionBendpoint) TransitionMetadata(com.liferay.ide.kaleo.core.model.TransitionMetadata) DiagramConnectionPart(org.eclipse.sapphire.ui.diagram.DiagramConnectionPart) ArrayList(java.util.ArrayList) WorkflowNodeMetadata(com.liferay.ide.kaleo.core.model.WorkflowNodeMetadata) Point(org.eclipse.sapphire.ui.Point) WorkflowNode(com.liferay.ide.kaleo.core.model.WorkflowNode)

Example 3 with Point

use of org.eclipse.sapphire.ui.Point in project liferay-ide by liferay.

the class WorkflowDefinitionLayoutPersistenceService method _writeTransitionBendPoints.

private void _writeTransitionBendPoints(Transition transition, DiagramConnectionPart connPart) {
    WorkflowNode workflowNode = transition.nearest(WorkflowNode.class);
    ElementHandle<WorkflowNodeMetadata> nodeMetadata = workflowNode.getMetadata();
    WorkflowNodeMetadata metadata = nodeMetadata.content(true);
    TransitionMetadata transitionMetadata = _getTransitionMetadata(transition, metadata, true);
    transitionMetadata.setName(transition.getName().content());
    ElementList<ConnectionBendpoint> bendpointsInMetadataList = transitionMetadata.getBendpoints();
    int bendpointsInMetadataSize = bendpointsInMetadataList.size();
    List<Point> bendpointsInPartList = connPart.getBendpoints();
    int bendpointsInPartSize = bendpointsInPartList.size();
    for (int i = 0, n = min(bendpointsInMetadataSize, bendpointsInPartSize); i < n; i++) {
        ConnectionBendpoint bendpointInMetadata = bendpointsInMetadataList.get(i);
        Point bendpointInPart = bendpointsInPartList.get(i);
        if (bendpointInMetadata.getX().content() != bendpointInPart.getX()) {
            bendpointInMetadata.setX(bendpointInPart.getX());
        }
        if (bendpointInMetadata.getY().content() != bendpointInPart.getY()) {
            bendpointInMetadata.setY(bendpointInPart.getY());
        }
    }
    if (bendpointsInMetadataSize < bendpointsInPartSize) {
        for (int i = bendpointsInMetadataSize; i < bendpointsInPartSize; i++) {
            ConnectionBendpoint bendpointInMetadata = bendpointsInMetadataList.insert();
            Point bendpointInPart = bendpointsInPartList.get(i);
            bendpointInMetadata.setX(bendpointInPart.getX());
            bendpointInMetadata.setY(bendpointInPart.getY());
        }
    } else if (bendpointsInMetadataSize > bendpointsInPartSize) {
        for (int i = bendpointsInMetadataSize - 1; i >= bendpointsInPartSize; i--) {
            bendpointsInMetadataList.remove(i);
        }
    }
    if ((connPart.getLabelPosition() != null) && !connPart.getLabelPosition().equals(DEFAULT_POINT)) {
        transitionMetadata.getLabelLocation().setX(connPart.getLabelPosition().getX());
        transitionMetadata.getLabelLocation().setY(connPart.getLabelPosition().getY());
    }
}
Also used : ConnectionBendpoint(com.liferay.ide.kaleo.core.model.ConnectionBendpoint) TransitionMetadata(com.liferay.ide.kaleo.core.model.TransitionMetadata) WorkflowNodeMetadata(com.liferay.ide.kaleo.core.model.WorkflowNodeMetadata) Point(org.eclipse.sapphire.ui.Point) WorkflowNode(com.liferay.ide.kaleo.core.model.WorkflowNode) ConnectionBendpoint(com.liferay.ide.kaleo.core.model.ConnectionBendpoint) Point(org.eclipse.sapphire.ui.Point)

Example 4 with Point

use of org.eclipse.sapphire.ui.Point in project liferay-ide by liferay.

the class WorkflowDefinitionLayoutPersistenceService method _isConnectionLayoutChanged.

private boolean _isConnectionLayoutChanged(DiagramConnectionPart connPart) {
    // Detect whether the connection bendpoints have been changed.
    List<Point> bendpoints = connPart.getBendpoints();
    Point labelPosition = connPart.getLabelPosition();
    ConnectionHashKey key = ConnectionHashKey.createKey(connPart);
    boolean changed = false;
    if (_connectionBendPoints.containsKey(key)) {
        List<Point> oldBendpoints = _connectionBendPoints.get(key);
        if (bendpoints.size() != oldBendpoints.size()) {
            changed = true;
        } else {
            for (int i = 0; i < bendpoints.size(); i++) {
                Point newPt = bendpoints.get(i);
                Point oldPt = oldBendpoints.get(i);
                if ((newPt.getX() != oldPt.getX()) || (newPt.getY() != oldPt.getY())) {
                    changed = true;
                    break;
                }
            }
        }
        if (!bendpoints.equals(oldBendpoints)) {
            changed = true;
        }
    } else {
        changed = true;
    }
    if (!changed && _connectionLabelPositions.containsKey(key)) {
        Point oldLabelPosition = _connectionLabelPositions.get(key);
        if ((labelPosition != null) && !labelPosition.equals(oldLabelPosition)) {
            changed = true;
        }
    } else {
        changed = true;
    }
    return changed;
}
Also used : ConnectionHashKey(org.eclipse.sapphire.ui.diagram.layout.ConnectionHashKey) Point(org.eclipse.sapphire.ui.Point) ConnectionBendpoint(com.liferay.ide.kaleo.core.model.ConnectionBendpoint) Point(org.eclipse.sapphire.ui.Point)

Example 5 with Point

use of org.eclipse.sapphire.ui.Point in project liferay-ide by liferay.

the class WorkflowDefinitionLayoutPersistenceService method _load.

private void _load() {
    SapphireDiagramEditorPagePart part = _part();
    part.setGridVisible(part.adapt(WorkflowDefinitionEditor.class).isGridVisible());
    part.setShowGuides(part.adapt(WorkflowDefinitionEditor.class).isShowGuides());
    ConnectionService connService = part.service(ConnectionService.class);
    for (WorkflowNode workflowNode : _definition().getDiagramNodes()) {
        DiagramNodePart nodePart = part.getDiagramNodePart(workflowNode);
        if (nodePart != null) {
            WorkflowNodeMetadata metadata = workflowNode.getMetadata().content(false);
            Position position = metadata.getPosition();
            Value<Integer> valueX = position.getX();
            Value<Integer> valueY = position.getY();
            DiagramNodeBounds bounds = new DiagramNodeBounds(valueX.content(), valueY.content(), -1, -1, false, false);
            nodePart.setNodeBounds(bounds);
            ListFactory<Transition> transitionsList = ListFactory.start();
            for (Transition transition : workflowNode.nearest(CanTransition.class).getTransitions()) {
                transitionsList.add(transition);
            }
            List<Transition> transitions = transitionsList.result();
            for (Transition transition : transitions) {
                DiagramConnectionPart connPart = _getConnectionPart(connService, transition);
                if (connPart != null) {
                    TransitionMetadata transitionMetadata = _getTransitionMetadata(transition, metadata);
                    if (transitionMetadata == null) {
                        continue;
                    }
                    List<ConnectionBendpoint> bendpoints = transitionMetadata.getBendpoints();
                    if (ListUtil.isNotEmpty(bendpoints)) {
                        int index = 0;
                        for (ConnectionBendpoint bendpoint : bendpoints) {
                            connPart.addBendpoint(index++, bendpoint.getX().content(), bendpoint.getY().content());
                        }
                    }
                    Position labelPosition = transitionMetadata.getLabelLocation();
                    if (labelPosition != null) {
                        connPart.setLabelPosition(new Point(labelPosition.getX().content(), labelPosition.getY().content()));
                    }
                }
            }
        }
    }
    for (DiagramConnectionPart connPart : connService.list()) {
        connPart.attach(_connectionPartListener);
    }
}
Also used : ConnectionService(org.eclipse.sapphire.ui.diagram.ConnectionService) ConnectionBendpoint(com.liferay.ide.kaleo.core.model.ConnectionBendpoint) Position(com.liferay.ide.kaleo.core.model.Position) TransitionMetadata(com.liferay.ide.kaleo.core.model.TransitionMetadata) CanTransition(com.liferay.ide.kaleo.core.model.CanTransition) WorkflowNodeMetadata(com.liferay.ide.kaleo.core.model.WorkflowNodeMetadata) Point(org.eclipse.sapphire.ui.Point) WorkflowNode(com.liferay.ide.kaleo.core.model.WorkflowNode) ConnectionBendpoint(com.liferay.ide.kaleo.core.model.ConnectionBendpoint) Point(org.eclipse.sapphire.ui.Point) DiagramNodeBounds(org.eclipse.sapphire.ui.diagram.editor.DiagramNodeBounds) SapphireDiagramEditorPagePart(org.eclipse.sapphire.ui.diagram.editor.SapphireDiagramEditorPagePart) DiagramConnectionPart(org.eclipse.sapphire.ui.diagram.DiagramConnectionPart) CanTransition(com.liferay.ide.kaleo.core.model.CanTransition) Transition(com.liferay.ide.kaleo.core.model.Transition) DiagramNodePart(org.eclipse.sapphire.ui.diagram.editor.DiagramNodePart)

Aggregations

Point (org.eclipse.sapphire.ui.Point)7 ConnectionBendpoint (com.liferay.ide.kaleo.core.model.ConnectionBendpoint)5 TransitionMetadata (com.liferay.ide.kaleo.core.model.TransitionMetadata)4 WorkflowNode (com.liferay.ide.kaleo.core.model.WorkflowNode)4 WorkflowNodeMetadata (com.liferay.ide.kaleo.core.model.WorkflowNodeMetadata)3 ConnectionService (org.eclipse.sapphire.ui.diagram.ConnectionService)3 DiagramConnectionPart (org.eclipse.sapphire.ui.diagram.DiagramConnectionPart)3 DiagramNodePart (org.eclipse.sapphire.ui.diagram.editor.DiagramNodePart)3 CanTransition (com.liferay.ide.kaleo.core.model.CanTransition)2 Position (com.liferay.ide.kaleo.core.model.Position)2 Transition (com.liferay.ide.kaleo.core.model.Transition)2 ArrayList (java.util.ArrayList)2 DiagramNodeBounds (org.eclipse.sapphire.ui.diagram.editor.DiagramNodeBounds)2 SapphireDiagramEditorPagePart (org.eclipse.sapphire.ui.diagram.editor.SapphireDiagramEditorPagePart)2 ConnectionHashKey (org.eclipse.sapphire.ui.diagram.layout.ConnectionHashKey)2 ISapphirePart (org.eclipse.sapphire.ui.ISapphirePart)1