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

ERD edit: associations resolve fix


Former-commit-id: 3efabb6b
上级 b486453c
......@@ -24,11 +24,12 @@ import org.jkiss.dbeaver.ext.erd.model.ERDEntity;
import org.jkiss.dbeaver.ext.erd.model.ERDUtils;
import org.jkiss.dbeaver.ext.erd.part.DiagramPart;
import org.jkiss.dbeaver.ext.erd.part.EntityPart;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.navigator.DBNDatabaseNode;
import org.jkiss.dbeaver.model.navigator.DBNNode;
import org.jkiss.dbeaver.model.runtime.VoidProgressMonitor;
import org.jkiss.dbeaver.model.struct.DBSEntity;
import org.jkiss.dbeaver.model.struct.DBSObjectContainer;
import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.dbeaver.model.struct.rdb.DBSTable;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.dialogs.BrowseObjectDialog;
......@@ -64,21 +65,24 @@ public class EntityAddCommand extends Command
if (entity.getObject() == null) {
// Entity is not initialized
if (entity.getDataSource() != null) {
DBNDatabaseNode dsNode = NavigatorUtils.getNodeByObject(entity.getDataSource().getContainer());
DBSObject selectedObject = DBUtils.getSelectedObject(entity.getDataSource(), true);
DBNDatabaseNode dsNode = NavigatorUtils.getNodeByObject(selectedObject != null ? selectedObject : entity.getDataSource().getContainer());
if (dsNode != null) {
DBNNode tableNode = BrowseObjectDialog.selectObject(
UIUtils.getActiveWorkbenchShell(),
"Select a table",
dsNode,
null,
new Class[]{DBSTable.class, DBSObjectContainer.class},
new Class[]{DBSTable.class},
new Class[]{DBSTable.class});
if (tableNode instanceof DBNDatabaseNode && ((DBNDatabaseNode) tableNode).getObject() instanceof DBSEntity) {
entity = ERDUtils.makeEntityFromObject(
monitor,
diagramPart.getDiagram(),
(DBSEntity)((DBNDatabaseNode) tableNode).getObject());
resolveRelations = true;
// This actually only loads unresolved relations.
// This happens only with entities added on diagram during editing
entity.addModelRelations(monitor, diagramPart.getDiagram().getEntityMap(), false, false);
}
}
}
......@@ -87,10 +91,6 @@ public class EntityAddCommand extends Command
continue;
}
diagramPart.getDiagram().addEntity(entity, true);
//diagramPart.getDiagram().addModelRelations(monitor, entity, true);
if (resolveRelations) {
entity.addModelRelations(monitor, diagramPart.getDiagram().getEntityMap(), false, true);
}
if (curLocation != null) {
// Put new entities in specified location
......
......@@ -191,7 +191,7 @@ public class ERDAssociation extends ERDObject<DBSEntityAssociation>
@Override
public String toString()
{
return getObject() + " [" + targetEntity + "->" + sourceEntity + "]";
return getObject() + " [" + sourceEntity + "->" + targetEntity + "]";
}
@NotNull
......
......@@ -261,7 +261,7 @@ public class ERDEntity extends ERDObject<DBSEntity> {
if (fk.getReferencedConstraint() != null) {
ERDEntity refEntity = tableMap.get(fk.getReferencedConstraint().getParentObject());
if (refEntity != null) {
new ERDAssociation(fk, refEntity, this, reflect);
new ERDAssociation(fk, this, refEntity, reflect);
iter.remove();
}
}
......
......@@ -140,6 +140,9 @@ public class EntityDiagram extends ERDObject<DBSObject> {
for (ERDAssociation rel : entity.getReferences()) {
rel.getSourceEntity().firePropertyChange(OUTPUT, null, rel);
}
for (ERDAssociation rel : entity.getAssociations()) {
rel.getTargetEntity().firePropertyChange(INPUT, null, rel);
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册