Search in sources :

Example 1 with NotePart

use of org.jkiss.dbeaver.ext.erd.part.NotePart in project dbeaver by serge-rider.

the class NoteDirectEditPolicy method revertOldEditValue.

/**
	 * @param request
	 */
@Override
protected void revertOldEditValue(DirectEditRequest request) {
    CellEditor cellEditor = request.getCellEditor();
    cellEditor.setValue(oldValue);
    NotePart entityPart = (NotePart) getHost();
    entityPart.revertNameChange();
}
Also used : NotePart(org.jkiss.dbeaver.ext.erd.part.NotePart) CellEditor(org.eclipse.jface.viewers.CellEditor)

Example 2 with NotePart

use of org.jkiss.dbeaver.ext.erd.part.NotePart in project dbeaver by serge-rider.

the class NoteDirectEditPolicy method showCurrentEditValue.

/**
	 * @see org.eclipse.gef.editpolicies.DirectEditPolicy#showCurrentEditValue(org.eclipse.gef.requests.DirectEditRequest)
	 */
@Override
protected void showCurrentEditValue(DirectEditRequest request) {
    String value = (String) request.getCellEditor().getValue();
    NotePart notePart = (NotePart) getHost();
    notePart.handleNameChange(value);
}
Also used : NotePart(org.jkiss.dbeaver.ext.erd.part.NotePart)

Example 3 with NotePart

use of org.jkiss.dbeaver.ext.erd.part.NotePart in project dbeaver by serge-rider.

the class DiagramLoader method save.

public static void save(DBRProgressMonitor monitor, DiagramPart diagramPart, final EntityDiagram diagram, boolean verbose, OutputStream out) throws IOException {
    // 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));
                }
                Rectangle tableBounds;
                if (tablePart != null) {
                    tableBounds = tablePart.getBounds();
                } else {
                    tableBounds = diagram.getInitBounds(erdEntity);
                }
                if (tableBounds != null) {
                    xml.addAttribute(ATTR_X, tableBounds.x);
                    xml.addAttribute(ATTR_Y, tableBounds.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(VoidProgressMonitor.INSTANCE)) {
                        xml.startElement(TAG_COLUMN);
                        xml.addAttribute(ATTR_NAME, column.getAttribute().getName());
                        try {
                            xml.addAttribute(ATTR_REF_NAME, DBUtils.getReferenceAttribute(monitor, association, column.getAttribute()).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) {
                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) NotePart(org.jkiss.dbeaver.ext.erd.part.NotePart) AssociationPart(org.jkiss.dbeaver.ext.erd.part.AssociationPart) EntityPart(org.jkiss.dbeaver.ext.erd.part.EntityPart) AbsoluteBendpoint(org.eclipse.draw2d.AbsoluteBendpoint) RelativeBendpoint(org.eclipse.draw2d.RelativeBendpoint) Bendpoint(org.eclipse.draw2d.Bendpoint)

Example 4 with NotePart

use of org.jkiss.dbeaver.ext.erd.part.NotePart in project dbeaver by dbeaver.

the class NoteDirectEditPolicy method showCurrentEditValue.

/**
 * @see org.eclipse.gef.editpolicies.DirectEditPolicy#showCurrentEditValue(org.eclipse.gef.requests.DirectEditRequest)
 */
@Override
protected void showCurrentEditValue(DirectEditRequest request) {
    String value = (String) request.getCellEditor().getValue();
    NotePart notePart = (NotePart) getHost();
    notePart.handleNameChange(value);
}
Also used : NotePart(org.jkiss.dbeaver.ext.erd.part.NotePart)

Example 5 with NotePart

use of org.jkiss.dbeaver.ext.erd.part.NotePart in project dbeaver by dbeaver.

the class NoteCreateCommand method execute.

@Override
public void execute() {
    diagramPart.getDiagram().addNote(note, true);
    if (location != null) {
        // Set new note location
        for (Object diagramChild : diagramPart.getChildren()) {
            if (diagramChild instanceof NotePart) {
                NotePart entityPart = (NotePart) diagramChild;
                if (entityPart.getNote() == note) {
                    final Dimension size = entityPart.getFigure().getPreferredSize();
                    final Rectangle newBounds = new Rectangle(location.x, location.y, size.width, size.height);
                    entityPart.modifyBounds(newBounds);
                    break;
                }
            }
        }
    }
}
Also used : NotePart(org.jkiss.dbeaver.ext.erd.part.NotePart) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Dimension(org.eclipse.draw2d.geometry.Dimension)

Aggregations

NotePart (org.jkiss.dbeaver.ext.erd.part.NotePart)9 Rectangle (org.eclipse.draw2d.geometry.Rectangle)5 Dimension (org.eclipse.draw2d.geometry.Dimension)2 CellEditor (org.eclipse.jface.viewers.CellEditor)2 NoteDeleteCommand (org.jkiss.dbeaver.ext.erd.command.NoteDeleteCommand)2 EntityDiagram (org.jkiss.dbeaver.ext.erd.model.EntityDiagram)2 AbsoluteBendpoint (org.eclipse.draw2d.AbsoluteBendpoint)1 Bendpoint (org.eclipse.draw2d.Bendpoint)1 RelativeBendpoint (org.eclipse.draw2d.RelativeBendpoint)1 Point (org.eclipse.draw2d.geometry.Point)1 DBException (org.jkiss.dbeaver.DBException)1 AssociationPart (org.jkiss.dbeaver.ext.erd.part.AssociationPart)1 EntityPart (org.jkiss.dbeaver.ext.erd.part.EntityPart)1 XMLBuilder (org.jkiss.utils.xml.XMLBuilder)1