use of org.eclipse.draw2d.AbsoluteBendpoint 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();
}
use of org.eclipse.draw2d.AbsoluteBendpoint in project knime-core by knime.
the class ConnectionBendpointEditPolicy method showMoveBendpointFeedback.
/**
* Shows feedback when a bendpoint is being moved. Also checks to see if the
* bendpoint should be deleted and then calls
* {@link #showDeleteBendpointFeedback(BendpointRequest)} if needed. The
* original figure is used for feedback and the original constraint is
* saved, so that it can be restored when feedback is erased.
*
* @param request the BendpointRequest
*/
protected void showMoveBendpointFeedback(final BendpointRequest request) {
Point p = new Point(request.getLocation());
if (!m_isDeleting) {
setReferencePoints(request);
}
if (lineContainsPoint(REF1, REF2, p)) {
if (!m_isDeleting) {
m_isDeleting = true;
eraseSourceFeedback(request);
showDeleteBendpointFeedback(request);
}
return;
}
if (m_isDeleting) {
m_isDeleting = false;
eraseSourceFeedback(request);
}
if (m_originalConstraint == null) {
saveOriginalConstraint();
}
List<Object> constraint = (List<Object>) getConnection().getRoutingConstraint();
getConnection().translateToRelative(p);
Bendpoint bp = new AbsoluteBendpoint(p);
constraint.set(request.getIndex(), bp);
getConnection().setRoutingConstraint(constraint);
}
use of org.eclipse.draw2d.AbsoluteBendpoint in project knime-core by knime.
the class ConnectionBendpointEditPolicy method showCreateBendpointFeedback.
/**
* Shows feedback when a bendpoint is being created. The original figure is
* used for feedback and the original constraint is saved, so that it can be
* restored when feedback is erased.
*
* @param request the BendpointRequest
*/
protected void showCreateBendpointFeedback(final BendpointRequest request) {
Point p = new Point(request.getLocation());
List<Object> constraint;
getConnection().translateToRelative(p);
Bendpoint bp = new AbsoluteBendpoint(p);
if (m_originalConstraint == null) {
saveOriginalConstraint();
constraint = (List<Object>) getConnection().getRoutingConstraint();
constraint.add(request.getIndex(), bp);
} else {
constraint = (List<Object>) getConnection().getRoutingConstraint();
}
constraint.set(request.getIndex(), bp);
getConnection().setRoutingConstraint(constraint);
}
use of org.eclipse.draw2d.AbsoluteBendpoint in project knime-core by knime.
the class ConnectionContainerEditPart method refreshVisuals.
/**
* {@inheritDoc}
*/
@Override
protected void refreshVisuals() {
super.refreshVisuals();
LOGGER.debug("refreshing visuals for: " + getModel());
ConnectionUIInformation ei = null;
ei = getModel().getUIInfo();
LOGGER.debug("modelling info: " + ei);
// make flow variable port connections look red.
CurvedPolylineConnection fig = (CurvedPolylineConnection) getFigure();
if (getModel().isFlowVariablePortConnection()) {
fig.setForegroundColor(AbstractPortFigure.getFlowVarPortColor());
}
// update 'curved' settings and line width
EditorUIInformation uiInfo = getCurrentEditorSettings();
fig.setCurved(uiInfo.getHasCurvedConnections());
fig.setLineWidth(uiInfo.getConnectionLineWidth());
// recreate list of bendpoints
ArrayList<AbsoluteBendpoint> constraint = new ArrayList<AbsoluteBendpoint>();
if (ei != null) {
int[][] p = ei.getAllBendpoints();
for (int i = 0; i < p.length; i++) {
AbsoluteBendpoint bp = new AbsoluteBendpoint(p[i][0], p[i][1]);
constraint.add(bp);
}
}
fig.setRoutingConstraint(constraint);
}
use of org.eclipse.draw2d.AbsoluteBendpoint 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();
}
Aggregations