use of org.eclipse.draw2d.AbsoluteBendpoint in project jbosstools-hibernate by jbosstools.
the class DirectedGraphLayoutVisitor method applyResults.
// ******************* RelationshipPart apply methods **********/
protected void applyResults(AssociationEditPart relationshipPart) {
Edge e = (Edge) partToNodesMap.get(relationshipPart);
PolylineConnection conn = (PolylineConnection) relationshipPart.getConnectionFigure();
if (e == null) {
// conn.setConnectionRouter(new ShortestPathConnectionRouter(diagram.getFigure()));
return;
}
NodeList nodes = e.vNodes;
if (nodes != null) {
List<AbsoluteBendpoint> bends = new ArrayList<AbsoluteBendpoint>();
for (int i = 0; i < nodes.size(); i++) {
Node vn = nodes.getNode(i);
int x = vn.x;
int y = vn.y;
if (e.isFeedback()) {
bends.add(new AbsoluteBendpoint(x, y + vn.height));
bends.add(new AbsoluteBendpoint(x, y));
} else {
bends.add(new AbsoluteBendpoint(x, y));
bends.add(new AbsoluteBendpoint(x, y + vn.height));
}
}
conn.setRoutingConstraint(bends);
} else {
conn.setRoutingConstraint(Collections.EMPTY_LIST);
}
}
use of org.eclipse.draw2d.AbsoluteBendpoint in project netxms by netxms.
the class BendpointEditor method saveBendPoints.
/**
* Save bend points into map link object
*/
private void saveBendPoints() {
long[] points = new long[handles.size() * 2 + 2];
int pos = 0;
for (AbsoluteBendpoint bp : bendpoints) {
points[pos++] = bp.x;
points[pos++] = bp.y;
}
points[pos++] = 0x7FFFFFFF;
points[pos++] = 0x7FFFFFFF;
linkObject.setBendPoints(points);
}
use of org.eclipse.draw2d.AbsoluteBendpoint in project netxms by netxms.
the class BendpointEditor method addBendPoint.
/**
* Add new bendpoint
*
* @param x
* @param y
*/
private void addBendPoint(int x, int y) {
if (bendpoints.size() >= 16)
return;
AbsoluteBendpoint bp = new AbsoluteBendpoint(x, y);
if (bendpoints.size() > 1) {
int index = 0;
for (int i = 0; i < bendpoints.size() - 1; i++) {
AbsoluteBendpoint p1 = bendpoints.get(i);
AbsoluteBendpoint p2 = bendpoints.get(i + 1);
if (isLineContainsPoint(p1.x, p1.y, p2.x, p2.y, x, y)) {
index = i + 1;
break;
}
}
if (index == 0) {
Point pnode = connectionFigure.getTargetAnchor().getReferencePoint();
AbsoluteBendpoint plast = bendpoints.get(bendpoints.size() - 1);
if (isLineContainsPoint(pnode.x, pnode.y, plast.x, plast.y, x, y))
index = bendpoints.size();
}
bendpoints.add(index, bp);
} else if (bendpoints.size() == 1) {
Point pnode = connectionFigure.getTargetAnchor().getReferencePoint();
AbsoluteBendpoint plast = bendpoints.get(bendpoints.size() - 1);
if (isLineContainsPoint(pnode.x, pnode.y, plast.x, plast.y, x, y))
bendpoints.add(bp);
else
bendpoints.add(0, bp);
} else {
bendpoints.add(bp);
}
setRoutingConstraints();
handles.put(bp, new BendpointHandle(bp));
}
use of org.eclipse.draw2d.AbsoluteBendpoint 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();
}
use of org.eclipse.draw2d.AbsoluteBendpoint in project dbeaver by dbeaver.
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();
}
Aggregations