Search in sources :

Example 16 with Connection

use of org.eclipse.draw2d.Connection in project dbeaver by dbeaver.

the class GraphAnimation method recordFinalState.

public static void recordFinalState(IFigure child) {
    if (child instanceof Connection) {
        recordFinalState((Connection) child);
        return;
    }
    Rectangle rect2 = child.getBounds().getCopy();
    Rectangle rect1 = (Rectangle) initialStates.get(child);
    if (rect1.isEmpty()) {
        rect1.x = rect2.x;
        rect1.y = rect2.y;
        rect1.width = rect2.width;
    }
    finalStates.put(child, rect2);
}
Also used : Connection(org.eclipse.draw2d.Connection) Rectangle(org.eclipse.draw2d.geometry.Rectangle)

Example 17 with Connection

use of org.eclipse.draw2d.Connection in project statecharts by Yakindu.

the class EditPartUtils method findEditPartForSemanticElement.

@SuppressWarnings("unchecked")
public static IGraphicalEditPart findEditPartForSemanticElement(EditPart editPart, EObject semanticElement) {
    if (semanticElement == null) {
        return null;
    }
    if (editPart instanceof IGraphicalEditPart) {
        EObject resolveSemanticElement = ((IGraphicalEditPart) editPart).resolveSemanticElement();
        if (resolveSemanticElement != null && EcoreUtil.getURI(resolveSemanticElement).equals(EcoreUtil.getURI(semanticElement))) {
            return (IGraphicalEditPart) editPart;
        }
    }
    for (Object child : editPart.getChildren()) {
        IGraphicalEditPart recursiveEditPart = findEditPartForSemanticElement((EditPart) child, semanticElement);
        if (recursiveEditPart != null) {
            return recursiveEditPart;
        }
    }
    if (editPart instanceof NodeEditPart) {
        List<Connection> connections = new ArrayList<Connection>();
        connections.addAll(((NodeEditPart) editPart).getSourceConnections());
        connections.addAll(((NodeEditPart) editPart).getTargetConnections());
        for (Object connection : connections) {
            EObject resolveSemanticElement = ((IGraphicalEditPart) connection).resolveSemanticElement();
            if (EcoreUtil.equals(resolveSemanticElement, semanticElement)) {
                return (IGraphicalEditPart) connection;
            }
        }
    }
    return null;
}
Also used : IGraphicalEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart) NodeEditPart(org.eclipse.gef.NodeEditPart) EObject(org.eclipse.emf.ecore.EObject) Connection(org.eclipse.draw2d.Connection) ArrayList(java.util.ArrayList) EObject(org.eclipse.emf.ecore.EObject)

Example 18 with Connection

use of org.eclipse.draw2d.Connection in project statecharts by Yakindu.

the class TreeLayoutUtil method getTreeFigureIncomingConnections.

// private static void setParentAnnotation(IFigure childFigure,
// IFigure parentFigure, EditPartViewer viewer) {
// final IGraphicalEditPart parentEditPart = (IGraphicalEditPart) viewer
// .getVisualPartMap().get(parentFigure);
// final IGraphicalEditPart childEditPart = (IGraphicalEditPart) viewer
// .getVisualPartMap().get(childFigure);
// try {
// CommandUtil
// .executeUndoableOperation(new SetTreeParentAnnotationCommand(
// childEditPart.getNotationView(), parentEditPart
// .getNotationView()));
// } catch (final ExecutionException e) {
// e.printStackTrace();
// }
// }
// 
// private static IFigure getAnnotatedParentFigure(IFigure figure,
// EditPartViewer viewer) {
// final IGraphicalEditPart editPart = (IGraphicalEditPart) viewer
// .getVisualPartMap().get(figure);
// final View view = editPart.getNotationView();
// 
// final EAnnotation xmiIdAnnotation = view
// .getEAnnotation(TREE_LAYOUT_ANNOTATION);
// 
// if (xmiIdAnnotation != null) {
// final String parentURI = xmiIdAnnotation.getDetails().get(
// TREE_NODE_PARENT_URI);
// if (parentURI != null) {
// final EObject object = view.eResource().getEObject(parentURI);
// final IGraphicalEditPart parentEditPart = (IGraphicalEditPart) viewer
// .getEditPartRegistry().get(object);
// return parentEditPart != null ? parentEditPart.getFigure()
// : null;
// }
// }
// return null;
// }
/**
 * Returns only elements parent figure is a direct parent. Indirect
 * connections are filtered out. Use if children can have many parents.
 *
 * @param connectionLayer
 * @param parentFigure
 * @return
 */
public static List<Connection> getTreeFigureIncomingConnections(ConnectionLayer connectionLayer, IFigure parentFigure) {
    final List<Connection> connectionList = getIncomingConnections(connectionLayer, parentFigure);
    final List<Connection> indirectChildren = new ArrayList<Connection>();
    final int parentFigureTreeLevel = getDeepestTreeLevel(connectionLayer, parentFigure);
    for (final Connection connection : connectionList) {
        final IFigure childFigure = connection.getSourceAnchor().getOwner();
        final int childTreeLevel = getDeepestTreeLevel(connectionLayer, childFigure);
        if (childTreeLevel == parentFigureTreeLevel + 1) {
            // get LayoutConstraint of child Figure;
            Object object = parentFigure.getParent().getLayoutManager().getConstraint(childFigure);
            if (object instanceof TreeLayoutConstraint) {
                TreeLayoutConstraint childConstraint = (TreeLayoutConstraint) object;
                final IFigure constrainedParentFig = childConstraint.getTreeParentFigure();
                if (constrainedParentFig == null) {
                    childConstraint.setTreeParentFigure(parentFigure);
                } else if (constrainedParentFig != parentFigure) {
                    indirectChildren.add(connection);
                }
            }
        } else {
            indirectChildren.add(connection);
        }
    }
    connectionList.removeAll(indirectChildren);
    return connectionList;
}
Also used : Connection(org.eclipse.draw2d.Connection) ArrayList(java.util.ArrayList) Point(org.eclipse.draw2d.geometry.Point) IFigure(org.eclipse.draw2d.IFigure)

Example 19 with Connection

use of org.eclipse.draw2d.Connection in project archi by archimatetool.

the class ManualBendpointEditPolicy method getCreateBendpointCommand.

@Override
protected Command getCreateBendpointCommand(BendpointRequest request) {
    CreateBendpointCommand command = new CreateBendpointCommand();
    Point p = request.getLocation();
    Connection conn = getConnection();
    conn.translateToRelative(p);
    command.setLocation(p);
    Point ref1 = getConnection().getSourceAnchor().getReferencePoint();
    Point ref2 = getConnection().getTargetAnchor().getReferencePoint();
    conn.translateToRelative(ref1);
    conn.translateToRelative(ref2);
    command.setRelativeDimensions(p.getDifference(ref1), p.getDifference(ref2));
    command.setDiagramModelConnection((IDiagramModelConnection) request.getSource().getModel());
    command.setIndex(request.getIndex());
    return command;
}
Also used : IDiagramModelConnection(com.archimatetool.model.IDiagramModelConnection) Connection(org.eclipse.draw2d.Connection) CreateBendpointCommand(com.archimatetool.editor.diagram.commands.CreateBendpointCommand) Point(org.eclipse.draw2d.geometry.Point)

Example 20 with Connection

use of org.eclipse.draw2d.Connection in project archi by archimatetool.

the class ManualBendpointEditPolicy method getMoveBendpointCommand.

@Override
protected Command getMoveBendpointCommand(BendpointRequest request) {
    MoveBendpointCommand command = new MoveBendpointCommand();
    Point p = request.getLocation();
    Connection conn = getConnection();
    conn.translateToRelative(p);
    command.setLocation(p);
    Point ref1 = getConnection().getSourceAnchor().getReferencePoint();
    Point ref2 = getConnection().getTargetAnchor().getReferencePoint();
    conn.translateToRelative(ref1);
    conn.translateToRelative(ref2);
    command.setRelativeDimensions(p.getDifference(ref1), p.getDifference(ref2));
    command.setDiagramModelConnection((IDiagramModelConnection) request.getSource().getModel());
    command.setIndex(request.getIndex());
    return command;
}
Also used : MoveBendpointCommand(com.archimatetool.editor.diagram.commands.MoveBendpointCommand) IDiagramModelConnection(com.archimatetool.model.IDiagramModelConnection) Connection(org.eclipse.draw2d.Connection) Point(org.eclipse.draw2d.geometry.Point)

Aggregations

Connection (org.eclipse.draw2d.Connection)20 Point (org.eclipse.draw2d.geometry.Point)11 Rectangle (org.eclipse.draw2d.geometry.Rectangle)7 ArrayList (java.util.ArrayList)5 IFigure (org.eclipse.draw2d.IFigure)4 PointList (org.eclipse.draw2d.geometry.PointList)3 IDiagramModelConnection (com.archimatetool.model.IDiagramModelConnection)2 List (java.util.List)2 IGraphicalEditPart (org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart)2 CreateBendpointCommand (com.archimatetool.editor.diagram.commands.CreateBendpointCommand)1 MoveBendpointCommand (com.archimatetool.editor.diagram.commands.MoveBendpointCommand)1 LinkedList (java.util.LinkedList)1 FixedPointsConnectionRouter (org.csstudio.opibuilder.editparts.FixedPointsConnectionRouter)1 ConnectionLayer (org.eclipse.draw2d.ConnectionLayer)1 Dimension (org.eclipse.draw2d.geometry.Dimension)1 PrecisionRectangle (org.eclipse.draw2d.geometry.PrecisionRectangle)1 Vector (org.eclipse.draw2d.geometry.Vector)1 EObject (org.eclipse.emf.ecore.EObject)1 ConnectionEditPart (org.eclipse.gef.ConnectionEditPart)1 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)1