Search in sources :

Example 1 with ERDEntityAttribute

use of org.jkiss.dbeaver.ext.erd.model.ERDEntityAttribute in project dbeaver by serge-rider.

the class AttributePart method createFigure.

/**
	 * @return the ColumnLabel representing the Column
	 */
@Override
protected AttributeItemFigure createFigure() {
    ERDEntityAttribute column = (ERDEntityAttribute) getModel();
    AttributeItemFigure attributeFigure = new AttributeItemFigure(column);
    DiagramPart diagramPart = (DiagramPart) getParent().getParent();
    boolean showNullability = diagramPart.getDiagram().hasAttributeStyle(ERDAttributeStyle.NULLABILITY);
    Font columnFont = diagramPart.getNormalFont();
    Color columnColor = diagramPart.getContentPane().getForegroundColor();
    if (column.isInPrimaryKey()) {
        columnFont = diagramPart.getBoldFont();
        if (showNullability && !column.getObject().isRequired()) {
            columnFont = diagramPart.getBoldItalicFont();
        }
    /*
            if (!column.isInForeignKey()) {
                columnFont = diagramPart.getBoldFont();
            } else {
                columnFont = diagramPart.getBoldItalicFont();
            }
*/
    } else {
        if (showNullability && !column.getObject().isRequired()) {
            columnFont = diagramPart.getItalicFont();
        }
    }
    if (column.isInForeignKey()) {
    //columnColor = Display.getDefault().getSystemColor(SWT.COLOR_DARK_BLUE);
    }
    attributeFigure.setFont(columnFont);
    attributeFigure.setForegroundColor(columnColor);
    return attributeFigure;
}
Also used : ERDEntityAttribute(org.jkiss.dbeaver.ext.erd.model.ERDEntityAttribute) Color(org.eclipse.swt.graphics.Color) AttributeItemFigure(org.jkiss.dbeaver.ext.erd.figures.AttributeItemFigure) Font(org.eclipse.swt.graphics.Font)

Example 2 with ERDEntityAttribute

use of org.jkiss.dbeaver.ext.erd.model.ERDEntityAttribute in project dbeaver by serge-rider.

the class ERDExportGraphML method exportDiagramToGraphML.

void exportDiagramToGraphML(String filePath) {
    try {
        try (FileOutputStream fos = new FileOutputStream(filePath)) {
            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(filePath);
    } catch (Exception e) {
        UIUtils.showErrorDialog(null, "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) 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 3 with ERDEntityAttribute

use of org.jkiss.dbeaver.ext.erd.model.ERDEntityAttribute in project dbeaver by dbeaver.

the class AttributePart method createFigure.

/**
 * @return the ColumnLabel representing the Column
 */
@Override
protected AttributeItemFigure createFigure() {
    ERDEntityAttribute column = (ERDEntityAttribute) getModel();
    AttributeItemFigure attributeFigure = new AttributeItemFigure(column);
    DiagramPart diagramPart = (DiagramPart) getParent().getParent();
    boolean showNullability = diagramPart.getDiagram().hasAttributeStyle(ERDAttributeStyle.NULLABILITY);
    Font columnFont = diagramPart.getNormalFont();
    Color columnColor = diagramPart.getContentPane().getForegroundColor();
    if (column.isInPrimaryKey()) {
        columnFont = diagramPart.getBoldFont();
        if (showNullability && !column.getObject().isRequired()) {
            columnFont = diagramPart.getBoldItalicFont();
        }
    /*
            if (!column.isInForeignKey()) {
                columnFont = diagramPart.getBoldFont();
            } else {
                columnFont = diagramPart.getBoldItalicFont();
            }
*/
    } else {
        if (showNullability && !column.getObject().isRequired()) {
            columnFont = diagramPart.getItalicFont();
        }
    }
    if (column.isInForeignKey()) {
    // columnColor = Display.getDefault().getSystemColor(SWT.COLOR_DARK_BLUE);
    }
    attributeFigure.setFont(columnFont);
    attributeFigure.setForegroundColor(columnColor);
    return attributeFigure;
}
Also used : ERDEntityAttribute(org.jkiss.dbeaver.ext.erd.model.ERDEntityAttribute) Color(org.eclipse.swt.graphics.Color) AttributeItemFigure(org.jkiss.dbeaver.ext.erd.figures.AttributeItemFigure) Font(org.eclipse.swt.graphics.Font)

Example 4 with ERDEntityAttribute

use of org.jkiss.dbeaver.ext.erd.model.ERDEntityAttribute in project dbeaver by dbeaver.

the class AttributePart method refreshVisuals.

/**
 * We don't need to explicitly handle refresh visuals because the times when
 * this needs to be done it is handled by the table e.g. handleNameChange()
 */
@Override
protected void refreshVisuals() {
    ERDEntityAttribute column = (ERDEntityAttribute) getModel();
    getFigure().setText(column.getLabelText());
}
Also used : ERDEntityAttribute(org.jkiss.dbeaver.ext.erd.model.ERDEntityAttribute)

Example 5 with ERDEntityAttribute

use of org.jkiss.dbeaver.ext.erd.model.ERDEntityAttribute in project dbeaver by serge-rider.

the class AttributePart method refreshVisuals.

/**
	 * We don't need to explicitly handle refresh visuals because the times when
	 * this needs to be done it is handled by the table e.g. handleNameChange()
	 */
@Override
protected void refreshVisuals() {
    ERDEntityAttribute column = (ERDEntityAttribute) getModel();
    getFigure().setText(column.getLabelText());
}
Also used : ERDEntityAttribute(org.jkiss.dbeaver.ext.erd.model.ERDEntityAttribute)

Aggregations

ERDEntityAttribute (org.jkiss.dbeaver.ext.erd.model.ERDEntityAttribute)6 FileOutputStream (java.io.FileOutputStream)2 HashMap (java.util.HashMap)2 Bendpoint (org.eclipse.draw2d.Bendpoint)2 Rectangle (org.eclipse.draw2d.geometry.Rectangle)2 Color (org.eclipse.swt.graphics.Color)2 Font (org.eclipse.swt.graphics.Font)2 AttributeItemFigure (org.jkiss.dbeaver.ext.erd.figures.AttributeItemFigure)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 AssociationPart (org.jkiss.dbeaver.ext.erd.part.AssociationPart)2 EntityPart (org.jkiss.dbeaver.ext.erd.part.EntityPart)2 XMLBuilder (org.jkiss.utils.xml.XMLBuilder)2 DBException (org.jkiss.dbeaver.DBException)1