Search in sources :

Example 11 with Bendpoint

use of org.eclipse.draw2d.Bendpoint in project knime-core by knime.

the class ConnectionBendpointEditPolicy method getMoveBendpointCommand.

/**
 * {@inheritDoc}
 */
protected Command getMoveBendpointCommand(final BendpointRequest request) {
    // index of the bendpoint to move
    int index = request.getIndex();
    Point loc = request.getLocation();
    ConnectionContainerEditPart edit = (ConnectionContainerEditPart) getHost();
    ZoomManager zoomManager = (ZoomManager) getHost().getRoot().getViewer().getProperty(ZoomManager.class.toString());
    WorkflowManager m = getWorkflowManager();
    return new NewBendpointMoveCommand(edit, m, index, loc, zoomManager);
}
Also used : ConnectionContainerEditPart(org.knime.workbench.editor2.editparts.ConnectionContainerEditPart) ZoomManager(org.eclipse.gef.editparts.ZoomManager) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) Point(org.eclipse.draw2d.geometry.Point) NewBendpointMoveCommand(org.knime.workbench.editor2.commands.NewBendpointMoveCommand) AbsoluteBendpoint(org.eclipse.draw2d.AbsoluteBendpoint) Point(org.eclipse.draw2d.geometry.Point) Bendpoint(org.eclipse.draw2d.Bendpoint)

Example 12 with Bendpoint

use of org.eclipse.draw2d.Bendpoint in project knime-core by knime.

the class SnapOffBendPointConnectionRouter method route.

/**
 * Routes the {@link Connection}. Expects the constraint to be a List of
 * {@link org.eclipse.draw2d.Bendpoint Bendpoints}.
 *
 * @param conn The connection to route
 */
@Override
public void route(final Connection conn) {
    PointList points = conn.getPoints();
    points.removeAllPoints();
    List bendpoints = (List) getConstraint(conn);
    if (bendpoints == null) {
        bendpoints = Collections.EMPTY_LIST;
    }
    Point ref1, ref2;
    if (bendpoints.isEmpty()) {
        ref1 = conn.getTargetAnchor().getReferencePoint();
        ref2 = conn.getSourceAnchor().getReferencePoint();
    } else {
        ref1 = new Point(((Bendpoint) bendpoints.get(0)).getLocation());
        conn.translateToAbsolute(ref1);
        ref2 = new Point(((Bendpoint) bendpoints.get(bendpoints.size() - 1)).getLocation());
        conn.translateToAbsolute(ref2);
    }
    A_POINT.setLocation(conn.getSourceAnchor().getLocation(ref1));
    conn.translateToRelative(A_POINT);
    points.addPoint(A_POINT);
    // add a point that forces the arrow to leave the source anchor
    // in a horizontal way
    points.addPoint(A_POINT.translate(8, 0));
    for (int i = 0; i < bendpoints.size(); i++) {
        Bendpoint bp = (Bendpoint) bendpoints.get(i);
        points.addPoint(bp.getLocation());
    }
    A_POINT.setLocation(conn.getTargetAnchor().getLocation(ref2));
    conn.translateToRelative(A_POINT);
    // add a point that forces the arrow to get into the anchor
    // in a horizontal way
    points.addPoint(A_POINT.translate(-8, 0));
    A_POINT.setLocation(conn.getTargetAnchor().getLocation(ref2));
    conn.translateToRelative(A_POINT);
    points.addPoint(A_POINT);
    conn.setPoints(points);
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) List(java.util.List) PointList(org.eclipse.draw2d.geometry.PointList) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) Bendpoint(org.eclipse.draw2d.Bendpoint) Bendpoint(org.eclipse.draw2d.Bendpoint) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint)

Example 13 with Bendpoint

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

the class ExtendedBendpointEditPolicy method createHandlesForUserBendpoints.

private List createHandlesForUserBendpoints() {
    List list = new ArrayList();
    ConnectionEditPart connEP = (ConnectionEditPart) getHost();
    PointList points = getConnection().getPoints();
    List bendPoints = (List) getConnection().getRoutingConstraint();
    int bendPointIndex = 0;
    Point currBendPoint = null;
    if (bendPoints == null)
        bendPoints = NULL_CONSTRAINT;
    else if (!bendPoints.isEmpty())
        currBendPoint = ((Bendpoint) bendPoints.get(0)).getLocation();
    for (int i = 0; i < points.size() - 1; i++) {
        // Put a create handle on the middle of every segment
        list.add(new ExtendedBendpointCreationHandle(connEP, bendPointIndex, i));
        // move handle
        if (i < points.size() - 1 && bendPointIndex < bendPoints.size() && currBendPoint.equals(points.getPoint(i + 1))) {
            list.add(new ExtendedBendpointMoveHandle(connEP, bendPointIndex, i + 1));
            // Go to the next user bendpoint
            bendPointIndex++;
            if (bendPointIndex < bendPoints.size())
                currBendPoint = ((Bendpoint) bendPoints.get(bendPointIndex)).getLocation();
        }
    }
    return list;
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) ConnectionEditPart(org.eclipse.gef.ConnectionEditPart) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) PointList(org.eclipse.draw2d.geometry.PointList) Point(org.eclipse.draw2d.geometry.Point) Bendpoint(org.eclipse.draw2d.Bendpoint) Bendpoint(org.eclipse.draw2d.Bendpoint) Point(org.eclipse.draw2d.geometry.Point)

Example 14 with Bendpoint

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

the class DiagramConnectionEditPart method refreshBendpoints.

/**
 * Updates the bendpoints, based on the model
 */
protected void refreshBendpoints() {
    if (getConnectionFigure().getConnectionRouter() instanceof ManhattanConnectionRouter) {
        return;
    }
    List<Bendpoint> figureConstraint = new ArrayList<Bendpoint>();
    EList<IDiagramModelBendpoint> bendpoints = getModel().getBendpoints();
    for (int i = 0; i < bendpoints.size(); i++) {
        IDiagramModelBendpoint bendpoint = bendpoints.get(i);
        RelativeBendpoint rbp = new RelativeBendpoint(getConnectionFigure());
        Dimension dim1 = new Dimension(bendpoint.getStartX(), bendpoint.getStartY());
        Dimension dim2 = new Dimension(bendpoint.getEndX(), bendpoint.getEndY());
        rbp.setRelativeDimensions(dim1, dim2);
        rbp.setWeight((i + 1) / ((float) bendpoints.size() + 1));
        figureConstraint.add(rbp);
    }
    getConnectionFigure().setRoutingConstraint(figureConstraint);
}
Also used : RelativeBendpoint(org.eclipse.draw2d.RelativeBendpoint) ArrayList(java.util.ArrayList) ManhattanConnectionRouter(org.eclipse.draw2d.ManhattanConnectionRouter) Dimension(org.eclipse.draw2d.geometry.Dimension) IDiagramModelBendpoint(com.archimatetool.model.IDiagramModelBendpoint) RelativeBendpoint(org.eclipse.draw2d.RelativeBendpoint) Bendpoint(org.eclipse.draw2d.Bendpoint) IDiagramModelBendpoint(com.archimatetool.model.IDiagramModelBendpoint) RelativeBendpoint(org.eclipse.draw2d.RelativeBendpoint) Bendpoint(org.eclipse.draw2d.Bendpoint) IDiagramModelBendpoint(com.archimatetool.model.IDiagramModelBendpoint)

Example 15 with Bendpoint

use of org.eclipse.draw2d.Bendpoint in project dbeaver by serge-rider.

the class ERDExportGraphML method exportDiagram.

@Override
public void exportDiagram(EntityDiagram diagram, IFigure figure, DiagramPart diagramPart, File targetFile) throws DBException {
    try {
        try (FileOutputStream fos = new FileOutputStream(targetFile)) {
            XMLBuilder xml = new XMLBuilder(fos, GeneralUtils.UTF8_ENCODING);
            xml.setButify(true);
            xml.startElement("graphml");
            xml.addAttribute("xmlns", "http://graphml.graphdrawing.org/xmlns");
            xml.addAttribute("xmlns:java", "http://www.yworks.com/xml/yfiles-common/1.0/java");
            xml.addAttribute("xmlns:sys", "http://www.yworks.com/xml/yfiles-common/markup/primitives/2.0");
            xml.addAttribute("xmlns:x", "http://www.yworks.com/xml/yfiles-common/markup/2.0");
            xml.addAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
            xml.addAttribute("xmlns:y", "http://www.yworks.com/xml/graphml");
            xml.addAttribute("xmlns:yed", "http://www.yworks.com/xml/yed/3");
            xml.addAttribute("xsi:schemaLocation", "http://graphml.graphdrawing.org/xmlns http://www.yworks.com/xml/schema/graphml/1.1/ygraphml.xsd");
            xml.startElement("key");
            xml.addAttribute("for", "node");
            xml.addAttribute("id", "nodegraph");
            xml.addAttribute("yfiles.type", "nodegraphics");
            xml.endElement();
            xml.startElement("key");
            xml.addAttribute("for", "edge");
            xml.addAttribute("id", "edgegraph");
            xml.addAttribute("yfiles.type", "edgegraphics");
            xml.endElement();
            xml.startElement("graph");
            xml.addAttribute("edgedefault", "directed");
            xml.addAttribute("id", "G");
            Map<ERDEntity, String> entityMap = new HashMap<>();
            int nodeNum = 0;
            for (ERDEntity entity : diagram.getEntities()) {
                nodeNum++;
                String nodeId = "n" + nodeNum;
                entityMap.put(entity, nodeId);
                // node
                xml.startElement("node");
                xml.addAttribute("id", nodeId);
                {
                    // Graph data
                    xml.startElement("data");
                    xml.addAttribute("key", "nodegraph");
                    {
                        // Generic node
                        EntityPart entityPart = diagramPart.getEntityPart(entity);
                        EntityFigure entityFigure = entityPart.getFigure();
                        Rectangle partBounds = entityPart.getBounds();
                        xml.startElement("y:GenericNode");
                        xml.addAttribute("configuration", "com.yworks.entityRelationship.big_entity");
                        // Geometry
                        xml.startElement("y:Geometry");
                        xml.addAttribute("height", partBounds.height);
                        xml.addAttribute("width", partBounds.width + getExtraTableLength(diagram, entity));
                        xml.addAttribute("x", partBounds.x());
                        xml.addAttribute("y", partBounds.y());
                        xml.endElement();
                        // Fill
                        xml.startElement("y:Fill");
                        xml.addAttribute("color", getHtmlColor(entityFigure.getBackgroundColor()));
                        // xml.addAttribute("color2", partBounds.width);
                        xml.addAttribute("transparent", "false");
                        xml.endElement();
                        // Border
                        xml.startElement("y:BorderStyle");
                        xml.addAttribute("color", getHtmlColor(entityFigure.getForegroundColor()));
                        xml.addAttribute("type", "line");
                        xml.addAttribute("width", "1.0");
                        xml.endElement();
                        {
                            // Entity Name
                            Rectangle nameBounds = entityFigure.getNameLabel().getBounds();
                            xml.startElement("y:NodeLabel");
                            xml.addAttribute("alignment", "center");
                            xml.addAttribute("autoSizePolicy", "content");
                            xml.addAttribute("configuration", "com.yworks.entityRelationship.label.name");
                            xml.addAttribute("fontFamily", "Courier");
                            xml.addAttribute("fontSize", fontSize);
                            xml.addAttribute("fontStyle", "plain");
                            xml.addAttribute("hasLineColor", "false");
                            xml.addAttribute("modelName", "internal");
                            xml.addAttribute("modelPosition", "t");
                            xml.addAttribute("backgroundColor", getHtmlColor(entityFigure.getNameLabel().getBackgroundColor()));
                            xml.addAttribute("textColor", "#FFFFFF");
                            xml.addAttribute("visible", "true");
                            xml.addAttribute("horizontalTextPosition", "center");
                            xml.addAttribute("iconTextGap", "4");
                            xml.addAttribute("height", nameBounds.height);
                            xml.addAttribute("width", nameBounds.width);
                            xml.addAttribute("x", 0);
                            xml.addAttribute("y", 4);
                            xml.addText(entity.getName());
                            xml.endElement();
                        }
                        {
                            // Attributes
                            AttributeListFigure columnsFigure = entityFigure.getColumnsFigure();
                            Rectangle attrsBounds = columnsFigure.getBounds();
                            xml.startElement("y:NodeLabel");
                            xml.addAttribute("alignment", "left");
                            xml.addAttribute("autoSizePolicy", "content");
                            xml.addAttribute("configuration", "com.yworks.entityRelationship.label.attributes");
                            xml.addAttribute("fontFamily", "Courier");
                            xml.addAttribute("fontSize", fontSize);
                            xml.addAttribute("fontStyle", "plain");
                            xml.addAttribute("hasLineColor", "false");
                            xml.addAttribute("modelName", "custom");
                            xml.addAttribute("modelPosition", "t");
                            xml.addAttribute("backgroundColor", getHtmlColor(columnsFigure.getBackgroundColor()));
                            xml.addAttribute("textColor", getHtmlColor(columnsFigure.getForegroundColor()));
                            xml.addAttribute("visible", "true");
                            xml.addAttribute("horizontalTextPosition", "center");
                            xml.addAttribute("iconTextGap", "4");
                            xml.addAttribute("height", attrsBounds.height);
                            xml.addAttribute("width", attrsBounds.width);
                            // numbers from yEd Graph Editor
                            xml.addAttribute("x", 2);
                            xml.addAttribute("y", 31.66796875);
                            StringBuilder attrsString = new StringBuilder();
                            for (ERDEntityAttribute attr : entity.getAttributes()) {
                                if (attrsString.length() > 0) {
                                    attrsString.append("\n");
                                }
                                attrsString.append(ERDUIUtils.getFullAttributeLabel(diagram, attr, true));
                            }
                            xml.addText(attrsString.toString());
                            xml.startElement("y:LabelModel");
                            xml.startElement("y:ErdAttributesNodeLabelModel");
                            xml.endElement();
                            xml.endElement();
                            xml.startElement("y:ModelParameter");
                            xml.startElement("y:ErdAttributesNodeLabelModelParameter");
                            xml.endElement();
                            xml.endElement();
                            xml.endElement();
                        }
                        xml.endElement();
                    }
                    xml.endElement();
                }
                xml.endElement();
            }
            int edgeNum = 0;
            for (ERDEntity entity : diagram.getEntities()) {
                EntityPart entityPart = diagramPart.getEntityPart(entity);
                for (ERDAssociation association : entity.getAssociations()) {
                    AssociationPart associationPart = entityPart.getConnectionPart(association, true);
                    if (associationPart == null) {
                        log.debug("Association part not found");
                        continue;
                    }
                    edgeNum++;
                    String edgeId = "e" + edgeNum;
                    xml.startElement("edge");
                    xml.addAttribute("id", edgeId);
                    xml.addAttribute("source", entityMap.get(entity));
                    xml.addAttribute("target", entityMap.get(association.getTargetEntity()));
                    xml.startElement("data");
                    xml.addAttribute("key", "edgegraph");
                    xml.startElement("y:PolyLineEdge");
                    // sx="0.0" sy="0.0" tx="0.0" ty="0.0"/>
                    xml.startElement("y:Path");
                    xml.addAttribute("sx", 0.0);
                    xml.addAttribute("sy", 0.0);
                    xml.addAttribute("tx", 0.0);
                    xml.addAttribute("ty", 0.0);
                    for (Bendpoint bp : associationPart.getBendpoints()) {
                        xml.startElement("y:Point");
                        xml.addAttribute("x", bp.getLocation().x);
                        xml.addAttribute("y", bp.getLocation().y);
                        xml.endElement();
                    }
                    xml.endElement();
                    boolean identifying = ERDUtils.isIdentifyingAssociation(association);
                    xml.startElement("y:LineStyle");
                    xml.addAttribute("color", "#000000");
                    xml.addAttribute("type", !identifying || association.isLogical() ? "dashed" : "line");
                    xml.addAttribute("width", "1.0");
                    xml.endElement();
                    xml.startElement("y:Arrows");
                    String sourceStyle = !identifying ? "white_diamond" : "none";
                    xml.addAttribute("source", sourceStyle);
                    xml.addAttribute("target", "circle");
                    xml.endElement();
                    xml.startElement("y:BendStyle");
                    xml.addAttribute("smoothed", "false");
                    xml.endElement();
                    xml.endElement();
                    xml.endElement();
                    xml.endElement();
                }
            }
            xml.endElement();
            xml.endElement();
            xml.flush();
            fos.flush();
        }
        UIUtils.launchProgram(targetFile.getAbsolutePath());
    } catch (Exception e) {
        DBWorkbench.getPlatformUI().showError("Save ERD as GraphML", null, e);
    }
}
Also used : EntityFigure(org.jkiss.dbeaver.erd.ui.figures.EntityFigure) HashMap(java.util.HashMap) ERDEntity(org.jkiss.dbeaver.erd.model.ERDEntity) Rectangle(org.eclipse.draw2d.geometry.Rectangle) ERDAssociation(org.jkiss.dbeaver.erd.model.ERDAssociation) XMLBuilder(org.jkiss.utils.xml.XMLBuilder) Bendpoint(org.eclipse.draw2d.Bendpoint) AttributeListFigure(org.jkiss.dbeaver.erd.ui.figures.AttributeListFigure) DBException(org.jkiss.dbeaver.DBException) ERDEntityAttribute(org.jkiss.dbeaver.erd.model.ERDEntityAttribute) FileOutputStream(java.io.FileOutputStream) AssociationPart(org.jkiss.dbeaver.erd.ui.part.AssociationPart) EntityPart(org.jkiss.dbeaver.erd.ui.part.EntityPart) Bendpoint(org.eclipse.draw2d.Bendpoint)

Aggregations

Bendpoint (org.eclipse.draw2d.Bendpoint)15 Point (org.eclipse.draw2d.geometry.Point)10 AbsoluteBendpoint (org.eclipse.draw2d.AbsoluteBendpoint)9 Rectangle (org.eclipse.draw2d.geometry.Rectangle)6 XMLBuilder (org.jkiss.utils.xml.XMLBuilder)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 PointList (org.eclipse.draw2d.geometry.PointList)5 DBException (org.jkiss.dbeaver.DBException)5 RelativeBendpoint (org.eclipse.draw2d.RelativeBendpoint)4 FileOutputStream (java.io.FileOutputStream)3 HashMap (java.util.HashMap)3 AssociationPart (org.jkiss.dbeaver.ext.erd.part.AssociationPart)3 EntityPart (org.jkiss.dbeaver.ext.erd.part.EntityPart)3 ConnectionEditPart (org.eclipse.gef.ConnectionEditPart)2 AttributeListFigure (org.jkiss.dbeaver.ext.erd.figures.AttributeListFigure)2 EntityFigure (org.jkiss.dbeaver.ext.erd.figures.EntityFigure)2 ERDAssociation (org.jkiss.dbeaver.ext.erd.model.ERDAssociation)2 ERDEntity (org.jkiss.dbeaver.ext.erd.model.ERDEntity)2 ERDEntityAttribute (org.jkiss.dbeaver.ext.erd.model.ERDEntityAttribute)2