|
Lines 27-36
Link Here
|
| 27 |
import java.util.Locale; |
27 |
import java.util.Locale; |
| 28 |
import java.util.Properties; |
28 |
import java.util.Properties; |
| 29 |
import java.util.Set; |
29 |
import java.util.Set; |
|
|
30 |
|
| 30 |
import org.eclipse.core.resources.IProject; |
31 |
import org.eclipse.core.resources.IProject; |
| 31 |
import org.eclipse.core.resources.IResource; |
32 |
import org.eclipse.core.resources.IResource; |
| 32 |
import org.eclipse.core.runtime.CoreException; |
33 |
import org.eclipse.core.runtime.CoreException; |
| 33 |
import org.eclipse.core.runtime.NullProgressMonitor; |
34 |
import org.eclipse.core.runtime.NullProgressMonitor; |
|
|
35 |
import org.eclipse.emf.transaction.RecordingCommand; |
| 36 |
import org.eclipse.emf.transaction.TransactionalEditingDomain; |
| 34 |
import org.eclipse.graphiti.features.IFeatureProvider; |
37 |
import org.eclipse.graphiti.features.IFeatureProvider; |
| 35 |
import org.eclipse.graphiti.features.context.IRemoveContext; |
38 |
import org.eclipse.graphiti.features.context.IRemoveContext; |
| 36 |
import org.eclipse.graphiti.features.context.impl.AddConnectionContext; |
39 |
import org.eclipse.graphiti.features.context.impl.AddConnectionContext; |
|
Lines 39-48
Link Here
|
| 39 |
import org.eclipse.graphiti.mm.pictograms.ContainerShape; |
42 |
import org.eclipse.graphiti.mm.pictograms.ContainerShape; |
| 40 |
import org.eclipse.graphiti.mm.pictograms.Shape; |
43 |
import org.eclipse.graphiti.mm.pictograms.Shape; |
| 41 |
import org.eclipse.graphiti.services.Graphiti; |
44 |
import org.eclipse.graphiti.services.Graphiti; |
|
|
45 |
import org.eclipse.graphiti.util.IColorConstant; |
| 42 |
import org.eclipse.jdt.core.ICompilationUnit; |
46 |
import org.eclipse.jdt.core.ICompilationUnit; |
| 43 |
import org.eclipse.jdt.core.IField; |
47 |
import org.eclipse.jdt.core.IField; |
| 44 |
import org.eclipse.jdt.core.IImportDeclaration; |
48 |
import org.eclipse.jdt.core.IImportDeclaration; |
| 45 |
import org.eclipse.jdt.core.IMethod; |
49 |
import org.eclipse.jdt.core.IMethod; |
|
|
50 |
import org.eclipse.jdt.core.IPackageDeclaration; |
| 46 |
import org.eclipse.jdt.core.IType; |
51 |
import org.eclipse.jdt.core.IType; |
| 47 |
import org.eclipse.jdt.core.JavaModelException; |
52 |
import org.eclipse.jdt.core.JavaModelException; |
| 48 |
import org.eclipse.jdt.core.dom.CompilationUnit; |
53 |
import org.eclipse.jdt.core.dom.CompilationUnit; |
|
Lines 50-60
Link Here
|
| 50 |
import org.eclipse.jpt.common.core.JptResourceModel; |
55 |
import org.eclipse.jpt.common.core.JptResourceModel; |
| 51 |
import org.eclipse.jpt.common.core.resource.java.Annotation; |
56 |
import org.eclipse.jpt.common.core.resource.java.Annotation; |
| 52 |
import org.eclipse.jpt.common.core.resource.java.JavaResourceAbstractType; |
57 |
import org.eclipse.jpt.common.core.resource.java.JavaResourceAbstractType; |
|
|
58 |
import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement.Kind; |
| 53 |
import org.eclipse.jpt.common.core.resource.java.JavaResourceAttribute; |
59 |
import org.eclipse.jpt.common.core.resource.java.JavaResourceAttribute; |
| 54 |
import org.eclipse.jpt.common.core.resource.java.JavaResourceCompilationUnit; |
60 |
import org.eclipse.jpt.common.core.resource.java.JavaResourceCompilationUnit; |
| 55 |
import org.eclipse.jpt.common.core.resource.java.JavaResourceType; |
61 |
import org.eclipse.jpt.common.core.resource.java.JavaResourceType; |
| 56 |
import org.eclipse.jpt.common.core.resource.java.NestableAnnotation; |
62 |
import org.eclipse.jpt.common.core.resource.java.NestableAnnotation; |
| 57 |
import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement.Kind; |
|
|
| 58 |
import org.eclipse.jpt.common.utility.internal.iterables.ArrayListIterable; |
63 |
import org.eclipse.jpt.common.utility.internal.iterables.ArrayListIterable; |
| 59 |
import org.eclipse.jpt.common.utility.internal.iterables.SubListIterableWrapper; |
64 |
import org.eclipse.jpt.common.utility.internal.iterables.SubListIterableWrapper; |
| 60 |
import org.eclipse.jpt.jpa.core.JpaFile; |
65 |
import org.eclipse.jpt.jpa.core.JpaFile; |
|
Lines 69-74
Link Here
|
| 69 |
import org.eclipse.jpt.jpa.core.context.java.JavaAttributeMapping; |
74 |
import org.eclipse.jpt.jpa.core.context.java.JavaAttributeMapping; |
| 70 |
import org.eclipse.jpt.jpa.core.context.java.JavaEntity; |
75 |
import org.eclipse.jpt.jpa.core.context.java.JavaEntity; |
| 71 |
import org.eclipse.jpt.jpa.core.context.java.JavaManyToManyMapping; |
76 |
import org.eclipse.jpt.jpa.core.context.java.JavaManyToManyMapping; |
|
|
77 |
import org.eclipse.jpt.jpa.core.context.java.JavaMappedSuperclass; |
| 72 |
import org.eclipse.jpt.jpa.core.context.java.JavaOneToManyMapping; |
78 |
import org.eclipse.jpt.jpa.core.context.java.JavaOneToManyMapping; |
| 73 |
import org.eclipse.jpt.jpa.core.context.java.JavaOneToOneMapping; |
79 |
import org.eclipse.jpt.jpa.core.context.java.JavaOneToOneMapping; |
| 74 |
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute; |
80 |
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute; |
|
Lines 78-85
Link Here
|
| 78 |
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit; |
84 |
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit; |
| 79 |
import org.eclipse.jpt.jpa.core.resource.java.AttributeOverrideAnnotation; |
85 |
import org.eclipse.jpt.jpa.core.resource.java.AttributeOverrideAnnotation; |
| 80 |
import org.eclipse.jpt.jpa.core.resource.java.ColumnAnnotation; |
86 |
import org.eclipse.jpt.jpa.core.resource.java.ColumnAnnotation; |
| 81 |
import org.eclipse.jpt.jpa.core.resource.java.EmbeddedIdAnnotation; |
|
|
| 82 |
import org.eclipse.jpt.jpa.core.resource.java.IdAnnotation; |
| 83 |
import org.eclipse.jpt.jpa.core.resource.java.IdClassAnnotation; |
87 |
import org.eclipse.jpt.jpa.core.resource.java.IdClassAnnotation; |
| 84 |
import org.eclipse.jpt.jpa.core.resource.java.JoinColumnAnnotation; |
88 |
import org.eclipse.jpt.jpa.core.resource.java.JoinColumnAnnotation; |
| 85 |
import org.eclipse.jpt.jpa.core.resource.java.ManyToManyAnnotation; |
89 |
import org.eclipse.jpt.jpa.core.resource.java.ManyToManyAnnotation; |
|
Lines 90-105
Link Here
|
| 90 |
import org.eclipse.jpt.jpa.core.resource.java.RelationshipMappingAnnotation; |
94 |
import org.eclipse.jpt.jpa.core.resource.java.RelationshipMappingAnnotation; |
| 91 |
import org.eclipse.jpt.jpa.core.resource.java.TableAnnotation; |
95 |
import org.eclipse.jpt.jpa.core.resource.java.TableAnnotation; |
| 92 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin; |
96 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin; |
|
|
97 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.AddInheritedEntityFeature; |
| 93 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.AddRelationFeature; |
98 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.AddRelationFeature; |
| 94 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.RemoveRelationFeature; |
99 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.RemoveRelationFeature; |
| 95 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.UpdateAttributeFeature; |
100 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.UpdateAttributeFeature; |
| 96 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages; |
101 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages; |
| 97 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.propertypage.JPADiagramPropertyPage; |
102 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.propertypage.JPADiagramPropertyPage; |
| 98 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider; |
103 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider; |
| 99 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.BidirectionalRelation; |
104 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IBidirectionalRelation; |
| 100 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation; |
105 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation; |
| 101 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation.RelDir; |
106 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation.RelDir; |
| 102 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation.RelType; |
107 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation.RelType; |
|
|
108 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IsARelation; |
| 103 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.ManyToManyBiDirRelation; |
109 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.ManyToManyBiDirRelation; |
| 104 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.ManyToManyUniDirRelation; |
110 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.ManyToManyUniDirRelation; |
| 105 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.ManyToOneBiDirRelation; |
111 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.ManyToOneBiDirRelation; |
|
Lines 130-135
Link Here
|
| 130 |
return INSTANCE; |
136 |
return INSTANCE; |
| 131 |
} |
137 |
} |
| 132 |
|
138 |
|
|
|
139 |
public void rearrangeIsARelations(IJPAEditorFeatureProvider fp) { |
| 140 |
Collection<IsARelation> isARels = produceAllMissingIsARelations(fp); |
| 141 |
addIsARelations(fp, isARels); |
| 142 |
fp.removeAllRedundantIsARelations(); |
| 143 |
} |
| 144 |
|
| 145 |
public void rearrangeIsARelationsInTransaction(final IJPAEditorFeatureProvider fp) { |
| 146 |
final Collection<IsARelation> isARels = produceAllMissingIsARelations(fp); |
| 147 |
if (!fp.existRedundantIsARelations() && (isARels.size() == 0)) |
| 148 |
return; |
| 149 |
TransactionalEditingDomain ted = fp.getTransactionalEditingDomain(); |
| 150 |
RecordingCommand rc = new RecordingCommand(ted) { |
| 151 |
protected void doExecute() { |
| 152 |
addIsARelations(fp, isARels); |
| 153 |
fp.removeAllRedundantIsARelations(); |
| 154 |
} |
| 155 |
}; |
| 156 |
ted.getCommandStack().execute(rc); |
| 157 |
} |
| 158 |
|
| 159 |
|
| 160 |
public Collection<IsARelation> produceAllMissingIsARelations(IJPAEditorFeatureProvider fp) { |
| 161 |
Collection<JavaPersistentType> persistentTypes = fp.getPersistentTypes(); |
| 162 |
Collection<IsARelation> res = new HashSet<IsARelation>(); |
| 163 |
Iterator<JavaPersistentType> it = persistentTypes.iterator(); |
| 164 |
HashSet<IsARelation> allExistingIsARelations = fp.getAllExistingIsARelations(); |
| 165 |
while (it.hasNext()) { |
| 166 |
JavaPersistentType jpt = it.next(); |
| 167 |
JavaPersistentType superclass = fp.getFirstSuperclassBelongingToTheDiagram(jpt); |
| 168 |
if (superclass == null) |
| 169 |
continue; |
| 170 |
IsARelation newRel = new IsARelation(jpt, superclass); |
| 171 |
if (!allExistingIsARelations.contains(newRel)) |
| 172 |
res.add(newRel); |
| 173 |
} |
| 174 |
return res; |
| 175 |
} |
| 176 |
|
| 133 |
public void addOneToOneUnidirectionalRelation(IFeatureProvider fp, JavaPersistentType jpt, |
177 |
public void addOneToOneUnidirectionalRelation(IFeatureProvider fp, JavaPersistentType jpt, |
| 134 |
JavaPersistentAttribute attribute) { |
178 |
JavaPersistentAttribute attribute) { |
| 135 |
addOneToOneRelation(fp, jpt, attribute, null, null, |
179 |
addOneToOneRelation(fp, jpt, attribute, null, null, |
|
Lines 516-524
Link Here
|
| 516 |
JavaResourceType jrpt = convertJPTToJRT(jpt); |
560 |
JavaResourceType jrpt = convertJPTToJRT(jpt); |
| 517 |
if (jrpt == null) |
561 |
if (jrpt == null) |
| 518 |
return false; |
562 |
return false; |
| 519 |
JavaEntity mapping = (JavaEntity) jpt.getMapping(); |
563 |
JavaTypeMapping jtm = jpt.getMapping(); |
| 520 |
if (mapping != null) |
564 |
if (jtm == null) |
|
|
565 |
return false; |
| 566 |
if (jtm instanceof JavaEntity) { |
| 567 |
JavaEntity mapping = (JavaEntity)jtm; |
| 521 |
return (mapping.getSpecifiedName() != null); |
568 |
return (mapping.getSpecifiedName() != null); |
|
|
569 |
} |
| 522 |
return false; |
570 |
return false; |
| 523 |
} |
571 |
} |
| 524 |
|
572 |
|
|
Lines 553-571
Link Here
|
| 553 |
} |
601 |
} |
| 554 |
*/ |
602 |
*/ |
| 555 |
|
603 |
|
|
|
604 |
public boolean hasEntityOrMappedSuperclassAnnotation(JavaPersistentType jpt) { |
| 605 |
return hasEntityAnnotation(jpt) || hasMappedSuperclassAnnotation(jpt); |
| 606 |
} |
| 607 |
|
| 556 |
public boolean hasEntityAnnotation(JavaPersistentType jpt) { |
608 |
public boolean hasEntityAnnotation(JavaPersistentType jpt) { |
| 557 |
return (jpt.getMapping() instanceof JavaEntity); |
609 |
return (jpt.getMappingKey() == MappingKeys.ENTITY_TYPE_MAPPING_KEY); |
| 558 |
} |
610 |
} |
| 559 |
|
611 |
|
|
|
612 |
public boolean hasMappedSuperclassAnnotation(JavaPersistentType jpt) { |
| 613 |
return (jpt.getMappingKey() == MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY); |
| 614 |
} |
| 615 |
|
| 560 |
public String getSpecifiedEntityName(JavaPersistentType jpt){ |
616 |
public String getSpecifiedEntityName(JavaPersistentType jpt){ |
| 561 |
JavaEntity gje = (JavaEntity) jpt.getMapping(); |
617 |
JavaTypeMapping jtm = jpt.getMapping(); |
|
|
618 |
if (jtm instanceof JavaEntity) { |
| 619 |
JavaEntity gje = (JavaEntity)jtm; |
| 562 |
return gje.getSpecifiedName(); |
620 |
return gje.getSpecifiedName(); |
| 563 |
} |
621 |
} |
|
|
622 |
JavaMappedSuperclass jms = (JavaMappedSuperclass)jtm; |
| 623 |
return jms.getName(); |
| 624 |
} |
| 564 |
|
625 |
|
| 565 |
public void renameEntity(JavaPersistentType jpt, String newName) { |
626 |
public void renameEntity(JavaPersistentType jpt, String newName) { |
| 566 |
JavaEntity gje = (JavaEntity)jpt.getMapping(); |
627 |
JavaTypeMapping jtm = jpt.getMapping(); |
|
|
628 |
if (jtm instanceof JavaEntity) { |
| 629 |
JavaEntity gje = (JavaEntity)jtm; |
| 567 |
gje.setSpecifiedName(newName); |
630 |
gje.setSpecifiedName(newName); |
| 568 |
} |
631 |
} |
|
|
632 |
} |
| 569 |
|
633 |
|
| 570 |
public JavaPersistentAttribute addAttribute(IJPAEditorFeatureProvider fp, JavaPersistentType jpt, |
634 |
public JavaPersistentAttribute addAttribute(IJPAEditorFeatureProvider fp, JavaPersistentType jpt, |
| 571 |
JavaPersistentType attributeType, String attributeName, |
635 |
JavaPersistentType attributeType, String attributeName, |
|
Lines 1361-1366
Link Here
|
| 1361 |
return null; |
1425 |
return null; |
| 1362 |
} |
1426 |
} |
| 1363 |
*/ |
1427 |
*/ |
|
|
1428 |
|
| 1429 |
public JavaPersistentType getJPT(String name, JpaProject jpaProject) { |
| 1430 |
ListIterator<PersistenceUnit> lit = jpaProject.getRootContextNode().getPersistenceXml().getPersistence().getPersistenceUnits().iterator(); |
| 1431 |
PersistenceUnit pu = lit.next(); |
| 1432 |
return getJPT(name, pu); |
| 1433 |
} |
| 1364 |
|
1434 |
|
| 1365 |
public JavaPersistentType getJPT(String name, PersistenceUnit pu) { |
1435 |
public JavaPersistentType getJPT(String name, PersistenceUnit pu) { |
| 1366 |
pu.getJpaProject().updateAndWait(); |
1436 |
pu.getJpaProject().updateAndWait(); |
|
Lines 1481-1487
Link Here
|
| 1481 |
IRelation rel = fp.getRelationRelatedToAttribute(oldAt); |
1551 |
IRelation rel = fp.getRelationRelatedToAttribute(oldAt); |
| 1482 |
String inverseJPAName = null; |
1552 |
String inverseJPAName = null; |
| 1483 |
JavaPersistentType inverseJPT = null; |
1553 |
JavaPersistentType inverseJPT = null; |
| 1484 |
if (BidirectionalRelation.class.isInstance(rel)) { |
1554 |
if (IBidirectionalRelation.class.isInstance(rel)) { |
| 1485 |
inverseJPT = rel.getInverse(); |
1555 |
inverseJPT = rel.getInverse(); |
| 1486 |
if (inverseJPT != oldAt.getParent()) { |
1556 |
if (inverseJPT != oldAt.getParent()) { |
| 1487 |
pu = JpaArtifactFactory.INSTANCE.getPersistenceUnit(jpt); |
1557 |
pu = JpaArtifactFactory.INSTANCE.getPersistenceUnit(jpt); |
|
Lines 1835-1841
Link Here
|
| 1835 |
return res; |
1905 |
return res; |
| 1836 |
} |
1906 |
} |
| 1837 |
|
1907 |
|
| 1838 |
private BidirectionalRelation produceBiDirRelation(JavaPersistentType jpt, |
1908 |
private IBidirectionalRelation produceBiDirRelation(JavaPersistentType jpt, |
| 1839 |
JavaPersistentAttribute at, Annotation an, |
1909 |
JavaPersistentAttribute at, Annotation an, |
| 1840 |
JavaPersistentType relJPT, JavaPersistentAttribute relAt, |
1910 |
JavaPersistentType relJPT, JavaPersistentAttribute relAt, |
| 1841 |
Annotation relAn, IJPAEditorFeatureProvider fp) { |
1911 |
Annotation relAn, IJPAEditorFeatureProvider fp) { |
|
Lines 1879-1885
Link Here
|
| 1879 |
} |
1949 |
} |
| 1880 |
} |
1950 |
} |
| 1881 |
|
1951 |
|
| 1882 |
BidirectionalRelation res = null; |
1952 |
IBidirectionalRelation res = null; |
| 1883 |
if (annotationName.equals(JPAEditorConstants.ANNOTATION_ONE_TO_ONE)) { |
1953 |
if (annotationName.equals(JPAEditorConstants.ANNOTATION_ONE_TO_ONE)) { |
| 1884 |
if (!fp.doesRelationExist(jpt, relJPT, ownerAttrName, RelType.ONE_TO_ONE, |
1954 |
if (!fp.doesRelationExist(jpt, relJPT, ownerAttrName, RelType.ONE_TO_ONE, |
| 1885 |
RelDir.BI)) |
1955 |
RelDir.BI)) |
|
Lines 2170-2175
Link Here
|
| 2170 |
Iterator<Connection> iter = Graphiti.getPeService().getAllConnections(cs).iterator(); |
2240 |
Iterator<Connection> iter = Graphiti.getPeService().getAllConnections(cs).iterator(); |
| 2171 |
while (iter.hasNext()) { |
2241 |
while (iter.hasNext()) { |
| 2172 |
Connection conn = iter.next(); |
2242 |
Connection conn = iter.next(); |
|
|
2243 |
String v = Graphiti.getPeService().getPropertyValue(conn, IsARelation.IS_A_CONNECTION_PROP_KEY); |
| 2244 |
if (Boolean.TRUE.toString().equals(v)) |
| 2245 |
continue; |
| 2173 |
IRemoveContext ctx = new RemoveContext(conn); |
2246 |
IRemoveContext ctx = new RemoveContext(conn); |
| 2174 |
ctxs.add(ctx); |
2247 |
ctxs.add(ctx); |
| 2175 |
} |
2248 |
} |
|
Lines 2203-2208
Link Here
|
| 2203 |
} |
2276 |
} |
| 2204 |
} |
2277 |
} |
| 2205 |
|
2278 |
|
|
|
2279 |
public void addIsARelations(IJPAEditorFeatureProvider fp, |
| 2280 |
Collection<IsARelation> rels) { |
| 2281 |
Iterator<IsARelation> it = rels.iterator(); |
| 2282 |
while (it.hasNext()) { |
| 2283 |
IsARelation rel = it.next(); |
| 2284 |
addNewIsARelation(fp, rel); |
| 2285 |
} |
| 2286 |
} |
| 2287 |
|
| 2206 |
private void addNewRelation(IJPAEditorFeatureProvider fp, IRelation rel) { |
2288 |
private void addNewRelation(IJPAEditorFeatureProvider fp, IRelation rel) { |
| 2207 |
AddConnectionContext ctx = new AddConnectionContext(JPAEditorUtil |
2289 |
AddConnectionContext ctx = new AddConnectionContext(JPAEditorUtil |
| 2208 |
.getAnchor(rel.getOwner(), fp), JPAEditorUtil.getAnchor(rel |
2290 |
.getAnchor(rel.getOwner(), fp), JPAEditorUtil.getAnchor(rel |
|
Lines 2215-2220
Link Here
|
| 2215 |
ft.add(ctx); |
2297 |
ft.add(ctx); |
| 2216 |
} |
2298 |
} |
| 2217 |
|
2299 |
|
|
|
2300 |
private void addNewIsARelation(IJPAEditorFeatureProvider fp, IsARelation rel) { |
| 2301 |
AddConnectionContext ctx = new AddConnectionContext(JPAEditorUtil |
| 2302 |
.getAnchor(rel.getSubclass(), fp), JPAEditorUtil.getAnchor(rel.getSuperclass(), fp)); |
| 2303 |
ctx.setNewObject(rel); |
| 2304 |
ctx.setTargetContainer(fp.getDiagramTypeProvider().getDiagram()); |
| 2305 |
refreshEntityModel(fp, rel.getSubclass()); |
| 2306 |
refreshEntityModel(fp, rel.getSuperclass()); |
| 2307 |
AddInheritedEntityFeature ft = new AddInheritedEntityFeature(fp); |
| 2308 |
ft.add(ctx); |
| 2309 |
} |
| 2310 |
|
| 2218 |
private String getRelTypeName(RelationshipMappingAnnotation an, |
2311 |
private String getRelTypeName(RelationshipMappingAnnotation an, |
| 2219 |
JavaResourceAttribute jra) { |
2312 |
JavaResourceAttribute jra) { |
| 2220 |
String relTypeName = null; |
2313 |
String relTypeName = null; |
|
Lines 2255-2272
Link Here
|
| 2255 |
return res.toArray(ret); |
2348 |
return res.toArray(ret); |
| 2256 |
} |
2349 |
} |
| 2257 |
|
2350 |
|
| 2258 |
public boolean isId(JavaPersistentAttribute jpa) { |
2351 |
// returns true even if the primary key is inherited |
|
|
2352 |
public boolean hasOrInheritsPrimaryKey(JavaPersistentType jpt) { |
| 2353 |
Iterable<ReadOnlyPersistentAttribute> attributes = jpt.getAllAttributes(); |
| 2354 |
Iterator<ReadOnlyPersistentAttribute> it = attributes.iterator(); |
| 2355 |
while (it.hasNext()) { |
| 2356 |
ReadOnlyPersistentAttribute at = it.next(); |
| 2357 |
if (isId(at)) |
| 2358 |
return true; |
| 2359 |
} |
| 2360 |
return false; |
| 2361 |
} |
| 2362 |
|
| 2363 |
public boolean hasPrimaryKey(JavaPersistentType jpt) { |
| 2364 |
for (JavaPersistentAttribute at : jpt.getAttributes()) |
| 2365 |
if (isId(at)) return true; |
| 2366 |
return false; |
| 2367 |
} |
| 2368 |
|
| 2369 |
|
| 2370 |
public boolean isId(ReadOnlyPersistentAttribute jpa) { |
| 2259 |
return isSimpleId(jpa) || isEmbeddedId(jpa); |
2371 |
return isSimpleId(jpa) || isEmbeddedId(jpa); |
| 2260 |
} |
2372 |
} |
| 2261 |
|
2373 |
|
| 2262 |
public boolean isSimpleId(JavaPersistentAttribute jpa) { |
2374 |
public boolean isSimpleId(ReadOnlyPersistentAttribute jpa) { |
| 2263 |
IdAnnotation an = (IdAnnotation)jpa.getResourceAttribute().getAnnotation(IdAnnotation.ANNOTATION_NAME); |
2375 |
return (jpa.getMappingKey() == MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); |
| 2264 |
return (an != null); |
|
|
| 2265 |
} |
2376 |
} |
| 2266 |
|
2377 |
|
| 2267 |
public boolean isEmbeddedId(JavaPersistentAttribute jpa) { |
2378 |
public boolean isEmbeddedId(ReadOnlyPersistentAttribute jpa) { |
| 2268 |
EmbeddedIdAnnotation an = (EmbeddedIdAnnotation)jpa.getResourceAttribute().getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME); |
2379 |
return (jpa.getMappingKey() == MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); |
| 2269 |
return (an != null); |
|
|
| 2270 |
} |
2380 |
} |
| 2271 |
|
2381 |
|
| 2272 |
public String getColumnName(JavaPersistentAttribute jpa) { |
2382 |
public String getColumnName(JavaPersistentAttribute jpa) { |
|
Lines 2281-2285
Link Here
|
| 2281 |
return columnName; |
2391 |
return columnName; |
| 2282 |
} |
2392 |
} |
| 2283 |
|
2393 |
|
|
|
2394 |
public IColorConstant getForeground(JPAEditorConstants.DIAGRAM_OBJECT_TYPE dot) { |
| 2395 |
IColorConstant foreground = dot.equals(JPAEditorConstants.DIAGRAM_OBJECT_TYPE.MappedSupeclass) ? |
| 2396 |
JPAEditorConstants.MAPPED_SUPERCLASS_BORDER_COLOR: |
| 2397 |
JPAEditorConstants.ENTITY_BORDER_COLOR; |
| 2398 |
return foreground; |
| 2399 |
} |
| 2284 |
|
2400 |
|
|
|
2401 |
public IColorConstant getBackground(JPAEditorConstants.DIAGRAM_OBJECT_TYPE dot) { |
| 2402 |
IColorConstant background = dot.equals(JPAEditorConstants.DIAGRAM_OBJECT_TYPE.MappedSupeclass) ? |
| 2403 |
JPAEditorConstants.MAPPED_SUPERCLASS_BACKGROUND: |
| 2404 |
JPAEditorConstants.ENTITY_BACKGROUND; |
| 2405 |
return background; |
| 2406 |
} |
| 2407 |
|
| 2408 |
public String getRenderingStyle(JPAEditorConstants.DIAGRAM_OBJECT_TYPE dot) { |
| 2409 |
String renderingStyle = dot.equals(JPAEditorConstants.DIAGRAM_OBJECT_TYPE.MappedSupeclass) ? |
| 2410 |
IJPAEditorPredefinedRenderingStyle.GREEN_WHITE_GLOSS_ID : |
| 2411 |
IJPAEditorPredefinedRenderingStyle.BLUE_WHITE_GLOSS_ID; |
| 2412 |
return renderingStyle; |
| 2413 |
} |
| 2414 |
|
| 2415 |
public JPAEditorConstants.DIAGRAM_OBJECT_TYPE determineDiagramObjectType(JavaPersistentType jpt) { |
| 2416 |
if (this.hasEntityAnnotation(jpt)) { |
| 2417 |
return JPAEditorConstants.DIAGRAM_OBJECT_TYPE.Entity; |
| 2418 |
} else if (this.hasMappedSuperclassAnnotation(jpt)) { |
| 2419 |
return JPAEditorConstants.DIAGRAM_OBJECT_TYPE.MappedSupeclass; |
| 2420 |
} |
| 2421 |
throw new IllegalArgumentException(); |
| 2422 |
} |
| 2423 |
|
| 2424 |
public String generateIdName(JavaPersistentType jpt) { |
| 2425 |
String name = "id"; //$NON-NLS-1$ |
| 2426 |
String genName = name; |
| 2427 |
for (int i = 0; i < 10000000; i++) { |
| 2428 |
if (!hasAttributeNamed(jpt, genName)) |
| 2429 |
return genName; |
| 2430 |
genName = name + "_" + i; //$NON-NLS-1$ |
| 2431 |
} |
| 2432 |
return genName; |
| 2433 |
} |
| 2434 |
|
| 2435 |
|
| 2436 |
private boolean hasAttributeNamed(JavaPersistentType jpt, String name) { |
| 2437 |
Iterable<String> hier = jpt.getAllAttributeNames(); |
| 2438 |
Iterator<String> it = hier.iterator(); |
| 2439 |
while (it.hasNext()) { |
| 2440 |
String atName = it.next(); |
| 2441 |
if (name.equals(atName)) |
| 2442 |
return true; |
| 2443 |
} |
| 2444 |
return false; |
| 2445 |
} |
| 2446 |
|
| 2447 |
public String getMappedSuperclassPackageDeclaration(JavaPersistentType jpt) throws JavaModelException { |
| 2448 |
String packageName = null; |
| 2449 |
IPackageDeclaration[] packages = JPAEditorUtil.getCompilationUnit(jpt) |
| 2450 |
.getPackageDeclarations(); |
| 2451 |
if (packages.length > 0) { |
| 2452 |
IPackageDeclaration packageDecl = packages[0]; |
| 2453 |
packageName = packageDecl.getElementName(); |
| 2454 |
} |
| 2455 |
return packageName; |
| 2456 |
} |
| 2457 |
|
| 2458 |
|
| 2285 |
} |
2459 |
} |