diff --git a/plugins/org.jkiss.dbeaver.ext.erd/src/org/jkiss/dbeaver/ext/erd/command/EntityAddCommand.java b/plugins/org.jkiss.dbeaver.ext.erd/src/org/jkiss/dbeaver/ext/erd/command/EntityAddCommand.java index 4a6f611bd2ef063ba1fd86a65e0799b213cabddf..7937aaae713f318027a3487393d9348127ee18af 100644 --- a/plugins/org.jkiss.dbeaver.ext.erd/src/org/jkiss/dbeaver/ext/erd/command/EntityAddCommand.java +++ b/plugins/org.jkiss.dbeaver.ext.erd/src/org/jkiss/dbeaver/ext/erd/command/EntityAddCommand.java @@ -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); } } diff --git a/plugins/org.jkiss.dbeaver.ext.erd/src/org/jkiss/dbeaver/ext/erd/command/EntityDeleteCommand.java b/plugins/org.jkiss.dbeaver.ext.erd/src/org/jkiss/dbeaver/ext/erd/command/EntityDeleteCommand.java index f74d81da37ef13c5507a270588f3219d59b56242..d0063d7df8ab4dc5eeea7a774759bf97424e8d8f 100644 --- a/plugins/org.jkiss.dbeaver.ext.erd/src/org/jkiss/dbeaver/ext/erd/command/EntityDeleteCommand.java +++ b/plugins/org.jkiss.dbeaver.ext.erd/src/org/jkiss/dbeaver/ext/erd/command/EntityDeleteCommand.java @@ -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); } diff --git a/plugins/org.jkiss.dbeaver.ext.erd/src/org/jkiss/dbeaver/ext/erd/model/EntityDiagram.java b/plugins/org.jkiss.dbeaver.ext.erd/src/org/jkiss/dbeaver/ext/erd/model/EntityDiagram.java index 86f16e2d3ae0abc0b876e66e713411b77bba0c6f..87ef8003f76bebfe992efc51fc6da7c4e10a7148 100644 --- a/plugins/org.jkiss.dbeaver.ext.erd/src/org/jkiss/dbeaver/ext/erd/model/EntityDiagram.java +++ b/plugins/org.jkiss.dbeaver.ext.erd/src/org/jkiss/dbeaver/ext/erd/model/EntityDiagram.java @@ -50,15 +50,15 @@ public class EntityDiagram extends ERDObject { private ERDDecorator decorator; private String name; - private List entities = new ArrayList<>(); + private final List entities = new ArrayList<>(); private boolean layoutManualDesired = true; private boolean layoutManualAllowed = false; private boolean needsAutoLayout; - private Map entityMap = new IdentityHashMap<>(); - private Map nodeVisuals = new IdentityHashMap<>(); + private final Map entityMap = new IdentityHashMap<>(); + private final Map nodeVisuals = new IdentityHashMap<>(); - private List notes = new ArrayList<>(); + private final List notes = new ArrayList<>(); private ERDAttributeVisibility attributeVisibility; private ERDViewStyle[] attributeStyles; @@ -102,17 +102,25 @@ public class EntityDiagram extends ERDObject { 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 { } } + private void resolveRelations(boolean reflect) { // Resolve incomplete relations for (ERDEntity erdEntity : getEntities()) { @@ -142,9 +151,11 @@ public class EntityDiagram extends ERDObject { } } - 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 { /** * @return the Tables for the current schema */ - public synchronized List getEntities() { + public List getEntities() { return entities; } - public synchronized List getNotes() { + public List 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 { copy.entityMap.putAll(this.entityMap); copy.layoutManualDesired = this.layoutManualDesired; copy.layoutManualAllowed = this.layoutManualAllowed; - copy.nodeVisuals = nodeVisuals; + copy.nodeVisuals.putAll(this.nodeVisuals); return copy; } diff --git a/plugins/org.jkiss.dbeaver.ext.erd/src/org/jkiss/dbeaver/ext/erd/part/AssociationPart.java b/plugins/org.jkiss.dbeaver.ext.erd/src/org/jkiss/dbeaver/ext/erd/part/AssociationPart.java index 3b1d735048a3a2f0d10b0bf13122570ad8a6c49d..2cb627bfa7135dd63be20289aa0e583eb96f279a 100644 --- a/plugins/org.jkiss.dbeaver.ext.erd/src/org/jkiss/dbeaver/ext/erd/part/AssociationPart.java +++ b/plugins/org.jkiss.dbeaver.ext.erd/src/org/jkiss/dbeaver/ext/erd/part/AssociationPart.java @@ -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 getEntityAttributes(EntityPart source, List columns) - { + private List getEntityAttributes(EntityPart source, List columns) { List result = new ArrayList<>(); - for (AttributePart attrPart : (List)source.getChildren()) { + for (AttributePart attrPart : (List) 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);