|
21 | 21 | import com.jgoodies.forms.builder.PanelBuilder; |
22 | 22 | import com.jgoodies.forms.layout.CellConstraints; |
23 | 23 | import com.jgoodies.forms.layout.FormLayout; |
24 | | -import org.apache.cayenne.CayenneRuntimeException; |
25 | 24 | import org.apache.cayenne.configuration.DataChannelDescriptor; |
26 | 25 | import org.apache.cayenne.dbsync.naming.NameBuilder; |
27 | 26 | import org.apache.cayenne.map.DbEntity; |
@@ -151,10 +150,6 @@ public ObjRelationshipInfoDialog modifyRelationship(ObjRelationship rel) { |
151 | 150 | this.relationship = rel; |
152 | 151 | this.undo = new ObjRelationshipUndoableEdit(session, rel); |
153 | 152 |
|
154 | | - // current limitation is that an ObjRelationship must have source |
155 | | - // and target entities present, with DbEntities chosen. |
156 | | - validateCanMap(); |
157 | | - |
158 | 153 | initFromModel(); |
159 | 154 | initBindings(); |
160 | 155 | return this; |
@@ -587,17 +582,28 @@ private void connectEnds() { |
587 | 582 | } |
588 | 583 |
|
589 | 584 | /** |
590 | | - * Checks if the entity can be edited with this inspector. |
| 585 | + * Checks whether the given source entity can be mapped with this inspector, showing an |
| 586 | + * informative message and returning false if not. Callers must use this to decide whether to |
| 587 | + * open the inspector at all — the dialog assumes a mappable source entity. |
591 | 588 | * NOTE: As of CAY-1077, the inspector can be opened even with no target entity set. |
592 | 589 | */ |
593 | | - private void validateCanMap() { |
594 | | - if (relationship.getSourceEntity() == null) { |
595 | | - throw new CayenneRuntimeException("Can't map relationship without source entity."); |
| 590 | + public static boolean canMap(ObjEntity source, Window owner) { |
| 591 | + if (source == null) { |
| 592 | + showCannotMapMessage(owner, "This relationship has no source ObjEntity, so it can't be mapped."); |
| 593 | + return false; |
596 | 594 | } |
597 | | - if (getStartEntity() == null) { |
598 | | - JOptionPane.showMessageDialog(this, "Can't map relationship without source DbEntity. Set source DbEntity."); |
599 | | - throw new CayenneRuntimeException("Can't map relationship without source DbEntity."); |
| 595 | + if (source.getDbEntity() == null) { |
| 596 | + String message = """ |
| 597 | + "ObjEntity '%s' is not mapped to a DbEntity. Set either DbEntity or super ObjEntity on the \ |
| 598 | + "ObjEntity" tab before mapping relationships.""".formatted(source.getName()); |
| 599 | + showCannotMapMessage(owner, message); |
| 600 | + return false; |
600 | 601 | } |
| 602 | + return true; |
| 603 | + } |
| 604 | + |
| 605 | + private static void showCannotMapMessage(Window owner, String message) { |
| 606 | + JOptionPane.showMessageDialog(owner, message, "Can't Map Relationship", JOptionPane.WARNING_MESSAGE); |
601 | 607 | } |
602 | 608 |
|
603 | 609 | private DbEntity getStartEntity() { |
|
0 commit comments