Search in sources :

Example 16 with EntityPart

use of org.jkiss.dbeaver.erd.ui.part.EntityPart in project dbeaver by serge-rider.

the class ERDGraphicalViewer method setContents.

@Override
public void setContents(EditPart editpart) {
    loadContents = true;
    try {
        super.setContents(editpart);
        // Reset palette contents
        if (editpart instanceof DiagramPart) {
            List<DBSEntity> tables = new ArrayList<>();
            for (Object child : editpart.getChildren()) {
                if (child instanceof EntityPart) {
                    tables.add(((EntityPart) child).getEntity().getObject());
                }
            }
            tables.sort(DBUtils.nameComparator());
            Map<PaletteDrawer, List<ToolEntryTable>> toolMap = new LinkedHashMap<>();
            for (DBSEntity table : tables) {
                DBPDataSourceContainer container = table.getDataSource().getContainer();
                PaletteDrawer drawer = getContainerPaletteDrawer(container);
                if (drawer != null) {
                    List<ToolEntryTable> tools = toolMap.get(drawer);
                    if (tools == null) {
                        tools = new ArrayList<>(tables.size());
                        toolMap.put(drawer, tools);
                    }
                    tools.add(new ToolEntryTable(table));
                }
            }
            for (Map.Entry<PaletteDrawer, List<ToolEntryTable>> entry : toolMap.entrySet()) {
                entry.getKey().setChildren(entry.getValue());
            }
        // editor.getPaletteContents().setChildren(tools);
        }
    } finally {
        loadContents = false;
    }
}
Also used : PaletteDrawer(org.eclipse.gef.palette.PaletteDrawer) DBSEntity(org.jkiss.dbeaver.model.struct.DBSEntity) EntityPart(org.jkiss.dbeaver.erd.ui.part.EntityPart) DiagramPart(org.jkiss.dbeaver.erd.ui.part.DiagramPart)

Example 17 with EntityPart

use of org.jkiss.dbeaver.erd.ui.part.EntityPart in project dbeaver by serge-rider.

the class SetPartSettingsAction method createColorCommand.

private Command createColorCommand(final Object[] objects) {
    return new Command() {

        private ViewSettings newSettings;

        private final Map<ICustomizablePart, ViewSettings> oldSettings = new HashMap<>();

        @Override
        public void execute() {
            final Shell shell = UIUtils.createCenteredShell(getWorkbenchPart().getSite().getShell());
            try {
                NodePart nodePart = null;
                boolean hasNotes = false, hasEntities = false;
                for (Object item : objects) {
                    if (item instanceof NodePart) {
                        if (nodePart == null) {
                            nodePart = (NodePart) item;
                        }
                        if (item instanceof NotePart) {
                            hasNotes = true;
                        } else if (item instanceof EntityPart) {
                            hasEntities = true;
                        }
                    }
                }
                PartSettingsDialog settingsDialog = new PartSettingsDialog(shell, nodePart, hasNotes, hasEntities);
                if (settingsDialog.open() != IDialogConstants.OK_ID) {
                    return;
                }
                newSettings = settingsDialog.newSettings;
                for (Object item : objects) {
                    if (item instanceof ICustomizablePart) {
                        ICustomizablePart part = (ICustomizablePart) item;
                        ViewSettings oldSettings = new ViewSettings();
                        oldSettings.transparency = part.getCustomTransparency();
                        oldSettings.background = part.getCustomBackgroundColor();
                        oldSettings.foreground = part.getCustomForegroundColor();
                        oldSettings.borderWidth = part.getCustomBorderWidth();
                        oldSettings.fontInfo = SharedFonts.toString(part.getCustomFont());
                        this.oldSettings.put(part, oldSettings);
                        setNodeSettings(part, newSettings);
                    }
                }
            } finally {
                UIUtils.disposeCenteredShell(shell);
            }
        }

        @Override
        public void undo() {
            for (Object item : objects) {
                if (item instanceof ICustomizablePart) {
                    ICustomizablePart colorizedPart = (ICustomizablePart) item;
                    ViewSettings viewSettings = oldSettings.get(colorizedPart);
                    if (viewSettings != null) {
                        setNodeSettings(colorizedPart, viewSettings);
                    }
                }
            }
        }

        @Override
        public void redo() {
            for (Object item : objects) {
                if (item instanceof ICustomizablePart) {
                    setNodeSettings((ICustomizablePart) item, newSettings);
                }
            }
        }

        private void setNodeSettings(ICustomizablePart part, ViewSettings settings) {
            if (part instanceof NotePart) {
                part.setCustomTransparency(settings.transparency);
            }
            part.setCustomBackgroundColor(settings.background);
            if (part instanceof NotePart) {
                part.setCustomForegroundColor(settings.foreground);
                part.setCustomBorderWidth(settings.borderWidth);
                part.setCustomFont(UIUtils.getSharedFonts().getFont(Display.getCurrent(), settings.fontInfo));
            }
        }
    };
}
Also used : NotePart(org.jkiss.dbeaver.erd.ui.part.NotePart) Command(org.eclipse.gef.commands.Command) ICustomizablePart(org.jkiss.dbeaver.erd.ui.part.ICustomizablePart) NodePart(org.jkiss.dbeaver.erd.ui.part.NodePart) EntityPart(org.jkiss.dbeaver.erd.ui.part.EntityPart) HashMap(java.util.HashMap) Map(java.util.Map)

Example 18 with EntityPart

use of org.jkiss.dbeaver.erd.ui.part.EntityPart 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)

Example 19 with EntityPart

use of org.jkiss.dbeaver.erd.ui.part.EntityPart in project dbeaver by serge-rider.

the class DirectedGraphLayoutVisitor method addEntityNode.

/**
 * Adds nodes to the graph object for use by the GraphLayoutAuto
 */
protected void addEntityNode(NodeEditPart nodeEditPart) {
    Node entityNode;
    if (nodeEditPart instanceof EntityPart && ((EntityPart) nodeEditPart).getEntity().hasSelfLinks()) {
        entityNode = new Subgraph(nodeEditPart);
    } else {
        entityNode = new Node(nodeEditPart);
    }
    Dimension preferredSize = nodeEditPart.getFigure().getPreferredSize(-1, -1);
    entityNode.width = preferredSize.width;
    entityNode.height = preferredSize.height;
    entityNode.setPadding(decorator.getDefaultEntityInsets());
    partToNodesMap.put(nodeEditPart, entityNode);
    graph.nodes.add(entityNode);
    if (entityNode instanceof Subgraph) {
        Node sourceAnchor = new Node("Fake node for source links", (Subgraph) entityNode);
        sourceAnchor.width = 0;
        sourceAnchor.height = 0;
        Node targetAnchor = new Node("Fake node for target links", (Subgraph) entityNode);
        targetAnchor.width = 0;
        targetAnchor.height = 0;
    }
/*
*/
}
Also used : Dimension(org.eclipse.draw2d.geometry.Dimension) EntityPart(org.jkiss.dbeaver.erd.ui.part.EntityPart)

Example 20 with EntityPart

use of org.jkiss.dbeaver.erd.ui.part.EntityPart in project dbeaver by serge-rider.

the class EntityDirectEditPolicy method showCurrentEditValue.

@Override
protected void showCurrentEditValue(DirectEditRequest request) {
    String value = (String) request.getCellEditor().getValue();
    EntityPart entityPart = (EntityPart) getHost();
    entityPart.handleNameChange(value);
}
Also used : EntityPart(org.jkiss.dbeaver.erd.ui.part.EntityPart)

Aggregations

EntityPart (org.jkiss.dbeaver.erd.ui.part.EntityPart)20 Rectangle (org.eclipse.draw2d.geometry.Rectangle)6 NodePart (org.jkiss.dbeaver.erd.ui.part.NodePart)6 HashMap (java.util.HashMap)4 Dimension (org.eclipse.draw2d.geometry.Dimension)4 ERDEntity (org.jkiss.dbeaver.erd.model.ERDEntity)4 NotePart (org.jkiss.dbeaver.erd.ui.part.NotePart)4 DBSEntity (org.jkiss.dbeaver.model.struct.DBSEntity)4 FileOutputStream (java.io.FileOutputStream)2 EventObject (java.util.EventObject)2 Map (java.util.Map)2 Bendpoint (org.eclipse.draw2d.Bendpoint)2 Figure (org.eclipse.draw2d.Figure)2 IFigure (org.eclipse.draw2d.IFigure)2 Point (org.eclipse.draw2d.geometry.Point)2 Command (org.eclipse.gef.commands.Command)2 PaletteDrawer (org.eclipse.gef.palette.PaletteDrawer)2 CellEditor (org.eclipse.jface.viewers.CellEditor)2 ISelection (org.eclipse.jface.viewers.ISelection)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2