Lines 19-24
Link Here
|
19 |
import java.util.HashSet; |
19 |
import java.util.HashSet; |
20 |
import java.util.List; |
20 |
import java.util.List; |
21 |
|
21 |
|
|
|
22 |
import org.eclipse.emf.transaction.RecordingCommand; |
23 |
import org.eclipse.emf.transaction.TransactionalEditingDomain; |
24 |
import org.eclipse.emf.transaction.util.TransactionUtil; |
22 |
import org.eclipse.graphiti.features.IFeatureProvider; |
25 |
import org.eclipse.graphiti.features.IFeatureProvider; |
23 |
import org.eclipse.graphiti.features.context.IAddContext; |
26 |
import org.eclipse.graphiti.features.context.IAddContext; |
24 |
import org.eclipse.graphiti.features.impl.AbstractAddShapeFeature; |
27 |
import org.eclipse.graphiti.features.impl.AbstractAddShapeFeature; |
Lines 56-67
Link Here
|
56 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorPredefinedColoredAreas; |
59 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorPredefinedColoredAreas; |
57 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil; |
60 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil; |
58 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory; |
61 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory; |
|
|
62 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.Wrp; |
59 |
|
63 |
|
60 |
|
64 |
|
61 |
@SuppressWarnings({ "restriction" }) |
65 |
@SuppressWarnings({ "restriction" }) |
62 |
public class AddJPAEntityFeature extends AbstractAddShapeFeature { |
66 |
public class AddJPAEntityFeature extends AbstractAddShapeFeature { |
63 |
|
67 |
|
64 |
private IPeUtilFacade facade; |
|
|
65 |
private boolean shouldRearrangeIsARelations = true; |
68 |
private boolean shouldRearrangeIsARelations = true; |
66 |
private static ContainerShape primaryShape; |
69 |
private static ContainerShape primaryShape; |
67 |
private static ContainerShape relationShape; |
70 |
private static ContainerShape relationShape; |
Lines 71-82
Link Here
|
71 |
public AddJPAEntityFeature(IFeatureProvider fp, boolean shouldRearrangeIsARelations) { |
74 |
public AddJPAEntityFeature(IFeatureProvider fp, boolean shouldRearrangeIsARelations) { |
72 |
super(fp); |
75 |
super(fp); |
73 |
this.shouldRearrangeIsARelations = shouldRearrangeIsARelations; |
76 |
this.shouldRearrangeIsARelations = shouldRearrangeIsARelations; |
74 |
facade = new PeUtilFacade(); |
|
|
75 |
} |
77 |
} |
76 |
|
78 |
|
77 |
public AddJPAEntityFeature(IFeatureProvider fp, IPeUtilFacade facade) { |
79 |
public AddJPAEntityFeature(IFeatureProvider fp) { |
78 |
super(fp); |
80 |
super(fp); |
79 |
this.facade = facade; |
|
|
80 |
} |
81 |
} |
81 |
|
82 |
|
82 |
public boolean canAdd(IAddContext context) { |
83 |
public boolean canAdd(IAddContext context) { |
Lines 121-128
Link Here
|
121 |
return (IJPAEditorFeatureProvider) super.getFeatureProvider(); |
122 |
return (IJPAEditorFeatureProvider) super.getFeatureProvider(); |
122 |
} |
123 |
} |
123 |
|
124 |
|
124 |
public PictogramElement add(IAddContext context) { |
125 |
public PictogramElement add(final IAddContext context) { |
125 |
IJPAEditorFeatureProvider fp = getFeatureProvider(); |
126 |
final IJPAEditorFeatureProvider fp = getFeatureProvider(); |
126 |
Object newObj = context.getNewObject(); |
127 |
Object newObj = context.getNewObject(); |
127 |
JavaPersistentType jpt = null; |
128 |
JavaPersistentType jpt = null; |
128 |
if (newObj instanceof JavaPersistentType) { |
129 |
if (newObj instanceof JavaPersistentType) { |
Lines 136-173
Link Here
|
136 |
jpt = JPAEditorUtil.getJPType(cu); |
137 |
jpt = JPAEditorUtil.getJPType(cu); |
137 |
} |
138 |
} |
138 |
final Diagram targetDiagram = (Diagram) context.getTargetContainer(); |
139 |
final Diagram targetDiagram = (Diagram) context.getTargetContainer(); |
139 |
|
140 |
final Wrp wrp = new Wrp(); |
140 |
ContainerShape entityShape = facade.createContainerShape(targetDiagram, true); |
141 |
createEntity(context, fp, targetDiagram, wrp, jpt); |
141 |
|
142 |
return (PictogramElement) wrp.getObj(); |
142 |
JPAEditorConstants.DIAGRAM_OBJECT_TYPE dot = JpaArtifactFactory.instance().determineDiagramObjectType(jpt); |
143 |
} |
143 |
createEntityRectangle(context, entityShape, dot, |
|
|
144 |
this.getFeatureProvider().getDiagramTypeProvider().getDiagram()); |
145 |
link(entityShape, jpt); |
146 |
Shape shape = Graphiti.getPeService().createShape(entityShape, false); |
147 |
Polyline headerBottomLine = Graphiti.getGaService().createPolyline(shape, new int[] { 0, |
148 |
30, JPAEditorConstants.ENTITY_WIDTH, 30 }); |
149 |
headerBottomLine |
150 |
.setForeground(manageColor(JPAEditorConstants.ENTITY_BORDER_COLOR)); |
151 |
headerBottomLine.setLineWidth(JPAEditorConstants.ENTITY_BORDER_WIDTH); |
152 |
|
144 |
|
153 |
addHeader(jpt, entityShape, JPAEditorConstants.ENTITY_WIDTH, dot); |
145 |
private void createEntity(final IAddContext context, final IJPAEditorFeatureProvider fp, final Diagram targetDiagram, |
|
|
146 |
final Wrp wrp, final JavaPersistentType jpt) { |
154 |
|
147 |
|
155 |
createCompartments(context, jpt, entityShape); |
148 |
TransactionalEditingDomain ted = TransactionUtil.getEditingDomain(targetDiagram); |
156 |
fillCompartments(jpt,entityShape); |
|
|
157 |
|
149 |
|
158 |
String key = fp.getKeyForBusinessObject(jpt); |
150 |
ted.getCommandStack().execute(new RecordingCommand(ted) { |
159 |
if (fp.getBusinessObjectForKey(key) == null) |
151 |
protected void doExecute() { |
160 |
fp.putKeyToBusinessObject(key, jpt); |
|
|
161 |
|
152 |
|
162 |
Graphiti.getPeService().createChopboxAnchor(entityShape); |
153 |
ContainerShape entityShape = Graphiti.getPeService().createContainerShape(targetDiagram, true); |
163 |
entityShape.setVisible(true); |
|
|
164 |
layoutPictogramElement(entityShape); |
165 |
|
154 |
|
166 |
UpdateAttributeFeature updateFeature = new UpdateAttributeFeature(fp); |
155 |
JPAEditorConstants.DIAGRAM_OBJECT_TYPE dot = JpaArtifactFactory.instance().determineDiagramObjectType(jpt); |
167 |
updateFeature.reconnect(jpt); |
156 |
createEntityRectangle(context, entityShape, dot, fp.getDiagramTypeProvider().getDiagram()); |
168 |
if (shouldRearrangeIsARelations) |
157 |
link(entityShape, jpt); |
169 |
JpaArtifactFactory.instance().rearrangeIsARelations(getFeatureProvider()); |
158 |
Shape shape = Graphiti.getPeService().createShape(entityShape, false); |
170 |
return entityShape; |
159 |
Polyline headerBottomLine = Graphiti.getGaService() |
|
|
160 |
.createPolyline(shape, new int[] { 0, 30, JPAEditorConstants.ENTITY_WIDTH, 30 }); |
161 |
headerBottomLine.setForeground(manageColor(JPAEditorConstants.ENTITY_BORDER_COLOR)); |
162 |
headerBottomLine.setLineWidth(JPAEditorConstants.ENTITY_BORDER_WIDTH); |
163 |
|
164 |
addHeader(jpt, entityShape, JPAEditorConstants.ENTITY_WIDTH, dot); |
165 |
|
166 |
createCompartments(context, jpt, entityShape); |
167 |
fillCompartments(jpt, entityShape); |
168 |
|
169 |
String key = fp.getKeyForBusinessObject(jpt); |
170 |
if (fp.getBusinessObjectForKey(key) == null) |
171 |
fp.putKeyToBusinessObject(key, jpt); |
172 |
|
173 |
Graphiti.getPeService().createChopboxAnchor(entityShape); |
174 |
entityShape.setVisible(true); |
175 |
layoutPictogramElement(entityShape); |
176 |
|
177 |
UpdateAttributeFeature updateFeature = new UpdateAttributeFeature(fp); |
178 |
updateFeature.reconnect(jpt); |
179 |
if (shouldRearrangeIsARelations) |
180 |
JpaArtifactFactory.instance().rearrangeIsARelations(getFeatureProvider()); |
181 |
wrp.setObj(entityShape); |
182 |
} |
183 |
}); |
171 |
} |
184 |
} |
172 |
|
185 |
|
173 |
private void createCompartments(IAddContext context, JavaPersistentType jpt, |
186 |
private void createCompartments(IAddContext context, JavaPersistentType jpt, |
Lines 295-304
Link Here
|
295 |
} |
308 |
} |
296 |
} |
309 |
} |
297 |
|
310 |
|
298 |
public interface IPeUtilFacade { |
|
|
299 |
public ContainerShape createContainerShape(Diagram diagram, boolean b); |
300 |
} |
301 |
|
302 |
public static RoundedRectangle createEntityRectangle(IAddContext context, |
311 |
public static RoundedRectangle createEntityRectangle(IAddContext context, |
303 |
ContainerShape entityShape, |
312 |
ContainerShape entityShape, |
304 |
JPAEditorConstants.DIAGRAM_OBJECT_TYPE dot, |
313 |
JPAEditorConstants.DIAGRAM_OBJECT_TYPE dot, |
Lines 327-339
Link Here
|
327 |
: context.getHeight()); |
336 |
: context.getHeight()); |
328 |
return entityRectangle; |
337 |
return entityRectangle; |
329 |
} |
338 |
} |
330 |
|
339 |
|
331 |
private static class PeUtilFacade implements IPeUtilFacade { |
|
|
332 |
public ContainerShape createContainerShape(Diagram diagram, boolean b) { |
333 |
return Graphiti.getPeService().createContainerShape(diagram, true); |
334 |
} |
335 |
} |
336 |
|
337 |
private ContainerShape addHeader(JavaPersistentType addedWrapper, |
340 |
private ContainerShape addHeader(JavaPersistentType addedWrapper, |
338 |
ContainerShape entityShape, |
341 |
ContainerShape entityShape, |
339 |
int width, |
342 |
int width, |