Search in sources :

Example 1 with DiagramNodePart

use of org.eclipse.sapphire.ui.diagram.editor.DiagramNodePart in project liferay-ide by liferay.

the class WorkflowDefinitionLayoutPersistenceService method _handleDiagramNodeEvent.

private void _handleDiagramNodeEvent(DiagramNodeEvent event) {
    DiagramNodePart nodePart = event.part();
    if (event instanceof DiagramNodeAddEvent) {
        _read(nodePart);
    } else if (event instanceof DiagramNodeDeleteEvent) {
        _refreshDirtyState();
    } else if (event instanceof DiagramNodeMoveEvent) {
        DiagramNodeBounds nodeBounds = nodePart.getNodeBounds();
        if (nodeBounds.isAutoLayout()) {
            /*
				 * need to add the node bounds to the persistence cache so that
				 * "revert" could work
				 */
            _addNodeToPersistenceCache(nodePart);
            _refreshDirtyState();
        } else if (!nodeBounds.isDefaultPosition()) {
            DiagramNodePart diagramNodePart = event.part();
            _write(diagramNodePart);
        }
    }
}
Also used : DiagramNodeDeleteEvent(org.eclipse.sapphire.ui.diagram.editor.DiagramNodeDeleteEvent) DiagramNodeAddEvent(org.eclipse.sapphire.ui.diagram.editor.DiagramNodeAddEvent) DiagramNodePart(org.eclipse.sapphire.ui.diagram.editor.DiagramNodePart) DiagramNodeMoveEvent(org.eclipse.sapphire.ui.diagram.editor.DiagramNodeMoveEvent) DiagramNodeBounds(org.eclipse.sapphire.ui.diagram.editor.DiagramNodeBounds)

Example 2 with DiagramNodePart

use of org.eclipse.sapphire.ui.diagram.editor.DiagramNodePart in project liferay-ide by liferay.

the class WorkflowDefinitionLayoutPersistenceService method _isDiagramLayoutChanged.

private boolean _isDiagramLayoutChanged() {
    boolean changed = false;
    SapphireDiagramEditorPagePart part = _part();
    if (!part.disposed()) {
        ConnectionService connService = part.service(ConnectionService.class);
        for (DiagramNodePart nodePart : part.getNodes()) {
            if (!nodePart.getLocalModelElement().disposed() && _isNodeLayoutChanged(nodePart)) {
                changed = true;
                break;
            }
        }
        for (DiagramConnectionPart connPart : connService.list()) {
            if (!connPart.getLocalModelElement().disposed() && _isConnectionLayoutChanged(connPart)) {
                changed = true;
                break;
            }
        }
    }
    return changed;
}
Also used : ConnectionService(org.eclipse.sapphire.ui.diagram.ConnectionService) SapphireDiagramEditorPagePart(org.eclipse.sapphire.ui.diagram.editor.SapphireDiagramEditorPagePart) DiagramConnectionPart(org.eclipse.sapphire.ui.diagram.DiagramConnectionPart) DiagramNodePart(org.eclipse.sapphire.ui.diagram.editor.DiagramNodePart)

Example 3 with DiagramNodePart

use of org.eclipse.sapphire.ui.diagram.editor.DiagramNodePart in project liferay-ide by liferay.

the class WorkflowDefinitionLayoutPersistenceService method _read.

private void _read(DiagramNodePart nodePart) {
    WorkflowNode workflowNode = nodePart.getLocalModelElement().nearest(WorkflowNode.class);
    if (!workflowNode.disposed()) {
        WorkflowNodeMetadata metadata = workflowNode.getMetadata().content();
        Position position = metadata.getPosition();
        Value<Integer> valueX = position.getX();
        Value<Integer> valueY = position.getY();
        if ((valueX.content() != -1) && (valueY.content() != -1)) {
            _writeWorkflowNodeMetaDataToBounds(metadata, nodePart);
        }
        String nodeId = nodePart.getId();
        if (_nodeBounds.containsKey(nodeId) && (_nodeBounds.get(nodeId) != null)) {
            nodePart.setNodeBounds(_nodeBounds.get(nodeId));
        } else {
            _nodeBounds.put(nodeId, nodePart.getNodeBounds());
        }
    }
    /*
		 * handle the case where a transition is added and its target node
		 * hasn't been. keep the transitions in a map and every time a new node
		 * is added, check if it is a target of unconnected transitions,
		 * reconnect the DiagramConnectionPart
		 */
    SapphireDiagramEditorPagePart part = _part();
    ConnectionService connService = part.service(ConnectionService.class);
    if (workflowNode instanceof CanTransition) {
        CanTransition canTransition = (CanTransition) workflowNode;
        for (Transition transition : canTransition.getTransitions()) {
            if (transition.getTarget().target() == null) {
                if (!_unconnectedTransitions.containsKey(transition.getTarget().content())) {
                    _unconnectedTransitions.put(transition.getTarget().content(), new LinkedList<Transition>());
                }
                if (!transition.disposed()) {
                    _unconnectedTransitions.get(transition.getTarget().content()).add(transition);
                }
            }
        }
    }
    if (_unconnectedTransitions.containsKey(workflowNode.getName().content())) {
        List<Transition> transitions = _unconnectedTransitions.get(workflowNode.getName().content());
        for (Transition transition : transitions) {
            DiagramConnectionPart connPart = _getConnectionPart(connService, transition);
            DiagramNodePart nodePart1 = part.getDiagramNodePart(transition.nearest(WorkflowNode.class));
            DiagramNodePart nodePart2 = part.getDiagramNodePart(workflowNode);
            connPart.reconnect(nodePart1, nodePart2);
        /*
				 * sometimes the reconnect doesn't work, an alternative way is
				 * to remove it and create a new one if( connPart != null ) {
				 * connPart.remove(); }
				 *
				 * connService.connect( nodePart1, nodePart2, "Transition" );
				 */
        }
        _unconnectedTransitions.remove(workflowNode.getName().content());
    }
}
Also used : ConnectionService(org.eclipse.sapphire.ui.diagram.ConnectionService) Position(com.liferay.ide.kaleo.core.model.Position) CanTransition(com.liferay.ide.kaleo.core.model.CanTransition) WorkflowNodeMetadata(com.liferay.ide.kaleo.core.model.WorkflowNodeMetadata) WorkflowNode(com.liferay.ide.kaleo.core.model.WorkflowNode) 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)

Example 4 with DiagramNodePart

use of org.eclipse.sapphire.ui.diagram.editor.DiagramNodePart in project liferay-ide by liferay.

the class WorkflowDefinitionLayoutPersistenceService method _refreshPersistedPartsCache.

private void _refreshPersistedPartsCache() {
    _nodeBounds.clear();
    _connectionBendPoints.clear();
    ConnectionService connService = _part().service(ConnectionService.class);
    for (DiagramConnectionPart connPart : connService.list()) {
        _addConnectionToPersistenceCache(connPart);
    }
    for (DiagramNodePart nodePart : _part().getNodes()) {
        _addNodeToPersistenceCache(nodePart);
    }
}
Also used : ConnectionService(org.eclipse.sapphire.ui.diagram.ConnectionService) DiagramConnectionPart(org.eclipse.sapphire.ui.diagram.DiagramConnectionPart) DiagramNodePart(org.eclipse.sapphire.ui.diagram.editor.DiagramNodePart)

Example 5 with DiagramNodePart

use of org.eclipse.sapphire.ui.diagram.editor.DiagramNodePart in project liferay-ide by liferay.

the class WorkflowDefinitionLayoutPersistenceService method _handleNodeLayoutChange.

private void _handleNodeLayoutChange(WorkflowNode workflowNode) {
    DiagramNodePart nodePart = _part().getDiagramNodePart(workflowNode);
    WorkflowNodeMetadata metadata = workflowNode.getMetadata().content();
    Position position = metadata.getPosition();
    Value<Integer> valueX = position.getX();
    Value<Integer> valueY = position.getY();
    DiagramNodeBounds nodeBounds = new DiagramNodeBounds(valueX.content(), valueY.content());
    nodePart.setNodeBounds(nodeBounds);
}
Also used : Position(com.liferay.ide.kaleo.core.model.Position) WorkflowNodeMetadata(com.liferay.ide.kaleo.core.model.WorkflowNodeMetadata) DiagramNodePart(org.eclipse.sapphire.ui.diagram.editor.DiagramNodePart) DiagramNodeBounds(org.eclipse.sapphire.ui.diagram.editor.DiagramNodeBounds)

Aggregations

DiagramNodePart (org.eclipse.sapphire.ui.diagram.editor.DiagramNodePart)11 DiagramConnectionPart (org.eclipse.sapphire.ui.diagram.DiagramConnectionPart)7 SapphireDiagramEditorPagePart (org.eclipse.sapphire.ui.diagram.editor.SapphireDiagramEditorPagePart)6 ConnectionService (org.eclipse.sapphire.ui.diagram.ConnectionService)5 DiagramNodeBounds (org.eclipse.sapphire.ui.diagram.editor.DiagramNodeBounds)5 CanTransition (com.liferay.ide.kaleo.core.model.CanTransition)4 Position (com.liferay.ide.kaleo.core.model.Position)4 Transition (com.liferay.ide.kaleo.core.model.Transition)4 WorkflowNode (com.liferay.ide.kaleo.core.model.WorkflowNode)4 WorkflowNodeMetadata (com.liferay.ide.kaleo.core.model.WorkflowNodeMetadata)3 ISapphirePart (org.eclipse.sapphire.ui.ISapphirePart)3 Point (org.eclipse.sapphire.ui.Point)3 ConnectionBendpoint (com.liferay.ide.kaleo.core.model.ConnectionBendpoint)2 TransitionMetadata (com.liferay.ide.kaleo.core.model.TransitionMetadata)2 ArrayList (java.util.ArrayList)2 Element (org.eclipse.sapphire.Element)2 SapphireDiagramEditor (org.eclipse.sapphire.ui.swt.gef.SapphireDiagramEditor)2 WorkflowDefinitionEditor (com.liferay.ide.kaleo.ui.editor.WorkflowDefinitionEditor)1 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)1 GraphicalViewer (org.eclipse.gef.GraphicalViewer)1