Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 334142 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddAllEntitiesFeature.java (-5 / +17 lines)
Lines 35-47 Link Here
35
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
35
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
36
import org.eclipse.graphiti.mm.pictograms.Shape;
36
import org.eclipse.graphiti.mm.pictograms.Shape;
37
import org.eclipse.jpt.jpa.core.JpaProject;
37
import org.eclipse.jpt.jpa.core.JpaProject;
38
import org.eclipse.jpt.jpa.core.MappingKeys;
39
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
38
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
40
import org.eclipse.jpt.jpa.core.context.persistence.ClassRef;
39
import org.eclipse.jpt.jpa.core.context.persistence.ClassRef;
41
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
40
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
42
import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages;
41
import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages;
43
import org.eclipse.jpt.jpadiagrameditor.ui.internal.modelintegration.util.ModelIntegrationUtil;
42
import org.eclipse.jpt.jpadiagrameditor.ui.internal.modelintegration.util.ModelIntegrationUtil;
43
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
44
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants;
44
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants;
45
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
45
46
46
47
47
public class AddAllEntitiesFeature extends AbstractCustomFeature implements IAddFeature {
48
public class AddAllEntitiesFeature extends AbstractCustomFeature implements IAddFeature {
Lines 90-100 Link Here
90
		numInARow = (numInARow > 0) ? numInARow : 1;
91
		numInARow = (numInARow > 0) ? numInARow : 1;
91
		
92
		
92
		lowerEdges[0] = lowestRightestPointOfExistingDiagram.y + ((lowestRightestPointOfExistingDiagram.y == 0) ? DIST_FROM_EDGE_V : DIST_V);		
93
		lowerEdges[0] = lowestRightestPointOfExistingDiagram.y + ((lowestRightestPointOfExistingDiagram.y == 0) ? DIST_FROM_EDGE_V : DIST_V);		
94
		TransactionalEditingDomain ted = ModelIntegrationUtil.getTransactionalEditingDomain(d);
93
		
95
		
94
		for (ClassRef classRef : unit.getClassRefs()) {
96
		for (ClassRef classRef : unit.getClassRefs()) {
95
			if (classRef.getJavaPersistentType() != null) { // null if
97
			if (classRef.getJavaPersistentType() != null) { // null if
96
				JavaPersistentType jpt = classRef.getJavaPersistentType(); 
98
				JavaPersistentType jpt = classRef.getJavaPersistentType(); 
97
				if (jpt.getMappingKey() == MappingKeys.ENTITY_TYPE_MAPPING_KEY) {
99
				if (JpaArtifactFactory.instance().hasEntityOrMappedSuperclassAnnotation(jpt)) {
98
					PictogramElement pe = getFeatureProvider().getPictogramElementForBusinessObject(jpt);
100
					PictogramElement pe = getFeatureProvider().getPictogramElementForBusinessObject(jpt);
99
					if (pe != null)
101
					if (pe != null)
100
						continue;
102
						continue;
Lines 107-116 Link Here
107
					
109
					
108
					int x = DIST_FROM_EDGE_H + ie.index * (JPAEditorConstants.ENTITY_WIDTH + DIST_H);
110
					int x = DIST_FROM_EDGE_H + ie.index * (JPAEditorConstants.ENTITY_WIDTH + DIST_H);
109
					ctx.setLocation(x, ie.lowerEdge);
111
					ctx.setLocation(x, ie.lowerEdge);
110
					final AddJPAEntityFeature ft = new AddJPAEntityFeature(getFeatureProvider());
112
					final AddJPAEntityFeature ft = new AddJPAEntityFeature(getFeatureProvider(), false);
111
					
113
					
112
					final Diagram targetDiagram = (Diagram) ctx.getTargetContainer();
113
					TransactionalEditingDomain ted = ModelIntegrationUtil.getTransactionalEditingDomain(targetDiagram);
114
					ted.getCommandStack().execute(new RecordingCommand(ted) {
114
					ted.getCommandStack().execute(new RecordingCommand(ted) {
115
						@Override
115
						@Override
116
						protected void doExecute() {
116
						protected void doExecute() {
Lines 122-127 Link Here
122
				}
122
				}
123
			}
123
			}
124
		}		
124
		}		
125
		ted.getCommandStack().execute(new RecordingCommand(ted) {
126
			@Override
127
			protected void doExecute() {
128
				JpaArtifactFactory.instance().rearrangeIsARelations(getFeatureProvider());
129
			}
130
		});
131
125
	}
132
	}
126
	
133
	
127
	private IndexAndLowerEdge getMinLowerEdge() {
134
	private IndexAndLowerEdge getMinLowerEdge() {
Lines 177-180 Link Here
177
		return JPAEditorMessages.JPAEditorToolBehaviorProvider_showAllTheEntities;
184
		return JPAEditorMessages.JPAEditorToolBehaviorProvider_showAllTheEntities;
178
	}
185
	}
179
	
186
	
187
	public IJPAEditorFeatureProvider getFeatureProvider() {
188
		return (IJPAEditorFeatureProvider) super.getFeatureProvider();
189
	}
190
191
	
180
}
192
}
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddInheritedEntityFeature.java (+86 lines)
Added Link Here
1
/*******************************************************************************
2
 * <copyright>
3
 *
4
 * Copyright (c) 2005, 2010 SAP AG.
5
 * All rights reserved. This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
8
 * http://www.eclipse.org/legal/epl-v10.html
9
 *
10
 * Contributors:
11
 *    Stefan Dimov - initial API, implementation and documentation
12
 *
13
 * </copyright>
14
 *
15
 *******************************************************************************/
16
package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature;
17
18
import org.eclipse.graphiti.features.IFeatureProvider;
19
import org.eclipse.graphiti.features.context.IAddConnectionContext;
20
import org.eclipse.graphiti.features.context.IAddContext;
21
import org.eclipse.graphiti.features.impl.AbstractAddFeature;
22
import org.eclipse.graphiti.mm.pictograms.ConnectionDecorator;
23
import org.eclipse.graphiti.mm.pictograms.Diagram;
24
import org.eclipse.graphiti.mm.pictograms.FreeFormConnection;
25
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
26
import org.eclipse.graphiti.services.Graphiti;
27
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
28
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorImageCreator;
29
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.JPAEditorImageCreator;
30
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IsARelation;
31
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.IJPAEditorUtil;
32
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtilImpl;
33
34
public class AddInheritedEntityFeature extends AbstractAddFeature {
35
36
	private IJPAEditorImageCreator imageCreator;
37
	
38
	public AddInheritedEntityFeature(IFeatureProvider fp) {
39
		this(fp, new JPAEditorImageCreator(), new JPAEditorUtilImpl());
40
	}
41
	
42
43
	public AddInheritedEntityFeature(IFeatureProvider fp,
44
		  IJPAEditorImageCreator imageCreator, 
45
		  IJPAEditorUtil jpaEditorUtil) {
46
		super(fp);
47
		this.imageCreator = imageCreator;
48
	}
49
	
50
	
51
	public boolean canAdd(IAddContext context) {
52
		return true;
53
	}
54
55
	public PictogramElement add(IAddContext context) {
56
        final IAddConnectionContext addConContext = (IAddConnectionContext) context;
57
		final IsARelation relation = (IsARelation)context.getNewObject();
58
		final Diagram diagram = getDiagram();
59
		FreeFormConnection connection = createIsAConnection(addConContext, relation, diagram);
60
		imageCreator.createIsAConnectionLine(diagram, connection);
61
		layoutPictogramElement(connection);
62
		return connection;	
63
	}
64
	
65
	private FreeFormConnection createIsAConnection(IAddConnectionContext addConContext, IsARelation relation,
66
			final Diagram diagram) {
67
		FreeFormConnection connection = getFeatureProvider().getPeService().createFreeFormConnection(diagram);
68
        connection.setStart(addConContext.getSourceAnchor());
69
        connection.setEnd(addConContext.getTargetAnchor());
70
        connection.setVisible(true);
71
        connection.setActive(true);
72
        getFeatureProvider().getPeServiceUtil().setPropertyValue(connection, IsARelation.IS_A_CONNECTION_PROP_KEY, Boolean.TRUE.toString());
73
        addDecorators(connection);
74
		return connection;
75
	}
76
	
77
	public IJPAEditorFeatureProvider getFeatureProvider() {
78
		return (IJPAEditorFeatureProvider)super.getFeatureProvider();
79
	}
80
	
81
	private void addDecorators(FreeFormConnection c) {
82
		ConnectionDecorator d = imageCreator.createArrowConnectionDecorator(c, 0.9999, true);
83
		Graphiti.getGaService().setLocation(d.getGraphicsAlgorithm(), 0, 0);
84
	}
85
	
86
}
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddJPAEntityFeature.java (-81 / +48 lines)
Lines 18-27 Link Here
18
import java.util.ArrayList;
18
import java.util.ArrayList;
19
import java.util.HashSet;
19
import java.util.HashSet;
20
import java.util.List;
20
import java.util.List;
21
21
import org.eclipse.graphiti.features.IFeatureProvider;
22
import org.eclipse.graphiti.features.IFeatureProvider;
22
import org.eclipse.graphiti.features.context.IAddContext;
23
import org.eclipse.graphiti.features.context.IAddContext;
23
import org.eclipse.graphiti.features.context.ICreateContext;
24
import org.eclipse.graphiti.features.context.impl.CreateContext;
25
import org.eclipse.graphiti.features.impl.AbstractAddShapeFeature;
24
import org.eclipse.graphiti.features.impl.AbstractAddShapeFeature;
26
import org.eclipse.graphiti.mm.algorithms.Image;
25
import org.eclipse.graphiti.mm.algorithms.Image;
27
import org.eclipse.graphiti.mm.algorithms.Polyline;
26
import org.eclipse.graphiti.mm.algorithms.Polyline;
Lines 35-49 Link Here
35
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
34
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
36
import org.eclipse.graphiti.mm.pictograms.Shape;
35
import org.eclipse.graphiti.mm.pictograms.Shape;
37
import org.eclipse.graphiti.services.Graphiti;
36
import org.eclipse.graphiti.services.Graphiti;
38
import org.eclipse.graphiti.util.IPredefinedRenderingStyle;
37
import org.eclipse.graphiti.util.IColorConstant;
39
import org.eclipse.graphiti.util.PredefinedColoredAreas;
40
import org.eclipse.jdt.core.ICompilationUnit;
38
import org.eclipse.jdt.core.ICompilationUnit;
41
import org.eclipse.jdt.core.IPackageDeclaration;
42
import org.eclipse.jdt.core.JavaModelException;
39
import org.eclipse.jdt.core.JavaModelException;
43
import org.eclipse.jdt.internal.core.SourceType;
40
import org.eclipse.jdt.internal.core.SourceType;
44
import org.eclipse.jpt.jpa.core.JpaProject;
41
import org.eclipse.jpt.jpa.core.JpaProject;
45
import org.eclipse.jpt.jpa.core.context.AttributeMapping;
46
import org.eclipse.jpt.jpa.core.context.java.JavaMappedSuperclass;
47
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
42
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
48
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
43
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
49
import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin;
44
import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin;
Lines 54-75 Link Here
54
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.JPAEditorImageProvider;
49
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.JPAEditorImageProvider;
55
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.GraphicsUpdater;
50
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.GraphicsUpdater;
56
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants;
51
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants;
52
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants.ShapeType;
53
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorPredefinedColoredAreas;
57
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil;
54
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil;
58
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
55
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
59
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants.ShapeType;
60
56
61
57
62
@SuppressWarnings({ "restriction" })
58
@SuppressWarnings({ "restriction" })
63
public class AddJPAEntityFeature extends AbstractAddShapeFeature {
59
public class AddJPAEntityFeature extends AbstractAddShapeFeature {
64
60
65
	private IPeUtilFacade facade;
61
	private IPeUtilFacade facade;
62
	private boolean shouldRearrangeIsARelations = true;
66
	private static ContainerShape primaryShape;
63
	private static ContainerShape primaryShape;
67
	private static ContainerShape relationShape;
64
	private static ContainerShape relationShape;
68
	private static ContainerShape basicShape;
65
	private static ContainerShape basicShape;
69
66
70
67
71
	public AddJPAEntityFeature(IFeatureProvider fp) {
68
	public AddJPAEntityFeature(IFeatureProvider fp, boolean shouldRearrangeIsARelations) {
72
		super(fp);
69
		super(fp);
70
		this.shouldRearrangeIsARelations = shouldRearrangeIsARelations;
73
		facade = new PeUtilFacade();
71
		facade = new PeUtilFacade();
74
	}
72
	}
75
73
Lines 126-140 Link Here
126
		JavaPersistentType jpt = null;
124
		JavaPersistentType jpt = null;
127
		if (newObj instanceof JavaPersistentType) {
125
		if (newObj instanceof JavaPersistentType) {
128
			jpt = (JavaPersistentType) newObj;
126
			jpt = (JavaPersistentType) newObj;
129
			if (jpt.getMapping() instanceof JavaMappedSuperclass) {
130
				jpt = createEntityFromExistingMappedSuperclass(fp, jpt);
131
			}			
132
		} else if (newObj instanceof ICompilationUnit) {
127
		} else if (newObj instanceof ICompilationUnit) {
133
			ICompilationUnit cu = (ICompilationUnit) newObj;
128
			ICompilationUnit cu = (ICompilationUnit) newObj;
134
			jpt = JPAEditorUtil.getJPType(cu);
129
			jpt = JPAEditorUtil.getJPType(cu);
135
			if (jpt.getMapping() instanceof JavaMappedSuperclass) {
136
				jpt = createEntityFromExistingMappedSuperclass(fp, jpt);
137
			}
138
130
139
		} else if (newObj instanceof SourceType) {
131
		} else if (newObj instanceof SourceType) {
140
			ICompilationUnit cu = ((SourceType)newObj).getCompilationUnit();
132
			ICompilationUnit cu = ((SourceType)newObj).getCompilationUnit();
Lines 144-151 Link Here
144
				
136
				
145
	    ContainerShape entityShape = facade.createContainerShape(targetDiagram, true);
137
	    ContainerShape entityShape = facade.createContainerShape(targetDiagram, true);
146
		
138
		
147
		createEntityRectangle(context, entityShape,
139
	    JPAEditorConstants.DIAGRAM_OBJECT_TYPE dot = JpaArtifactFactory.instance().determineDiagramObjectType(jpt);
148
								this.getFeatureProvider().getDiagramTypeProvider().getDiagram());
140
		createEntityRectangle(context, entityShape, dot,
141
							  this.getFeatureProvider().getDiagramTypeProvider().getDiagram());
149
		link(entityShape, jpt);
142
		link(entityShape, jpt);
150
		Shape shape = Graphiti.getPeService().createShape(entityShape, false);
143
		Shape shape = Graphiti.getPeService().createShape(entityShape, false);
151
		Polyline headerBottomLine = Graphiti.getGaService().createPolyline(shape, new int[] { 0,
144
		Polyline headerBottomLine = Graphiti.getGaService().createPolyline(shape, new int[] { 0,
Lines 154-160 Link Here
154
				.setForeground(manageColor(JPAEditorConstants.ENTITY_BORDER_COLOR));
147
				.setForeground(manageColor(JPAEditorConstants.ENTITY_BORDER_COLOR));
155
		headerBottomLine.setLineWidth(JPAEditorConstants.ENTITY_BORDER_WIDTH);
148
		headerBottomLine.setLineWidth(JPAEditorConstants.ENTITY_BORDER_WIDTH);
156
149
157
		addHeader(jpt, entityShape, JPAEditorConstants.ENTITY_WIDTH);
150
		addHeader(jpt, entityShape, JPAEditorConstants.ENTITY_WIDTH, dot);
158
		
151
		
159
		createCompartments(context, jpt, entityShape);
152
		createCompartments(context, jpt, entityShape);
160
		fillCompartments(jpt,entityShape);
153
		fillCompartments(jpt,entityShape);
Lines 169-232 Link Here
169
162
170
		UpdateAttributeFeature updateFeature = new UpdateAttributeFeature(fp);
163
		UpdateAttributeFeature updateFeature = new UpdateAttributeFeature(fp);
171
		updateFeature.reconnect(jpt);
164
		updateFeature.reconnect(jpt);
172
	
165
		if (shouldRearrangeIsARelations)
166
			JpaArtifactFactory.instance().rearrangeIsARelations(getFeatureProvider());	
173
		return entityShape;
167
		return entityShape;
174
	}
168
	}
175
176
	private JavaPersistentType createEntityFromExistingMappedSuperclass(
177
			IJPAEditorFeatureProvider fp, JavaPersistentType jpt) {
178
		ICreateContext cont = new CreateContext();
179
		String packageName = null;
180
		try {
181
			packageName = getMappedSuperclassPackageDeclaration(fp, jpt,
182
					packageName);
183
		} catch (JavaModelException e) {
184
			JPADiagramEditorPlugin.logError(e); 	     					
185
		}
186
187
		boolean hasPrimaryKey = hasMappedSuperclassPrimaryKeyAttribute(jpt);
188
189
		CreateJPAEntityFeature createFeature = new CreateJPAEntityFeature(fp,
190
				true, jpt.getName(), packageName, hasPrimaryKey);
191
		Object[] objects = createFeature.create(cont);
192
		if (objects.length != 0) {
193
			Object obj = objects[0];
194
			if (obj instanceof JavaPersistentType) {
195
				jpt = (JavaPersistentType) obj;
196
			}
197
		}
198
		return jpt;
199
	}
200
201
	private boolean hasMappedSuperclassPrimaryKeyAttribute(
202
			JavaPersistentType jpt) {
203
		
204
		for (AttributeMapping map : ((JavaMappedSuperclass) jpt.getMapping()).getAllAttributeMappings()) {
205
			if (map.getPrimaryKeyColumnName() != null) {
206
				return true;
207
			}
208
		}
209
		return false;
210
	}
211
212
	private String getMappedSuperclassPackageDeclaration(
213
			IJPAEditorFeatureProvider fp, JavaPersistentType jpt,
214
			String packageName) throws JavaModelException {
215
		IPackageDeclaration[] packages = fp.getCompilationUnit(jpt)
216
				.getPackageDeclarations();
217
		if (packages.length > 0) {
218
			IPackageDeclaration packageDecl = packages[0];
219
			packageName = packageDecl.getElementName();
220
		}
221
		return packageName;
222
	}
223
	
169
	
224
	private void createCompartments(IAddContext context, JavaPersistentType jpt,
170
	private void createCompartments(IAddContext context, JavaPersistentType jpt,
225
			ContainerShape entityShape) {
171
			ContainerShape entityShape) {
226
		primaryShape = createCompartmentRectangle(entityShape, JPAEditorConstants.ENTITY_MIN_HEIGHT, JPAEditorMessages.AddJPAEntityFeature_primaryKeysShape);
172
		JPAEditorConstants.DIAGRAM_OBJECT_TYPE dot = JpaArtifactFactory.instance().determineDiagramObjectType(jpt);
227
		relationShape = createCompartmentRectangle(entityShape, GraphicsUpdater.getNextCompartmentY(primaryShape) + JPAEditorConstants.SEPARATOR_HEIGHT,
173
		primaryShape = createCompartmentRectangle(entityShape, 
228
				 JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes);
174
												  JPAEditorConstants.ENTITY_MIN_HEIGHT, 
229
		basicShape = createCompartmentRectangle(entityShape, GraphicsUpdater.getNextCompartmentY(relationShape) + JPAEditorConstants.SEPARATOR_HEIGHT, JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes);
175
												  JPAEditorMessages.AddJPAEntityFeature_primaryKeysShape,
176
												  dot);
177
		relationShape = createCompartmentRectangle(entityShape, 
178
												   GraphicsUpdater.getNextCompartmentY(primaryShape) + JPAEditorConstants.SEPARATOR_HEIGHT,
179
												   JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes,
180
												   dot);
181
		basicShape = createCompartmentRectangle(entityShape, 
182
												GraphicsUpdater.getNextCompartmentY(relationShape) + JPAEditorConstants.SEPARATOR_HEIGHT, 
183
												JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes,
184
												dot);
230
		if (IAddEntityContext.class.isInstance(context)) {
185
		if (IAddEntityContext.class.isInstance(context)) {
231
			IAddEntityContext entityContext = (IAddEntityContext) context;
186
			IAddEntityContext entityContext = (IAddEntityContext) context;
232
			GraphicsUpdater.setCollapsed(primaryShape, entityContext.isPrimaryCollapsed());
187
			GraphicsUpdater.setCollapsed(primaryShape, entityContext.isPrimaryCollapsed());
Lines 255-261 Link Here
255
	}
210
	}
256
211
257
	private ContainerShape createCompartmentRectangle(
212
	private ContainerShape createCompartmentRectangle(
258
			ContainerShape entityShape, int y, String attribTxt) {
213
			ContainerShape entityShape, int y, String attribTxt,
214
			JPAEditorConstants.DIAGRAM_OBJECT_TYPE dot) {
259
		int width = entityShape.getGraphicsAlgorithm().getWidth();
215
		int width = entityShape.getGraphicsAlgorithm().getWidth();
260
		ContainerShape containerShape = Graphiti.getPeService().createContainerShape(
216
		ContainerShape containerShape = Graphiti.getPeService().createContainerShape(
261
				entityShape, false);
217
				entityShape, false);
Lines 268-274 Link Here
268
		
224
		
269
		UpdateAttributeFeature updateFeature = new UpdateAttributeFeature(getFeatureProvider());
225
		UpdateAttributeFeature updateFeature = new UpdateAttributeFeature(getFeatureProvider());
270
		
226
		
271
		updateFeature.addSeparatorsToShape(containerShape);
227
		updateFeature.addSeparatorsToShape(containerShape, dot);
272
		
228
		
273
		return containerShape;
229
		return containerShape;
274
	}
230
	}
Lines 341-357 Link Here
341
	}
297
	}
342
298
343
	public static RoundedRectangle createEntityRectangle(IAddContext context,
299
	public static RoundedRectangle createEntityRectangle(IAddContext context,
344
			ContainerShape entityShape, Diagram diagram) {
300
														 ContainerShape entityShape, 
345
301
														 JPAEditorConstants.DIAGRAM_OBJECT_TYPE dot,  
302
														 Diagram diagram) {
303
304
		IColorConstant foreground = JpaArtifactFactory.instance().getForeground(dot);
305
		IColorConstant background = JpaArtifactFactory.instance().getBackground(dot);
306
		String renderingStyle = JpaArtifactFactory.instance().getRenderingStyle(dot);
307
		
346
		RoundedRectangle entityRectangle = Graphiti.getGaService().createRoundedRectangle(
308
		RoundedRectangle entityRectangle = Graphiti.getGaService().createRoundedRectangle(
347
				entityShape, JPAEditorConstants.ENTITY_CORNER_WIDTH,
309
				entityShape, JPAEditorConstants.ENTITY_CORNER_WIDTH,
348
				JPAEditorConstants.ENTITY_CORNER_HEIGHT);
310
				JPAEditorConstants.ENTITY_CORNER_HEIGHT);
349
		entityRectangle
311
		entityRectangle
350
				.setForeground(Graphiti.getGaService().manageColor(diagram, JPAEditorConstants.ENTITY_BORDER_COLOR));
312
				.setForeground(Graphiti.getGaService().manageColor(diagram, foreground));
351
		entityRectangle
313
		entityRectangle
352
				.setBackground(Graphiti.getGaService().manageColor(diagram, JPAEditorConstants.ENTITY_BACKGROUND));
314
				.setBackground(Graphiti.getGaService().manageColor(diagram, background));
353
		Graphiti.getGaService().setRenderingStyle(entityRectangle.getPictogramElement().getGraphicsAlgorithm(), 
315
		Graphiti.getGaService().setRenderingStyle(entityRectangle.getPictogramElement().getGraphicsAlgorithm(), 
354
				PredefinedColoredAreas.getAdaptedGradientColoredAreas(IPredefinedRenderingStyle.BLUE_WHITE_GLOSS_ID));
316
				JPAEditorPredefinedColoredAreas.getAdaptedGradientColoredAreas(renderingStyle));
355
		entityRectangle.setLineWidth(JPAEditorConstants.ENTITY_BORDER_WIDTH);
317
		entityRectangle.setLineWidth(JPAEditorConstants.ENTITY_BORDER_WIDTH);
356
		entityRectangle.setLineStyle(LineStyle.SOLID);
318
		entityRectangle.setLineStyle(LineStyle.SOLID);
357
		Graphiti.getGaService().setLocationAndSize(entityRectangle, context
319
		Graphiti.getGaService().setLocationAndSize(entityRectangle, context
Lines 370-377 Link Here
370
	}
332
	}
371
333
372
	private ContainerShape addHeader(JavaPersistentType addedWrapper,
334
	private ContainerShape addHeader(JavaPersistentType addedWrapper,
373
			ContainerShape entityShape, int width) {
335
									 ContainerShape entityShape, 
374
336
									 int width,
337
									 JPAEditorConstants.DIAGRAM_OBJECT_TYPE dot) {
338
		String entityIconId = dot.equals(JPAEditorConstants.DIAGRAM_OBJECT_TYPE.Entity) ? 
339
									JPAEditorImageProvider.JPA_ENTITY :
340
									JPAEditorImageProvider.MAPPED_SUPERCLASS;
341
		
375
		ContainerShape headerIconShape = Graphiti.getPeService().createContainerShape(
342
		ContainerShape headerIconShape = Graphiti.getPeService().createContainerShape(
376
				entityShape, false);
343
				entityShape, false);
377
		Rectangle iconRect = Graphiti.getGaService().createRectangle(headerIconShape);
344
		Rectangle iconRect = Graphiti.getGaService().createRectangle(headerIconShape);
Lines 383-389 Link Here
383
		iconRect.setHeight(JPAEditorConstants.HEADER_ICON_RECT_HEIGHT);
350
		iconRect.setHeight(JPAEditorConstants.HEADER_ICON_RECT_HEIGHT);
384
		iconRect.setY(0);
351
		iconRect.setY(0);
385
		Image headerIcon = Graphiti.getGaService().createImage(iconRect,
352
		Image headerIcon = Graphiti.getGaService().createImage(iconRect,
386
				JPAEditorImageProvider.JPA_ENTITY);
353
				entityIconId);
387
		Graphiti.getGaService().setLocationAndSize(headerIcon, 
354
		Graphiti.getGaService().setLocationAndSize(headerIcon, 
388
													JPAEditorConstants.ICON_HEADER_X,
355
													JPAEditorConstants.ICON_HEADER_X,
389
													JPAEditorConstants.ICON_HEADER_Y,
356
													JPAEditorConstants.ICON_HEADER_Y,
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddRelationFeature.java (-3 / +3 lines)
Lines 103-109 Link Here
103
        
103
        
104
	private FreeFormConnection createConnection(IAddConnectionContext addConContext, IRelation relation,
104
	private FreeFormConnection createConnection(IAddConnectionContext addConContext, IRelation relation,
105
			final Diagram diagram) {
105
			final Diagram diagram) {
106
        FreeFormConnection connection = getFeatureProvider().getPeUtil().createFreeFormConnection(diagram);
106
        FreeFormConnection connection = getFeatureProvider().getPeServiceUtil().createFreeFormConnection(diagram);
107
        connection.setStart(addConContext.getSourceAnchor());
107
        connection.setStart(addConContext.getSourceAnchor());
108
        connection.setEnd(addConContext.getTargetAnchor());
108
        connection.setEnd(addConContext.getTargetAnchor());
109
        connection.setVisible(true);
109
        connection.setVisible(true);
Lines 154-160 Link Here
154
		double endCoefficient = 1.0 - startCoefficient;	
154
		double endCoefficient = 1.0 - startCoefficient;	
155
		int len = JPAEditorUtil.calcConnectionLength(c);		
155
		int len = JPAEditorUtil.calcConnectionLength(c);		
156
		if (UNI.equals(direction)) {
156
		if (UNI.equals(direction)) {
157
			ConnectionDecorator d = imageCreator.createArrowConnectionDecorator(c, endCoefficient);
157
			ConnectionDecorator d = imageCreator.createArrowConnectionDecorator(c, endCoefficient, false);
158
			Graphiti.getGaService().setLocation(d.getGraphicsAlgorithm(),Math.round(-len/10), 0);				
158
			Graphiti.getGaService().setLocation(d.getGraphicsAlgorithm(),Math.round(-len/10), 0);				
159
		} 
159
		} 
160
	}
160
	}
Lines 175-181 Link Here
175
		ConnectionDecorator d1 = imageCreator.createManyStartDecorator(c, startCoefficient);
175
		ConnectionDecorator d1 = imageCreator.createManyStartDecorator(c, startCoefficient);
176
		Graphiti.getGaService().setLocation(d1.getGraphicsAlgorithm(),Math.round(len/10), 0);
176
		Graphiti.getGaService().setLocation(d1.getGraphicsAlgorithm(),Math.round(len/10), 0);
177
		if (UNI.equals(direction)) {
177
		if (UNI.equals(direction)) {
178
			ConnectionDecorator d2 = imageCreator.createArrowConnectionDecorator(c, endCoefficient);
178
			ConnectionDecorator d2 = imageCreator.createArrowConnectionDecorator(c, endCoefficient, false);
179
			Graphiti.getGaService().setLocation(d2.getGraphicsAlgorithm(),Math.round(-len/10), 0);
179
			Graphiti.getGaService().setLocation(d2.getGraphicsAlgorithm(),Math.round(-len/10), 0);
180
		} 
180
		} 
181
    }
181
    }
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateInheritedEntityFeature.java (+106 lines)
Added Link Here
1
/*******************************************************************************
2
 * <copyright>
3
 *
4
 * Copyright (c) 2005, 2010 SAP AG.
5
 * All rights reserved. This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
8
 * http://www.eclipse.org/legal/epl-v10.html
9
 *
10
 * Contributors:
11
 *    Stefan Dimov - initial API, implementation and documentation
12
 *
13
 * </copyright>
14
 *
15
 *******************************************************************************/
16
package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature;
17
18
import org.eclipse.graphiti.features.IFeatureProvider;
19
import org.eclipse.graphiti.features.context.ICreateConnectionContext;
20
import org.eclipse.graphiti.features.context.ICreateContext;
21
import org.eclipse.graphiti.features.context.impl.AddContext;
22
import org.eclipse.graphiti.features.context.impl.CreateContext;
23
import org.eclipse.graphiti.features.impl.AbstractCreateConnectionFeature;
24
import org.eclipse.graphiti.mm.pictograms.Anchor;
25
import org.eclipse.graphiti.mm.pictograms.Connection;
26
import org.eclipse.graphiti.mm.pictograms.Diagram;
27
import org.eclipse.jdt.core.JavaModelException;
28
import org.eclipse.jpt.jpa.core.context.PersistentType;
29
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
30
import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin;
31
import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages;
32
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
33
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.JPAEditorImageProvider;
34
35
public class CreateInheritedEntityFeature extends AbstractCreateConnectionFeature {
36
37
	public CreateInheritedEntityFeature(IFeatureProvider fp) {
38
		this(fp, JPAEditorMessages.CreateIsARelationFeature_name,	JPAEditorMessages.CreateIsARelationFeature_description);
39
	}
40
		
41
	public CreateInheritedEntityFeature(IFeatureProvider fp, String name,
42
			String description) {
43
		super(fp, name, description);
44
	}
45
46
	public boolean canCreate(ICreateConnectionContext context) {
47
		JavaPersistentType superclass = (JavaPersistentType)getPersistentType(context.getSourceAnchor());
48
	    if (superclass == null)
49
	    	return false;
50
	    if (context.getTargetAnchor() == null)
51
	    	return true;
52
		if (context.getTargetAnchor().getParent() instanceof Diagram)
53
			return true;
54
	    return false;
55
	}
56
57
	public Connection create(ICreateConnectionContext context) {
58
		JavaPersistentType mappedSuperclass = (JavaPersistentType)getPersistentType(context.getSourceAnchor());
59
		CreateJPAEntityFeature createEntityFeature = null;
60
		try {
61
			createEntityFeature = new CreateJPAEntityFeature(
62
					getFeatureProvider(), mappedSuperclass);
63
		} catch (JavaModelException e) {
64
			JPADiagramEditorPlugin.logError("Cannot create a new JPA entity class", e); //$NON-NLS-1$	
65
			return null;
66
		}
67
		ICreateContext ctx = new CreateContext();
68
		Object[] res = createEntityFeature.create(ctx);
69
		JavaPersistentType newEntity = (JavaPersistentType)res[0];
70
		AddJPAEntityFeature ft = new AddJPAEntityFeature(getFeatureProvider(), true);
71
		AddContext cont = new AddContext();
72
		cont.setTargetContainer(getFeatureProvider().getDiagram());
73
		cont.setNewObject(newEntity);
74
		cont.setLocation(context.getTargetLocation().getX(), context.getTargetLocation().getY());
75
		ft.add(cont);		
76
		return null;
77
	}
78
79
	public boolean canStartConnection(ICreateConnectionContext context) {
80
		JavaPersistentType superclass = (JavaPersistentType)getPersistentType(context.getSourceAnchor()); 
81
	    if (superclass == null) 
82
	        return false;
83
	    return true;
84
	}
85
	
86
    public String getCreateImageId() {
87
        return JPAEditorImageProvider.ADD_INHERITED_ENTITY;
88
    }	
89
    
90
	protected PersistentType getPersistentType(Anchor anchor) {
91
	    if (anchor != null) {
92
	        Object refObject =
93
	            getBusinessObjectForPictogramElement(anchor.getParent());
94
	        if (refObject instanceof PersistentType) {
95
	            return (PersistentType) refObject;
96
	        }
97
	    }
98
	    return null;
99
	}
100
	
101
	public IJPAEditorFeatureProvider getFeatureProvider() {
102
		return (IJPAEditorFeatureProvider)super.getFeatureProvider(); 
103
	}
104
105
106
}
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateJPAEntityFeature.java (-4 / +27 lines)
Lines 30-35 Link Here
30
import org.eclipse.graphiti.mm.pictograms.Diagram;
30
import org.eclipse.graphiti.mm.pictograms.Diagram;
31
import org.eclipse.graphiti.mm.pictograms.Shape;
31
import org.eclipse.graphiti.mm.pictograms.Shape;
32
import org.eclipse.jdt.core.ICompilationUnit;
32
import org.eclipse.jdt.core.ICompilationUnit;
33
import org.eclipse.jdt.core.JavaModelException;
33
import org.eclipse.jface.dialogs.ErrorDialog;
34
import org.eclipse.jface.dialogs.ErrorDialog;
34
import org.eclipse.jface.preference.IPreferenceStore;
35
import org.eclipse.jface.preference.IPreferenceStore;
35
import org.eclipse.jpt.jpa.core.JpaProject;
36
import org.eclipse.jpt.jpa.core.JpaProject;
Lines 43-48 Link Here
43
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
44
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
44
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.JPAEditorImageProvider;
45
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.JPAEditorImageProvider;
45
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil;
46
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil;
47
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
46
import org.eclipse.swt.widgets.Shell;
48
import org.eclipse.swt.widgets.Shell;
47
import org.eclipse.ui.IEditorPart;
49
import org.eclipse.ui.IEditorPart;
48
import org.eclipse.ui.IWorkbenchSite;
50
import org.eclipse.ui.IWorkbenchSite;
Lines 52-60 Link Here
52
	
54
	
53
	private IPreferenceStore jpaPreferenceStore = JPADiagramEditorPlugin.getDefault().getPreferenceStore();
55
	private IPreferenceStore jpaPreferenceStore = JPADiagramEditorPlugin.getDefault().getPreferenceStore();
54
	private boolean isMappedSuperclassChild;
56
	private boolean isMappedSuperclassChild;
57
	private JavaPersistentType mappedSuperclass;
55
	private String mappedSuperclassName;
58
	private String mappedSuperclassName;
56
	private String mappedSuperclassPackage;
59
	private String mappedSuperclassPackage;
57
	private boolean hasPrimarykey;
60
	private boolean superHasPrimarykey;
58
61
59
62
60
	public CreateJPAEntityFeature(IFeatureProvider fp) {
63
	public CreateJPAEntityFeature(IFeatureProvider fp) {
Lines 75-88 Link Here
75
78
76
	public CreateJPAEntityFeature(IFeatureProvider fp,
79
	public CreateJPAEntityFeature(IFeatureProvider fp,
77
			boolean isMappedSuperclassChild, String mappedSuperclassName,
80
			boolean isMappedSuperclassChild, String mappedSuperclassName,
78
			String mappedSuperClassPackage, boolean hasPrimaryKey) {
81
			String mappedSuperClassPackage, boolean superHasPrimaryKey) {
79
		this(fp);
82
		this(fp);
80
		this.isMappedSuperclassChild = isMappedSuperclassChild;
83
		this.isMappedSuperclassChild = isMappedSuperclassChild;
81
		this.mappedSuperclassName = mappedSuperclassName;
84
		this.mappedSuperclassName = mappedSuperclassName;
82
		this.mappedSuperclassPackage = mappedSuperClassPackage;
85
		this.mappedSuperclassPackage = mappedSuperClassPackage;
83
		this.hasPrimarykey = hasPrimaryKey;
86
		this.superHasPrimarykey = superHasPrimaryKey;
84
	}
87
	}
85
88
89
	public CreateJPAEntityFeature(IJPAEditorFeatureProvider fp,
90
			JavaPersistentType mappedSuperclass) throws JavaModelException {
91
		this(fp);
92
		this.isMappedSuperclassChild = true;
93
		this.mappedSuperclass = mappedSuperclass; 
94
		this.mappedSuperclassName = mappedSuperclass.getName();
95
		this.mappedSuperclassPackage = JpaArtifactFactory.instance().getMappedSuperclassPackageDeclaration(mappedSuperclass);
96
		this.superHasPrimarykey = JpaArtifactFactory.instance().hasOrInheritsPrimaryKey(mappedSuperclass);
97
	}
98
	
86
99
87
    public boolean canCreate(ICreateContext context) {
100
    public boolean canCreate(ICreateContext context) {
88
        return context.getTargetContainer() instanceof Diagram;
101
        return context.getTargetContainer() instanceof Diagram;
Lines 122-128 Link Here
122
		}
135
		}
123
		
136
		
124
		try {
137
		try {
125
			this.getFeatureProvider().getJPAEditorUtil().createEntityInProject(targetProject, entityName, jpaPreferenceStore, isMappedSuperclassChild, mappedSuperclassName, mappedSuperclassPackage, hasPrimarykey);
138
			if (mappedSuperclass != null) {
139
				this.getFeatureProvider().
140
				getJPAEditorUtil().
141
					createEntityInProject(targetProject, entityName, mappedSuperclass);	//$NON-NLS-1$								
142
			} else {
143
				this.getFeatureProvider().
144
				getJPAEditorUtil().
145
					createEntityInProject(targetProject, entityName, jpaPreferenceStore, 
146
										  isMappedSuperclassChild, mappedSuperclassName, 
147
										  mappedSuperclassPackage, "id", superHasPrimarykey);	//$NON-NLS-1$				
148
			}
126
		} catch (Exception e1) {
149
		} catch (Exception e1) {
127
			JPADiagramEditorPlugin.logError("Cannot create an entity in the project " + targetProject.getName(), e1);  //$NON-NLS-1$		 
150
			JPADiagramEditorPlugin.logError("Cannot create an entity in the project " + targetProject.getName(), e1);  //$NON-NLS-1$		 
128
		}
151
		}
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToManyBiDirRelationFeature.java (-2 / +2 lines)
Lines 25-32 Link Here
25
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
25
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
26
26
27
27
28
public class CreateManyToManyBiDirRelationFeature extends
28
public class CreateManyToManyBiDirRelationFeature extends CreateManyToManyRelationFeature 
29
		CreateManyToManyRelationFeature {
29
												  implements ICreateBiDirRelationFeature {
30
30
31
	public CreateManyToManyBiDirRelationFeature(IJPAEditorFeatureProvider fp) {
31
	public CreateManyToManyBiDirRelationFeature(IJPAEditorFeatureProvider fp) {
32
		super(fp, JPAEditorMessages.CreateManyToManyBiDirRelationFeature_manyToManyBiDirFeatureName,  
32
		super(fp, JPAEditorMessages.CreateManyToManyBiDirRelationFeature_manyToManyBiDirFeatureName,  
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToManyUniDirRelationFeature.java (-2 / +2 lines)
Lines 25-32 Link Here
25
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
25
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
26
26
27
27
28
public class CreateManyToManyUniDirRelationFeature extends
28
public class CreateManyToManyUniDirRelationFeature extends CreateManyToManyRelationFeature 
29
		CreateManyToManyRelationFeature {
29
												   implements ICreateUniDirRelationFeature {
30
30
31
	public CreateManyToManyUniDirRelationFeature(IJPAEditorFeatureProvider fp) {
31
	public CreateManyToManyUniDirRelationFeature(IJPAEditorFeatureProvider fp) {
32
		super(fp, JPAEditorMessages.CreateManyToManyUniDirRelationFeature_manyToManyUniDirFeatureName, 
32
		super(fp, JPAEditorMessages.CreateManyToManyUniDirRelationFeature_manyToManyUniDirFeatureName, 
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneBiDirRelationFeature.java (-2 / +2 lines)
Lines 25-32 Link Here
25
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
25
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
26
26
27
27
28
public class CreateManyToOneBiDirRelationFeature extends
28
public class CreateManyToOneBiDirRelationFeature extends CreateManyToOneRelationFeature 
29
		CreateManyToOneRelationFeature {
29
												 implements ICreateBiDirRelationFeature {
30
30
31
	public CreateManyToOneBiDirRelationFeature(IJPAEditorFeatureProvider fp) {
31
	public CreateManyToOneBiDirRelationFeature(IJPAEditorFeatureProvider fp) {
32
		super(fp, JPAEditorMessages.CreateManyToOneBiDirRelationFeature_manyToOneBiDirFeatureName,  
32
		super(fp, JPAEditorMessages.CreateManyToOneBiDirRelationFeature_manyToOneBiDirFeatureName,  
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneUniDirRelationFeature.java (-2 / +2 lines)
Lines 25-32 Link Here
25
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
25
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
26
26
27
27
28
public class CreateManyToOneUniDirRelationFeature extends
28
public class CreateManyToOneUniDirRelationFeature extends CreateManyToOneRelationFeature 
29
		CreateManyToOneRelationFeature {
29
												  implements ICreateUniDirRelationFeature {
30
30
31
	public CreateManyToOneUniDirRelationFeature(IJPAEditorFeatureProvider fp) {
31
	public CreateManyToOneUniDirRelationFeature(IJPAEditorFeatureProvider fp) {
32
		super(fp, JPAEditorMessages.CreateManyToOneUniDirRelationFeature_manyToOneUniDirFeatureName,  
32
		super(fp, JPAEditorMessages.CreateManyToOneUniDirRelationFeature_manyToOneUniDirFeatureName,  
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateMappedSuperclassFeature.java (+121 lines)
Added Link Here
1
/*******************************************************************************
2
 * <copyright>
3
 *
4
 * Copyright (c) 2005, 2010 SAP AG.
5
 * All rights reserved. This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
8
 * http://www.eclipse.org/legal/epl-v10.html
9
 *
10
 * Contributors:
11
 *    Stefan Dimov - initial API, implementation and documentation
12
 *
13
 * </copyright>
14
 *
15
 *******************************************************************************/
16
package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature;
17
18
import java.util.List;
19
20
import org.eclipse.core.resources.IProject;
21
import org.eclipse.graphiti.features.IFeatureProvider;
22
import org.eclipse.graphiti.features.context.ICreateContext;
23
import org.eclipse.graphiti.features.impl.AbstractCreateFeature;
24
import org.eclipse.graphiti.mm.pictograms.Diagram;
25
import org.eclipse.graphiti.mm.pictograms.Shape;
26
import org.eclipse.jdt.core.ICompilationUnit;
27
import org.eclipse.jpt.jpa.core.JpaProject;
28
import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
29
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
30
import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin;
31
import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages;
32
import org.eclipse.jpt.jpadiagrameditor.ui.internal.propertypage.JPADiagramPropertyPage;
33
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
34
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.JPAEditorImageProvider;
35
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil;
36
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
37
import org.eclipse.ui.IEditorPart;
38
import org.eclipse.ui.IWorkbenchSite;
39
  
40
41
42
public class CreateMappedSuperclassFeature extends
43
		AbstractCreateFeature {
44
45
	public CreateMappedSuperclassFeature(IFeatureProvider fp) {
46
		super(
47
				fp,
48
				JPAEditorMessages.CreateMappedSuperclassFeature_createMappedSuperclassFeatureName,
49
				JPAEditorMessages.CreateMappedSuperclassFeature_createMappedSuperclassFeatureDescription);
50
	}
51
52
	public boolean canCreate(ICreateContext context) {
53
		return context.getTargetContainer() instanceof Diagram;
54
	}
55
56
	public Object[] create(ICreateContext context) {
57
		List<Shape> shapes = this.getFeatureProvider().getDiagramTypeProvider()
58
				.getDiagram().getChildren();
59
		IProject targetProject = null;
60
		JpaProject jpaProject = null;
61
		if ((shapes == null) || (shapes.size() == 0)) {
62
			jpaProject = getTargetJPAProject();
63
			targetProject = jpaProject.getProject();
64
		} else {
65
			Shape sh = shapes.get(0);
66
			JavaPersistentType jpt = (JavaPersistentType) getFeatureProvider()
67
					.getBusinessObjectForPictogramElement(sh);
68
			if (jpt == null)
69
				return new Object[] {};
70
			jpaProject = jpt.getJpaProject();
71
			targetProject = jpaProject.getProject();
72
		}
73
		
74
		String mappedSuperclassName = getFeatureProvider()
75
				.getJPAEditorUtil()
76
				.generateUniqueMappedSuperclassName(
77
						jpaProject,
78
						JPADiagramPropertyPage.getDefaultPackage(jpaProject.getProject()),
79
						getFeatureProvider());
80
		
81
		if (!JptJpaCorePlugin.discoverAnnotatedClasses(jpaProject.getProject())) {
82
			JPAEditorUtil.createRegisterEntityInXMLJob(jpaProject, mappedSuperclassName);
83
		}
84
				
85
		try {
86
			getFeatureProvider().getJPAEditorUtil().createMappedSuperclassInProject(targetProject, mappedSuperclassName);
87
		} catch (Exception e1) {
88
			JPADiagramEditorPlugin.logError("Cannot create a mapped superclass in the project " + targetProject.getName(), e1);  //$NON-NLS-1$		 
89
		}
90
		jpaProject.updateAndWait();
91
		JavaPersistentType jpt = JpaArtifactFactory.instance().getJPT(mappedSuperclassName, jpaProject);
92
		
93
		if (jpt != null) {
94
			addGraphicalRepresentation(context, jpt);
95
	        IWorkbenchSite ws = ((IEditorPart)getDiagramEditor()).getSite();
96
	        ICompilationUnit cu = getFeatureProvider().getCompilationUnit(jpt);
97
	        getFeatureProvider().getJPAEditorUtil().formatCode(cu, ws);			
98
			return new Object[] { jpt };
99
		} else {
100
			JPADiagramEditorPlugin.logError("The mapped superclass " + 						//$NON-NLS-1$
101
						mappedSuperclassName + " could not be created", new Exception());	//$NON-NLS-1$	 
102
		}				
103
104
		return new Object[] {};
105
	}
106
107
	public String getCreateImageId() {
108
		return JPAEditorImageProvider.ADD_MAPPED_SUPERCLASS;
109
	}
110
111
112
	public IJPAEditorFeatureProvider getFeatureProvider() {
113
		return (IJPAEditorFeatureProvider) super.getFeatureProvider();
114
	}
115
116
	private JpaProject getTargetJPAProject() {
117
		return getFeatureProvider().getMoinIntegrationUtil()
118
				.getProjectByDiagram(getDiagram());
119
	}
120
121
}
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToManyUniDirRelationFeature.java (-2 / +2 lines)
Lines 25-32 Link Here
25
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
25
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
26
26
27
27
28
public class CreateOneToManyUniDirRelationFeature extends
28
public class CreateOneToManyUniDirRelationFeature extends CreateOneToManyRelationFeature 
29
		CreateOneToManyRelationFeature {
29
												  implements ICreateUniDirRelationFeature {
30
30
31
	public CreateOneToManyUniDirRelationFeature(IJPAEditorFeatureProvider fp) {
31
	public CreateOneToManyUniDirRelationFeature(IJPAEditorFeatureProvider fp) {
32
		super(fp, JPAEditorMessages.CreateOneToManyUniDirRelationFeature_oneToManyUniDirFeatureName,  
32
		super(fp, JPAEditorMessages.CreateOneToManyUniDirRelationFeature_oneToManyUniDirFeatureName,  
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneBiDirRelationFeature.java (-1 / +2 lines)
Lines 25-31 Link Here
25
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
25
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
26
26
27
27
28
public class CreateOneToOneBiDirRelationFeature extends CreateOneToOneRelationFeature {
28
public class CreateOneToOneBiDirRelationFeature extends CreateOneToOneRelationFeature
29
												implements ICreateBiDirRelationFeature {
29
	
30
	
30
	public CreateOneToOneBiDirRelationFeature(IJPAEditorFeatureProvider fp) {
31
	public CreateOneToOneBiDirRelationFeature(IJPAEditorFeatureProvider fp) {
31
		super(fp, JPAEditorMessages.CreateOneToOneBiDirRelationFeature_oneToOneBiDirFeatureName,  
32
		super(fp, JPAEditorMessages.CreateOneToOneBiDirRelationFeature_oneToOneBiDirFeatureName,  
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneUniDirRelationFeature.java (-2 / +2 lines)
Lines 25-32 Link Here
25
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
25
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
26
26
27
27
28
28
public class CreateOneToOneUniDirRelationFeature extends CreateOneToOneRelationFeature
29
public class CreateOneToOneUniDirRelationFeature extends CreateOneToOneRelationFeature {
29
												 implements ICreateUniDirRelationFeature {
30
	
30
	
31
	public CreateOneToOneUniDirRelationFeature(IJPAEditorFeatureProvider fp) {
31
	public CreateOneToOneUniDirRelationFeature(IJPAEditorFeatureProvider fp) {
32
		super(fp, JPAEditorMessages.CreateOneToOneUniDirRelationFeature_oneToOneUniDirFeatureName, 
32
		super(fp, JPAEditorMessages.CreateOneToOneUniDirRelationFeature_oneToOneUniDirFeatureName, 
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateRelationFeature.java (-12 / +21 lines)
Lines 25-30 Link Here
25
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
25
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
26
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
26
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
27
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.AbstractRelation;
27
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.AbstractRelation;
28
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
28
29
29
30
30
abstract public class CreateRelationFeature extends AbstractCreateConnectionFeature {
31
abstract public class CreateRelationFeature extends AbstractCreateConnectionFeature {
Lines 34-58 Link Here
34
	}
35
	}
35
36
36
	public boolean canCreate(ICreateConnectionContext context) {
37
	public boolean canCreate(ICreateConnectionContext context) {
37
		JavaPersistentType source = (JavaPersistentType)getPersistentType(context.getSourceAnchor());
38
		JavaPersistentType owner = (JavaPersistentType)getPersistentType(context.getSourceAnchor());
38
		JavaPersistentType target = (JavaPersistentType)getPersistentType(context.getTargetAnchor());
39
		JavaPersistentType inverse = (JavaPersistentType)getPersistentType(context.getTargetAnchor());
39
	    if (source != null && target != null) {
40
	    if ((owner == null) || (inverse == null)) 
40
	        return true;
41
	        return false;
41
	    }
42
	    if (JpaArtifactFactory.instance().hasMappedSuperclassAnnotation(inverse))
42
	    return false;
43
	    	return false;
44
	    if ((this instanceof ICreateBiDirRelationFeature) && 
45
	    	(JpaArtifactFactory.instance().hasMappedSuperclassAnnotation(owner)))
46
	    	return false;
47
	    return true;
43
	}
48
	}
44
49
45
	public boolean canStartConnection(ICreateConnectionContext context) {
50
	public boolean canStartConnection(ICreateConnectionContext context) {
46
	    if (getPersistentType(context.getSourceAnchor()) != null) 
51
		JavaPersistentType owner = (JavaPersistentType)getPersistentType(context.getSourceAnchor()); 
47
	        return true;
52
	    if (owner == null) 
48
	    return false;
53
	        return false;
54
	    if ((this instanceof ICreateBiDirRelationFeature) &&
55
	    	JpaArtifactFactory.instance().hasMappedSuperclassAnnotation(owner))
56
	    	return false;
57
	    return true;
49
	}
58
	}
50
	
59
	
51
	public Connection create(ICreateConnectionContext context) {
60
	public Connection create(ICreateConnectionContext context) {
52
	    Connection newConnection = null;
61
	    Connection newConnection = null;
53
	    PersistentType source = getPersistentType(context.getSourceAnchor());
62
	    PersistentType owner = getPersistentType(context.getSourceAnchor());
54
	    PersistentType target = getPersistentType(context.getTargetAnchor());
63
	    PersistentType inverse = getPersistentType(context.getTargetAnchor());
55
	    if (source != null && target != null) {
64
	    if (owner != null && inverse != null) {
56
	    	AbstractRelation rel = createRelation(getFeatureProvider(), context.getSourceAnchor().getParent(), 
65
	    	AbstractRelation rel = createRelation(getFeatureProvider(), context.getSourceAnchor().getParent(), 
57
	    													context.getTargetAnchor().getParent());
66
	    													context.getTargetAnchor().getParent());
58
	        AddConnectionContext addContext =
67
	        AddConnectionContext addContext =
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/DeleteRelationFeature.java (-15 / +4 lines)
Lines 26-32 Link Here
26
import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages;
26
import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages;
27
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
27
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
28
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.AbstractRelation;
28
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.AbstractRelation;
29
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.BidirectionalRelation;
29
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IBidirectionalRelation;
30
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation;
30
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation;
31
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.UnidirectionalRelation;
31
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.UnidirectionalRelation;
32
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.IJPAEditorUtil;
32
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.IJPAEditorUtil;
Lines 81-88 Link Here
81
    		feat.delete(delCtx, false);
81
    		feat.delete(delCtx, false);
82
    	}    	
82
    	}    	
83
83
84
        if (rel instanceof BidirectionalRelation) { 			
84
        if (rel instanceof IBidirectionalRelation) { 			
85
        	BidirectionalRelation relation = (BidirectionalRelation)(rel);
85
        	IBidirectionalRelation relation = (IBidirectionalRelation)(rel);
86
        	ClickRemoveAttributeButtonFeature feat = new ClickRemoveAttributeButtonFeature(getFeatureProvider());
86
        	ClickRemoveAttributeButtonFeature feat = new ClickRemoveAttributeButtonFeature(getFeatureProvider());
87
        	
87
        	
88
    		JavaPersistentAttribute ownerAttribute = relation.getOwnerAnnotatedAttribute();
88
    		JavaPersistentAttribute ownerAttribute = relation.getOwnerAnnotatedAttribute();
Lines 97-113 Link Here
97
    	}    	
97
    	}    	
98
98
99
        postDelete(context);
99
        postDelete(context);
100
        
101
        /*
102
        IRemoveContext rc = new RemoveContext(pe);
103
        IFeatureProvider featureProvider = getFeatureProvider();
104
        IRemoveFeature removeFeature = featureProvider.getRemoveFeature(rc);
105
        if (removeFeature != null) {
106
            removeFeature.remove(rc);
107
        }
108
        */
109
        
110
        
111
    }	
100
    }	
112
    
101
    
113
	public void postDelete(IDeleteContext context) {
102
	public void postDelete(IDeleteContext context) {
Lines 117-123 Link Here
117
		IWorkbenchSite ws = ((IEditorPart)getDiagramEditor()).getSite();
106
		IWorkbenchSite ws = ((IEditorPart)getDiagramEditor()).getSite();
118
		ICompilationUnit cu = getFeatureProvider().getCompilationUnit(rel.getOwner());		
107
		ICompilationUnit cu = getFeatureProvider().getCompilationUnit(rel.getOwner());		
119
        ut.organizeImports(cu, ws);        
108
        ut.organizeImports(cu, ws);        
120
		if (rel instanceof BidirectionalRelation) {
109
		if (rel instanceof IBidirectionalRelation) {
121
			cu = getFeatureProvider().getCompilationUnit(rel.getInverse());
110
			cu = getFeatureProvider().getCompilationUnit(rel.getInverse());
122
			ut.organizeImports(cu, ws);  
111
			ut.organizeImports(cu, ws);  
123
		}
112
		}
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/DirectEditAttributeFeature.java (-2 / +2 lines)
Lines 35-41 Link Here
35
import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin;
35
import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin;
36
import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages;
36
import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages;
37
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
37
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
38
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.BidirectionalRelation;
38
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IBidirectionalRelation;
39
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation;
39
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation;
40
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil;
40
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil;
41
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
41
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
Lines 106-112 Link Here
106
106
107
		IRelation rel = getFeatureProvider().getRelationRelatedToAttribute(oldAt);
107
		IRelation rel = getFeatureProvider().getRelationRelatedToAttribute(oldAt);
108
		String inverseJPTName = null;
108
		String inverseJPTName = null;
109
		if (BidirectionalRelation.class.isInstance(rel)) 
109
		if (IBidirectionalRelation.class.isInstance(rel)) 
110
			inverseJPTName = rel.getInverse().getName();
110
			inverseJPTName = rel.getInverse().getName();
111
		if (oldAt.getName().equals(value))
111
		if (oldAt.getName().equals(value))
112
			return;
112
			return;
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/GraphicalRemoveAttributeFeature.java (-5 / +6 lines)
Lines 92-109 Link Here
92
					.getAnchors().iterator().next());
92
					.getAnchors().iterator().next());
93
			ctx.setNewObject(rel);
93
			ctx.setNewObject(rel);
94
			relF.add(ctx);
94
			relF.add(ctx);
95
//			JpaArtifactFactory.instance().refreshEntityModel(fp, jpt);
96
		}
95
		}
96
		JpaArtifactFactory.instance().rearrangeIsARelations(getFeatureProvider());
97
97
	}
98
	}
98
99
99
	@SuppressWarnings("deprecation")
100
	@SuppressWarnings("deprecation")
100
	private void readdCompartmentsChildren(JavaPersistentType javaPersistentType, ContainerShape entityShape,
101
	private void readdCompartmentsChildren(JavaPersistentType javaPersistentType, ContainerShape entityShape,
101
			ContainerShape primaryShape, ContainerShape relationShape, ContainerShape basicShape) {
102
			ContainerShape primaryShape, ContainerShape relationShape, ContainerShape basicShape) {
102
103
		JPAEditorConstants.DIAGRAM_OBJECT_TYPE dot = JpaArtifactFactory.instance().determineDiagramObjectType(javaPersistentType);
103
		UpdateAttributeFeature updateFeature = new UpdateAttributeFeature(getFeatureProvider());
104
		UpdateAttributeFeature updateFeature = new UpdateAttributeFeature(getFeatureProvider());
104
		updateFeature.addSeparatorsToShape(primaryShape);
105
		updateFeature.addSeparatorsToShape(primaryShape, dot);
105
		updateFeature.addSeparatorsToShape(relationShape);
106
		updateFeature.addSeparatorsToShape(relationShape, dot);
106
		updateFeature.addSeparatorsToShape(basicShape);
107
		updateFeature.addSeparatorsToShape(basicShape, dot);
107
108
108
		for (JavaPersistentAttribute attribute : javaPersistentType.getAttributes()) {
109
		for (JavaPersistentAttribute attribute : javaPersistentType.getAttributes()) {
109
			updateFeature.addAttributes(entityShape, attribute);
110
			updateFeature.addAttributes(entityShape, attribute);
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/ICreateBiDirRelationFeature.java (+5 lines)
Added Link Here
1
package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature;
2
3
public interface ICreateBiDirRelationFeature {
4
5
}
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/ICreateUniDirRelationFeature.java (+5 lines)
Added Link Here
1
package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature;
2
3
public interface ICreateUniDirRelationFeature {
4
5
}
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/LayoutJPAEntityFeature.java (-1 / +1 lines)
Lines 45-51 Link Here
45
45
46
    public LayoutJPAEntityFeature(IJPAEditorFeatureProvider fp) {
46
    public LayoutJPAEntityFeature(IJPAEditorFeatureProvider fp) {
47
        super(fp);
47
        super(fp);
48
        peUtil = fp.getPeUtil();
48
        peUtil = fp.getPeServiceUtil();
49
    }
49
    }
50
50
51
    public boolean canLayout(ILayoutContext context) {
51
    public boolean canLayout(ILayoutContext context) {
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RefactorEntityFeature.java (-5 / +8 lines)
Lines 114-119 Link Here
114
		final Shape pict = (Shape)getFeatureProvider().getPictogramElementForBusinessObject(jpt);
114
		final Shape pict = (Shape)getFeatureProvider().getPictogramElementForBusinessObject(jpt);
115
		JavaPersistentType jpt = (JavaPersistentType)getFeatureProvider().
115
		JavaPersistentType jpt = (JavaPersistentType)getFeatureProvider().
116
									getBusinessObjectForPictogramElement(pict);
116
									getBusinessObjectForPictogramElement(pict);
117
		final JPAEditorConstants.DIAGRAM_OBJECT_TYPE dot = JpaArtifactFactory.instance().determineDiagramObjectType(jpt);
117
		final PersistenceUnit pu = JpaArtifactFactory.instance().getPersistenceUnit(jpt);
118
		final PersistenceUnit pu = JpaArtifactFactory.instance().getPersistenceUnit(jpt);
118
		final Semaphore s = new Semaphore(0);
119
		final Semaphore s = new Semaphore(0);
119
		final JPAProjectListener lsnr = new JPAProjectListener(s);
120
		final JPAProjectListener lsnr = new JPAProjectListener(s);
Lines 137-148 Link Here
137
		ted.getCommandStack().execute(new RecordingCommand(ted) {
138
		ted.getCommandStack().execute(new RecordingCommand(ted) {
138
			@Override
139
			@Override
139
			protected void doExecute() {
140
			protected void doExecute() {
140
				remapEntity(oldName, pict, pu, rename, lsnr, getFeatureProvider());
141
				remapEntity(oldName, pict, pu, rename, lsnr, dot, getFeatureProvider());
141
			}
142
			}
142
		});	
143
		});	
143
	}
144
	}
144
	
145
	
145
	public void execute(ICustomContext context, String newName, ICompilationUnit cu, JavaPersistentType jpt) {
146
	public void execute(ICustomContext context, String newName, ICompilationUnit cu, JavaPersistentType jpt) {
147
		final JPAEditorConstants.DIAGRAM_OBJECT_TYPE dot = JpaArtifactFactory.instance().determineDiagramObjectType(jpt);
146
		final String oldName = jpt.getName();
148
		final String oldName = jpt.getName();
147
		final Shape pict = (Shape)getFeatureProvider().getPictogramElementForBusinessObject(jpt);
149
		final Shape pict = (Shape)getFeatureProvider().getPictogramElementForBusinessObject(jpt);
148
		jpt = (JavaPersistentType)getFeatureProvider().
150
		jpt = (JavaPersistentType)getFeatureProvider().
Lines 161-167 Link Here
161
		ted.getCommandStack().execute(new RecordingCommand(ted) {
163
		ted.getCommandStack().execute(new RecordingCommand(ted) {
162
			@Override
164
			@Override
163
			protected void doExecute() {
165
			protected void doExecute() {
164
				remapEntity(oldName, pict, pu, true, lsnr, getFeatureProvider());
166
				remapEntity(oldName, pict, pu, true, lsnr, dot, getFeatureProvider());
165
			}
167
			}
166
		});
168
		});
167
	}
169
	}
Lines 171-176 Link Here
171
								   final PersistenceUnit pu,
173
								   final PersistenceUnit pu,
172
								   final boolean rename,
174
								   final boolean rename,
173
								   final JPAProjectListener lsnr,
175
								   final JPAProjectListener lsnr,
176
								   final JPAEditorConstants.DIAGRAM_OBJECT_TYPE dot,
174
								   final IJPAEditorFeatureProvider fp) {
177
								   final IJPAEditorFeatureProvider fp) {
175
		BusyIndicator.showWhile(Display.getCurrent(), new Runnable() {
178
		BusyIndicator.showWhile(Display.getCurrent(), new Runnable() {
176
			public void run() {
179
			public void run() {
Lines 189-199 Link Here
189
				cont.setY(y);
192
				cont.setY(y);
190
				cont.setWidth(width);
193
				cont.setWidth(width);
191
				cont.setHeight(height);
194
				cont.setHeight(height);
192
				RoundedRectangle rect = AddJPAEntityFeature.createEntityRectangle(cont, cs, fp.getDiagramTypeProvider().getDiagram()); 	
195
				RoundedRectangle rect = AddJPAEntityFeature.createEntityRectangle(cont, cs, dot, fp.getDiagramTypeProvider().getDiagram()); 	
193
				rect.setFilled(true);
196
				rect.setFilled(true);
194
				
197
				
195
				IRemoveContext ctx = new RemoveContext(pict); 
198
				IRemoveContext ctx = new RemoveContext(pict); 
196
				RemoveJPAEntityFeature ft = new RemoveJPAEntityFeature(fp);
199
				RemoveJPAEntityFeature ft = new RemoveJPAEntityFeature(fp, true);
197
				
200
				
198
				boolean primaryCollapsed = JPAEditorConstants.TRUE_STRING.equals(Graphiti.getPeService().getPropertyValue(pict, JPAEditorConstants.PRIMARY_COLLAPSED));
201
				boolean primaryCollapsed = JPAEditorConstants.TRUE_STRING.equals(Graphiti.getPeService().getPropertyValue(pict, JPAEditorConstants.PRIMARY_COLLAPSED));
199
				boolean relationCollapsed = JPAEditorConstants.TRUE_STRING.equals(Graphiti.getPeService().getPropertyValue(pict, JPAEditorConstants.RELATION_COLLAPSED));
202
				boolean relationCollapsed = JPAEditorConstants.TRUE_STRING.equals(Graphiti.getPeService().getPropertyValue(pict, JPAEditorConstants.RELATION_COLLAPSED));
Lines 216-222 Link Here
216
				addCtx.setY(y);
219
				addCtx.setY(y);
217
				addCtx.setWidth(width);
220
				addCtx.setWidth(width);
218
				addCtx.setHeight(height);
221
				addCtx.setHeight(height);
219
				AddJPAEntityFeature ft1 = new AddJPAEntityFeature(fp);
222
				AddJPAEntityFeature ft1 = new AddJPAEntityFeature(fp, true);
220
				ft.remove(ctx);
223
				ft.remove(ctx);
221
				ft1.add(addCtx);
224
				ft1.add(addCtx);
222
				PictogramElement pe = fp.getPictogramElementForBusinessObject(newJPT);
225
				PictogramElement pe = fp.getPictogramElementForBusinessObject(newJPT);
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RemoveAllEntitiesFeature.java (-5 / +7 lines)
Lines 27-34 Link Here
27
import org.eclipse.graphiti.features.context.IRemoveContext;
27
import org.eclipse.graphiti.features.context.IRemoveContext;
28
import org.eclipse.graphiti.features.context.impl.RemoveContext;
28
import org.eclipse.graphiti.features.context.impl.RemoveContext;
29
import org.eclipse.graphiti.features.custom.AbstractCustomFeature;
29
import org.eclipse.graphiti.features.custom.AbstractCustomFeature;
30
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
31
import org.eclipse.graphiti.mm.pictograms.Shape;
30
import org.eclipse.graphiti.mm.pictograms.Shape;
31
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
32
32
33
public abstract class RemoveAllEntitiesFeature extends AbstractCustomFeature {
33
public abstract class RemoveAllEntitiesFeature extends AbstractCustomFeature {
34
34
Lines 45-58 Link Here
45
	}
45
	}
46
	
46
	
47
	public void execute(ICustomContext context) {
47
	public void execute(ICustomContext context) {
48
		TransactionalEditingDomain ted = TransactionUtil.getEditingDomain(getFeatureProvider().getDiagram());
48
		Iterator<Shape> it = allShapes.iterator();
49
		Iterator<Shape> it = allShapes.iterator();
49
		while (it.hasNext()) {
50
		while (it.hasNext()) {
50
			Shape sh = it.next();
51
			Shape sh = it.next();
51
			final RemoveJPAEntityFeature ft = new RemoveJPAEntityFeature(this.getFeatureProvider());
52
			final RemoveJPAEntityFeature ft = new RemoveJPAEntityFeature(this.getFeatureProvider(), false);
52
			final IRemoveContext ctx = new RemoveContext(sh);
53
			final IRemoveContext ctx = new RemoveContext(sh);
53
			PictogramElement pe = ctx.getPictogramElement();
54
			
55
			TransactionalEditingDomain ted = TransactionUtil.getEditingDomain(pe);
56
			ted.getCommandStack().execute(new RecordingCommand(ted) {
54
			ted.getCommandStack().execute(new RecordingCommand(ted) {
57
				@Override
55
				@Override
58
				protected void doExecute() {
56
				protected void doExecute() {
Lines 62-65 Link Here
62
		}
60
		}
63
	}
61
	}
64
62
63
	public IJPAEditorFeatureProvider getFeatureProvider() {
64
		return (IJPAEditorFeatureProvider) super.getFeatureProvider();
65
	}
66
65
}
67
}
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RemoveAndSaveEntityFeature.java (+6 lines)
Lines 30-35 Link Here
30
import org.eclipse.jpt.jpa.core.context.PersistentType;
30
import org.eclipse.jpt.jpa.core.context.PersistentType;
31
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
31
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
32
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
32
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
33
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
33
34
34
35
35
36
Lines 67-70 Link Here
67
		return  (IJPAEditorFeatureProvider)super.getFeatureProvider();
68
		return  (IJPAEditorFeatureProvider)super.getFeatureProvider();
68
	}
69
	}
69
70
71
    public void postRemove(IRemoveContext context) {
72
    	JpaArtifactFactory.instance().rearrangeIsARelations(getFeatureProvider());    	
73
    }
74
	
75
70
}
76
}
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RemoveAttributeFeature.java (-1 / +1 lines)
Lines 154-161 Link Here
154
			cntx.setNewObject(rel);
154
			cntx.setNewObject(rel);
155
			AddRelationFeature ft = new AddRelationFeature(getFeatureProvider());
155
			AddRelationFeature ft = new AddRelationFeature(getFeatureProvider());
156
			ft.add(cntx);
156
			ft.add(cntx);
157
//			JpaArtifactFactory.instance().refreshEntityModel(getFeatureProvider(), jpt);
158
		}
157
		}
158
		JpaArtifactFactory.instance().rearrangeIsARelations(getFeatureProvider());
159
	}
159
	}
160
160
161
}
161
}
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RemoveJPAEntityFeature.java (-24 / +9 lines)
Lines 43-60 Link Here
43
43
44
public class RemoveJPAEntityFeature extends DefaultRemoveFeature {
44
public class RemoveJPAEntityFeature extends DefaultRemoveFeature {
45
	
45
	
46
	private boolean shouldRearrangeIsARelations = true;
46
	
47
	
47
    public RemoveJPAEntityFeature(IFeatureProvider fp) {
48
    public RemoveJPAEntityFeature(IFeatureProvider fp, boolean shouldRearrangeIsARelations) {
48
    	super(fp);
49
    	super(fp);
50
    	this.shouldRearrangeIsARelations = shouldRearrangeIsARelations;
49
    }
51
    }
50
    
52
    
51
    public void preRemove(IRemoveContext context) {
53
    public void preRemove(IRemoveContext context) {
52
    	PictogramElement pe = context.getPictogramElement();
54
    	PictogramElement pe = context.getPictogramElement();
53
    			
54
//		RestoreEntityFeature ft = new RestoreEntityFeature(getFeatureProvider());
55
//		ICustomContext customContext = new CustomContext(new PictogramElement[] { pe });
56
//		ft.execute(customContext);
57
    	
58
    	final Object bo = getFeatureProvider().getBusinessObjectForPictogramElement(pe);
55
    	final Object bo = getFeatureProvider().getBusinessObjectForPictogramElement(pe);
59
    	Set<Shape> shapesForDeletion = new HashSet<Shape>();
56
    	Set<Shape> shapesForDeletion = new HashSet<Shape>();
60
    	if (bo instanceof JavaPersistentType) {
57
    	if (bo instanceof JavaPersistentType) {
Lines 75-94 Link Here
75
				IRemoveContext ctx = new RemoveContext(it.next());
72
				IRemoveContext ctx = new RemoveContext(it.next());
76
				f.remove(ctx);    			
73
				f.remove(ctx);    			
77
    		}
74
    		}
78
    		//---------------------------------------------------------------------
75
    		String name = ((PersistentType)bo).getName();
79
    		//--Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=281345
76
			getFeatureProvider().remove(name, true);
80
    		//Job job = new Job("Remove JPA entity") {				//$NON-NLS-1$
81
			//	protected IStatus run(IProgressMonitor monitor) {
82
		    		String name = ((PersistentType)bo).getName();
83
					getFeatureProvider().remove(name, true);
84
					//return new Status(IStatus.OK, 
85
					//	  JPADiagramEditorPlugin.PLUGIN_ID, 
86
					//	  name + " is removed"); 	//$NON-NLS-1$
87
									  
88
			//	}
89
    		//};
90
    		//job.schedule();
91
    		//---------------------------------------------------------------------
92
    	} 			
77
    	} 			
93
    }
78
    }
94
    
79
    
Lines 123-131 Link Here
123
		super.execute(context);
108
		super.execute(context);
124
	}
109
	}
125
	
110
	
126
	
111
    public void postRemove(IRemoveContext context) {
127
	
112
    	if (shouldRearrangeIsARelations)
128
113
    		JpaArtifactFactory.instance().rearrangeIsARelations(getFeatureProvider());
129
	
114
    }
130
	
115
	
131
}
116
}
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/UpdateAttributeFeature.java (-6 / +11 lines)
Lines 31-36 Link Here
31
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
31
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
32
import org.eclipse.graphiti.mm.pictograms.Shape;
32
import org.eclipse.graphiti.mm.pictograms.Shape;
33
import org.eclipse.graphiti.services.Graphiti;
33
import org.eclipse.graphiti.services.Graphiti;
34
import org.eclipse.graphiti.util.IColorConstant;
34
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
35
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
35
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
36
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
36
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
37
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
Lines 128-144 Link Here
128
		return rect;
129
		return rect;
129
	}
130
	}
130
131
131
	public void addSeparatorsToShape(ContainerShape compartmentShape) {
132
	public void addSeparatorsToShape(ContainerShape compartmentShape,
132
		addSeparatorToCollection(compartmentShape, 0);
133
			JPAEditorConstants.DIAGRAM_OBJECT_TYPE dot) {
133
		addSeparatorToCollection(compartmentShape, JPAEditorConstants.COMPARTMENT_MIN_HEIGHT);
134
		addSeparatorToCollection(compartmentShape, 0, dot);
135
		addSeparatorToCollection(compartmentShape, JPAEditorConstants.COMPARTMENT_MIN_HEIGHT, dot);
134
	}
136
	}
135
137
136
	private Shape addSeparatorToCollection(ContainerShape containerShape, int y) {
138
	private Shape addSeparatorToCollection(ContainerShape containerShape, int y, 
139
										   JPAEditorConstants.DIAGRAM_OBJECT_TYPE dot) {
137
		final int width = containerShape.getGraphicsAlgorithm().getWidth();
140
		final int width = containerShape.getGraphicsAlgorithm().getWidth();
138
		Shape shape = Graphiti.getPeService().createShape(containerShape, false);
141
		Shape shape = Graphiti.getPeService().createShape(containerShape, false);
139
		Rectangle rectangle = Graphiti.getGaService().createRectangle(shape);
142
		Rectangle rectangle = Graphiti.getGaService().createRectangle(shape);
140
		rectangle.setForeground(manageColor(JPAEditorConstants.ENTITY_BACKGROUND));
143
		IColorConstant foreground = JpaArtifactFactory.instance().getForeground(dot);
141
		rectangle.setBackground(manageColor(JPAEditorConstants.ENTITY_BORDER_COLOR));
144
		IColorConstant background = JpaArtifactFactory.instance().getBackground(dot);
145
		rectangle.setForeground(manageColor(background));
146
		rectangle.setBackground(manageColor(foreground));
142
		rectangle.setLineVisible(false);
147
		rectangle.setLineVisible(false);
143
		Graphiti.getGaService().setSize(rectangle, width, JPAEditorConstants.SEPARATOR_HEIGHT);
148
		Graphiti.getGaService().setSize(rectangle, width, JPAEditorConstants.SEPARATOR_HEIGHT);
144
		Graphiti.getGaService().setLocationAndSize(rectangle, 0, y, width, JPAEditorConstants.SEPARATOR_HEIGHT);
149
		Graphiti.getGaService().setLocationAndSize(rectangle, 0, y, width, JPAEditorConstants.SEPARATOR_HEIGHT);
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/i18n/JPAEditorMessages.java (-4 / +8 lines)
Lines 36-53 Link Here
36
	public static String CreateDiagramJob_createDiagramJobName;
36
	public static String CreateDiagramJob_createDiagramJobName;
37
	public static String CreateDiagramJob_getJPADiagramMonitorTaskName;
37
	public static String CreateDiagramJob_getJPADiagramMonitorTaskName;
38
	
38
	
39
	public static String CreateIsARelationFeature_description;
40
	public static String CreateIsARelationFeature_name;
41
	
39
	public static String CreateJPAEntityFeature_createEntityErrorMsg;
42
	public static String CreateJPAEntityFeature_createEntityErrorMsg;
40
41
	public static String CreateJPAEntityFeature_createEntityErrorMsgTitle;
43
	public static String CreateJPAEntityFeature_createEntityErrorMsgTitle;
42
43
	public static String CreateJPAEntityFeature_createEntityErrorStatusMsg;
44
	public static String CreateJPAEntityFeature_createEntityErrorStatusMsg;
44
45
	public static String CreateJPAEntityFeature_jpaEntityFeatureDescription;
45
	public static String CreateJPAEntityFeature_jpaEntityFeatureDescription;
46
	public static String CreateJPAEntityFeature_jpaEntityFeatureName;
46
	public static String CreateJPAEntityFeature_jpaEntityFeatureName;
47
	public static String CreateJPAEntityFeature_jpaProjectSelectionDialogDescription;
47
	public static String CreateJPAEntityFeature_jpaProjectSelectionDialogDescription;
48
	public static String CreateJPAEntityFeature_jpaProjectSelectionDialogTitle;
48
	public static String CreateJPAEntityFeature_jpaProjectSelectionDialogTitle;
49
	public static String CreateJPAEntityFromMappedSuperclassFeature_createInheritedEntityFeatureDescription;
49
	public static String CreateJPAEntityFromMappedSuperclassFeature_createInheritedEntityFeatureDescription;
50
	public static String CreateJPAEntityFromMappedSuperclassFeature_createInheritedEntityFeatureName;
50
	public static String CreateJPAEntityFromMappedSuperclassFeature_createInheritedEntityFeatureName;
51
	public static String CreateMappedSuperclassFeature_createMappedSuperclassFeatureDescription;
52
	public static String CreateMappedSuperclassFeature_createMappedSuperclassFeatureName;
51
	
53
	
52
	public static String CreateManyToManyBiDirRelationFeature_manyToManyBiDirFeatureName;
54
	public static String CreateManyToManyBiDirRelationFeature_manyToManyBiDirFeatureName;
53
	public static String CreateManyToManyBiDirRelationFeature_manyToManyUniDirFeatureDescription;
55
	public static String CreateManyToManyBiDirRelationFeature_manyToManyUniDirFeatureDescription;
Lines 181-187 Link Here
181
	public static String JPAEditorToolBehaviorProvider_expandEntitymenuItemDescr;
183
	public static String JPAEditorToolBehaviorProvider_expandEntitymenuItemDescr;
182
	
184
	
183
	public static String JPAEditorToolBehaviorProvider_expandAllEntitiesMenuItem;
185
	public static String JPAEditorToolBehaviorProvider_expandAllEntitiesMenuItem;
184
	public static String JPAEditorToolBehaviorProvider_expandAllEntitiesMenuItemDescr;	
186
	public static String JPAEditorToolBehaviorProvider_expandAllEntitiesMenuItemDescr;
187
188
	public static String JPAEditorToolBehaviorProvider_InheritanceCompartmentTitle;	
185
189
186
	public static String JPAEditorToolBehaviorProvider_refactorAttributeType; 
190
	public static String JPAEditorToolBehaviorProvider_refactorAttributeType; 
187
	public static String JPAEditorToolBehaviorProvider_refactorAttributeTypeDesc;
191
	public static String JPAEditorToolBehaviorProvider_refactorAttributeTypeDesc;
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/i18n/messages.properties (+7 lines)
Lines 25-30 Link Here
25
25
26
CreateDiagramJob_createDiagramJobName=Creating diagram for: {0}...
26
CreateDiagramJob_createDiagramJobName=Creating diagram for: {0}...
27
CreateDiagramJob_getJPADiagramMonitorTaskName=Get JPA Diagram
27
CreateDiagramJob_getJPADiagramMonitorTaskName=Get JPA Diagram
28
29
CreateIsARelationFeature_description=Click on an entity or mapped superclass and then click somewhere in the diagram to create new inherited entity
30
CreateIsARelationFeature_name=Inherited Entity
31
28
CreateJPAEntityFeature_createEntityErrorMsg=Entity could not be created.
32
CreateJPAEntityFeature_createEntityErrorMsg=Entity could not be created.
29
CreateJPAEntityFeature_createEntityErrorMsgTitle=Cannot Create Entity
33
CreateJPAEntityFeature_createEntityErrorMsgTitle=Cannot Create Entity
30
CreateJPAEntityFeature_createEntityErrorStatusMsg=Persistence API library is not into the project's classpath.
34
CreateJPAEntityFeature_createEntityErrorStatusMsg=Persistence API library is not into the project's classpath.
Lines 34-39 Link Here
34
CreateJPAEntityFeature_jpaProjectSelectionDialogTitle=Select JPA Project
38
CreateJPAEntityFeature_jpaProjectSelectionDialogTitle=Select JPA Project
35
CreateJPAEntityFromMappedSuperclassFeature_createInheritedEntityFeatureDescription=Create a new JPA entity that will inherit a new Mapped Superclass.
39
CreateJPAEntityFromMappedSuperclassFeature_createInheritedEntityFeatureDescription=Create a new JPA entity that will inherit a new Mapped Superclass.
36
CreateJPAEntityFromMappedSuperclassFeature_createInheritedEntityFeatureName=Inherited Entity
40
CreateJPAEntityFromMappedSuperclassFeature_createInheritedEntityFeatureName=Inherited Entity
41
CreateMappedSuperclassFeature_createMappedSuperclassFeatureDescription=Create a new Mapped Superclass.
42
CreateMappedSuperclassFeature_createMappedSuperclassFeatureName=Mapped Superclass
37
43
38
CreateManyToManyBiDirRelationFeature_manyToManyBiDirFeatureName=Many-to-Many
44
CreateManyToManyBiDirRelationFeature_manyToManyBiDirFeatureName=Many-to-Many
39
CreateManyToManyBiDirRelationFeature_manyToManyUniDirFeatureDescription=Create new bidirectional many-to-many relation.
45
CreateManyToManyBiDirRelationFeature_manyToManyUniDirFeatureDescription=Create new bidirectional many-to-many relation.
Lines 152-157 Link Here
152
JPAEditorToolBehaviorProvider_expandEntitymenuItemDescr=Expand entity.
158
JPAEditorToolBehaviorProvider_expandEntitymenuItemDescr=Expand entity.
153
JPAEditorToolBehaviorProvider_expandAllEntitiesMenuItem=Expand All
159
JPAEditorToolBehaviorProvider_expandAllEntitiesMenuItem=Expand All
154
JPAEditorToolBehaviorProvider_expandAllEntitiesMenuItemDescr=Expand all entities.
160
JPAEditorToolBehaviorProvider_expandAllEntitiesMenuItemDescr=Expand all entities.
161
JPAEditorToolBehaviorProvider_InheritanceCompartmentTitle=Inheritance
155
JPAEditorToolBehaviorProvider_refactorAttributeType=Refactor Attribute Type...
162
JPAEditorToolBehaviorProvider_refactorAttributeType=Refactor Attribute Type...
156
JPAEditorToolBehaviorProvider_refactorAttributeTypeDesc=Change the type of the selected attribute.
163
JPAEditorToolBehaviorProvider_refactorAttributeTypeDesc=Change the type of the selected attribute.
157
JPAEditorToolBehaviorProvider_removeAllEntitiesMenu=Remove All Entities From Diagram
164
JPAEditorToolBehaviorProvider_removeAllEntitiesMenu=Remove All Entities From Diagram
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/modelintegration/util/ModelIntegrationUtil.java (+2 lines)
Lines 298-303 Link Here
298
		
298
		
299
	public static JPAEditorDiagramTypeProvider getProviderByDiagram(String diagramName) {
299
	public static JPAEditorDiagramTypeProvider getProviderByDiagram(String diagramName) {
300
		IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
300
		IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
301
		if (workbenchWindow == null)
302
			return null;
301
		IWorkbenchPage workbenchPage = workbenchWindow.getActivePage();
303
		IWorkbenchPage workbenchPage = workbenchWindow.getActivePage();
302
		IEditorReference[] editorRefs = workbenchPage.getEditorReferences();
304
		IEditorReference[] editorRefs = workbenchPage.getEditorReferences();
303
		for (IEditorReference editorRef : editorRefs) {
305
		for (IEditorReference editorRef : editorRefs) {
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/IJPAEditorFeatureProvider.java (-1 / +22 lines)
Lines 15-20 Link Here
15
 *******************************************************************************/
15
 *******************************************************************************/
16
package org.eclipse.jpt.jpadiagrameditor.ui.internal.provider;
16
package org.eclipse.jpt.jpadiagrameditor.ui.internal.provider;
17
17
18
import java.util.Collection;
19
import java.util.HashSet;
18
import java.util.Properties;
20
import java.util.Properties;
19
21
20
import org.eclipse.core.resources.IProject;
22
import org.eclipse.core.resources.IProject;
Lines 23-29 Link Here
23
import org.eclipse.graphiti.features.IFeatureProvider;
25
import org.eclipse.graphiti.features.IFeatureProvider;
24
import org.eclipse.graphiti.features.context.IDeleteContext;
26
import org.eclipse.graphiti.features.context.IDeleteContext;
25
import org.eclipse.graphiti.features.custom.ICustomFeature;
27
import org.eclipse.graphiti.features.custom.ICustomFeature;
28
import org.eclipse.graphiti.mm.pictograms.Diagram;
26
import org.eclipse.graphiti.mm.pictograms.Shape;
29
import org.eclipse.graphiti.mm.pictograms.Shape;
30
import org.eclipse.graphiti.services.IPeService;
27
import org.eclipse.jdt.core.ICompilationUnit;
31
import org.eclipse.jdt.core.ICompilationUnit;
28
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
32
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
29
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
33
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
Lines 32-37 Link Here
32
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation;
36
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation;
33
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation.RelDir;
37
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation.RelDir;
34
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation.RelType;
38
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation.RelType;
39
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IsARelation;
35
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.IGraphicsUpdater;
40
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.IGraphicsUpdater;
36
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.IJPAEditorUtil;
41
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.IJPAEditorUtil;
37
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.IPeServiceUtil;
42
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.IPeServiceUtil;
Lines 39-44 Link Here
39
44
40
public interface IJPAEditorFeatureProvider extends IFeatureProvider{
45
public interface IJPAEditorFeatureProvider extends IFeatureProvider{
41
46
47
	public Diagram getDiagram();
48
	
49
	public HashSet<IsARelation> getAllRedundantIsARelations(); 
50
	
51
	public HashSet<IsARelation> getAllExistingIsARelations();
52
	
42
	public ICompilationUnit getCompilationUnit(JavaPersistentType jpt);
53
	public ICompilationUnit getCompilationUnit(JavaPersistentType jpt);
43
	
54
	
44
	public boolean hasObjectWithName(String name);
55
	public boolean hasObjectWithName(String name);
Lines 80-87 Link Here
80
    public void replaceAttribute(JavaPersistentAttribute oldAt, JavaPersistentAttribute newAt);
91
    public void replaceAttribute(JavaPersistentAttribute oldAt, JavaPersistentAttribute newAt);
81
    	
92
    	
82
	public void renewAttributeJoiningStrategyPropertyListener(JavaPersistentAttribute jpa);
93
	public void renewAttributeJoiningStrategyPropertyListener(JavaPersistentAttribute jpa);
94
	
95
	public IPeService getPeService();
83
96
84
	public IPeServiceUtil getPeUtil();
97
	public IPeServiceUtil getPeServiceUtil();
85
	
98
	
86
	public IJPAEditorUtil getJPAEditorUtil();
99
	public IJPAEditorUtil getJPAEditorUtil();
87
100
Lines 99-102 Link Here
99
	
112
	
100
	public Properties loadProperties(IProject project);
113
	public Properties loadProperties(IProject project);
101
114
115
	public Collection<JavaPersistentType> getPersistentTypes();
116
	
117
	public JavaPersistentType getFirstSuperclassBelongingToTheDiagram(JavaPersistentType subclass);
118
	
119
	public void removeAllRedundantIsARelations();
120
	
121
	public boolean existRedundantIsARelations();
122
102
}
123
}
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/IJPAEditorImageCreator.java (-1 / +5 lines)
Lines 31-39 Link Here
31
31
32
	public Polyline createConnectionLine(Diagram d, Connection connection);
32
	public Polyline createConnectionLine(Diagram d, Connection connection);
33
33
34
	public Polyline createIsAConnectionLine(Diagram d, Connection connection);
35
34
	//public ConnectionDecorator createTextConnectionDecorator(Connection connection, String text, double location);
36
	//public ConnectionDecorator createTextConnectionDecorator(Connection connection, String text, double location);
35
37
36
	public ConnectionDecorator createArrowConnectionDecorator(Connection connection, double location);
38
	public ConnectionDecorator createArrowConnectionDecorator(Connection connection, double location, boolean isA);
37
39
38
	public ConnectionDecorator createManyEndWithArrowDecorator(Connection connection, double location);
40
	public ConnectionDecorator createManyEndWithArrowDecorator(Connection connection, double location);
39
41
Lines 45-49 Link Here
45
	
47
	
46
	public ConnectionDecorator createCardinalityConnectionDecorator(Diagram d, Connection c, String text, double location);
48
	public ConnectionDecorator createCardinalityConnectionDecorator(Diagram d, Connection c, String text, double location);
47
	
49
	
50
	public ConnectionDecorator createIsATextConnectionDecorator(Diagram d, Connection c);
51
	
48
52
49
}
53
}
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorDiagramTypeProvider.java (-1 / +2 lines)
Lines 266-275 Link Here
266
						ctx.setHeight(sp.getHeight());
266
						ctx.setHeight(sp.getHeight());
267
						ctx.setX(sp.getX());
267
						ctx.setX(sp.getX());
268
						ctx.setY(sp.getY());
268
						ctx.setY(sp.getY());
269
						AddJPAEntityFeature ft = new AddJPAEntityFeature(getFeatureProvider());
269
						AddJPAEntityFeature ft = new AddJPAEntityFeature(getFeatureProvider(), false);
270
						ft.add(ctx);
270
						ft.add(ctx);
271
					}
271
					}
272
				}
272
				}
273
				JpaArtifactFactory.instance().rearrangeIsARelations(getFeatureProvider());
273
			}			
274
			}			
274
		});
275
		});
275
		getDiagramEditor().saveWithoutEntities(new NullProgressMonitor());
276
		getDiagramEditor().saveWithoutEntities(new NullProgressMonitor());
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorFeatureProvider.java (-10 / +117 lines)
Lines 19-28 Link Here
19
import java.util.Collection;
19
import java.util.Collection;
20
import java.util.HashSet;
20
import java.util.HashSet;
21
import java.util.Iterator;
21
import java.util.Iterator;
22
import java.util.LinkedList;
22
import java.util.List;
23
import java.util.List;
23
import java.util.Properties;
24
import java.util.Properties;
24
25
25
import org.eclipse.core.resources.IProject;
26
import org.eclipse.core.resources.IProject;
27
import org.eclipse.emf.common.util.EList;
26
import org.eclipse.emf.transaction.RecordingCommand;
28
import org.eclipse.emf.transaction.RecordingCommand;
27
import org.eclipse.emf.transaction.TransactionalEditingDomain;
29
import org.eclipse.emf.transaction.TransactionalEditingDomain;
28
import org.eclipse.emf.transaction.util.TransactionUtil;
30
import org.eclipse.emf.transaction.util.TransactionUtil;
Lines 61-72 Link Here
61
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
63
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
62
import org.eclipse.graphiti.mm.pictograms.Shape;
64
import org.eclipse.graphiti.mm.pictograms.Shape;
63
import org.eclipse.graphiti.services.Graphiti;
65
import org.eclipse.graphiti.services.Graphiti;
66
import org.eclipse.graphiti.services.IPeService;
64
import org.eclipse.graphiti.ui.features.DefaultFeatureProvider;
67
import org.eclipse.graphiti.ui.features.DefaultFeatureProvider;
65
import org.eclipse.jdt.core.ICompilationUnit;
68
import org.eclipse.jdt.core.ICompilationUnit;
66
import org.eclipse.jdt.internal.core.CompilationUnit;
69
import org.eclipse.jdt.internal.core.CompilationUnit;
67
import org.eclipse.jdt.internal.core.SourceType;
70
import org.eclipse.jdt.internal.core.SourceType;
68
import org.eclipse.jpt.jpa.core.JpaNode;
71
import org.eclipse.jpt.jpa.core.JpaNode;
69
import org.eclipse.jpt.jpa.core.context.PersistentAttribute;
72
import org.eclipse.jpt.jpa.core.context.PersistentAttribute;
73
import org.eclipse.jpt.jpa.core.context.PersistentType;
70
import org.eclipse.jpt.jpa.core.context.java.JavaEntity;
74
import org.eclipse.jpt.jpa.core.context.java.JavaEntity;
71
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
75
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
72
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
76
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
Lines 82-92 Link Here
82
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CollapseCompartmentShapeFeature;
86
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CollapseCompartmentShapeFeature;
83
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CollapseEntityFeature;
87
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CollapseEntityFeature;
84
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CreateJPAEntityFeature;
88
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CreateJPAEntityFeature;
85
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CreateJPAEntityFromMappedSuperclassFeature;
86
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CreateManyToManyBiDirRelationFeature;
89
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CreateManyToManyBiDirRelationFeature;
87
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CreateManyToManyUniDirRelationFeature;
90
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CreateManyToManyUniDirRelationFeature;
88
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CreateManyToOneBiDirRelationFeature;
91
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CreateManyToOneBiDirRelationFeature;
89
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CreateManyToOneUniDirRelationFeature;
92
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CreateManyToOneUniDirRelationFeature;
93
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CreateMappedSuperclassFeature;
90
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CreateOneToManyUniDirRelationFeature;
94
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CreateOneToManyUniDirRelationFeature;
91
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CreateOneToOneBiDirRelationFeature;
95
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CreateOneToOneBiDirRelationFeature;
92
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CreateOneToOneUniDirRelationFeature;
96
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CreateOneToOneUniDirRelationFeature;
Lines 113-118 Link Here
113
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation;
117
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation;
114
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation.RelDir;
118
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation.RelDir;
115
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation.RelType;
119
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation.RelType;
120
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IsARelation;
116
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.GraphicsUpdaterImpl;
121
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.GraphicsUpdaterImpl;
117
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.IGraphicsUpdater;
122
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.IGraphicsUpdater;
118
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.IJPAEditorUtil;
123
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.IJPAEditorUtil;
Lines 132-138 Link Here
132
	
137
	
133
	private ClickAddAttributeButtonFeature clickAddAttBtnFeat = null;
138
	private ClickAddAttributeButtonFeature clickAddAttBtnFeat = null;
134
	private ClickRemoveAttributeButtonFeature clickRemoveAttBtnFeat = null;
139
	private ClickRemoveAttributeButtonFeature clickRemoveAttBtnFeat = null;
135
	private IPeServiceUtil peUtil = new PeServiceUtilImpl();
140
	private IPeServiceUtil peServiceUtil = new PeServiceUtilImpl();
141
	private IPeService peService = Graphiti.getPeService();
136
	private IJPAEditorUtil jpaEditorUtil = new JPAEditorUtilImpl();
142
	private IJPAEditorUtil jpaEditorUtil = new JPAEditorUtilImpl();
137
	private IModelIntegrationUtil moinIntegrationUtil = new ModelIntegrationUtilImpl(); 
143
	private IModelIntegrationUtil moinIntegrationUtil = new ModelIntegrationUtilImpl(); 
138
	private IGraphicsUpdater graphicsUpdater = new GraphicsUpdaterImpl(); 
144
	private IGraphicsUpdater graphicsUpdater = new GraphicsUpdaterImpl(); 
Lines 148-153 Link Here
148
    		((JPASolver)getIndependenceSolver()).stopThread();
154
    		((JPASolver)getIndependenceSolver()).stopThread();
149
    }
155
    }
150
    
156
    
157
	public Diagram getDiagram() {
158
		return getDiagramTypeProvider().getDiagram();
159
	}
160
161
	public HashSet<IsARelation> getAllExistingIsARelations() {
162
		EList<Connection> allCons = getDiagram().getConnections();
163
		HashSet<IsARelation> res = new HashSet<IsARelation>();
164
		HashSet<Connection> tbd = new HashSet<Connection>();
165
		for (Connection conn : allCons) {
166
			if (IsARelation.isIsAConnection(conn)) 
167
				try { 
168
					res.add(new IsARelation(this, conn));
169
				} catch (NullPointerException e) {
170
					tbd.add(conn);
171
				}
172
		}
173
		Iterator<Connection> it = tbd.iterator();
174
		while (it.hasNext()) {
175
			Graphiti.getPeService().deletePictogramElement(it.next());
176
		}
177
		return res;
178
	}
179
	
180
	public HashSet<IsARelation> getAllRedundantIsARelations() {
181
		EList<Connection> allCons = getDiagram().getConnections();
182
		HashSet<IsARelation> res = new HashSet<IsARelation>();
183
		for (Connection conn : allCons) {
184
			if (IsARelation.isIsAConnection(conn)) 
185
				res.add(new IsARelation(this, conn));
186
		}
187
		return res;
188
	}
189
	
190
	public void removeAllRedundantIsARelations() {
191
		EList<Connection> allCons = getDiagram().getConnections();
192
		Collection<Connection> redundantConnections = new LinkedList<Connection>();
193
		for (Connection conn : allCons) {
194
			if (IsARelation.isIsAConnection(conn)) {
195
				IsARelation rel = null;
196
				try {
197
					rel = new IsARelation(this, conn);	
198
				} catch (NullPointerException e) {
199
					redundantConnections.add(conn);
200
					continue;
201
				}
202
				if (!rel.getSuperclass().equals(getFirstSuperclassBelongingToTheDiagram(rel.getSubclass()))) {
203
					redundantConnections.add(conn);
204
				}
205
			}
206
		}
207
		Iterator<Connection> it = redundantConnections.iterator();
208
		while (it.hasNext()) {
209
			Connection conn = it.next();
210
			peService.deletePictogramElement(conn);
211
		}	
212
	}
213
	
214
	public boolean existRedundantIsARelations() {
215
		EList<Connection> allCons = getDiagram().getConnections();
216
		for (Connection conn : allCons) {
217
			if (IsARelation.isIsAConnection(conn)) {
218
				IsARelation rel = null;
219
				try {
220
					rel = new IsARelation(this, conn);	
221
				} catch (NullPointerException e) {
222
					return true;
223
				}
224
				if (!rel.getSuperclass().equals(getFirstSuperclassBelongingToTheDiagram(rel.getSubclass()))) {
225
					return true;
226
				}
227
			}
228
		}
229
		return false;
230
	}
231
		
232
	public JavaPersistentType getFirstSuperclassBelongingToTheDiagram(JavaPersistentType subclass) {
233
		Iterable<PersistentType> h = subclass.getInheritanceHierarchy();
234
		Iterator<PersistentType> iter = h.iterator();
235
		if (!iter.hasNext())
236
			return null;
237
		HashSet<PersistentType> cycleChecker = new HashSet<PersistentType>();
238
		cycleChecker.add(iter.next());
239
		while (iter.hasNext()) {
240
			PersistentType superclass = iter.next();
241
			if (hasObjectWithName(getKeyForBusinessObject(superclass))) {
242
				return (JavaPersistentType) superclass;
243
			}
244
			if (!cycleChecker.add(superclass))
245
				return null;
246
		}
247
		return null;
248
	}
249
	
250
    
151
	public void addJPTForUpdate(String jptName) {
251
	public void addJPTForUpdate(String jptName) {
152
		((JPASolver)getIndependenceSolver()).addJPTForUpdate(jptName);
252
		((JPASolver)getIndependenceSolver()).addJPTForUpdate(jptName);
153
	}
253
	}
Lines 178-184 Link Here
178
    public IAddFeature getAddFeature(IAddContext context) {
278
    public IAddFeature getAddFeature(IAddContext context) {
179
    	Object newObj = context.getNewObject(); 
279
    	Object newObj = context.getNewObject(); 
180
        if (newObj instanceof JavaPersistentType) {
280
        if (newObj instanceof JavaPersistentType) {
181
            return new AddJPAEntityFeature(this);
281
            return new AddJPAEntityFeature(this, true);
182
        } else if (newObj instanceof AbstractRelation) {
282
        } else if (newObj instanceof AbstractRelation) {
183
        	 return new AddRelationFeature(this);
283
        	 return new AddRelationFeature(this);
184
        } else if (newObj instanceof PersistentAttribute) { 
284
        } else if (newObj instanceof PersistentAttribute) { 
Lines 190-200 Link Here
190
        } else if (newObj instanceof CompilationUnit) {
290
        } else if (newObj instanceof CompilationUnit) {
191
        	CompilationUnit cu = (CompilationUnit)newObj;
291
        	CompilationUnit cu = (CompilationUnit)newObj;
192
        	JavaPersistentType jpt = JPAEditorUtil.getJPType(cu);
292
        	JavaPersistentType jpt = JPAEditorUtil.getJPType(cu);
193
        	if (jpt != null) return new AddJPAEntityFeature(this);
293
        	if (jpt != null) return new AddJPAEntityFeature(this, true);
194
        } else if ((newObj instanceof JpaNode)) {
294
        } else if ((newObj instanceof JpaNode)) {
195
        	return new AddAllEntitiesFeature(this);
295
        	return new AddAllEntitiesFeature(this);
196
        } else if (newObj instanceof SourceType) {
296
        } else if (newObj instanceof SourceType) {
197
        	return new AddJPAEntityFeature(this);
297
        	return new AddJPAEntityFeature(this, true);
198
        }
298
        }
199
        return super.getAddFeature(context);
299
        return super.getAddFeature(context);
200
    }
300
    }
Lines 202-208 Link Here
202
    
302
    
203
    @Override
303
    @Override
204
    public ICreateFeature[] getCreateFeatures() {
304
    public ICreateFeature[] getCreateFeatures() {
205
    	return new ICreateFeature[] { new CreateJPAEntityFeature(this), new CreateJPAEntityFromMappedSuperclassFeature(this) };
305
    	return new ICreateFeature[] {new CreateJPAEntityFeature(this), 
306
    								 new CreateMappedSuperclassFeature(this)};
206
    }
307
    }
207
    
308
    
208
    @Override
309
    @Override
Lines 278-284 Link Here
278
        if (bo == null)
379
        if (bo == null)
279
        	super.getRemoveFeature(context);
380
        	super.getRemoveFeature(context);
280
    	if (bo instanceof JavaPersistentType) {
381
    	if (bo instanceof JavaPersistentType) {
281
    		return new RemoveJPAEntityFeature(this);	
382
    		return new RemoveJPAEntityFeature(this, true);	
282
    	} else if (bo instanceof AbstractRelation) { 
383
    	} else if (bo instanceof AbstractRelation) { 
283
    		return new RemoveRelationFeature(this);
384
    		return new RemoveRelationFeature(this);
284
    	}
385
    	}
Lines 456-461 Link Here
456
    	return ((JPASolver)getIndependenceSolver()).remove(key);
557
    	return ((JPASolver)getIndependenceSolver()).remove(key);
457
    }    
558
    }    
458
    
559
    
560
    public Collection<JavaPersistentType> getPersistentTypes() {
561
    	return ((JPASolver)getIndependenceSolver()).getPersistentTypes();
562
    }
459
    
563
    
460
    protected void removeAllConnections(Shape shape) {
564
    protected void removeAllConnections(Shape shape) {
461
		for (Iterator<Anchor> iter = shape.getAnchors().iterator(); iter.hasNext();) {
565
		for (Iterator<Anchor> iter = shape.getAnchors().iterator(); iter.hasNext();) {
Lines 590-599 Link Here
590
		((JPASolver)getIndependenceSolver()).dispose();
694
		((JPASolver)getIndependenceSolver()).dispose();
591
		setIndependenceSolver(null);
695
		setIndependenceSolver(null);
592
	}
696
	}
697
	
698
	public IPeService getPeService() {
699
		return peService;
700
	}
593
701
594
702
	public IPeServiceUtil getPeServiceUtil() {
595
	public IPeServiceUtil getPeUtil() {
703
		return peServiceUtil;
596
		return peUtil;
597
	}
704
	}
598
	
705
	
599
	public IJPAEditorUtil getJPAEditorUtil() {
706
	public IJPAEditorUtil getJPAEditorUtil() {
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorImageCreator.java (-15 / +26 lines)
Lines 18-23 Link Here
18
import org.eclipse.graphiti.mm.algorithms.Image;
18
import org.eclipse.graphiti.mm.algorithms.Image;
19
import org.eclipse.graphiti.mm.algorithms.Polyline;
19
import org.eclipse.graphiti.mm.algorithms.Polyline;
20
import org.eclipse.graphiti.mm.algorithms.Text;
20
import org.eclipse.graphiti.mm.algorithms.Text;
21
import org.eclipse.graphiti.mm.algorithms.styles.LineStyle;
21
import org.eclipse.graphiti.mm.pictograms.Connection;
22
import org.eclipse.graphiti.mm.pictograms.Connection;
22
import org.eclipse.graphiti.mm.pictograms.ConnectionDecorator;
23
import org.eclipse.graphiti.mm.pictograms.ConnectionDecorator;
23
import org.eclipse.graphiti.mm.pictograms.Diagram;
24
import org.eclipse.graphiti.mm.pictograms.Diagram;
Lines 37-54 Link Here
37
		return polyline;
38
		return polyline;
38
	}
39
	}
39
40
40
	/*
41
	public Polyline createIsAConnectionLine(Diagram d, Connection connection) {
41
	public ConnectionDecorator createTextConnectionDecorator(Connection connection, String text, double location) {
42
		Polyline polyline = Graphiti.getGaService().createPolyline(connection);
42
		ConnectionDecorator textDecorator = Graphiti.getPeService().createConnectionDecorator(connection, true, 0.5, true);
43
		polyline.setForeground(Graphiti.getGaService().manageColor(d, JPAEditorConstants.IS_A_CONNECTION_LINE_COLOR));
43
		Text txt = Graphiti.getGaService().createDefaultText(textDecorator);
44
		polyline.setLineWidth(JPAEditorConstants.IS_A_CONNECTION_LINE_WIDTH);
44
		txt.setLineWidth(JPAEditorConstants.CONNECTION_LINE_WIDTH);
45
		polyline.setLineStyle(LineStyle.DASH);
45
		txt.setValue(text);
46
		return polyline;
46
		Graphiti.getGaService().manageColor(connection.getParent(), IColorConstant.BLACK);
47
		Graphiti.getGaService().setLocation(txt, 5, -20);
48
		return textDecorator;
49
	}
47
	}
50
	*/
48
		
51
	
52
	public ConnectionDecorator createCardinalityConnectionDecorator(Diagram d, Connection c, String text, double location) {
49
	public ConnectionDecorator createCardinalityConnectionDecorator(Diagram d, Connection c, String text, double location) {
53
		ConnectionDecorator textDecorator = Graphiti.getPeService().createConnectionDecorator(c, true, location, true);
50
		ConnectionDecorator textDecorator = Graphiti.getPeService().createConnectionDecorator(c, true, location, true);
54
		Text txt = Graphiti.getGaService().createDefaultText(d, textDecorator);
51
		Text txt = Graphiti.getGaService().createDefaultText(d, textDecorator);
Lines 60-70 Link Here
60
		return textDecorator;
57
		return textDecorator;
61
	}
58
	}
62
59
63
	public ConnectionDecorator createArrowConnectionDecorator(Connection connection, double location) {
60
	public ConnectionDecorator createArrowConnectionDecorator(Connection connection, 
61
															  double location,
62
															  boolean isA) {
64
		ConnectionDecorator cd = Graphiti.getPeService().createConnectionDecorator(connection, false, location, true);
63
		ConnectionDecorator cd = Graphiti.getPeService().createConnectionDecorator(connection, false, location, true);
65
		Polyline arrow = null; 
64
		Polyline arrow = Graphiti.getGaService().createPolyline(cd, new int[] { 11, 3, 0, 0, 11, -3, 11, 3 });
66
			arrow = Graphiti.getGaService().createPolyline(cd, new int[] { 11, 3, 0, 0, 11, -3, 11, 3});
65
		arrow.setForeground(Graphiti.getGaService().manageColor(connection.getParent(), isA ? 
67
		arrow.setForeground(Graphiti.getGaService().manageColor(connection.getParent(), JPAEditorConstants.CONNECTION_LINE_COLOR));
66
																						JPAEditorConstants.IS_A_CONNECTION_LINE_COLOR : 
67
																						JPAEditorConstants.CONNECTION_LINE_COLOR));
68
		arrow.setLineWidth(JPAEditorConstants.CONNECTION_LINE_WIDTH);
68
		arrow.setLineWidth(JPAEditorConstants.CONNECTION_LINE_WIDTH);
69
		return cd;
69
		return cd;
70
	}
70
	}
Lines 107-110 Link Here
107
		return iconDecorator;
107
		return iconDecorator;
108
	}
108
	}
109
109
110
	public ConnectionDecorator createIsATextConnectionDecorator(Diagram d, Connection c) {
111
		ConnectionDecorator textDecorator = Graphiti.getPeService().createConnectionDecorator(c, true, 0.5, true);
112
		Text txt = Graphiti.getGaService().createDefaultText(d, textDecorator);
113
		txt.setLineWidth(JPAEditorConstants.CONNECTION_LINE_WIDTH);
114
		txt.setValue(JPAEditorConstants.IS_A);
115
		Graphiti.getGaService().manageColor(c.getParent(), IColorConstant.BLACK);
116
		//Point pt = JPAEditorUtil.recalcTextDecoratorPosition((FreeFormConnection)c, textDecorator);
117
		Graphiti.getGaService().setLocation(txt, 5, 5, false);
118
		return textDecorator;		
119
	}
120
110
}
121
}
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorImageProvider.java (-55 / +60 lines)
Lines 18-59 Link Here
18
import org.eclipse.graphiti.ui.platform.AbstractImageProvider;
18
import org.eclipse.graphiti.ui.platform.AbstractImageProvider;
19
19
20
public class JPAEditorImageProvider extends AbstractImageProvider {
20
public class JPAEditorImageProvider extends AbstractImageProvider {
21
21
	
22
    public final static String ID = "org.eclipse.jpt.jpadiagrameditor.ui.JPAEditorImageProvider";	//$NON-NLS-1$
22
	private final static String PREFIX = "org.eclipse.jpt.jpadiagrameditor.ui."; 						//$NON-NLS-1$
23
    static final String PRE = "org.eclipse.jpt.jpadiagrameditor.ui."; 							//$NON-NLS-1$
23
    public final static String ID	= "org.eclipse.jpt.jpadiagrameditor.ui.JPAEditorImageProvider";		//$NON-NLS-1$
24
    public static final String JPA_ENTITY = PRE + "entity"; 								//$NON-NLS-1$
24
    
25
    public static final String ADD_JPA_ENTITY = PRE + "add_entity"; 								//$NON-NLS-1$    
25
    public static final String JPA_ENTITY 				= PREFIX + "entity"; 							//$NON-NLS-1$
26
    public static final String ADD_INHERITED_ENTITY = PRE + "mapped_superclass";            //$NON-NLS-1$
26
    public static final String MAPPED_SUPERCLASS 		= PREFIX + "mapped_superclass"; 				//$NON-NLS-1$
27
    public static final String PRIMARY_KEY = PRE + "pk"; 									//$NON-NLS-1$
27
    public static final String ADD_JPA_ENTITY 			= PREFIX + "add_entity"; 						//$NON-NLS-1$    
28
    public static final String ICON_BASIC = PRE + "field"; 										//$NON-NLS-1$
28
    public static final String ADD_INHERITED_ENTITY 	= PREFIX + "add_inherited_entity";		        //$NON-NLS-1$
29
    public static final String ADD_ATTRIBUTE = PRE + "add_attribute"; 						//$NON-NLS-1$
29
    public static final String ADD_MAPPED_SUPERCLASS	= PREFIX + "add_mapped_superclass";	        	//$NON-NLS-1$    
30
    public static final String REMOVE_ATTRIBUTE = PRE + "remove_attribute"; 				//$NON-NLS-1$
30
    public static final String PRIMARY_KEY 				= PREFIX + "pk"; 								//$NON-NLS-1$
31
    public static final String ICON_ONE_TO_ONE = PRE + "one_to_one_relation"; 			//$NON-NLS-1$
31
    public static final String ICON_BASIC 				= PREFIX + "field"; 							//$NON-NLS-1$
32
    public static final String ICON_ONE_TO_MANY = PRE + "one_to_many_relation"; 			//$NON-NLS-1$
32
    public static final String ADD_ATTRIBUTE 			= PREFIX + "add_attribute"; 					//$NON-NLS-1$
33
    public static final String ICON_MANY_TO_ONE = PRE + "many_to_one_relation"; 			//$NON-NLS-1$
33
    public static final String REMOVE_ATTRIBUTE 		= PREFIX + "remove_attribute"; 					//$NON-NLS-1$
34
    public static final String ICON_MANY_TO_MANY = PRE + "many_to_many_relation"; 			//$NON-NLS-1$
34
    public static final String ICON_ONE_TO_ONE 			= PREFIX + "one_to_one_relation"; 				//$NON-NLS-1$
35
    public static final String ICON_EMBEDDED_ID = PRE + "embedded_id"; //$NON-NLS-1$
35
    public static final String ICON_ONE_TO_MANY 		= PREFIX + "one_to_many_relation"; 				//$NON-NLS-1$
36
    public static final String ICON_VERSION = PRE + "version"; //$NON-NLS-1$ 
36
    public static final String ICON_MANY_TO_ONE 		= PREFIX + "many_to_one_relation"; 				//$NON-NLS-1$
37
    public static final String ICON_TRANSIENT = PRE + "transient"; //$NON-NLS-1$  
37
    public static final String ICON_MANY_TO_MANY 		= PREFIX + "many_to_many_relation"; 			//$NON-NLS-1$
38
    public static final String ICON_EMBEDDED = PRE + "embedded"; //$NON-NLS-1$ 
38
    public static final String ICON_EMBEDDED_ID 		= PREFIX + "embedded_id"; 						//$NON-NLS-1$
39
    public static final String ICON_UNMAPPED = PRE + "unmapped"; //$NON-NLS-1$  
39
    public static final String ICON_VERSION 			= PREFIX + "version"; 							//$NON-NLS-1$ 
40
40
    public static final String ICON_TRANSIENT 			= PREFIX + "transient"; 						//$NON-NLS-1$  
41
41
    public static final String ICON_EMBEDDED 			= PREFIX + "embedded"; 							//$NON-NLS-1$ 
42
    public static final String ICON_ONE_TO_ONE_1_DIR = PRE + "one_to_one_1_dir_relation"; 			//$NON-NLS-1$
42
    public static final String ICON_UNMAPPED 			= PREFIX + "unmapped"; 							//$NON-NLS-1$  
43
    public static final String ICON_ONE_TO_MANY_1_DIR = PRE + "one_to_many_1_dir_relation"; 			//$NON-NLS-1$
43
44
    public static final String ICON_MANY_TO_ONE_1_DIR = PRE + "many_to_one_1_dir_relation"; 			//$NON-NLS-1$    
44
45
    public static final String ICON_MANY_TO_MANY_1_DIR = PRE + "many_to_many_1_dir_relation"; 			//$NON-NLS-1$
45
    public static final String ICON_ONE_TO_ONE_1_DIR 	= PREFIX + "one_to_one_1_dir_relation"; 		//$NON-NLS-1$
46
46
    public static final String ICON_ONE_TO_MANY_1_DIR 	= PREFIX + "one_to_many_1_dir_relation"; 		//$NON-NLS-1$
47
    public static final String ICON_ONE_TO_ONE_2_DIR = PRE + "one_to_one_2_dir_relation"; 			//$NON-NLS-1$
47
    public static final String ICON_MANY_TO_ONE_1_DIR 	= PREFIX + "many_to_one_1_dir_relation"; 		//$NON-NLS-1$    
48
    public static final String ICON_MANY_TO_ONE_2_DIR = PRE + "many_to_one_2_dir_relation"; 			//$NON-NLS-1$    
48
    public static final String ICON_MANY_TO_MANY_1_DIR 	= PREFIX + "many_to_many_1_dir_relation"; 		//$NON-NLS-1$
49
    public static final String ICON_MANY_TO_MANY_2_DIR = PRE + "many_to_many_2_dir_relation"; 			//$NON-NLS-1$
49
50
    public static final String ICON_ONE_TO_ONE_2_DIR 	= PREFIX + "one_to_one_2_dir_relation"; 		//$NON-NLS-1$
51
    public static final String ICON_MANY_TO_ONE_2_DIR 	= PREFIX + "many_to_one_2_dir_relation"; 		//$NON-NLS-1$    
52
    public static final String ICON_MANY_TO_MANY_2_DIR 	= PREFIX + "many_to_many_2_dir_relation"; 		//$NON-NLS-1$
50
    
53
    
51
    
54
    
52
    public static final String ICON_SAVE = PRE + "save"; 			//$NON-NLS-1$
55
    public static final String ICON_SAVE 				= PREFIX + "save"; 								//$NON-NLS-1$
53
    public static final String ICON_RESTORE = PRE + "restore"; 			//$NON-NLS-1$
56
    public static final String ICON_RESTORE 			= PREFIX + "restore"; 							//$NON-NLS-1$
54
    public static final String ICON_SAVE_AND_REMOVE = PRE + "save_and_remove"; 			//$NON-NLS-1$
57
    public static final String ICON_SAVE_AND_REMOVE 	= PREFIX + "save_and_remove"; 					//$NON-NLS-1$
55
58
56
	private static final String ROOT_FOLDER_FOR_IMG = "icons/"; //$NON-NLS-1$
59
	private static final String ROOT_FOLDER_FOR_IMG 	= "icons/"; 									//$NON-NLS-1$
57
60
58
    public JPAEditorImageProvider() {
61
    public JPAEditorImageProvider() {
59
        super();
62
        super();
Lines 62-95 Link Here
62
    @Override
65
    @Override
63
    protected void addAvailableImages() {        
66
    protected void addAvailableImages() {        
64
        addImageFilePath(ICON_BASIC, ROOT_FOLDER_FOR_IMG + "ent/basic.gif");							//$NON-NLS-1$
67
        addImageFilePath(ICON_BASIC, ROOT_FOLDER_FOR_IMG + "ent/basic.gif");							//$NON-NLS-1$
65
        addImageFilePath(JPA_ENTITY, ROOT_FOLDER_FOR_IMG + "ent/entity.gif");					//$NON-NLS-1$
68
        addImageFilePath(JPA_ENTITY, ROOT_FOLDER_FOR_IMG + "ent/entity.gif");							//$NON-NLS-1$
69
        addImageFilePath(MAPPED_SUPERCLASS, ROOT_FOLDER_FOR_IMG + "ent/mapped-superclass.gif");			//$NON-NLS-1$
66
        addImageFilePath(ADD_JPA_ENTITY, ROOT_FOLDER_FOR_IMG + "ent/add_entity.gif");					//$NON-NLS-1$        
70
        addImageFilePath(ADD_JPA_ENTITY, ROOT_FOLDER_FOR_IMG + "ent/add_entity.gif");					//$NON-NLS-1$        
67
        addImageFilePath(ADD_INHERITED_ENTITY, ROOT_FOLDER_FOR_IMG + "ent/mapped-superclass.gif"); //$NON-NLS-1$
71
        addImageFilePath(ADD_INHERITED_ENTITY, ROOT_FOLDER_FOR_IMG + "ent/add_entity.gif"); 			//$NON-NLS-1$
68
        addImageFilePath(PRIMARY_KEY, ROOT_FOLDER_FOR_IMG + "ent/id.gif");						//$NON-NLS-1$
72
        addImageFilePath(ADD_MAPPED_SUPERCLASS, ROOT_FOLDER_FOR_IMG + "ent/add_mapped-superclass.gif"); //$NON-NLS-1$
69
        addImageFilePath(ADD_ATTRIBUTE, ROOT_FOLDER_FOR_IMG + "ent/add_attribute.gif");			//$NON-NLS-1$
73
        addImageFilePath(PRIMARY_KEY, ROOT_FOLDER_FOR_IMG + "ent/id.gif");								//$NON-NLS-1$
70
        addImageFilePath(REMOVE_ATTRIBUTE, ROOT_FOLDER_FOR_IMG + "ent/remove_attribute.gif");	//$NON-NLS-1$
74
        addImageFilePath(ADD_ATTRIBUTE, ROOT_FOLDER_FOR_IMG + "ent/add_attribute.gif");					//$NON-NLS-1$
71
        addImageFilePath(ICON_ONE_TO_ONE, ROOT_FOLDER_FOR_IMG + "ent/one-to-one.gif");		//$NON-NLS-1$
75
        addImageFilePath(REMOVE_ATTRIBUTE, ROOT_FOLDER_FOR_IMG + "ent/remove_attribute.gif");			//$NON-NLS-1$
72
        addImageFilePath(ICON_ONE_TO_MANY, ROOT_FOLDER_FOR_IMG + "ent/one-to-many.gif");		//$NON-NLS-1$
76
        addImageFilePath(ICON_ONE_TO_ONE, ROOT_FOLDER_FOR_IMG + "ent/one-to-one.gif");					//$NON-NLS-1$
73
        addImageFilePath(ICON_MANY_TO_ONE, ROOT_FOLDER_FOR_IMG + "ent/many-to-one.gif");		//$NON-NLS-1$
77
        addImageFilePath(ICON_ONE_TO_MANY, ROOT_FOLDER_FOR_IMG + "ent/one-to-many.gif");				//$NON-NLS-1$
74
        addImageFilePath(ICON_MANY_TO_MANY, ROOT_FOLDER_FOR_IMG + "ent/many-to-many.gif");		//$NON-NLS-1$
78
        addImageFilePath(ICON_MANY_TO_ONE, ROOT_FOLDER_FOR_IMG + "ent/many-to-one.gif");				//$NON-NLS-1$
75
        addImageFilePath(ICON_EMBEDDED_ID, ROOT_FOLDER_FOR_IMG + "ent/embedded-id.gif"); //$NON-NLS-1$
79
        addImageFilePath(ICON_MANY_TO_MANY, ROOT_FOLDER_FOR_IMG + "ent/many-to-many.gif");				//$NON-NLS-1$
76
        addImageFilePath(ICON_VERSION, ROOT_FOLDER_FOR_IMG + "ent/version.gif"); //$NON-NLS-1$
80
        addImageFilePath(ICON_EMBEDDED_ID, ROOT_FOLDER_FOR_IMG + "ent/embedded-id.gif"); 				//$NON-NLS-1$
77
        addImageFilePath(ICON_TRANSIENT, ROOT_FOLDER_FOR_IMG + "ent/transient.gif"); //$NON-NLS-1$
81
        addImageFilePath(ICON_VERSION, ROOT_FOLDER_FOR_IMG + "ent/version.gif"); 						//$NON-NLS-1$
78
        addImageFilePath(ICON_EMBEDDED, ROOT_FOLDER_FOR_IMG + "ent/embedded.gif"); //$NON-NLS-1$
82
        addImageFilePath(ICON_TRANSIENT, ROOT_FOLDER_FOR_IMG + "ent/transient.gif"); 					//$NON-NLS-1$
79
        addImageFilePath(ICON_UNMAPPED, ROOT_FOLDER_FOR_IMG + "ent/null-attribute-mapping.gif"); //$NON-NLS-1$
83
        addImageFilePath(ICON_EMBEDDED, ROOT_FOLDER_FOR_IMG + "ent/embedded.gif"); 						//$NON-NLS-1$
84
        addImageFilePath(ICON_UNMAPPED, ROOT_FOLDER_FOR_IMG + "ent/null-attribute-mapping.gif"); 		//$NON-NLS-1$
80
85
81
        addImageFilePath(ICON_ONE_TO_ONE_1_DIR, ROOT_FOLDER_FOR_IMG + "ent/one-to-one-1-dir.gif");		//$NON-NLS-1$
86
        addImageFilePath(ICON_ONE_TO_ONE_1_DIR, ROOT_FOLDER_FOR_IMG + "ent/one-to-one-1-dir.gif");		//$NON-NLS-1$
82
        addImageFilePath(ICON_ONE_TO_MANY_1_DIR, ROOT_FOLDER_FOR_IMG + "ent/one-to-many-1-dir.gif");		//$NON-NLS-1$
87
        addImageFilePath(ICON_ONE_TO_MANY_1_DIR, ROOT_FOLDER_FOR_IMG + "ent/one-to-many-1-dir.gif");	//$NON-NLS-1$
83
        addImageFilePath(ICON_MANY_TO_ONE_1_DIR, ROOT_FOLDER_FOR_IMG + "ent/many-to-one-1-dir.gif");		//$NON-NLS-1$        
88
        addImageFilePath(ICON_MANY_TO_ONE_1_DIR, ROOT_FOLDER_FOR_IMG + "ent/many-to-one-1-dir.gif");	//$NON-NLS-1$        
84
        addImageFilePath(ICON_MANY_TO_MANY_1_DIR, ROOT_FOLDER_FOR_IMG + "ent/many-to-many-1-dir.gif");		//$NON-NLS-1$
89
        addImageFilePath(ICON_MANY_TO_MANY_1_DIR, ROOT_FOLDER_FOR_IMG + "ent/many-to-many-1-dir.gif");	//$NON-NLS-1$
85
        
90
        
86
        addImageFilePath(ICON_ONE_TO_ONE_2_DIR, ROOT_FOLDER_FOR_IMG + "ent/one-to-one-2-dir.gif");		//$NON-NLS-1$
91
        addImageFilePath(ICON_ONE_TO_ONE_2_DIR, ROOT_FOLDER_FOR_IMG + "ent/one-to-one-2-dir.gif");		//$NON-NLS-1$
87
        addImageFilePath(ICON_MANY_TO_ONE_2_DIR, ROOT_FOLDER_FOR_IMG + "ent/many-to-one-2-dir.gif");		//$NON-NLS-1$        
92
        addImageFilePath(ICON_MANY_TO_ONE_2_DIR, ROOT_FOLDER_FOR_IMG + "ent/many-to-one-2-dir.gif");	//$NON-NLS-1$        
88
        addImageFilePath(ICON_MANY_TO_MANY_2_DIR, ROOT_FOLDER_FOR_IMG + "ent/many-to-many-2-dir.gif");		//$NON-NLS-1$        
93
        addImageFilePath(ICON_MANY_TO_MANY_2_DIR, ROOT_FOLDER_FOR_IMG + "ent/many-to-many-2-dir.gif");	//$NON-NLS-1$        
89
                
94
                
90
        addImageFilePath(ICON_SAVE, ROOT_FOLDER_FOR_IMG + "save.gif");		//$NON-NLS-1$
95
        addImageFilePath(ICON_SAVE, ROOT_FOLDER_FOR_IMG + "save.gif");									//$NON-NLS-1$
91
        addImageFilePath(ICON_RESTORE, ROOT_FOLDER_FOR_IMG + "restore.gif");		//$NON-NLS-1$
96
        addImageFilePath(ICON_RESTORE, ROOT_FOLDER_FOR_IMG + "restore.gif");							//$NON-NLS-1$
92
        addImageFilePath(ICON_SAVE_AND_REMOVE, ROOT_FOLDER_FOR_IMG + "save_and_remove.gif");		//$NON-NLS-1$
97
        addImageFilePath(ICON_SAVE_AND_REMOVE, ROOT_FOLDER_FOR_IMG + "save_and_remove.gif");			//$NON-NLS-1$
93
    }
98
    }
94
    
99
    
95
}
100
}
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorToolBehaviorProvider.java (-1 / +15 lines)
Lines 46-51 Link Here
46
import org.eclipse.graphiti.mm.pictograms.Shape;
46
import org.eclipse.graphiti.mm.pictograms.Shape;
47
import org.eclipse.graphiti.palette.IPaletteCompartmentEntry;
47
import org.eclipse.graphiti.palette.IPaletteCompartmentEntry;
48
import org.eclipse.graphiti.palette.IToolEntry;
48
import org.eclipse.graphiti.palette.IToolEntry;
49
import org.eclipse.graphiti.palette.impl.ConnectionCreationToolEntry;
49
import org.eclipse.graphiti.palette.impl.PaletteCompartmentEntry;
50
import org.eclipse.graphiti.palette.impl.PaletteCompartmentEntry;
50
import org.eclipse.graphiti.platform.IPlatformImageConstants;
51
import org.eclipse.graphiti.platform.IPlatformImageConstants;
51
import org.eclipse.graphiti.services.Graphiti;
52
import org.eclipse.graphiti.services.Graphiti;
Lines 68-73 Link Here
68
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CollapseAllEntitiesFeature;
69
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CollapseAllEntitiesFeature;
69
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CollapseCompartmentShapeFeature;
70
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CollapseCompartmentShapeFeature;
70
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CollapseEntityFeature;
71
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CollapseEntityFeature;
72
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CreateInheritedEntityFeature;
71
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.DeleteJPAEntityFeature;
73
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.DeleteJPAEntityFeature;
72
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.DiscardAndRemoveAllEntitiesFeature;
74
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.DiscardAndRemoveAllEntitiesFeature;
73
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.ExpandAllEntitiesFeature;
75
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.ExpandAllEntitiesFeature;
Lines 88-95 Link Here
88
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.GraphicsUpdater;
90
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.GraphicsUpdater;
89
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.IEclipseFacade;
91
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.IEclipseFacade;
90
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants;
92
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants;
91
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil;
92
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants.ShapeType;
93
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants.ShapeType;
94
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil;
93
import org.eclipse.ui.PartInitException;
95
import org.eclipse.ui.PartInitException;
94
96
95
@SuppressWarnings("restriction")
97
@SuppressWarnings("restriction")
Lines 236-241 Link Here
236
        IPaletteCompartmentEntry en = ret.get(0);
238
        IPaletteCompartmentEntry en = ret.get(0);
237
        ret.set(0, ret.get(1));
239
        ret.set(0, ret.get(1));
238
        ret.set(1, en);
240
        ret.set(1, en);
241
        
242
    	PaletteCompartmentEntry ent = new PaletteCompartmentEntry(JPAEditorMessages.JPAEditorToolBehaviorProvider_InheritanceCompartmentTitle, superCompartments[1].getIconId());     
243
    	CreateInheritedEntityFeature ft = new CreateInheritedEntityFeature(this.getFeatureProvider());
244
    	ConnectionCreationToolEntry isARelToolEntry = new ConnectionCreationToolEntry(ft.getCreateName(),
245
				ft.getCreateDescription(), ft.getCreateImageId(), ft.getCreateLargeImageId());
246
    	isARelToolEntry.addCreateConnectionFeature(ft);
247
    	
248
		ent.addToolEntry(isARelToolEntry);
249
250
    	
251
    	ret.add(1, ent);
252
239
        return ret.toArray(new IPaletteCompartmentEntry[ret.size()]);
253
        return ret.toArray(new IPaletteCompartmentEntry[ret.size()]);
240
    }
254
    }
241
   
255
   
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/BidirectionalRelation.java (-30 lines)
Removed Link Here
1
/*******************************************************************************
2
 * <copyright>
3
 *
4
 * Copyright (c) 2005, 2010 SAP AG.
5
 * All rights reserved. This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
8
 * http://www.eclipse.org/legal/epl-v10.html
9
 *
10
 * Contributors:
11
 *    Stefan Dimov - initial API, implementation and documentation
12
 *
13
 * </copyright>
14
 *
15
 *******************************************************************************/
16
package org.eclipse.jpt.jpadiagrameditor.ui.internal.relations;
17
18
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
19
20
public interface BidirectionalRelation extends IRelation {
21
	
22
	public abstract JavaPersistentAttribute getOwnerAnnotatedAttribute();
23
24
	public abstract JavaPersistentAttribute getInverseAnnotatedAttribute();
25
26
	public abstract void setOwnerAnnotatedAttribute(JavaPersistentAttribute ownerAnnotatedAttribute);
27
28
	public abstract void setInverseAnnotatedAttribute(JavaPersistentAttribute inverseAnnotatedAttribute); 
29
30
}
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/IBidirectionalRelation.java (+30 lines)
Added Link Here
1
/*******************************************************************************
2
 * <copyright>
3
 *
4
 * Copyright (c) 2005, 2010 SAP AG.
5
 * All rights reserved. This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
8
 * http://www.eclipse.org/legal/epl-v10.html
9
 *
10
 * Contributors:
11
 *    Stefan Dimov - initial API, implementation and documentation
12
 *
13
 * </copyright>
14
 *
15
 *******************************************************************************/
16
package org.eclipse.jpt.jpadiagrameditor.ui.internal.relations;
17
18
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
19
20
public interface IBidirectionalRelation extends IRelation {
21
	
22
	public abstract JavaPersistentAttribute getOwnerAnnotatedAttribute();
23
24
	public abstract JavaPersistentAttribute getInverseAnnotatedAttribute();
25
26
	public abstract void setOwnerAnnotatedAttribute(JavaPersistentAttribute ownerAnnotatedAttribute);
27
28
	public abstract void setInverseAnnotatedAttribute(JavaPersistentAttribute inverseAnnotatedAttribute); 
29
30
}
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/IsARelation.java (+107 lines)
Added Link Here
1
/*******************************************************************************
2
 * <copyright>
3
 *
4
 * Copyright (c) 2005, 2010 SAP AG.
5
 * All rights reserved. This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
8
 * http://www.eclipse.org/legal/epl-v10.html
9
 *
10
 * Contributors:
11
 *    Stefan Dimov - initial API, implementation and documentation
12
 *
13
 * </copyright>
14
 *
15
 *******************************************************************************/
16
package org.eclipse.jpt.jpadiagrameditor.ui.internal.relations;
17
18
import org.eclipse.graphiti.mm.pictograms.Anchor;
19
import org.eclipse.graphiti.mm.pictograms.Connection;
20
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
21
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
22
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
23
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants;
24
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil;
25
26
public class IsARelation {
27
28
	protected final static String SEPARATOR = ";isA;";							//$NON-NLS-1$
29
	public final static String IS_A_CONNECTION_PROP_KEY = "is_is_a_connection";	//$NON-NLS-1$
30
	
31
	
32
	protected JavaPersistentType subclass;
33
	protected JavaPersistentType superclass;
34
	
35
	public IsARelation(JavaPersistentType subclass, 
36
					   JavaPersistentType superclass) {
37
		this.subclass = subclass;
38
		this.superclass = superclass;
39
	}
40
	
41
	public IsARelation(IJPAEditorFeatureProvider fp, Connection conn) {
42
		Anchor start = conn.getStart();
43
		Anchor end = conn.getEnd();
44
		Object startObj = fp.getBusinessObjectForPictogramElement((ContainerShape)start.eContainer());
45
		Object endObj = fp.getBusinessObjectForPictogramElement((ContainerShape)end.eContainer());
46
		if ((startObj == null) || (endObj == null))
47
			throw new NullPointerException("Some of the connection ends is null");	//$NON-NLS-1$
48
		if (!(startObj instanceof JavaPersistentType) || !(endObj instanceof JavaPersistentType))
49
			throw new IllegalArgumentException();
50
		this.subclass = (JavaPersistentType)startObj;
51
		this.superclass = (JavaPersistentType)endObj;
52
	}
53
	
54
	
55
	public JavaPersistentType getSubclass() {
56
		return subclass; 
57
	}
58
	
59
	public JavaPersistentType getSuperclass() {
60
		return superclass; 
61
	}
62
	
63
	public static boolean isIsAConnection(Connection conn) {
64
		String val = JPAEditorUtil.getPeUtil().getPropertyValue(conn, IS_A_CONNECTION_PROP_KEY);
65
		return (Boolean.TRUE.toString().equals(val));
66
	}
67
68
69
	public String getId() {
70
		return generateId(subclass, superclass);
71
	}
72
	
73
	public static String generateId(IJPAEditorFeatureProvider fp, Connection conn) {
74
		Anchor start = conn.getStart();
75
		Anchor end = conn.getEnd();
76
		Object startObj = fp.getBusinessObjectForPictogramElement((ContainerShape)start.eContainer());
77
		Object endObj = fp.getBusinessObjectForPictogramElement((ContainerShape)end.eContainer());
78
		if ((startObj == null) || (endObj == null))
79
			return null;
80
		if (!(startObj instanceof JavaPersistentType) || !(endObj instanceof JavaPersistentType))
81
			return null;
82
		JavaPersistentType startJpt = (JavaPersistentType)startObj;
83
		JavaPersistentType endJpt = (JavaPersistentType)endObj;
84
		return generateId(startJpt, endJpt);
85
	}
86
	
87
	private static String generateId(JavaPersistentType startJpt, JavaPersistentType endJpt) {
88
		return JPAEditorConstants.IS_A_RELATION_ID_PREFIX + 
89
				startJpt.getName() + SEPARATOR + endJpt.getName();
90
	}
91
	
92
	public boolean equals(Object obj) {
93
		if (obj == null)
94
			return false;
95
		if (this.hashCode() != obj.hashCode())
96
			return false;
97
		if (!(obj instanceof IsARelation))
98
			return false;
99
		IsARelation rel = (IsARelation)obj; 
100
		return this.getId().equals(rel.getId());
101
	}
102
	
103
	public int hashCode() {
104
		return getId().hashCode();
105
	}
106
107
}
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToManyBiDirRelation.java (-1 / +1 lines)
Lines 24-30 Link Here
24
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
24
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
25
25
26
26
27
public class ManyToManyBiDirRelation extends ManyToManyRelation implements BidirectionalRelation {
27
public class ManyToManyBiDirRelation extends ManyToManyRelation implements IBidirectionalRelation {
28
	
28
	
29
	public ManyToManyBiDirRelation(IJPAEditorFeatureProvider fp, JavaPersistentType owner, 
29
	public ManyToManyBiDirRelation(IJPAEditorFeatureProvider fp, JavaPersistentType owner, 
30
								   JavaPersistentType inverse,
30
								   JavaPersistentType inverse,
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToOneBiDirRelation.java (-1 / +1 lines)
Lines 24-30 Link Here
24
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
24
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
25
25
26
26
27
public class ManyToOneBiDirRelation  extends ManyToOneRelation implements BidirectionalRelation{
27
public class ManyToOneBiDirRelation  extends ManyToOneRelation implements IBidirectionalRelation{
28
28
29
	public ManyToOneBiDirRelation(IJPAEditorFeatureProvider fp, JavaPersistentType owner, 
29
	public ManyToOneBiDirRelation(IJPAEditorFeatureProvider fp, JavaPersistentType owner, 
30
								  JavaPersistentType inverse, 
30
								  JavaPersistentType inverse, 
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToOneBiDirRelation.java (-2 / +1 lines)
Lines 23-29 Link Here
23
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
23
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
24
24
25
25
26
public class OneToOneBiDirRelation extends OneToOneRelation implements BidirectionalRelation{
26
public class OneToOneBiDirRelation extends OneToOneRelation implements IBidirectionalRelation{
27
	public OneToOneBiDirRelation(IJPAEditorFeatureProvider fp, JavaPersistentType owner, 
27
	public OneToOneBiDirRelation(IJPAEditorFeatureProvider fp, JavaPersistentType owner, 
28
								 JavaPersistentType inverse, 
28
								 JavaPersistentType inverse, 
29
								 String ownerAttributeName,
29
								 String ownerAttributeName,
Lines 59-65 Link Here
59
	private void createRelation(IJPAEditorFeatureProvider fp, ICompilationUnit ownerCU, ICompilationUnit inverseCU) {
59
	private void createRelation(IJPAEditorFeatureProvider fp, ICompilationUnit ownerCU, ICompilationUnit inverseCU) {
60
		String name = JPAEditorUtil.returnSimpleName(inverse.getName());
60
		String name = JPAEditorUtil.returnSimpleName(inverse.getName());
61
		String actName = JPAEditorUtil.returnSimpleName(JpaArtifactFactory.instance().getEntityName(inverse));
61
		String actName = JPAEditorUtil.returnSimpleName(JpaArtifactFactory.instance().getEntityName(inverse));
62
63
		String nameWithNonCapitalLetter = JPAEditorUtil.decapitalizeFirstLetter(name);
62
		String nameWithNonCapitalLetter = JPAEditorUtil.decapitalizeFirstLetter(name);
64
		String actNameWithNonCapitalLetter = JPAEditorUtil.decapitalizeFirstLetter(actName);
63
		String actNameWithNonCapitalLetter = JPAEditorUtil.decapitalizeFirstLetter(actName);
65
		
64
		
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/EntityChangeListener.java (-19 / +3 lines)
Lines 20-29 Link Here
20
import java.util.Hashtable;
20
import java.util.Hashtable;
21
import java.util.Iterator;
21
import java.util.Iterator;
22
import java.util.Set;
22
import java.util.Set;
23
23
import org.eclipse.graphiti.features.context.impl.RemoveContext;
24
import org.eclipse.graphiti.features.context.impl.RemoveContext;
24
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
25
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
25
import org.eclipse.jdt.core.ICompilationUnit;
26
import org.eclipse.jdt.core.JavaModelException;
27
import org.eclipse.jpt.common.core.resource.java.Annotation;
26
import org.eclipse.jpt.common.core.resource.java.Annotation;
28
import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
27
import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
29
import org.eclipse.jpt.jpa.core.context.MappedByRelationship;
28
import org.eclipse.jpt.jpa.core.context.MappedByRelationship;
Lines 122-128 Link Here
122
						PersistenceUnit pu = JpaArtifactFactory.instance().getPersistenceUnit(jpt);
121
						PersistenceUnit pu = JpaArtifactFactory.instance().getPersistenceUnit(jpt);
123
						PersistentType pt = pu.getPersistentType(jpt.getName());
122
						PersistentType pt = pu.getPersistentType(jpt.getName());
124
						
123
						
125
						if ((pt == null) || !JpaArtifactFactory.instance().hasEntityAnnotation(jpt)) {
124
						if ((pt == null) || !JpaArtifactFactory.instance().hasEntityOrMappedSuperclassAnnotation(jpt)) {
126
							
125
							
127
							JpaArtifactFactory.instance().forceSaveEntityClass(jpt, featureProvider);
126
							JpaArtifactFactory.instance().forceSaveEntityClass(jpt, featureProvider);
128
							
127
							
Lines 136-156 Link Here
136
							RemoveAndSaveEntityFeature ft = new RemoveAndSaveEntityFeature(featureProvider);
135
							RemoveAndSaveEntityFeature ft = new RemoveAndSaveEntityFeature(featureProvider);
137
							ft.remove(ctx);
136
							ft.remove(ctx);
138
							break;
137
							break;
139
						} else {	
140
							
141
							ICompilationUnit cu = featureProvider.getCompilationUnit(jpt);
142
							String entName = JPAEditorUtil.returnSimpleName(JpaArtifactFactory.instance().getEntityName(jpt)); 
143
							try {
144
								final String newHeader = (cu.hasUnsavedChanges() ? "* " : "") + entName;	//$NON-NLS-1$ //$NON-NLS-2$
145
								Display.getDefault().asyncExec(new Runnable() {
146
									public void run() {
147
										GraphicsUpdater.updateHeader(entShape, newHeader);
148
									}
149
								});
150
												
151
							} catch (JavaModelException e) {
152
								JPADiagramEditorPlugin.logError("Cannot check compilation unit for unsaved changes", e); //$NON-NLS-1$				
153
							}								
154
						}
138
						}
155
					}
139
					}
156
				}		
140
				}		
Lines 192-198 Link Here
192
					}
176
					}
193
				}
177
				}
194
			} catch(Exception e) {
178
			} catch(Exception e) {
195
				//$NON-NLS-1$ 
179
				//ignore 
196
			}			
180
			}			
197
		}
181
		}
198
	}
182
	}
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/GraphicsUpdater.java (-14 / +24 lines)
Lines 166-174 Link Here
166
	}
166
	}
167
	
167
	
168
	public static void updateHeader(ContainerShape entityShape, final String newHeader) {
168
	public static void updateHeader(ContainerShape entityShape, final String newHeader) {
169
		if(entityShape == null)
169
		final Text txt = getHeaderText(entityShape);
170
		if (txt == null)
170
			return;
171
			return;
171
		
172
		//if (!JPAEditorUtil.areHeadersEqual(txt.getValue(), newHeader)) {
173
174
		if (!txt.getValue().equals(newHeader)) {
175
			TransactionalEditingDomain ted = TransactionUtil.getEditingDomain(txt);
176
			RecordingCommand rc = new RecordingCommand(ted) {
177
				protected void doExecute() {
178
					txt.setValue(newHeader);		
179
				}		
180
			};			
181
			ted.getCommandStack().execute(rc);
182
		}
183
	}
184
	
185
	private static Text getHeaderText(ContainerShape entityShape) {
186
		if(entityShape == null)
187
			return null;		
172
		List<Shape> shapes = entityShape.getChildren();
188
		List<Shape> shapes = entityShape.getChildren();
173
		Iterator<Shape> shIt = shapes.iterator();
189
		Iterator<Shape> shIt = shapes.iterator();
174
		Shape headerShape = null;;
190
		Shape headerShape = null;;
Lines 180-198 Link Here
180
			headerShape = null;
196
			headerShape = null;
181
		}
197
		}
182
		if (headerShape == null)
198
		if (headerShape == null)
183
			return;
199
			return null;
184
		GraphicsAlgorithm ga = headerShape.getGraphicsAlgorithm();
200
		GraphicsAlgorithm ga = headerShape.getGraphicsAlgorithm();
185
		if (ga == null)
201
		if (ga == null)
186
			return;
202
			return null;
187
		final Text txt = (Text)ga.getGraphicsAlgorithmChildren().get(0);
203
		if (ga.getGraphicsAlgorithmChildren().size() == 0)
188
		if (!JPAEditorUtil.areHeadersEqual(txt.getValue(), newHeader)) {
204
			return null;
189
			TransactionalEditingDomain ted = TransactionUtil.getEditingDomain(txt);
205
		Text txt = (Text)ga.getGraphicsAlgorithmChildren().get(0);
190
			RecordingCommand rc = new RecordingCommand(ted) {
206
		return txt;
191
				protected void doExecute() {
192
					txt.setValue(newHeader);		
193
				}		
194
			};			
195
			ted.getCommandStack().execute(rc);
196
		}
197
	}
207
	}
198
}
208
}
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/IJPAEditorPredefinedRenderingStyle.java (+27 lines)
Added Link Here
1
/*******************************************************************************
2
 * <copyright>
3
 *
4
 * Copyright (c) 2005, 2010 SAP AG.
5
 * All rights reserved. This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
8
 * http://www.eclipse.org/legal/epl-v10.html
9
 *
10
 * Contributors:
11
 *    Stefan Dimov - initial API, implementation and documentation
12
 *
13
 * </copyright>
14
 *
15
 *******************************************************************************/
16
package org.eclipse.jpt.jpadiagrameditor.ui.internal.util;
17
18
import org.eclipse.graphiti.util.IPredefinedRenderingStyle;
19
20
public interface IJPAEditorPredefinedRenderingStyle extends IPredefinedRenderingStyle {
21
22
	/**
23
	 * The ID for a green-to-white gradient with a gloss-effect.
24
	 */
25
	public static final String GREEN_WHITE_GLOSS_ID = "green-white-gloss"; //$NON-NLS-1$
26
	
27
}
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/IJPAEditorUtil.java (+13 lines)
Lines 18-23 Link Here
18
import java.util.List;
18
import java.util.List;
19
19
20
import org.eclipse.core.resources.IFile;
20
import org.eclipse.core.resources.IFile;
21
import org.eclipse.core.resources.IFolder;
21
import org.eclipse.core.resources.IProject;
22
import org.eclipse.core.resources.IProject;
22
import org.eclipse.graphiti.mm.pictograms.ConnectionDecorator;
23
import org.eclipse.graphiti.mm.pictograms.ConnectionDecorator;
23
import org.eclipse.graphiti.mm.pictograms.FreeFormConnection;
24
import org.eclipse.graphiti.mm.pictograms.FreeFormConnection;
Lines 64-74 Link Here
64
									   boolean isMappedSuperClassChild, 
65
									   boolean isMappedSuperClassChild, 
65
									   String mappedSuperclassName, 
66
									   String mappedSuperclassName, 
66
									   String mappedSuperclassPackage, 
67
									   String mappedSuperclassPackage, 
68
									   String idName,
67
									   boolean hasPrimaryKey) throws Exception;
69
									   boolean hasPrimaryKey) throws Exception;
70
	
71
	public IFile createEntityInProject(IProject project, 
72
									   String entityName, 
73
									   JavaPersistentType mappedSuperclass) throws Exception;
74
	
68
75
69
	public IFile createEntityFromMappedSuperclassInProject(IProject project,
76
	public IFile createEntityFromMappedSuperclassInProject(IProject project,
70
			String mappedSuperclassName, IPreferenceStore jpaPreferenceStore) throws Exception;
77
			String mappedSuperclassName, IPreferenceStore jpaPreferenceStore) throws Exception;
71
	
78
	
79
	public IFile createMappedSuperclassInProject(IProject project,
80
			IFolder folder, String mappedSuperclassName) throws Exception;
81
	
82
	public IFile createMappedSuperclassInProject(IProject project,
83
			String mappedSuperclassName) throws Exception;	
84
	
72
	public boolean isCardinalityDecorator(ConnectionDecorator cd);
85
	public boolean isCardinalityDecorator(ConnectionDecorator cd);
73
	
86
	
74
	public void discardWorkingCopyOnce(ICompilationUnit cu);
87
	public void discardWorkingCopyOnce(ICompilationUnit cu);
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorConstants.java (+20 lines)
Lines 25-30 Link Here
25
25
26
public class JPAEditorConstants {
26
public class JPAEditorConstants {
27
	
27
	
28
	public static enum DIAGRAM_OBJECT_TYPE {
29
		Entity,
30
		MappedSupeclass
31
	};
32
	
33
	public static final String IS_A_RELATION_ID_PREFIX = "is_a_relation:"; 	//$NON-NLS-1$
34
	
35
	public static final String IS_A = "is-a";	//$NON-NLS-1$
36
	
28
	public static final String HEADER_PREFIX_DIRTY = "* ";	//$NON-NLS-1$
37
	public static final String HEADER_PREFIX_DIRTY = "* ";	//$NON-NLS-1$
29
	
38
	
30
	public static Hashtable<String, String> PRIMITIVE_TO_WRAPPER = new Hashtable<String,String>();
39
	public static Hashtable<String, String> PRIMITIVE_TO_WRAPPER = new Hashtable<String,String>();
Lines 41-56 Link Here
41
		
50
		
42
	public static final IColorConstant ENTITY_BACKGROUND =
51
	public static final IColorConstant ENTITY_BACKGROUND =
43
        new ColorConstant(212, 231, 248);
52
        new ColorConstant(212, 231, 248);
53
	
54
	public static final IColorConstant MAPPED_SUPERCLASS_BACKGROUND =
55
	        new ColorConstant(212, 248, 231);
44
56
45
	public static final IColorConstant CONNECTION_LINE_COLOR = 
57
	public static final IColorConstant CONNECTION_LINE_COLOR = 
46
        new ColorConstant(98, 131,167);	
58
        new ColorConstant(98, 131,167);	
47
	
59
	
60
	public static final IColorConstant IS_A_CONNECTION_LINE_COLOR = 
61
	        new ColorConstant(98, 167, 131);	
62
	
48
	public static final IColorConstant ENTITY_BORDER_COLOR = 
63
	public static final IColorConstant ENTITY_BORDER_COLOR = 
49
        new ColorConstant(98, 131,167);		
64
        new ColorConstant(98, 131,167);		
50
	
65
	
66
	public static final IColorConstant MAPPED_SUPERCLASS_BORDER_COLOR = 
67
	        new ColorConstant(98, 167, 131);		
68
	
51
	public final static String TRUE_STRING = Boolean.toString(true);
69
	public final static String TRUE_STRING = Boolean.toString(true);
52
	
70
	
53
	public final static int CONNECTION_LINE_WIDTH = 2;
71
	public final static int CONNECTION_LINE_WIDTH = 2;
72
	public final static int IS_A_CONNECTION_LINE_WIDTH = 2;
73
54
	public final static int ENTITY_BORDER_WIDTH = 2;
74
	public final static int ENTITY_BORDER_WIDTH = 2;
55
	
75
	
56
	public final static int ENTITY_CORNER_WIDTH = 6;
76
	public final static int ENTITY_CORNER_WIDTH = 6;
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorPredefinedColoredAreas.java (+150 lines)
Added Link Here
1
/*******************************************************************************
2
 * <copyright>
3
 *
4
 * Copyright (c) 2005, 2010 SAP AG.
5
 * All rights reserved. This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
8
 * http://www.eclipse.org/legal/epl-v10.html
9
 *
10
 * Contributors:
11
 *    Stefan Dimov - initial API, implementation and documentation
12
 *
13
 * </copyright>
14
 *
15
 *******************************************************************************/
16
package org.eclipse.jpt.jpadiagrameditor.ui.internal.util;
17
18
import org.eclipse.emf.common.util.EList;
19
import org.eclipse.graphiti.mm.algorithms.styles.AdaptedGradientColoredAreas;
20
import org.eclipse.graphiti.mm.algorithms.styles.GradientColoredArea;
21
import org.eclipse.graphiti.mm.algorithms.styles.GradientColoredAreas;
22
import org.eclipse.graphiti.mm.algorithms.styles.LocationType;
23
import org.eclipse.graphiti.mm.algorithms.styles.StylesFactory;
24
import org.eclipse.graphiti.util.IGradientType;
25
import org.eclipse.graphiti.util.IPredefinedRenderingStyle;
26
import org.eclipse.graphiti.util.PredefinedColoredAreas;
27
28
public class JPAEditorPredefinedColoredAreas extends PredefinedColoredAreas 
29
											 implements IJPAEditorPredefinedRenderingStyle {
30
31
	/**
32
	 * The color-areas, which are used for default elements with the ID
33
	 * {@link #GREEN_WHITE_GLOSS_ID}.
34
	 */
35
	private static GradientColoredAreas getGreenWhiteGlossDefaultAreas() {
36
		final GradientColoredAreas gradientColoredAreas = StylesFactory.eINSTANCE.createGradientColoredAreas();
37
		final EList<GradientColoredArea> gcas = gradientColoredAreas.getGradientColor();
38
39
		addGradientColoredArea(gcas, "F8FEFB", 0, LocationType.LOCATION_TYPE_ABSOLUTE_START, "F8FEFB", 1, //$NON-NLS-1$ //$NON-NLS-2$
40
				LocationType.LOCATION_TYPE_ABSOLUTE_START);
41
		addGradientColoredArea(gcas, "EDFCF5", 1, LocationType.LOCATION_TYPE_ABSOLUTE_START, "EDFCF5", 2, //$NON-NLS-1$ //$NON-NLS-2$
42
				LocationType.LOCATION_TYPE_ABSOLUTE_START);
43
		addGradientColoredArea(gcas, "DEFAED", 2, LocationType.LOCATION_TYPE_ABSOLUTE_START, "DEFAED", 3, //$NON-NLS-1$ //$NON-NLS-2$
44
				LocationType.LOCATION_TYPE_ABSOLUTE_START);
45
		addGradientColoredArea(gcas, "D4F8E7", 3, LocationType.LOCATION_TYPE_ABSOLUTE_START, "FAFCFB", 2, //$NON-NLS-1$ //$NON-NLS-2$
46
				LocationType.LOCATION_TYPE_ABSOLUTE_END);
47
		addGradientColoredArea(gcas, "E2E9E5", 2, LocationType.LOCATION_TYPE_ABSOLUTE_END, "E2E9E5", 0, //$NON-NLS-1$ //$NON-NLS-2$
48
				LocationType.LOCATION_TYPE_ABSOLUTE_END);
49
		gradientColoredAreas.setStyleAdaption(IPredefinedRenderingStyle.STYLE_ADAPTATION_DEFAULT);
50
		return gradientColoredAreas;
51
	}
52
53
	/**
54
	 * The color-areas, which are used for primary selected elements with the ID
55
	 * {@link #GREEN_WHITE_GLOSS_ID}.
56
	 */
57
	private static GradientColoredAreas getGreenWhiteGlossPrimarySelectedAreas() {
58
		final GradientColoredAreas gradientColoredAreas = StylesFactory.eINSTANCE.createGradientColoredAreas();
59
		gradientColoredAreas.setStyleAdaption(IPredefinedRenderingStyle.STYLE_ADAPTATION_PRIMARY_SELECTED);
60
		final EList<GradientColoredArea> gcas = gradientColoredAreas.getGradientColor();
61
62
		addGradientColoredArea(gcas, "EEFDF6", 0, LocationType.LOCATION_TYPE_ABSOLUTE_START, "EEFDF6", 1, //$NON-NLS-1$ //$NON-NLS-2$
63
				LocationType.LOCATION_TYPE_ABSOLUTE_START);
64
		addGradientColoredArea(gcas, "D0F9E6", 1, LocationType.LOCATION_TYPE_ABSOLUTE_START, "D0F9E6", 2, //$NON-NLS-1$ //$NON-NLS-2$
65
				LocationType.LOCATION_TYPE_ABSOLUTE_START);
66
		addGradientColoredArea(gcas, "ACF4D2", 2, LocationType.LOCATION_TYPE_ABSOLUTE_START, "ACF4D2", 3, //$NON-NLS-1$ //$NON-NLS-2$
67
				LocationType.LOCATION_TYPE_ABSOLUTE_START);
68
		addGradientColoredArea(gcas, "81EAB9", 3, LocationType.LOCATION_TYPE_ABSOLUTE_START, "AAF2D0", 2, //$NON-NLS-1$ //$NON-NLS-2$
69
				LocationType.LOCATION_TYPE_ABSOLUTE_END);
70
		addGradientColoredArea(gcas, "9AE0BF", 2, LocationType.LOCATION_TYPE_ABSOLUTE_END, "9AE0BF", 0, //$NON-NLS-1$ //$NON-NLS-2$
71
				LocationType.LOCATION_TYPE_ABSOLUTE_END);
72
		return gradientColoredAreas;
73
	}
74
75
	/**
76
	 * The color-areas, which are used for secondary selected elements with the
77
	 * ID {@link #GREEN_WHITE_GLOSS_ID}.
78
	 */
79
	private static GradientColoredAreas getGreenWhiteGlossSecondarySelectedAreas() {
80
		final GradientColoredAreas gradientColoredAreas = StylesFactory.eINSTANCE.createGradientColoredAreas();
81
		gradientColoredAreas.setStyleAdaption(IPredefinedRenderingStyle.STYLE_ADAPTATION_SECONDARY_SELECTED);
82
		final EList<GradientColoredArea> gcas = gradientColoredAreas.getGradientColor();
83
84
		addGradientColoredArea(gcas, "F5FEF9", 0, LocationType.LOCATION_TYPE_ABSOLUTE_START, "F5FEF9", 1, //$NON-NLS-1$ //$NON-NLS-2$
85
				LocationType.LOCATION_TYPE_ABSOLUTE_START);
86
		addGradientColoredArea(gcas, "E2FCEF", 1, LocationType.LOCATION_TYPE_ABSOLUTE_START, "E2FCEF", 2, //$NON-NLS-1$ //$NON-NLS-2$
87
				LocationType.LOCATION_TYPE_ABSOLUTE_START);
88
		addGradientColoredArea(gcas, "CBF9E3", 2, LocationType.LOCATION_TYPE_ABSOLUTE_START, "CBF9E3", 3, //$NON-NLS-1$ //$NON-NLS-2$
89
				LocationType.LOCATION_TYPE_ABSOLUTE_START);
90
		addGradientColoredArea(gcas, "BBF7DA", 3, LocationType.LOCATION_TYPE_ABSOLUTE_START, "C5F7E0", 2, //$NON-NLS-1$ //$NON-NLS-2$
91
				LocationType.LOCATION_TYPE_ABSOLUTE_END);
92
		addGradientColoredArea(gcas, "B2E5CD", 2, LocationType.LOCATION_TYPE_ABSOLUTE_END, "B2E5CD", 0, //$NON-NLS-1$ //$NON-NLS-2$
93
				LocationType.LOCATION_TYPE_ABSOLUTE_END);
94
		return gradientColoredAreas;
95
	}
96
97
	/**
98
	 * The color-areas, which are used for elements where an action is allowed
99
	 * with the ID {@link #GREEN_WHITE_GLOSS_ID}.
100
	 */
101
	private static GradientColoredAreas getGreeenWhiteGlossActionAllowedAreas() {
102
		final GradientColoredAreas gradientColoredAreas = StylesFactory.eINSTANCE.createGradientColoredAreas();
103
		gradientColoredAreas.setStyleAdaption(IPredefinedRenderingStyle.STYLE_ADAPTATION_ACTION_ALLOWED);
104
		final EList<GradientColoredArea> gcas = gradientColoredAreas.getGradientColor();
105
106
		addGradientColoredArea(gcas, "9900CC", 0, LocationType.LOCATION_TYPE_ABSOLUTE_START, "336699", 0, //$NON-NLS-1$ //$NON-NLS-2$
107
				LocationType.LOCATION_TYPE_ABSOLUTE_END);
108
		return gradientColoredAreas;
109
	}
110
111
	/**
112
	 * The color-areas, which are used for elements where an action is forbidden
113
	 * with the ID {@link #GREEN_WHITE_GLOSS_ID}.
114
	 */
115
	private static GradientColoredAreas getGreenWhiteGlossActionForbiddenAreas() {
116
		final GradientColoredAreas gradientColoredAreas = StylesFactory.eINSTANCE.createGradientColoredAreas();
117
		gradientColoredAreas.setStyleAdaption(IPredefinedRenderingStyle.STYLE_ADAPTATION_ACTION_FORBIDDEN);
118
		final EList<GradientColoredArea> gcas = gradientColoredAreas.getGradientColor();
119
120
		addGradientColoredArea(gcas, "FF00CC", 0, LocationType.LOCATION_TYPE_ABSOLUTE_START, "FF0066", 0, //$NON-NLS-1$ //$NON-NLS-2$
121
				LocationType.LOCATION_TYPE_ABSOLUTE_END);
122
		return gradientColoredAreas;
123
	}
124
	
125
	
126
	public static AdaptedGradientColoredAreas getGreenWhiteGlossAdaptions() {
127
		final AdaptedGradientColoredAreas agca = StylesFactory.eINSTANCE.createAdaptedGradientColoredAreas();
128
		agca.setDefinedStyleId(GREEN_WHITE_GLOSS_ID);
129
		agca.setGradientType(IGradientType.VERTICAL);
130
		agca.getAdaptedGradientColoredAreas().add(IPredefinedRenderingStyle.STYLE_ADAPTATION_DEFAULT, getGreenWhiteGlossDefaultAreas());
131
		agca.getAdaptedGradientColoredAreas().add(IPredefinedRenderingStyle.STYLE_ADAPTATION_PRIMARY_SELECTED,
132
				getGreenWhiteGlossPrimarySelectedAreas());
133
		agca.getAdaptedGradientColoredAreas().add(IPredefinedRenderingStyle.STYLE_ADAPTATION_SECONDARY_SELECTED,
134
				getGreenWhiteGlossSecondarySelectedAreas());
135
		agca.getAdaptedGradientColoredAreas().add(IPredefinedRenderingStyle.STYLE_ADAPTATION_ACTION_ALLOWED,
136
				getGreeenWhiteGlossActionAllowedAreas());
137
		agca.getAdaptedGradientColoredAreas().add(IPredefinedRenderingStyle.STYLE_ADAPTATION_ACTION_FORBIDDEN,
138
				getGreenWhiteGlossActionForbiddenAreas());
139
		return agca;
140
	}	
141
142
	public static AdaptedGradientColoredAreas getAdaptedGradientColoredAreas(String id) {
143
		AdaptedGradientColoredAreas res = PredefinedColoredAreas.getAdaptedGradientColoredAreas(id);
144
		if (res != null)
145
			return res;
146
		if (GREEN_WHITE_GLOSS_ID.equals(id))
147
			return getGreenWhiteGlossAdaptions();
148
		return null;
149
	}
150
}
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorUtil.java (-35 / +69 lines)
Lines 159-165 Link Here
159
	
159
	
160
    public static Anchor getAnchor(ContainerShape cs) { 
160
    public static Anchor getAnchor(ContainerShape cs) { 
161
    	Collection<Anchor> anchors  = cs.getAnchors();
161
    	Collection<Anchor> anchors  = cs.getAnchors();
162
	    return anchors.iterator().next();    	
162
    	if (anchors.iterator().hasNext())
163
    		return anchors.iterator().next();
164
    	return null;
163
    }
165
    }
164
    
166
    
165
    public static Anchor getAnchor(JavaPersistentType jpt, IFeatureProvider fp) {
167
    public static Anchor getAnchor(JavaPersistentType jpt, IFeatureProvider fp) {
Lines 547-553 Link Here
547
		Iterator<Connection> consIt = cons.iterator();
549
		Iterator<Connection> consIt = cons.iterator();
548
		while (consIt.hasNext()) {
550
		while (consIt.hasNext()) {
549
			Connection con = consIt.next();
551
			Connection con = consIt.next();
550
			ContainerShape cs1 = (ContainerShape)con.getStart().getParent(); 
552
			ContainerShape cs1 = null;
553
			try {
554
				cs1 = (ContainerShape)con.getStart().getParent();
555
			} catch (NullPointerException e) {
556
				continue;
557
			}
551
			if (cs1 != cs)
558
			if (cs1 != cs)
552
				res.add(cs1);
559
				res.add(cs1);
553
			cs1 = (ContainerShape)con.getEnd().getParent();
560
			cs1 = (ContainerShape)con.getEnd().getParent();
Lines 858-864 Link Here
858
						Iterator<Connection> cIter = set.iterator();
865
						Iterator<Connection> cIter = set.iterator();
859
						while (cIter.hasNext()) {
866
						while (cIter.hasNext()) {
860
							Connection c = cIter.next();
867
							Connection c = cIter.next();
861
							IRelation rel = (IRelation)fp.getBusinessObjectForPictogramElement(c);
868
							Object o = fp.getBusinessObjectForPictogramElement(c);
869
							if (!(o instanceof IRelation))
870
								continue;
871
							IRelation rel = (IRelation)o; 
862
							rearrangeConnection(c, cnt, setSize,  rel.getOwner() == rel.getInverse());
872
							rearrangeConnection(c, cnt, setSize,  rel.getOwner() == rel.getInverse());
863
							cnt++;
873
							cnt++;
864
						}
874
						}
Lines 1078-1084 Link Here
1078
	
1088
	
1079
	static public String generateUniqueMappedSuperclassName(
1089
	static public String generateUniqueMappedSuperclassName(
1080
			JpaProject jpaProject, String pack, IJPAEditorFeatureProvider fp) {
1090
			JpaProject jpaProject, String pack, IJPAEditorFeatureProvider fp) {
1081
		String NAME = pack + ".MappedSuperclass"; //$NON-NLS-1$
1091
		String NAME = pack + ".MpdSuprcls"; //$NON-NLS-1$
1082
		String name = null;
1092
		String name = null;
1083
1093
1084
		HashSet<String> JPAProjectEntityNames = getEntityNames(jpaProject);
1094
		HashSet<String> JPAProjectEntityNames = getEntityNames(jpaProject);
Lines 1095-1111 Link Here
1095
		return name;
1105
		return name;
1096
	}
1106
	}
1097
				
1107
				
1098
1108
	static public IFile createEntityInProject(IProject project,
1109
											  String entityName,
1110
											  JavaPersistentType mappedSuperclass) throws Exception {
1111
		IFolder folder = getPackageFolder(project);
1112
		return createEntity(project, folder, entityName,
1113
				true, mappedSuperclass.getName(),
1114
				JpaArtifactFactory.instance().getMappedSuperclassPackageDeclaration(mappedSuperclass), 
1115
				JpaArtifactFactory.instance().generateIdName(mappedSuperclass), 
1116
				JpaArtifactFactory.instance().hasOrInheritsPrimaryKey(mappedSuperclass));
1117
	}
1099
	
1118
	
1100
	static public IFile createEntityInProject(IProject project,
1119
	static public IFile createEntityInProject(IProject project,
1101
			String entityName, IPreferenceStore jpaPreferenceStore,
1120
			String entityName, IPreferenceStore jpaPreferenceStore,
1102
			boolean isMappedSuperclassChild, String mappedSuperclassName,
1121
			boolean isMappedSuperclassChild, String mappedSuperclassName,
1103
			String mappedSuperclassPackage, boolean hasPrimaryKey)
1122
			String mappedSuperclassPackage, String idName, boolean hasPrimaryKey)
1104
			throws Exception {
1123
			throws Exception {
1105
		IFolder folder = getPackageFolder(project);
1124
		IFolder folder = getPackageFolder(project);
1106
		return createEntity(project, folder, entityName,
1125
		return createEntity(project, folder, entityName,
1107
				isMappedSuperclassChild, mappedSuperclassName,
1126
				isMappedSuperclassChild, mappedSuperclassName,
1108
				mappedSuperclassPackage, hasPrimaryKey);
1127
				mappedSuperclassPackage, idName, hasPrimaryKey);
1109
	}
1128
	}
1110
1129
1111
				
1130
				
Lines 1113-1120 Link Here
1113
			IProject project, String mappedSuperclassName,
1132
			IProject project, String mappedSuperclassName,
1114
			IPreferenceStore jpaPreferenceStore) throws Exception {
1133
			IPreferenceStore jpaPreferenceStore) throws Exception {
1115
		IFolder folder = getPackageFolder(project);
1134
		IFolder folder = getPackageFolder(project);
1116
		createMappedSuperclass(project, folder, mappedSuperclassName);
1135
		return createMappedSuperclassInProject(project, folder, mappedSuperclassName);
1117
		return createMappedSuperclass(project, folder, mappedSuperclassName);
1118
	}
1136
	}
1119
1137
1120
	@SuppressWarnings("deprecation")
1138
	@SuppressWarnings("deprecation")
Lines 1141-1147 Link Here
1141
1159
1142
	}
1160
	}
1143
	
1161
	
1144
	static private IFile createMappedSuperclass(IProject project,
1162
	static public IFile createMappedSuperclassInProject(IProject project,
1163
			String mappedSuperclassName) throws Exception {
1164
		IFolder folder = getPackageFolder(project);
1165
		return createMappedSuperclassInProject(project, folder, mappedSuperclassName);
1166
	}
1167
	
1168
	static public IFile createMappedSuperclassInProject(IProject project,
1145
			IFolder folder, String mappedSuperclassName) throws Exception {
1169
			IFolder folder, String mappedSuperclassName) throws Exception {
1146
1170
1147
		String mappedSuperclassShortName = mappedSuperclassName
1171
		String mappedSuperclassShortName = mappedSuperclassName
Lines 1286-1295 Link Here
1286
			}
1310
			}
1287
	}
1311
	}
1288
		
1312
		
1289
	static private IFile createEntity(IProject project, IFolder folder, String entityName, boolean isMappedSuperclassChild, 
1313
	static private IFile createEntity(IProject project, 
1290
			String mappedSuperclassName, String mappedSuperclassPackage, boolean hasPrimaryKey) throws Exception {
1314
									  IFolder folder, 
1291
1315
									  String entityName, 
1292
1316
									  boolean isMappedSuperclassChild, 
1317
									  String mappedSuperclassName, 
1318
									  String mappedSuperclassPackage, 
1319
									  String idName,
1320
									  boolean hasPrimaryKey) throws Exception {
1293
		
1321
		
1294
		String entityShortName = entityName.substring(entityName.lastIndexOf('.') + 1);		
1322
		String entityShortName = entityName.substring(entityName.lastIndexOf('.') + 1);		
1295
		if (!folder.exists()) {
1323
		if (!folder.exists()) {
Lines 1317-1344 Link Here
1317
		}
1345
		}
1318
1346
1319
		String primaryKeyDeclaration = ""; //$NON-NLS-1$
1347
		String primaryKeyDeclaration = ""; //$NON-NLS-1$
1320
		if (!hasPrimaryKey) {
1348
		if (!hasPrimaryKey) 
1321
			primaryKeyDeclaration = (fieldBasedAccess ? "  @Id \n" : "") //$NON-NLS-1$ //$NON-NLS-2$
1349
			primaryKeyDeclaration = generatePrimaryKeyDeclaration(fieldBasedAccess, idName);
1322
					+ "  private long id;\n\n" //$NON-NLS-1$
1323
					+ (fieldBasedAccess ? "" : "  @Id \n") //$NON-NLS-1$ //$NON-NLS-2$
1324
					+ "  public long getId() {\n" //$NON-NLS-1$
1325
					+ "    return id;\n" //$NON-NLS-1$
1326
					+ "  }\n\n" //$NON-NLS-1$
1327
					+ "  public void setId(long id) {\n" //$NON-NLS-1$
1328
					+ "    this.id = id;\n" //$NON-NLS-1$
1329
					+ "  }\n\n"; //$NON-NLS-1$
1330
		}
1331
1332
		
1350
		
1333
		if (!file.exists()) {
1351
		if (!file.exists()) {
1334
			  String content = "package " + JPADiagramPropertyPage.getDefaultPackage(project, props) + ";\n\n" //$NON-NLS-1$	//$NON-NLS-2$
1352
			  String content = "package " + JPADiagramPropertyPage.getDefaultPackage(project, props)	//$NON-NLS-1$ 
1335
					+ "import javax.persistence.*;\n"  //$NON-NLS-1$
1353
					  		 + ";\n\n"																	//$NON-NLS-1$	
1336
					+ packageImport+"\n\n" //$NON-NLS-1$
1354
					  		 + "import javax.persistence.*;\n"  										//$NON-NLS-1$
1337
					+ "@Entity \n" //$NON-NLS-1$
1355
					  		 + packageImport+"\n\n" 													//$NON-NLS-1$
1338
					+ ((tableName.length() > 0) ? ("@Table(name=\"" + tableName + "\")\n") : "")  //$NON-NLS-1$	//$NON-NLS-2$	//$NON-NLS-3$
1356
					  		 + "@Entity \n" 															//$NON-NLS-1$
1339
					+ classDeclarationStringContent
1357
					  		 + ((tableName.length() > 0) ? ("@Table(name=\"" 							//$NON-NLS-1$
1340
					+ primaryKeyDeclaration
1358
					  		 + tableName + "\")\n") : "")  												//$NON-NLS-1$	//$NON-NLS-2$
1341
					+"}"; //$NON-NLS-1$
1359
					  		 + classDeclarationStringContent
1360
					  		 + primaryKeyDeclaration
1361
					  		 +"}"; 																		//$NON-NLS-1$
1342
			ByteArrayOutputStream stream = new ByteArrayOutputStream();
1362
			ByteArrayOutputStream stream = new ByteArrayOutputStream();
1343
			try {
1363
			try {
1344
				stream.write(content.getBytes());
1364
				stream.write(content.getBytes());
Lines 1349-1355 Link Here
1349
			}	
1369
			}	
1350
		}
1370
		}
1351
		return file;
1371
		return file;
1352
	}		
1372
	}	
1373
	
1374
	static private String generatePrimaryKeyDeclaration(boolean fieldBasedAccess, String primaryKeyName) {
1375
		String primaryKeyDeclaration = (fieldBasedAccess ? "  @Id \n" : "") 				//$NON-NLS-1$	//$NON-NLS-2$
1376
				+ "  private long " + primaryKeyName + ";\n\n" 								//$NON-NLS-1$	//$NON-NLS-2$
1377
				+ (fieldBasedAccess ? "" : "  @Id \n") 										//$NON-NLS-1$	//$NON-NLS-2$
1378
				+ "  public long get" + capitalizeFirstLetter(primaryKeyName) + "() {\n" 	//$NON-NLS-1$	//$NON-NLS-2$
1379
				+ "    return " + primaryKeyName + ";\n" 									//$NON-NLS-1$	//$NON-NLS-2$
1380
				+ "  }\n\n" 																//$NON-NLS-1$
1381
				+ "  public void set" + capitalizeFirstLetter(primaryKeyName) 				//$NON-NLS-1$ 
1382
				+ "(long " + primaryKeyName + ") {\n" 										//$NON-NLS-1$	//$NON-NLS-2$
1383
				+ "    this." + primaryKeyName + " = " + primaryKeyName + ";\n" 			//$NON-NLS-1$	//$NON-NLS-2$	//$NON-NLS-3$
1384
				+ "  }\n\n"; 																//$NON-NLS-1$
1385
		return primaryKeyDeclaration;
1386
	}
1353
	
1387
	
1354
	static private HashSet<String> getEntityNames(JpaProject jpaProject) {
1388
	static private HashSet<String> getEntityNames(JpaProject jpaProject) {
1355
		HashSet<String> names = new HashSet<String>();
1389
		HashSet<String> names = new HashSet<String>();
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorUtilImpl.java (-2 / +20 lines)
Lines 18-23 Link Here
18
import java.util.List;
18
import java.util.List;
19
19
20
import org.eclipse.core.resources.IFile;
20
import org.eclipse.core.resources.IFile;
21
import org.eclipse.core.resources.IFolder;
21
import org.eclipse.core.resources.IProject;
22
import org.eclipse.core.resources.IProject;
22
import org.eclipse.graphiti.mm.pictograms.ConnectionDecorator;
23
import org.eclipse.graphiti.mm.pictograms.ConnectionDecorator;
23
import org.eclipse.graphiti.mm.pictograms.FreeFormConnection;
24
import org.eclipse.graphiti.mm.pictograms.FreeFormConnection;
Lines 78-88 Link Here
78
79
79
	
80
	
80
	public IFile createEntityInProject(IProject project, String entityName, IPreferenceStore jpaPreferenceStore,
81
	public IFile createEntityInProject(IProject project, String entityName, IPreferenceStore jpaPreferenceStore,
81
			boolean isMappedSuperclassChild, String mappedSuperclassName, String mappedSuperclassPackage, boolean hasPrimaryKey) throws Exception {
82
									   boolean isMappedSuperclassChild, String mappedSuperclassName, 
83
									   String mappedSuperclassPackage, String idName, 
84
									   boolean hasPrimaryKey) throws Exception {
82
		return JPAEditorUtil.createEntityInProject(project, entityName, jpaPreferenceStore, isMappedSuperclassChild, 
85
		return JPAEditorUtil.createEntityInProject(project, entityName, jpaPreferenceStore, isMappedSuperclassChild, 
83
				mappedSuperclassName, mappedSuperclassPackage, hasPrimaryKey);
86
				mappedSuperclassName, mappedSuperclassPackage, idName, hasPrimaryKey);
84
 	}
87
 	}
85
88
89
	public IFile createEntityInProject(IProject project, 
90
			   String entityName, 
91
			   JavaPersistentType mappedSuperclass) throws Exception {
92
		return JPAEditorUtil.createEntityInProject(project, entityName, mappedSuperclass);		
93
	}
86
	
94
	
87
	public ICompilationUnit getCompilationUnit(JavaPersistentType jpt) {
95
	public ICompilationUnit getCompilationUnit(JavaPersistentType jpt) {
88
		return JPAEditorUtil.getCompilationUnit(jpt);
96
		return JPAEditorUtil.getCompilationUnit(jpt);
Lines 100-104 Link Here
100
			String mappedSuperclassName, IPreferenceStore jpaPreferenceStore) throws Exception {
108
			String mappedSuperclassName, IPreferenceStore jpaPreferenceStore) throws Exception {
101
		return JPAEditorUtil.createEntityFromMappedSuperclassInProject(project, mappedSuperclassName, jpaPreferenceStore);
109
		return JPAEditorUtil.createEntityFromMappedSuperclassInProject(project, mappedSuperclassName, jpaPreferenceStore);
102
	}
110
	}
111
	
112
	public IFile createMappedSuperclassInProject(IProject project,
113
			IFolder folder, String mappedSuperclassName) throws Exception {
114
		return JPAEditorUtil.createMappedSuperclassInProject(project, folder, mappedSuperclassName);
115
	}
116
	
117
	public IFile createMappedSuperclassInProject(IProject project,
118
			String mappedSuperclassName) throws Exception {
119
		return JPAEditorUtil.createMappedSuperclassInProject(project, mappedSuperclassName);
120
	}
103
121
104
}
122
}
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPASolver.java (-16 / +24 lines)
Lines 25-30 Link Here
25
import java.util.List;
25
import java.util.List;
26
import java.util.Set;
26
import java.util.Set;
27
import java.util.WeakHashMap;
27
import java.util.WeakHashMap;
28
28
import org.eclipse.core.internal.resources.File;
29
import org.eclipse.core.internal.resources.File;
29
import org.eclipse.core.resources.IFile;
30
import org.eclipse.core.resources.IFile;
30
import org.eclipse.core.resources.IMarkerDelta;
31
import org.eclipse.core.resources.IMarkerDelta;
Lines 115-121 Link Here
115
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
116
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
116
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.JPAEditorDiagramTypeProvider;
117
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.JPAEditorDiagramTypeProvider;
117
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.AbstractRelation;
118
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.AbstractRelation;
118
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.BidirectionalRelation;
119
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IBidirectionalRelation;
119
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation;
120
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation;
120
import org.eclipse.swt.graphics.Point;
121
import org.eclipse.swt.graphics.Point;
121
import org.eclipse.swt.widgets.Display;
122
import org.eclipse.swt.widgets.Display;
Lines 143-148 Link Here
143
	private IJPAEditorFeatureProvider featureProvider;
144
	private IJPAEditorFeatureProvider featureProvider;
144
	private HashSet<String> removeIgnore = new HashSet<String>();
145
	private HashSet<String> removeIgnore = new HashSet<String>();
145
	private HashSet<String> removeRelIgnore = new HashSet<String>();
146
	private HashSet<String> removeRelIgnore = new HashSet<String>();
147
	private Collection<JavaPersistentType> persistentTypes = new HashSet<JavaPersistentType>();
146
148
147
	private HashSet<String> addIgnore = new HashSet<String>();
149
	private HashSet<String> addIgnore = new HashSet<String>();
148
	private Hashtable<String, IRelation> attribToRel = new Hashtable<String, IRelation>();
150
	private Hashtable<String, IRelation> attribToRel = new Hashtable<String, IRelation>();
Lines 221-227 Link Here
221
			eclipseFacade.getDisplay().asyncExec(new Runnable() {
223
			eclipseFacade.getDisplay().asyncExec(new Runnable() {
222
				public void run() {
224
				public void run() {
223
					if(featureProvider != null)
225
					if(featureProvider != null)
224
						featureProvider.getDiagramTypeProvider().getDiagramEditor().refresh();
226
						try {
227
							featureProvider.getDiagramTypeProvider().getDiagramEditor().refresh();
228
						} catch (Exception e) {
229
							// ignore
230
						}
225
				}
231
				}
226
			});
232
			});
227
233
Lines 323-332 Link Here
323
			addListenersToEntity(jpt);
329
			addListenersToEntity(jpt);
324
			PictogramElement pe = featureProvider.getPictogramElementForBusinessObject(jpt);
330
			PictogramElement pe = featureProvider.getPictogramElementForBusinessObject(jpt);
325
			Graphiti.getPeService().setPropertyValue(pe, JPAEditorConstants.PROP_ENTITY_CLASS_NAME, jpt.getName());
331
			Graphiti.getPeService().setPropertyValue(pe, JPAEditorConstants.PROP_ENTITY_CLASS_NAME, jpt.getName());
332
			persistentTypes.add(jpt);
326
		} else if (bo instanceof AbstractRelation) {
333
		} else if (bo instanceof AbstractRelation) {
327
			AbstractRelation rel = (AbstractRelation) bo;
334
			AbstractRelation rel = (AbstractRelation) bo;
328
			attribToRel.put(produceOwnerKeyForRel(rel), rel);
335
			attribToRel.put(produceOwnerKeyForRel(rel), rel);
329
			if (rel instanceof BidirectionalRelation) {
336
			if (rel instanceof IBidirectionalRelation) {
330
				attribToRel.put(produceInverseKeyForRel(rel), rel);
337
				attribToRel.put(produceInverseKeyForRel(rel), rel);
331
			}
338
			}
332
		} else if (bo instanceof JavaPersistentAttribute) {
339
		} else if (bo instanceof JavaPersistentAttribute) {
Lines 344-350 Link Here
344
				String k = getKeyForBusinessObject(at);
351
				String k = getKeyForBusinessObject(at);
345
				remove(k);
352
				remove(k);
346
			}
353
			}
347
			
354
			persistentTypes.remove(jpt);
348
			removeListenersFromEntity(jpt);
355
			removeListenersFromEntity(jpt);
349
			Diagram d = featureProvider.getDiagramTypeProvider().getDiagram();
356
			Diagram d = featureProvider.getDiagramTypeProvider().getDiagram();
350
			if (d.getChildren().size() == 1) {
357
			if (d.getChildren().size() == 1) {
Lines 361-367 Link Here
361
		} else if (o instanceof AbstractRelation) {
368
		} else if (o instanceof AbstractRelation) {
362
			AbstractRelation rel = (AbstractRelation) o;
369
			AbstractRelation rel = (AbstractRelation) o;
363
			attribToRel.remove(produceOwnerKeyForRel(rel));
370
			attribToRel.remove(produceOwnerKeyForRel(rel));
364
			if (rel instanceof BidirectionalRelation) 
371
			if (rel instanceof IBidirectionalRelation) 
365
				attribToRel.remove(produceInverseKeyForRel(rel));
372
				attribToRel.remove(produceInverseKeyForRel(rel));
366
		} else if (o instanceof JavaPersistentAttribute) {
373
		} else if (o instanceof JavaPersistentAttribute) {
367
			removeListenersFromAttribute((JavaPersistentAttribute)o);
374
			removeListenersFromAttribute((JavaPersistentAttribute)o);
Lines 939-946 Link Here
939
		util = null;
946
		util = null;
940
		keyToBO.clear();
947
		keyToBO.clear();
941
		attribToRel.clear();
948
		attribToRel.clear();
949
		persistentTypes.clear();
942
		keyToBO = null;
950
		keyToBO = null;
943
		attribToRel = null;	
951
		attribToRel = null;
952
		persistentTypes = null;
944
		removeAllListeners();
953
		removeAllListeners();
945
		featureProvider = null;
954
		featureProvider = null;
946
		synchronized (JPASolver.class) {
955
		synchronized (JPASolver.class) {
Lines 977-1001 Link Here
977
			
986
			
978
			for (ICompilationUnit cu : affectedCompilationUnits) {
987
			for (ICompilationUnit cu : affectedCompilationUnits) {
979
				JavaPersistentType jpt = JPAEditorUtil.getJPType(cu);
988
				JavaPersistentType jpt = JPAEditorUtil.getJPType(cu);
980
				for (JPASolver solver : solversSet) {
989
				for (final JPASolver solver : solversSet) {
981
					final ContainerShape cs = (ContainerShape)solver.featureProvider.getPictogramElementForBusinessObject(jpt);
990
					final ContainerShape cs = (ContainerShape)solver.featureProvider.getPictogramElementForBusinessObject(jpt);
982
					if (cs == null)
991
					if (cs == null)
983
						return;
992
						return;
984
					String entName = JPAEditorUtil.getText(jpt);
993
					String entName = JPAEditorUtil.getText(jpt);
985
					try {
994
					try {
986
						final String newHeader = (cu.hasUnsavedChanges() ? "* " : "") + entName;	//$NON-NLS-1$ //$NON-NLS-2$
995
						final String newHeader = (cu.hasUnsavedChanges() ? "* " : "") + entName;	//$NON-NLS-1$ //$NON-NLS-2$
987
						Display.getDefault().asyncExec(new Runnable() {
996
						GraphicsUpdater.updateHeader(cs, newHeader);
988
							public void run() {
997
						JpaArtifactFactory.instance().rearrangeIsARelationsInTransaction(solver.featureProvider);
989
								GraphicsUpdater.updateHeader(cs, newHeader);
990
							}
991
						});
992
										
993
					} catch (JavaModelException e) {
998
					} catch (JavaModelException e) {
994
						JPADiagramEditorPlugin.logError("Cannot check compilation unit for unsaved changes", e); //$NON-NLS-1$				 
999
						JPADiagramEditorPlugin.logError("Cannot check compilation unit for unsaved changes", e); //$NON-NLS-1$				 
995
					}	
1000
					}
996
				}
1001
				}
997
				
1002
			}
998
			}			
999
		}
1003
		}
1000
		
1004
		
1001
		private Set<ICompilationUnit> getAffectedCompilationUnits(IJavaElementDelta delta) { 
1005
		private Set<ICompilationUnit> getAffectedCompilationUnits(IJavaElementDelta delta) { 
Lines 1470-1473 Link Here
1470
		return resources;
1474
		return resources;
1471
	}
1475
	}
1472
1476
1477
	public Collection<JavaPersistentType> getPersistentTypes() {
1478
		return persistentTypes;
1479
	}
1480
1473
}
1481
}
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JpaArtifactFactory.java (-19 / +193 lines)
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
}
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/ResourceChangeListener.java (-4 / +48 lines)
Lines 1-3 Link Here
1
/*******************************************************************************
2
 * <copyright>
3
 *
4
 * Copyright (c) 2005, 2010 SAP AG.
5
 * All rights reserved. This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
8
 * http://www.eclipse.org/legal/epl-v10.html
9
 *
10
 * Contributors:
11
 *    Stefan Dimov - initial API, implementation and documentation
12
 *
13
 * </copyright>
14
 *
15
 *******************************************************************************/
1
package org.eclipse.jpt.jpadiagrameditor.ui.internal.util;
16
package org.eclipse.jpt.jpadiagrameditor.ui.internal.util;
2
17
3
import org.eclipse.core.resources.IFile;
18
import org.eclipse.core.resources.IFile;
Lines 7-14 Link Here
7
import org.eclipse.core.resources.IResourceChangeEvent;
22
import org.eclipse.core.resources.IResourceChangeEvent;
8
import org.eclipse.core.resources.IResourceChangeListener;
23
import org.eclipse.core.resources.IResourceChangeListener;
9
import org.eclipse.core.resources.IResourceDelta;
24
import org.eclipse.core.resources.IResourceDelta;
25
import org.eclipse.graphiti.mm.pictograms.Diagram;
10
import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin;
26
import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin;
11
import org.eclipse.jpt.jpadiagrameditor.ui.internal.modelintegration.util.ModelIntegrationUtil;
27
import org.eclipse.jpt.jpadiagrameditor.ui.internal.modelintegration.util.ModelIntegrationUtil;
28
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.JPAEditorDiagramTypeProvider;
12
import org.eclipse.ui.IEditorPart;
29
import org.eclipse.ui.IEditorPart;
13
import org.eclipse.ui.IEditorReference;
30
import org.eclipse.ui.IEditorReference;
14
import org.eclipse.ui.IWorkbenchPage;
31
import org.eclipse.ui.IWorkbenchPage;
Lines 18-33 Link Here
18
35
19
	public void resourceChanged(IResourceChangeEvent event) {
36
	public void resourceChanged(IResourceChangeEvent event) {
20
		IMarkerDelta[] markerDeltas = event.findMarkerDeltas(null, true);
37
		IMarkerDelta[] markerDeltas = event.findMarkerDeltas(null, true);
21
38
		IProject pr = null;
22
		for (IMarkerDelta delta : markerDeltas) {
39
		for (IMarkerDelta delta : markerDeltas) {
23
			if (delta.getResource().getType() != IResource.FILE)
40
			int resType = delta.getResource().getType();
41
			if (resType == IResource.PROJECT) {
42
				pr = (IProject)delta.getResource();
24
				continue;
43
				continue;
25
			if (delta.getKind() != IResourceDelta.REMOVED) 
44
			}
45
			if (resType != IResource.FILE)
26
				continue;
46
				continue;
27
			final IFile file = (IFile) delta.getResource();
47
			final IFile file = (IFile) delta.getResource();
48
			pr = file.getProject();
28
			if (file.exists())
49
			if (file.exists())
29
				continue;
50
				continue;
51
			if (delta.getKind() != IResourceDelta.REMOVED) 
52
				continue;
30
			final IProject project = file.getProject();
53
			final IProject project = file.getProject();
54
			pr = project;
31
			final String name = project.getName();
55
			final String name = project.getName();
32
			if (file.getFullPath().equals(ModelIntegrationUtil.getDiagramXMLFullPath(name))) {
56
			if (file.getFullPath().equals(ModelIntegrationUtil.getDiagramXMLFullPath(name))) {
33
				PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
57
				PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
Lines 49-55 Link Here
49
				});
73
				});
50
				
74
				
51
			}
75
			}
52
		}		
76
		}	
77
		
78
		if (pr == null)
79
			return;
80
		rearrangeIsARelations(pr);
81
82
	}
83
	
84
	private void rearrangeIsARelations(IProject pr) {
85
		if (pr == null) return;
86
		final Diagram d = ModelIntegrationUtil.getDiagramByProject(pr);
87
		if (d == null) return;
88
		final JPAEditorDiagramTypeProvider provider = ModelIntegrationUtil.getProviderByDiagram(d.getName());
89
		if (provider == null)
90
			return;
91
		PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
92
			public void run() {
93
				JpaArtifactFactory.instance().rearrangeIsARelationsInTransaction(provider.getFeatureProvider());
94
			}
95
		});
96
		
53
	}
97
	}
54
		
98
		
55
}
99
}
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/AllJpaEditorTests.java (-1 / +1 lines)
Lines 83-89 Link Here
83
    @BeforeClass
83
    @BeforeClass
84
    public static void verifyRequiredJarsExists() throws NoSuchElementException {
84
    public static void verifyRequiredJarsExists() throws NoSuchElementException {
85
    	verifyJpaJarExists();
85
    	verifyJpaJarExists();
86
    	verifyEclipseLinkJarExists();
86
    	//verifyEclipseLinkJarExists();
87
    }
87
    }
88
88
89
	private static void verifyJpaJarExists() throws NoSuchElementException {
89
	private static void verifyJpaJarExists() throws NoSuchElementException {
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/AddRelationFeatureTest.java (-6 / +6 lines)
Lines 76-82 Link Here
76
76
77
	private IAddConnectionContext context;
77
	private IAddConnectionContext context;
78
78
79
	private IPeServiceUtil peUtil;
79
	private IPeServiceUtil peServiceUtil;
80
	
80
	
81
	private IGaService gaUtil;
81
	private IGaService gaUtil;
82
	
82
	
Lines 100-106 Link Here
100
		diagramProvider = EasyMock.createMock(IDiagramTypeProvider.class);
100
		diagramProvider = EasyMock.createMock(IDiagramTypeProvider.class);
101
		diagram = EasyMock.createMock(Diagram.class);
101
		diagram = EasyMock.createMock(Diagram.class);
102
		context = EasyMock.createMock(IAddConnectionContext.class);
102
		context = EasyMock.createMock(IAddConnectionContext.class);
103
		peUtil = EasyMock.createMock(IPeServiceUtil.class);
103
		peServiceUtil = EasyMock.createMock(IPeServiceUtil.class);
104
		gaUtil = EasyMock.createMock(IGaService.class);
104
		gaUtil = EasyMock.createMock(IGaService.class);
105
		ft = EasyMock.createMock(IAddBendpointFeature.class);
105
		ft = EasyMock.createMock(IAddBendpointFeature.class);
106
		
106
		
Lines 191-197 Link Here
191
		Polyline pl = EasyMock.createMock(Polyline.class);
191
		Polyline pl = EasyMock.createMock(Polyline.class);
192
		expect(pl.getX()).andReturn(0);
192
		expect(pl.getX()).andReturn(0);
193
		expect(pl.getY()).andReturn(0);
193
		expect(pl.getY()).andReturn(0);
194
		expect(imageCreator.createArrowConnectionDecorator(isA(Connection.class), eq(location))).andReturn(d);
194
		expect(imageCreator.createArrowConnectionDecorator(isA(Connection.class), eq(location), false)).andReturn(d);
195
		expect(d.getGraphicsAlgorithm()).andReturn(pl);
195
		expect(d.getGraphicsAlgorithm()).andReturn(pl);
196
		replay(d, pl);
196
		replay(d, pl);
197
	}
197
	}
Lines 213-219 Link Here
213
	private void configureProvidersForAdd(IRelation relation) {
213
	private void configureProvidersForAdd(IRelation relation) {
214
		expect(diagramProvider.getDiagram()).andReturn(diagram);
214
		expect(diagramProvider.getDiagram()).andReturn(diagram);
215
		expect(featureProvider.getDiagramTypeProvider()).andReturn(diagramProvider);
215
		expect(featureProvider.getDiagramTypeProvider()).andReturn(diagramProvider);
216
		expect(featureProvider.getPeUtil()).andReturn(peUtil);
216
		expect(featureProvider.getPeServiceUtil()).andReturn(peServiceUtil);
217
		expect(featureProvider.getAddBendpointFeature(isA(IAddBendpointContext.class))).andStubReturn(ft);
217
		expect(featureProvider.getAddBendpointFeature(isA(IAddBendpointContext.class))).andStubReturn(ft);
218
		expect(context.getNewObject()).andReturn(relation);
218
		expect(context.getNewObject()).andReturn(relation);
219
219
Lines 255-261 Link Here
255
		gaUtil.setLocation(isA(Polyline.class), EasyMock.anyInt() , EasyMock.anyInt());
255
		gaUtil.setLocation(isA(Polyline.class), EasyMock.anyInt() , EasyMock.anyInt());
256
256
257
		FreeFormConnection connection = createConnection(startAnchor, endAnchor);
257
		FreeFormConnection connection = createConnection(startAnchor, endAnchor);
258
		expect(peUtil.createFreeFormConnection(diagram)).andReturn(connection);
258
		expect(peServiceUtil.createFreeFormConnection(diagram)).andReturn(connection);
259
		expect(imageCreator.createConnectionLine(diagram, connection)).andReturn(null);
259
		expect(imageCreator.createConnectionLine(diagram, connection)).andReturn(null);
260
		ft.addBendpoint(isA(IAddBendpointContext.class));
260
		ft.addBendpoint(isA(IAddBendpointContext.class));
261
		
261
		
Lines 320-326 Link Here
320
		replay(diagramProvider);
320
		replay(diagramProvider);
321
		replay(diagram);
321
		replay(diagram);
322
		replay(context);
322
		replay(context);
323
		replay(peUtil);
323
		replay(peServiceUtil);
324
		replay(gaUtil);
324
		replay(gaUtil);
325
		replay(ft);
325
		replay(ft);
326
		return new AddRelationFeature(featureProvider, imageCreator, jpaEditorUtil);
326
		return new AddRelationFeature(featureProvider, imageCreator, jpaEditorUtil);
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/DeleteRelationFeatureTest.java (-2 / +2 lines)
Lines 28-34 Link Here
28
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
28
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
29
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.DeleteRelationFeature;
29
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.DeleteRelationFeature;
30
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
30
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
31
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.BidirectionalRelation;
31
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IBidirectionalRelation;
32
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.IJPAEditorUtil;
32
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.IJPAEditorUtil;
33
import org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.util.IEditor;
33
import org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.util.IEditor;
34
import org.eclipse.ui.IWorkbenchPartSite;
34
import org.eclipse.ui.IWorkbenchPartSite;
Lines 45-51 Link Here
45
		IDeleteContext ctx = EasyMock.createMock(IDeleteContext.class);
45
		IDeleteContext ctx = EasyMock.createMock(IDeleteContext.class);
46
		PictogramElement pe = EasyMock.createMock(PictogramElement.class);
46
		PictogramElement pe = EasyMock.createMock(PictogramElement.class);
47
		expect(ctx.getPictogramElement()).andStubReturn(pe);
47
		expect(ctx.getPictogramElement()).andStubReturn(pe);
48
		BidirectionalRelation rel = EasyMock.createMock(BidirectionalRelation.class); 
48
		IBidirectionalRelation rel = EasyMock.createMock(IBidirectionalRelation.class); 
49
		ICompilationUnit cu1 = EasyMock.createMock(ICompilationUnit.class);
49
		ICompilationUnit cu1 = EasyMock.createMock(ICompilationUnit.class);
50
		ICompilationUnit cu2 = EasyMock.createMock(ICompilationUnit.class);
50
		ICompilationUnit cu2 = EasyMock.createMock(ICompilationUnit.class);
51
		JavaPersistentType jpt1 = EasyMock.createMock(JavaPersistentType.class);
51
		JavaPersistentType jpt1 = EasyMock.createMock(JavaPersistentType.class);
(-)src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/LayoutEntityFeatureTest.java (-1 / +1 lines)
Lines 45-51 Link Here
45
		EList<Shape> shList = new BasicInternalEList<Shape>(Shape.class); 
45
		EList<Shape> shList = new BasicInternalEList<Shape>(Shape.class); 
46
		EasyMock.expect(cs.getChildren()).andStubReturn(shList);
46
		EasyMock.expect(cs.getChildren()).andStubReturn(shList);
47
		IPeServiceUtil peUtil = EasyMock.createMock(IPeServiceUtil.class);
47
		IPeServiceUtil peUtil = EasyMock.createMock(IPeServiceUtil.class);
48
		EasyMock.expect(fp.getPeUtil()).andStubReturn(peUtil);
48
		EasyMock.expect(fp.getPeServiceUtil()).andStubReturn(peUtil);
49
		EasyMock.expect(peUtil.getProperty(cs, JPAEditorConstants.COLLAPSE_FEATURES)).andStubReturn(null);
49
		EasyMock.expect(peUtil.getProperty(cs, JPAEditorConstants.COLLAPSE_FEATURES)).andStubReturn(null);
50
		EasyMock.expect(peUtil.removeProperty(cs, JPAEditorConstants.COLLAPSE_FEATURES)).andStubReturn(false);
50
		EasyMock.expect(peUtil.removeProperty(cs, JPAEditorConstants.COLLAPSE_FEATURES)).andStubReturn(false);
51
		IGraphicsUpdater gu = EasyMock.createMock(IGraphicsUpdater.class);
51
		IGraphicsUpdater gu = EasyMock.createMock(IGraphicsUpdater.class);

Return to bug 334142