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

ERD join render


Former-commit-id: 36ffc0ec
上级 7a0c9611
......@@ -78,7 +78,7 @@ public class EntityAddCommand extends Command
public void undo()
{
for (ERDEntity entity : entities) {
diagramPart.getDiagram().removeTable(entity, true);
diagramPart.getDiagram().removeEntity(entity, true);
}
}
......
......@@ -95,7 +95,7 @@ public class EntityDeleteCommand extends Command
// Delete entity
deleteRelationships(entity);
index = entityDiagram.getEntities().indexOf(entity);
entityDiagram.removeTable(entity, true);
entityDiagram.removeEntity(entity, true);
}
/**
......@@ -109,16 +109,12 @@ public class EntityDeleteCommand extends Command
private void restoreRelationships()
{
for (int i = 0; i < foreignKeyRelationships.size(); i++)
{
ERDAssociation r = foreignKeyRelationships.get(i);
for (ERDAssociation r : foreignKeyRelationships) {
r.getSourceEntity().addAssociation(r, true);
r.getTargetEntity().addReferenceAssociation(r, true);
}
foreignKeyRelationships.clear();
for (int i = 0; i < primaryKeyRelationships.size(); i++)
{
ERDAssociation r = primaryKeyRelationships.get(i);
for (ERDAssociation r : primaryKeyRelationships) {
r.getSourceEntity().addAssociation(r, true);
r.getTargetEntity().addReferenceAssociation(r, true);
}
......
......@@ -50,15 +50,15 @@ public class EntityDiagram extends ERDObject<DBSObject> {
private ERDDecorator decorator;
private String name;
private List<ERDEntity> entities = new ArrayList<>();
private final List<ERDEntity> entities = new ArrayList<>();
private boolean layoutManualDesired = true;
private boolean layoutManualAllowed = false;
private boolean needsAutoLayout;
private Map<DBSEntity, ERDEntity> entityMap = new IdentityHashMap<>();
private Map<ERDObject, NodeVisualInfo> nodeVisuals = new IdentityHashMap<>();
private final Map<DBSEntity, ERDEntity> entityMap = new IdentityHashMap<>();
private final Map<ERDObject, NodeVisualInfo> nodeVisuals = new IdentityHashMap<>();
private List<ERDNote> notes = new ArrayList<>();
private final List<ERDNote> notes = new ArrayList<>();
private ERDAttributeVisibility attributeVisibility;
private ERDViewStyle[] attributeStyles;
......@@ -102,17 +102,25 @@ public class EntityDiagram extends ERDObject<DBSObject> {
ERDAttributeVisibility.setDefaultVisibility(ERDActivator.getDefault().getPreferences(), attributeVisibility);
}
public synchronized void addEntity(ERDEntity entity, boolean reflect) {
public int getEntityOrder(ERDEntity entity) {
synchronized (entities) {
return entities.indexOf(entity);
}
}
public void addEntity(ERDEntity entity, boolean reflect) {
addEntity(entity, -1, reflect);
}
public synchronized void addEntity(ERDEntity entity, int i, boolean reflect) {
if (i < 0) {
entities.add(entity);
} else {
entities.add(i, entity);
public void addEntity(ERDEntity entity, int i, boolean reflect) {
synchronized (entities) {
if (i < 0) {
entities.add(entity);
} else {
entities.add(i, entity);
}
entityMap.put(entity.getObject(), entity);
}
entityMap.put(entity.getObject(), entity);
if (reflect) {
firePropertyChange(CHILD, null, entity);
......@@ -135,6 +143,7 @@ public class EntityDiagram extends ERDObject<DBSObject> {
}
}
private void resolveRelations(boolean reflect) {
// Resolve incomplete relations
for (ERDEntity erdEntity : getEntities()) {
......@@ -142,9 +151,11 @@ public class EntityDiagram extends ERDObject<DBSObject> {
}
}
public synchronized void removeTable(ERDEntity entity, boolean reflect) {
entityMap.remove(entity.getObject());
entities.remove(entity);
public synchronized void removeEntity(ERDEntity entity, boolean reflect) {
synchronized (entities) {
entityMap.remove(entity.getObject());
entities.remove(entity);
}
if (reflect) {
firePropertyChange(CHILD, entity, null);
}
......@@ -153,24 +164,28 @@ public class EntityDiagram extends ERDObject<DBSObject> {
/**
* @return the Tables for the current schema
*/
public synchronized List<ERDEntity> getEntities() {
public List<ERDEntity> getEntities() {
return entities;
}
public synchronized List<ERDNote> getNotes() {
public List<ERDNote> getNotes() {
return notes;
}
public synchronized void addNote(ERDNote note, boolean reflect) {
notes.add(note);
public void addNote(ERDNote note, boolean reflect) {
synchronized (notes) {
notes.add(note);
}
if (reflect) {
firePropertyChange(CHILD, null, note);
}
}
public synchronized void removeNote(ERDNote note, boolean reflect) {
notes.remove(note);
public void removeNote(ERDNote note, boolean reflect) {
synchronized (notes) {
notes.remove(note);
}
if (reflect) {
firePropertyChange(CHILD, note, null);
......@@ -228,7 +243,7 @@ public class EntityDiagram extends ERDObject<DBSObject> {
copy.entityMap.putAll(this.entityMap);
copy.layoutManualDesired = this.layoutManualDesired;
copy.layoutManualAllowed = this.layoutManualAllowed;
copy.nodeVisuals = nodeVisuals;
copy.nodeVisuals.putAll(this.nodeVisuals);
return copy;
}
......
......@@ -56,12 +56,10 @@ public class AssociationPart extends PropertyAwareConnectionPart {
// Keep original line width to visualize selection
private Integer oldLineWidth;
public AssociationPart()
{
public AssociationPart() {
}
public ERDAssociation getAssociation()
{
public ERDAssociation getAssociation() {
return (ERDAssociation) getModel();
}
......@@ -170,7 +168,7 @@ public class AssociationPart extends PropertyAwareConnectionPart {
if (!identifying || association.isLogical()) {
conn.setLineStyle(SWT.LINE_CUSTOM);
conn.setLineDash(new float[] {5} );
conn.setLineDash(new float[]{5});
}
//ChopboxAnchor sourceAnchor = new ChopboxAnchor(classFigure);
......@@ -214,18 +212,17 @@ public class AssociationPart extends PropertyAwareConnectionPart {
}
Color columnColor = value != EditPart.SELECTED_NONE ? Display.getDefault().getSystemColor(SWT.COLOR_RED) : getViewer().getControl().getForeground();
for (AttributePart attrPart : getEntityAttributes((EntityPart)getSource(), getAssociation().getSourceAttributes())) {
for (AttributePart attrPart : getEntityAttributes((EntityPart) getSource(), getAssociation().getSourceAttributes())) {
attrPart.getFigure().setForegroundColor(columnColor);
}
for (AttributePart attrPart : getEntityAttributes((EntityPart)getTarget(), getAssociation().getTargetAttributes())) {
for (AttributePart attrPart : getEntityAttributes((EntityPart) getTarget(), getAssociation().getTargetAttributes())) {
attrPart.getFigure().setForegroundColor(columnColor);
}
}
private List<AttributePart> getEntityAttributes(EntityPart source, List<ERDEntityAttribute> columns)
{
private List<AttributePart> getEntityAttributes(EntityPart source, List<ERDEntityAttribute> columns) {
List<AttributePart> result = new ArrayList<>();
for (AttributePart attrPart : (List<AttributePart>)source.getChildren()) {
for (AttributePart attrPart : (List<AttributePart>) source.getChildren()) {
if (columns.contains(attrPart.getAttribute())) {
result.add(attrPart);
}
......@@ -234,8 +231,7 @@ public class AssociationPart extends PropertyAwareConnectionPart {
}
@Override
public void performRequest(Request request)
{
public void performRequest(Request request) {
if (request.getType() == RequestConstants.REQ_OPEN) {
ERDUtils.openObjectEditor(getAssociation());
}
......@@ -291,8 +287,7 @@ public class AssociationPart extends PropertyAwareConnectionPart {
}
@Override
public String toString()
{
public String toString() {
return getAssociation().getObject().getConstraintType().getName() + " " + getAssociation().getObject().getName();
}
......@@ -305,25 +300,24 @@ public class AssociationPart extends PropertyAwareConnectionPart {
super();
}
public void setRadius(int radius)
{
public void setRadius(int radius) {
this.radius = radius;
}
@Override
public void setLocation(Point p) {
location = p;
Rectangle bounds = new Rectangle(location.x- radius, location.y- radius, radius *2, radius *2);
Rectangle bounds = new Rectangle(location.x - radius, location.y - radius, radius * 2, radius * 2);
setBounds(bounds);
}
@Override
public void setReferencePoint(Point p) {
// length of line between reference point and location
double d = Math.sqrt(Math.pow((location.x-p.x), 2)+Math.pow(location.y-p.y,2));
double d = Math.sqrt(Math.pow((location.x - p.x), 2) + Math.pow(location.y - p.y, 2));
// do nothing if link is too short.
if(d < radius)
if (d < radius)
return;
//
......@@ -356,40 +350,42 @@ public class AssociationPart extends PropertyAwareConnectionPart {
//
// remember that d > radius.
//
double k = (d- radius)/d;
double longx = Math.abs(p.x-location.x);
double longy = Math.abs(p.y-location.y);
double k = (d - radius) / d;
double longx = Math.abs(p.x - location.x);
double longy = Math.abs(p.y - location.y);
double shortx = k*longx;
double shorty = k*longy;
double shortx = k * longx;
double shorty = k * longy;
// now create locate the new point using the distances depending on the location of the original points.
int rx, ry;
if(location.x < p.x) {
rx = p.x - (int)shortx;
if (location.x < p.x) {
rx = p.x - (int) shortx;
} else {
rx = p.x + (int)shortx;
rx = p.x + (int) shortx;
}
if(location.y > p.y) {
ry = p.y + (int)shorty;
if (location.y > p.y) {
ry = p.y + (int) shorty;
} else {
ry = p.y - (int)shorty;
ry = p.y - (int) shorty;
}
// For reasons that are still unknown to me, I had to increase the radius
// of the circle for the graphics to look right.
setBounds(new Rectangle(rx- radius, ry- radius, (int)(radius *2.5), (int)(radius *2.5)));
setBounds(new Rectangle(rx - radius, ry - radius, (int) (radius * 2.5), (int) (radius * 2.5)));
}
}
public static class RhombusDecoration extends PolygonDecoration {
private static PointList GEOMETRY = new PointList();
static {
GEOMETRY.addPoint(0, 0);
GEOMETRY.addPoint(-1, 1);
GEOMETRY.addPoint(-2, 0);
GEOMETRY.addPoint(-1, -1);
}
public RhombusDecoration() {
setTemplate(GEOMETRY);
setFill(true);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册