### Eclipse Workspace Patch 1.0 #P org.eclipse.jpt.jpadiagrameditor.ui Index: src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddJPAEntityFeature.java =================================================================== RCS file: /cvsroot/webtools/org.eclipse.jpa/components/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddJPAEntityFeature.java,v retrieving revision 1.10 diff -u -r1.10 AddJPAEntityFeature.java --- src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddJPAEntityFeature.java 15 May 2012 17:39:12 -0000 1.10 +++ src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddJPAEntityFeature.java 28 May 2012 14:45:42 -0000 @@ -19,6 +19,9 @@ import java.util.HashSet; import java.util.List; +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.emf.transaction.util.TransactionUtil; import org.eclipse.graphiti.features.IFeatureProvider; import org.eclipse.graphiti.features.context.IAddContext; import org.eclipse.graphiti.features.impl.AbstractAddShapeFeature; @@ -56,12 +59,12 @@ import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorPredefinedColoredAreas; import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil; import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory; +import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.Wrp; @SuppressWarnings({ "restriction" }) public class AddJPAEntityFeature extends AbstractAddShapeFeature { - private IPeUtilFacade facade; private boolean shouldRearrangeIsARelations = true; private static ContainerShape primaryShape; private static ContainerShape relationShape; @@ -71,12 +74,10 @@ public AddJPAEntityFeature(IFeatureProvider fp, boolean shouldRearrangeIsARelations) { super(fp); this.shouldRearrangeIsARelations = shouldRearrangeIsARelations; - facade = new PeUtilFacade(); } - public AddJPAEntityFeature(IFeatureProvider fp, IPeUtilFacade facade) { + public AddJPAEntityFeature(IFeatureProvider fp) { super(fp); - this.facade = facade; } public boolean canAdd(IAddContext context) { @@ -121,8 +122,8 @@ return (IJPAEditorFeatureProvider) super.getFeatureProvider(); } - public PictogramElement add(IAddContext context) { - IJPAEditorFeatureProvider fp = getFeatureProvider(); + public PictogramElement add(final IAddContext context) { + final IJPAEditorFeatureProvider fp = getFeatureProvider(); Object newObj = context.getNewObject(); JavaPersistentType jpt = null; if (newObj instanceof JavaPersistentType) { @@ -136,38 +137,50 @@ jpt = JPAEditorUtil.getJPType(cu); } final Diagram targetDiagram = (Diagram) context.getTargetContainer(); - - ContainerShape entityShape = facade.createContainerShape(targetDiagram, true); - - JPAEditorConstants.DIAGRAM_OBJECT_TYPE dot = JpaArtifactFactory.instance().determineDiagramObjectType(jpt); - createEntityRectangle(context, entityShape, dot, - this.getFeatureProvider().getDiagramTypeProvider().getDiagram()); - link(entityShape, jpt); - Shape shape = Graphiti.getPeService().createShape(entityShape, false); - Polyline headerBottomLine = Graphiti.getGaService().createPolyline(shape, new int[] { 0, - 30, JPAEditorConstants.ENTITY_WIDTH, 30 }); - headerBottomLine - .setForeground(manageColor(JPAEditorConstants.ENTITY_BORDER_COLOR)); - headerBottomLine.setLineWidth(JPAEditorConstants.ENTITY_BORDER_WIDTH); + final Wrp wrp = new Wrp(); + createEntity(context, fp, targetDiagram, wrp, jpt); + return (PictogramElement) wrp.getObj(); + } - addHeader(jpt, entityShape, JPAEditorConstants.ENTITY_WIDTH, dot); + private void createEntity(final IAddContext context, final IJPAEditorFeatureProvider fp, final Diagram targetDiagram, + final Wrp wrp, final JavaPersistentType jpt) { - createCompartments(context, jpt, entityShape); - fillCompartments(jpt,entityShape); + TransactionalEditingDomain ted = TransactionUtil.getEditingDomain(targetDiagram); - String key = fp.getKeyForBusinessObject(jpt); - if (fp.getBusinessObjectForKey(key) == null) - fp.putKeyToBusinessObject(key, jpt); + ted.getCommandStack().execute(new RecordingCommand(ted) { + protected void doExecute() { - Graphiti.getPeService().createChopboxAnchor(entityShape); - entityShape.setVisible(true); - layoutPictogramElement(entityShape); + ContainerShape entityShape = Graphiti.getPeService().createContainerShape(targetDiagram, true); - UpdateAttributeFeature updateFeature = new UpdateAttributeFeature(fp); - updateFeature.reconnect(jpt); - if (shouldRearrangeIsARelations) - JpaArtifactFactory.instance().rearrangeIsARelations(getFeatureProvider()); - return entityShape; + JPAEditorConstants.DIAGRAM_OBJECT_TYPE dot = JpaArtifactFactory.instance().determineDiagramObjectType(jpt); + createEntityRectangle(context, entityShape, dot, fp.getDiagramTypeProvider().getDiagram()); + link(entityShape, jpt); + Shape shape = Graphiti.getPeService().createShape(entityShape, false); + Polyline headerBottomLine = Graphiti.getGaService() + .createPolyline(shape, new int[] { 0, 30, JPAEditorConstants.ENTITY_WIDTH, 30 }); + headerBottomLine.setForeground(manageColor(JPAEditorConstants.ENTITY_BORDER_COLOR)); + headerBottomLine.setLineWidth(JPAEditorConstants.ENTITY_BORDER_WIDTH); + + addHeader(jpt, entityShape, JPAEditorConstants.ENTITY_WIDTH, dot); + + createCompartments(context, jpt, entityShape); + fillCompartments(jpt, entityShape); + + String key = fp.getKeyForBusinessObject(jpt); + if (fp.getBusinessObjectForKey(key) == null) + fp.putKeyToBusinessObject(key, jpt); + + Graphiti.getPeService().createChopboxAnchor(entityShape); + entityShape.setVisible(true); + layoutPictogramElement(entityShape); + + UpdateAttributeFeature updateFeature = new UpdateAttributeFeature(fp); + updateFeature.reconnect(jpt); + if (shouldRearrangeIsARelations) + JpaArtifactFactory.instance().rearrangeIsARelations(getFeatureProvider()); + wrp.setObj(entityShape); + } + }); } private void createCompartments(IAddContext context, JavaPersistentType jpt, @@ -295,10 +308,6 @@ } } - public interface IPeUtilFacade { - public ContainerShape createContainerShape(Diagram diagram, boolean b); - } - public static RoundedRectangle createEntityRectangle(IAddContext context, ContainerShape entityShape, JPAEditorConstants.DIAGRAM_OBJECT_TYPE dot, @@ -327,13 +336,7 @@ : context.getHeight()); return entityRectangle; } - - private static class PeUtilFacade implements IPeUtilFacade { - public ContainerShape createContainerShape(Diagram diagram, boolean b) { - return Graphiti.getPeService().createContainerShape(diagram, true); - } - } - + private ContainerShape addHeader(JavaPersistentType addedWrapper, ContainerShape entityShape, int width, Index: src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RemoveAndSaveEntityFeature.java =================================================================== RCS file: /cvsroot/webtools/org.eclipse.jpa/components/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RemoveAndSaveEntityFeature.java,v retrieving revision 1.2 diff -u -r1.2 RemoveAndSaveEntityFeature.java --- src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RemoveAndSaveEntityFeature.java 26 Mar 2012 13:54:58 -0000 1.2 +++ src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RemoveAndSaveEntityFeature.java 28 May 2012 14:45:42 -0000 @@ -20,7 +20,11 @@ import java.util.List; import java.util.Set; +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.emf.transaction.util.TransactionUtil; import org.eclipse.graphiti.features.IFeatureProvider; +import org.eclipse.graphiti.features.context.IContext; import org.eclipse.graphiti.features.context.IRemoveContext; import org.eclipse.graphiti.features.context.impl.RemoveContext; import org.eclipse.graphiti.features.impl.DefaultRemoveFeature; @@ -64,6 +68,23 @@ } } + public void execute(IContext context) { + if (!IRemoveContext.class.isInstance(context)) + return; + final IRemoveContext removeContext = (IRemoveContext)context; + PictogramElement pe = removeContext.getPictogramElement(); + TransactionalEditingDomain ted = TransactionUtil.getEditingDomain(pe); + ted.getCommandStack().execute(new RecordingCommand(ted) { + protected void doExecute() { + removeEntityFromDiagram(removeContext); + } + }); + } + + public void removeEntityFromDiagram(IRemoveContext context){ + super.remove(context); + } + public IJPAEditorFeatureProvider getFeatureProvider() { return (IJPAEditorFeatureProvider)super.getFeatureProvider(); } Index: src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RemoveJPAEntityFeature.java =================================================================== RCS file: /cvsroot/webtools/org.eclipse.jpa/components/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RemoveJPAEntityFeature.java,v retrieving revision 1.3 diff -u -r1.3 RemoveJPAEntityFeature.java --- src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RemoveJPAEntityFeature.java 26 Mar 2012 13:54:58 -0000 1.3 +++ src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RemoveJPAEntityFeature.java 28 May 2012 14:45:42 -0000 @@ -20,8 +20,12 @@ import java.util.List; import java.util.Set; +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.emf.transaction.util.TransactionUtil; import org.eclipse.graphiti.features.IFeatureProvider; import org.eclipse.graphiti.features.context.IContext; +import org.eclipse.graphiti.features.context.IDeleteContext; import org.eclipse.graphiti.features.context.IRemoveContext; import org.eclipse.graphiti.features.context.impl.RemoveContext; import org.eclipse.graphiti.features.impl.DefaultRemoveFeature; @@ -73,7 +77,7 @@ f.remove(ctx); } String name = ((PersistentType)bo).getName(); - getFeatureProvider().remove(name, true); + getFeatureProvider().remove(name, false); } } @@ -85,7 +89,7 @@ public void execute(IContext ctx) { if (!IRemoveContext.class.isInstance(ctx)) return; - IRemoveContext context = (IRemoveContext)ctx; + final IRemoveContext context = (IRemoveContext)ctx; PictogramElement pe = context.getPictogramElement(); Object bo = getFeatureProvider().getBusinessObjectForPictogramElement(pe); if (!JavaPersistentType.class.isInstance(bo)) @@ -105,9 +109,19 @@ if (dialog.open() != 0) return; } - super.execute(context); + TransactionalEditingDomain ted = TransactionUtil.getEditingDomain(pe); + ted.getCommandStack().execute(new RecordingCommand(ted) { + protected void doExecute() { + removeEntityFromDiagram(context); + } + }); + } + public void removeEntityFromDiagram(IRemoveContext context){ + super.execute(context); + } + public void postRemove(IRemoveContext context) { if (shouldRearrangeIsARelations) JpaArtifactFactory.instance().rearrangeIsARelations(getFeatureProvider()); Index: src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPASolver.java =================================================================== RCS file: /cvsroot/webtools/org.eclipse.jpa/components/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPASolver.java,v retrieving revision 1.8 diff -u -r1.8 JPASolver.java --- src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPASolver.java 26 Mar 2012 13:54:58 -0000 1.8 +++ src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPASolver.java 28 May 2012 14:45:42 -0000 @@ -1406,7 +1406,8 @@ PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { public void run() { IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); - if ((ModelIntegrationUtil.getProjectByDiagram(diagram.getName()).getProject()).equals(resource)) { + JpaProject jpaProject = ModelIntegrationUtil.getProjectByDiagram(diagram.getName()); + if (jpaProject != null && (jpaProject.getProject()).equals(resource)) { page.closeEditor(diagramBySelectedProject, false); } } Index: src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JpaArtifactFactory.java =================================================================== RCS file: /cvsroot/webtools/org.eclipse.jpa/components/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JpaArtifactFactory.java,v retrieving revision 1.19 diff -u -r1.19 JpaArtifactFactory.java --- src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JpaArtifactFactory.java 26 Mar 2012 13:54:58 -0000 1.19 +++ src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JpaArtifactFactory.java 28 May 2012 14:45:42 -0000 @@ -471,7 +471,7 @@ public void forceSaveEntityClass(final JavaPersistentType jpt, IJPAEditorFeatureProvider fp) { final ICompilationUnit cu = fp.getCompilationUnit(jpt); - Display.getDefault().asyncExec(new Runnable() { + Display.getDefault().syncExec(new Runnable() { public void run() { try { if (cu.isWorkingCopy())