Search in sources :

Example 6 with Bendpoint

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

the class ConnectionBendpointEditPolicy method setReferencePoints.

private void setReferencePoints(final BendpointRequest request) {
    PointList points = getConnection().getPoints();
    int bpIndex = -1;
    List bendPoints = (List) getConnection().getRoutingConstraint();
    Point bp = ((Bendpoint) bendPoints.get(request.getIndex())).getLocation();
    int smallestDistance = -1;
    for (int i = 0; i < points.size(); i++) {
        if (smallestDistance == -1 || points.getPoint(i).getDistance2(bp) < smallestDistance) {
            bpIndex = i;
            smallestDistance = points.getPoint(i).getDistance2(bp);
            if (smallestDistance == 0) {
                break;
            }
        }
    }
    if (bpIndex > 0) {
        points.getPoint(REF1, bpIndex - 1);
    }
    getConnection().translateToAbsolute(REF1);
    if (bpIndex < points.size() - 1) {
        points.getPoint(REF2, bpIndex + 1);
    }
    getConnection().translateToAbsolute(REF2);
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) ArrayList(java.util.ArrayList) PointList(org.eclipse.draw2d.geometry.PointList) List(java.util.List) Point(org.eclipse.draw2d.geometry.Point) AbsoluteBendpoint(org.eclipse.draw2d.AbsoluteBendpoint) Bendpoint(org.eclipse.draw2d.Bendpoint) AbsoluteBendpoint(org.eclipse.draw2d.AbsoluteBendpoint) Point(org.eclipse.draw2d.geometry.Point) Bendpoint(org.eclipse.draw2d.Bendpoint)

Example 7 with Bendpoint

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

the class DiagramLoader method save.

public static void save(DBRProgressMonitor monitor, @Nullable DiagramPart diagramPart, final EntityDiagram diagram, boolean verbose, OutputStream out) throws IOException {
    List allNodeFigures = diagramPart == null ? new ArrayList() : diagramPart.getFigure().getChildren();
    // Prepare DS objects map
    Map<DBPDataSourceContainer, DataSourceObjects> dsMap = new IdentityHashMap<>();
    if (diagram != null) {
        for (ERDEntity erdEntity : diagram.getEntities()) {
            final DBPDataSourceContainer dsContainer = erdEntity.getObject().getDataSource().getContainer();
            DataSourceObjects desc = dsMap.get(dsContainer);
            if (desc == null) {
                desc = new DataSourceObjects();
                dsMap.put(dsContainer, desc);
            }
            desc.entities.add(erdEntity);
        }
    }
    Map<ERDEntity, TableSaveInfo> infoMap = new IdentityHashMap<>();
    // Save as XML
    XMLBuilder xml = new XMLBuilder(out, GeneralUtils.UTF8_ENCODING);
    xml.setButify(true);
    if (verbose) {
        xml.addContent("\n<!DOCTYPE diagram [\n" + "<!ATTLIST diagram version CDATA #REQUIRED\n" + " name CDATA #IMPLIED\n" + " time CDATA #REQUIRED>\n" + "<!ELEMENT diagram (entities, relations, notes)>\n" + "<!ELEMENT entities (data-source*)>\n" + "<!ELEMENT data-source (entity*)>\n" + "<!ATTLIST data-source id CDATA #REQUIRED>\n" + "<!ELEMENT entity (path*)>\n" + "<!ATTLIST entity id ID #REQUIRED\n" + " name CDATA #REQUIRED\n" + " fq-name CDATA #REQUIRED>\n" + "<!ELEMENT relations (relation*)>\n" + "<!ELEMENT relation (bend*)>\n" + "<!ATTLIST relation name CDATA #REQUIRED\n" + " fq-name CDATA #REQUIRED\n" + " pk-ref IDREF #REQUIRED\n" + " fk-ref IDREF #REQUIRED>\n" + "]>\n");
    }
    xml.startElement(TAG_DIAGRAM);
    xml.addAttribute(ATTR_VERSION, ERD_VERSION_1);
    if (diagram != null) {
        xml.addAttribute(ATTR_NAME, diagram.getName());
    }
    xml.addAttribute(ATTR_TIME, RuntimeUtils.getCurrentTimeStamp());
    if (diagram != null) {
        xml.startElement(TAG_ENTITIES);
        for (DBPDataSourceContainer dsContainer : dsMap.keySet()) {
            xml.startElement(TAG_DATA_SOURCE);
            xml.addAttribute(ATTR_ID, dsContainer.getId());
            final DataSourceObjects desc = dsMap.get(dsContainer);
            int tableCounter = ERD_VERSION_1;
            for (ERDEntity erdEntity : desc.entities) {
                final DBSEntity table = erdEntity.getObject();
                EntityPart tablePart = diagramPart == null ? null : diagramPart.getEntityPart(erdEntity);
                TableSaveInfo info = new TableSaveInfo(erdEntity, tablePart, tableCounter++);
                infoMap.put(erdEntity, info);
                xml.startElement(TAG_ENTITY);
                xml.addAttribute(ATTR_ID, info.objectId);
                xml.addAttribute(ATTR_NAME, table.getName());
                if (table instanceof DBPQualifiedObject) {
                    xml.addAttribute(ATTR_FQ_NAME, ((DBPQualifiedObject) table).getFullyQualifiedName(DBPEvaluationContext.UI));
                }
                EntityDiagram.NodeVisualInfo visualInfo;
                if (tablePart != null) {
                    visualInfo = new EntityDiagram.NodeVisualInfo();
                    visualInfo.initBounds = tablePart.getBounds();
                    visualInfo.bgColor = tablePart.getCustomBackgroundColor();
                    saveColorAndOrder(allNodeFigures, xml, tablePart);
                } else {
                    visualInfo = diagram.getVisualInfo(erdEntity);
                }
                if (visualInfo != null && visualInfo.initBounds != null) {
                    xml.addAttribute(ATTR_X, visualInfo.initBounds.x);
                    xml.addAttribute(ATTR_Y, visualInfo.initBounds.y);
                }
                for (DBSObject parent = table.getParentObject(); parent != null && parent != dsContainer; parent = parent.getParentObject()) {
                    xml.startElement(TAG_PATH);
                    xml.addAttribute(ATTR_NAME, parent.getName());
                    xml.endElement();
                }
                xml.endElement();
            }
            xml.endElement();
        }
        xml.endElement();
        // Relations
        xml.startElement(TAG_RELATIONS);
        for (ERDEntity erdEntity : diagram.getEntities()) {
            for (ERDAssociation rel : erdEntity.getPrimaryKeyRelationships()) {
                xml.startElement(TAG_RELATION);
                DBSEntityAssociation association = rel.getObject();
                xml.addAttribute(ATTR_NAME, association.getName());
                if (association instanceof DBPQualifiedObject) {
                    xml.addAttribute(ATTR_FQ_NAME, ((DBPQualifiedObject) association).getFullyQualifiedName(DBPEvaluationContext.UI));
                }
                xml.addAttribute(ATTR_TYPE, association.getConstraintType().getId());
                TableSaveInfo pkInfo = infoMap.get(rel.getPrimaryKeyEntity());
                if (pkInfo == null) {
                    log.error("Cannot find PK table '" + DBUtils.getObjectFullName(rel.getPrimaryKeyEntity().getObject(), DBPEvaluationContext.UI) + "' in info map");
                    continue;
                }
                TableSaveInfo fkInfo = infoMap.get(rel.getForeignKeyEntity());
                if (fkInfo == null) {
                    log.error("Cannot find FK table '" + DBUtils.getObjectFullName(rel.getForeignKeyEntity().getObject(), DBPEvaluationContext.UI) + "' in info map");
                    continue;
                }
                xml.addAttribute(ATTR_PK_REF, pkInfo.objectId);
                xml.addAttribute(ATTR_FK_REF, fkInfo.objectId);
                if (association instanceof ERDLogicalForeignKey) {
                    // Save columns
                    for (DBSEntityAttributeRef column : ((ERDLogicalForeignKey) association).getAttributeReferences(new VoidProgressMonitor())) {
                        xml.startElement(TAG_COLUMN);
                        xml.addAttribute(ATTR_NAME, column.getAttribute().getName());
                        try {
                            DBSEntityAttribute referenceAttribute = DBUtils.getReferenceAttribute(monitor, association, column.getAttribute(), false);
                            if (referenceAttribute != null) {
                                xml.addAttribute(ATTR_REF_NAME, referenceAttribute.getName());
                            }
                        } catch (DBException e) {
                            log.warn("Error getting reference attribute", e);
                        }
                        xml.endElement();
                    }
                }
                // Save bends
                if (pkInfo.tablePart != null) {
                    AssociationPart associationPart = pkInfo.tablePart.getConnectionPart(rel, false);
                    if (associationPart != null) {
                        final List<Bendpoint> bendpoints = associationPart.getBendpoints();
                        if (!CommonUtils.isEmpty(bendpoints)) {
                            for (Bendpoint bendpoint : bendpoints) {
                                xml.startElement(TAG_BEND);
                                if (bendpoint instanceof AbsoluteBendpoint) {
                                    xml.addAttribute(ATTR_TYPE, BEND_ABSOLUTE);
                                    xml.addAttribute(ATTR_X, bendpoint.getLocation().x);
                                    xml.addAttribute(ATTR_Y, bendpoint.getLocation().y);
                                } else if (bendpoint instanceof RelativeBendpoint) {
                                    xml.addAttribute(ATTR_TYPE, BEND_RELATIVE);
                                    xml.addAttribute(ATTR_X, bendpoint.getLocation().x);
                                    xml.addAttribute(ATTR_Y, bendpoint.getLocation().y);
                                }
                                xml.endElement();
                            }
                        }
                    }
                }
                xml.endElement();
            }
        }
        xml.endElement();
        // Notes
        xml.startElement(TAG_NOTES);
        for (ERDNote note : diagram.getNotes()) {
            NotePart notePart = diagramPart == null ? null : diagramPart.getNotePart(note);
            xml.startElement(TAG_NOTE);
            if (notePart != null) {
                saveColorAndOrder(allNodeFigures, xml, notePart);
                Rectangle noteBounds = notePart.getBounds();
                if (noteBounds != null) {
                    xml.addAttribute(ATTR_X, noteBounds.x);
                    xml.addAttribute(ATTR_Y, noteBounds.y);
                    xml.addAttribute(ATTR_W, noteBounds.width);
                    xml.addAttribute(ATTR_H, noteBounds.height);
                }
            }
            xml.addText(note.getObject());
            xml.endElement();
        }
        xml.endElement();
    }
    xml.endElement();
    xml.flush();
}
Also used : DBException(org.jkiss.dbeaver.DBException) Rectangle(org.eclipse.draw2d.geometry.Rectangle) XMLBuilder(org.jkiss.utils.xml.XMLBuilder) AbsoluteBendpoint(org.eclipse.draw2d.AbsoluteBendpoint) AbsoluteBendpoint(org.eclipse.draw2d.AbsoluteBendpoint) Point(org.eclipse.draw2d.geometry.Point) RelativeBendpoint(org.eclipse.draw2d.RelativeBendpoint) Bendpoint(org.eclipse.draw2d.Bendpoint) RelativeBendpoint(org.eclipse.draw2d.RelativeBendpoint) VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor) AbsoluteBendpoint(org.eclipse.draw2d.AbsoluteBendpoint) RelativeBendpoint(org.eclipse.draw2d.RelativeBendpoint) Bendpoint(org.eclipse.draw2d.Bendpoint)

Example 8 with Bendpoint

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

the class DiagramLoader method serializeDiagram.

public static String serializeDiagram(DBRProgressMonitor monitor, @Nullable DiagramPart diagramPart, final EntityDiagram diagram, boolean verbose, boolean compact) throws IOException {
    List allNodeFigures = diagramPart == null ? new ArrayList() : diagramPart.getFigure().getChildren();
    Map<DBPDataSourceContainer, DataSourceObjects> dsMap = createDataSourceObjectMap(diagram);
    Map<ERDElement, ElementSaveInfo> elementInfoMap = new IdentityHashMap<>();
    int elementCounter = ERD_VERSION_1;
    // Save as XML
    StringWriter out = new StringWriter(1000);
    XMLBuilder xml = new XMLBuilder(out, GeneralUtils.UTF8_ENCODING, !compact);
    xml.setButify(!compact);
    if (verbose) {
        xml.addContent("\n<!DOCTYPE diagram [\n" + "<!ATTLIST diagram version CDATA #REQUIRED\n" + " name CDATA #IMPLIED\n" + " time CDATA #REQUIRED>\n" + "<!ELEMENT diagram (entities, relations, notes)>\n" + "<!ELEMENT entities (data-source*)>\n" + "<!ELEMENT data-source (entity*)>\n" + "<!ATTLIST data-source id CDATA #REQUIRED>\n" + "<!ELEMENT entity (path*)>\n" + "<!ATTLIST entity id ID #REQUIRED\n" + " name CDATA #REQUIRED\n" + " fq-name CDATA #REQUIRED>\n" + "<!ELEMENT relations (relation*)>\n" + "<!ELEMENT relation (bend*)>\n" + "<!ATTLIST relation name CDATA #REQUIRED\n" + " fq-name CDATA #REQUIRED\n" + " pk-ref IDREF #REQUIRED\n" + " fk-ref IDREF #REQUIRED>\n" + "]>\n");
    }
    xml.startElement(TAG_DIAGRAM);
    xml.addAttribute(ATTR_VERSION, ERD_VERSION_1);
    if (diagram != null) {
        xml.addAttribute(ATTR_NAME, diagram.getName());
    }
    if (compact) {
        xml.addAttribute(ATTR_TIME, RuntimeUtils.getCurrentTimeStamp());
    }
    if (diagram != null) {
        xml.startElement(TAG_ENTITIES);
        for (DBPDataSourceContainer dsContainer : dsMap.keySet()) {
            xml.startElement(TAG_DATA_SOURCE);
            xml.addAttribute(ATTR_ID, dsContainer.getId());
            final DataSourceObjects desc = dsMap.get(dsContainer);
            for (ERDEntity erdEntity : desc.entities) {
                final DBSEntity table = erdEntity.getObject();
                EntityPart tablePart = diagramPart == null ? null : diagramPart.getEntityPart(erdEntity);
                ElementSaveInfo info = new ElementSaveInfo(erdEntity, tablePart, elementCounter++);
                elementInfoMap.put(erdEntity, info);
                xml.startElement(TAG_ENTITY);
                xml.addAttribute(ATTR_ID, info.objectId);
                xml.addAttribute(ATTR_NAME, table.getName());
                if (table instanceof DBPQualifiedObject) {
                    xml.addAttribute(ATTR_FQ_NAME, ((DBPQualifiedObject) table).getFullyQualifiedName(DBPEvaluationContext.UI));
                }
                if (!CommonUtils.isEmpty(erdEntity.getAlias())) {
                    xml.addAttribute(ATTR_ALIAS, erdEntity.getAlias());
                }
                if (erdEntity.getAttributeVisibility() != null) {
                    xml.addAttribute(ATTR_ATTRIBUTE_VISIBILITY, erdEntity.getAttributeVisibility().name());
                }
                EntityDiagram.NodeVisualInfo visualInfo;
                if (tablePart != null) {
                    visualInfo = new EntityDiagram.NodeVisualInfo();
                    visualInfo.initBounds = tablePart.getBounds();
                    visualInfo.bgColor = tablePart.getCustomBackgroundColor();
                    saveColorAndOrder(allNodeFigures, xml, tablePart);
                } else {
                    visualInfo = diagram.getVisualInfo(erdEntity.getObject());
                }
                if (visualInfo != null && visualInfo.initBounds != null) {
                    xml.addAttribute(ATTR_X, visualInfo.initBounds.x);
                    xml.addAttribute(ATTR_Y, visualInfo.initBounds.y);
                }
                for (DBSObject parent = table.getParentObject(); parent != null && DBUtils.getPublicObjectContainer(parent) != dsContainer; parent = parent.getParentObject()) {
                    xml.startElement(TAG_PATH);
                    xml.addAttribute(ATTR_NAME, parent.getName());
                    xml.endElement();
                }
                xml.endElement();
            }
            xml.endElement();
        }
        xml.endElement();
        if (!CommonUtils.isEmpty(diagram.getNotes())) {
            // Notes
            xml.startElement(TAG_NOTES);
            for (ERDNote note : diagram.getNotes()) {
                NotePart notePart = diagramPart == null ? null : diagramPart.getNotePart(note);
                xml.startElement(TAG_NOTE);
                if (notePart != null) {
                    ElementSaveInfo info = new ElementSaveInfo(note, notePart, elementCounter++);
                    elementInfoMap.put(note, info);
                    xml.addAttribute(ATTR_ID, info.objectId);
                    saveColorAndOrder(allNodeFigures, xml, notePart);
                    Rectangle noteBounds = notePart.getBounds();
                    if (noteBounds != null) {
                        xml.addAttribute(ATTR_X, noteBounds.x);
                        xml.addAttribute(ATTR_Y, noteBounds.y);
                        xml.addAttribute(ATTR_W, noteBounds.width);
                        xml.addAttribute(ATTR_H, noteBounds.height);
                    }
                }
                xml.addText(note.getObject());
                xml.endElement();
            }
            xml.endElement();
        }
        // Relations
        xml.startElement(TAG_RELATIONS);
        List<ERDElement> allElements = new ArrayList<>();
        allElements.addAll(diagram.getEntities());
        allElements.addAll(diagram.getNotes());
        for (ERDElement<?> element : allElements) {
            for (ERDAssociation rel : element.getReferences()) {
                ElementSaveInfo pkInfo = elementInfoMap.get(rel.getTargetEntity());
                if (pkInfo == null) {
                    log.error("Cannot find PK table '" + rel.getTargetEntity().getName() + "' in info map");
                    continue;
                }
                ElementSaveInfo fkInfo = elementInfoMap.get(rel.getSourceEntity());
                if (fkInfo == null) {
                    log.error("Cannot find FK table '" + rel.getSourceEntity().getName() + "' in info map");
                    continue;
                }
                DBSEntityAssociation association = rel.getObject();
                xml.startElement(TAG_RELATION);
                xml.addAttribute(ATTR_NAME, association.getName());
                if (association instanceof DBPQualifiedObject) {
                    xml.addAttribute(ATTR_FQ_NAME, ((DBPQualifiedObject) association).getFullyQualifiedName(DBPEvaluationContext.UI));
                }
                xml.addAttribute(ATTR_TYPE, association.getConstraintType().getId());
                xml.addAttribute(ATTR_PK_REF, pkInfo.objectId);
                xml.addAttribute(ATTR_FK_REF, fkInfo.objectId);
                if (association instanceof ERDLogicalAssociation) {
                    // Save columns
                    for (DBSEntityAttributeRef column : ((ERDLogicalAssociation) association).getAttributeReferences(new VoidProgressMonitor())) {
                        xml.startElement(TAG_COLUMN);
                        xml.addAttribute(ATTR_NAME, column.getAttribute().getName());
                        try {
                            DBSEntityAttribute referenceAttribute = DBUtils.getReferenceAttribute(monitor, association, column.getAttribute(), false);
                            if (referenceAttribute != null) {
                                xml.addAttribute(ATTR_REF_NAME, referenceAttribute.getName());
                            }
                        } catch (DBException e) {
                            log.warn("Error getting reference attribute", e);
                        }
                        xml.endElement();
                    }
                }
                // Save bends
                if (pkInfo.nodePart != null) {
                    AssociationPart associationPart = pkInfo.nodePart.getConnectionPart(rel, false);
                    if (associationPart != null) {
                        final List<Bendpoint> bendpoints = associationPart.getBendpoints();
                        if (!CommonUtils.isEmpty(bendpoints)) {
                            for (Bendpoint bendpoint : bendpoints) {
                                xml.startElement(TAG_BEND);
                                if (bendpoint instanceof AbsoluteBendpoint) {
                                    xml.addAttribute(ATTR_TYPE, BEND_ABSOLUTE);
                                    xml.addAttribute(ATTR_X, bendpoint.getLocation().x);
                                    xml.addAttribute(ATTR_Y, bendpoint.getLocation().y);
                                } else if (bendpoint instanceof RelativeBendpoint) {
                                    xml.addAttribute(ATTR_TYPE, BEND_RELATIVE);
                                    xml.addAttribute(ATTR_X, bendpoint.getLocation().x);
                                    xml.addAttribute(ATTR_Y, bendpoint.getLocation().y);
                                }
                                xml.endElement();
                            }
                        }
                    }
                }
                xml.endElement();
            }
        }
        xml.endElement();
    }
    xml.endElement();
    xml.flush();
    return out.toString();
}
Also used : DBException(org.jkiss.dbeaver.DBException) Rectangle(org.eclipse.draw2d.geometry.Rectangle) XMLBuilder(org.jkiss.utils.xml.XMLBuilder) AbsoluteBendpoint(org.eclipse.draw2d.AbsoluteBendpoint) StringWriter(java.io.StringWriter) AbsoluteBendpoint(org.eclipse.draw2d.AbsoluteBendpoint) RelativeBendpoint(org.eclipse.draw2d.RelativeBendpoint) Bendpoint(org.eclipse.draw2d.Bendpoint) RelativeBendpoint(org.eclipse.draw2d.RelativeBendpoint) VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor) AbsoluteBendpoint(org.eclipse.draw2d.AbsoluteBendpoint) RelativeBendpoint(org.eclipse.draw2d.RelativeBendpoint) Bendpoint(org.eclipse.draw2d.Bendpoint)

Example 9 with Bendpoint

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

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:xsi", "http://www.w3.org/2001/XMLSchema-instance");
            xml.addAttribute("xsi:schemaLocation", "http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd");
            xml.addAttribute("xmlns:y", "http://www.yworks.com/xml/graphml");
            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 = (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);
                        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", "12");
                            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", getHtmlColor(entityFigure.getNameLabel().getForegroundColor()));
                            xml.addAttribute("visible", "true");
                            xml.addAttribute("height", nameBounds.height());
                            xml.addAttribute("width", nameBounds.width);
                            xml.addAttribute("x", nameBounds.x());
                            xml.addAttribute("y", nameBounds.y());
                            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", "12");
                            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("height", attrsBounds.height());
                            xml.addAttribute("width", attrsBounds.width);
                            xml.addAttribute("x", attrsBounds.x());
                            xml.addAttribute("y", attrsBounds.y());
                            StringBuilder attrsString = new StringBuilder();
                            for (ERDEntityAttribute attr : entity.getColumns()) {
                                if (attrsString.length() > 0) {
                                    attrsString.append("\n");
                                }
                                attrsString.append(attr.getName());
                            }
                            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.getForeignKeyRelationships()) {
                    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.getPrimaryKeyEntity()));
                    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");
                    for (Bendpoint bp : associationPart.getBendpoints()) {
                        xml.startElement("y:Point");
                        xml.addAttribute("x", bp.getLocation().x);
                        xml.addAttribute("y", bp.getLocation().x);
                        xml.endElement();
                    }
                    xml.endElement();
                    xml.startElement("y:LineStyle");
                    xml.addAttribute("color", "#000000");
                    xml.addAttribute("type", !association.isIdentifying() || association.isLogical() ? "dashed" : "line");
                    xml.addAttribute("width", "1.0");
                    xml.endElement();
                    xml.startElement("y:Arrows");
                    String sourceStyle = !association.isIdentifying() ? "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) {
        DBUserInterface.getInstance().showError("Save ERD as GraphML", null, e);
    }
}
Also used : EntityFigure(org.jkiss.dbeaver.ext.erd.figures.EntityFigure) HashMap(java.util.HashMap) ERDEntity(org.jkiss.dbeaver.ext.erd.model.ERDEntity) Rectangle(org.eclipse.draw2d.geometry.Rectangle) ERDAssociation(org.jkiss.dbeaver.ext.erd.model.ERDAssociation) XMLBuilder(org.jkiss.utils.xml.XMLBuilder) Bendpoint(org.eclipse.draw2d.Bendpoint) AttributeListFigure(org.jkiss.dbeaver.ext.erd.figures.AttributeListFigure) DBException(org.jkiss.dbeaver.DBException) ERDEntityAttribute(org.jkiss.dbeaver.ext.erd.model.ERDEntityAttribute) FileOutputStream(java.io.FileOutputStream) AssociationPart(org.jkiss.dbeaver.ext.erd.part.AssociationPart) EntityPart(org.jkiss.dbeaver.ext.erd.part.EntityPart) Bendpoint(org.eclipse.draw2d.Bendpoint)

Example 10 with Bendpoint

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

the class ConnectionBendpointEditPolicy method createHandlesForUserBendpoints.

private List createHandlesForUserBendpoints() {
    List<Object> list = new ArrayList<Object>();
    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 ConnectionBendpointCreationHandel(connEP, bendPointIndex, i));
        // move handle
        if (i < points.size() - 1 && bendPointIndex < bendPoints.size() && currBendPoint.equals(points.getPoint(i + 1))) {
            list.add(new ConnectionBendpointMoveHandel(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) ConnectionBendpointMoveHandel(org.knime.workbench.editor2.editparts.snap.ConnectionBendpointMoveHandel) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) PointList(org.eclipse.draw2d.geometry.PointList) List(java.util.List) Point(org.eclipse.draw2d.geometry.Point) AbsoluteBendpoint(org.eclipse.draw2d.AbsoluteBendpoint) Bendpoint(org.eclipse.draw2d.Bendpoint) AbsoluteBendpoint(org.eclipse.draw2d.AbsoluteBendpoint) Point(org.eclipse.draw2d.geometry.Point) Bendpoint(org.eclipse.draw2d.Bendpoint) ConnectionBendpointCreationHandel(org.knime.workbench.editor2.editparts.snap.ConnectionBendpointCreationHandel)

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