提交 dea84a02 编写于 作者: S serge-rider

ERD layout fix


Former-commit-id: 56ccbe94
上级 2de3e718
......@@ -69,7 +69,7 @@ public class GraphLayoutAuto extends AbstractLayout
*/
// TODO: REPLACE WITH ZEST!
new DirectedGraphLayoutVisitor().layoutDiagram(diagram);
new DirectedGraphLayoutVisitor(diagram.getDiagram().getDecorator()).layoutDiagram(diagram);
diagram.setTableModelBounds();
//new ZestGraphLayout().layoutDiagram(diagram);
......
......@@ -23,7 +23,6 @@ package org.jkiss.dbeaver.ext.erd.layout.algorithm.direct;
import org.jkiss.dbeaver.Log;
import org.eclipse.draw2d.*;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Insets;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.draw2d.graph.*;
import org.eclipse.gef.EditPart;
......@@ -32,6 +31,7 @@ import org.eclipse.gef.NodeEditPart;
import org.eclipse.gef.editparts.AbstractConnectionEditPart;
import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
import org.jkiss.dbeaver.ext.erd.layout.GraphAnimation;
import org.jkiss.dbeaver.ext.erd.model.ERDDecorator;
import org.jkiss.dbeaver.ext.erd.part.EntityPart;
import java.util.ArrayList;
......@@ -48,8 +48,13 @@ import java.util.Map;
public class DirectedGraphLayoutVisitor {
private static final Log log = Log.getLog(DirectedGraphLayoutVisitor.class);
Map<EditPart, Object> partToNodesMap;
DirectedGraph graph;
private final ERDDecorator decorator;
private Map<EditPart, Object> partToNodesMap;
private DirectedGraph graph;
public DirectedGraphLayoutVisitor(ERDDecorator decorator) {
this.decorator = decorator;
}
/**
* Public method for reading graph nodes
......@@ -100,7 +105,7 @@ public class DirectedGraphLayoutVisitor {
Dimension preferredSize = nodeEditPart.getFigure().getPreferredSize(-1, -1);
entityNode.width = preferredSize.width;
entityNode.height = preferredSize.height;
entityNode.setPadding(new Insets(20, 20, 10, 20));
entityNode.setPadding(decorator.getDefaultEntityInsets());
partToNodesMap.put(nodeEditPart, entityNode);
graph.nodes.add(entityNode);
......
......@@ -16,6 +16,7 @@
*/
package org.jkiss.dbeaver.ext.erd.model;
import org.eclipse.draw2d.geometry.Insets;
import org.eclipse.gef.EditPartFactory;
import org.eclipse.gef.palette.PaletteRoot;
import org.jkiss.code.NotNull;
......@@ -32,6 +33,11 @@ public interface ERDDecorator {
boolean allowEntityDuplicates();
/**
* Margin around entity figure. This affects diagram connections layout
*/
Insets getDefaultEntityInsets();
@NotNull
EditPartFactory createPartFactory();
......
......@@ -16,6 +16,7 @@
*/
package org.jkiss.dbeaver.ext.erd.model;
import org.eclipse.draw2d.geometry.Insets;
import org.eclipse.gef.EditPartFactory;
import org.eclipse.gef.RequestConstants;
import org.eclipse.gef.palette.*;
......@@ -61,6 +62,11 @@ public class ERDDecoratorDefault implements ERDDecorator {
return false;
}
@Override
public Insets getDefaultEntityInsets() {
return new Insets(20, 20, 10, 20);
}
@Override
public EditPartFactory createPartFactory() {
return new ERDEditPartFactory();
......
......@@ -27,7 +27,6 @@ import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.*;
import org.eclipse.gef.editpolicies.ConnectionEndpointEditPolicy;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.jkiss.dbeaver.ext.erd.ERDConstants;
import org.jkiss.dbeaver.ext.erd.model.ERDAssociation;
import org.jkiss.dbeaver.ext.erd.model.ERDEntityAttribute;
......@@ -89,14 +88,15 @@ public class AssociationPart extends PropertyAwareConnectionPart {
conn.setForegroundColor(UIUtils.getColorRegistry().get(ERDConstants.COLOR_ERD_LINES_FOREGROUND));
setConnectionStyles(association, conn);
setConnectionRouting(association, conn);
setConnectionStyles(conn);
setConnectionRouting(conn);
setConnectionToolTip(conn);
return conn;
}
protected void setConnectionRouting(ERDAssociation association, PolylineConnection conn) {
protected void setConnectionRouting(PolylineConnection conn) {
ERDAssociation association = getAssociation();
// Set router and initial bends
ConnectionLayer cLayer = (ConnectionLayer) getLayer(LayerConstants.CONNECTION_LAYER);
conn.setConnectionRouter(cLayer.getConnectionRouter());
......@@ -130,8 +130,9 @@ public class AssociationPart extends PropertyAwareConnectionPart {
}
}
protected void setConnectionStyles(ERDAssociation association, PolylineConnection conn) {
protected void setConnectionStyles(PolylineConnection conn) {
ERDAssociation association = getAssociation();
boolean identifying = ERDUtils.isIdentifyingAssociation(association);
if (association.getObject().getConstraintType() == DBSEntityConstraintType.INHERITANCE) {
......
......@@ -86,9 +86,9 @@ public class DiagramXYLayoutPolicy extends XYLayoutEditPolicy
{
IFigure fig = child.getFigure();
Rectangle rectangle = (Rectangle) fig.getParent().getLayoutManager().getConstraint(fig);
if (rectangle == null)
{
Object constraint = fig.getParent().getLayoutManager().getConstraint(fig);
Rectangle rectangle = constraint instanceof Rectangle ? (Rectangle) constraint : null;
if (rectangle == null) {
rectangle = fig.getBounds();
}
return rectangle;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册