summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetya Sabeva2012-08-28 04:54:16 (EDT)
committerPetya Sabeva2012-08-28 04:54:16 (EDT)
commit9eafbee1fd7f91461baebe0b262a3dc41e7db514 (patch)
treeb41e3400c09c79897882e287a79fb7eaf083e97f
parent0c48289ad0c3a335b93ecf3da8e17f96121e0247 (diff)
downloadwebtools.dali-9eafbee1fd7f91461baebe0b262a3dc41e7db514.zip
webtools.dali-9eafbee1fd7f91461baebe0b262a3dc41e7db514.tar.gz
webtools.dali-9eafbee1fd7f91461baebe0b262a3dc41e7db514.tar.bz2
Trying to change the dali model synchronously,
using ProjectManager.execute(command, ExtendedCommandExecutor) Change-Id: I2d902635f3a3926f5b916eae13f20c7c562a8c3a
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/META-INF/MANIFEST.MF3
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JpaArtifactFactory.java67
2 files changed, 57 insertions, 13 deletions
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/META-INF/MANIFEST.MF b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/META-INF/MANIFEST.MF
index 80b1d02..142825a 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/META-INF/MANIFEST.MF
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/META-INF/MANIFEST.MF
@@ -28,7 +28,8 @@ Require-Bundle: org.eclipse.core.expressions;bundle-version="[3.4.0,4.0.0)",
org.eclipse.ui.views.properties.tabbed;bundle-version="[3.4.0,4.0.0)",
org.eclipse.wst.common.emf;bundle-version="[1.1.200,2.0.0)",
org.eclipse.wst.common.project.facet.core;bundle-version="[1.3.0,2.0.0)",
- org.eclipse.core.filesystem;bundle-version="1.3.100"
+ org.eclipse.core.filesystem;bundle-version="1.3.100",
+ org.eclipse.jpt.common.ui;bundle-version="1.2.0"
Export-Package: org.eclipse.jpt.jpadiagrameditor.ui.internal;x-internal:=true,
org.eclipse.jpt.jpadiagrameditor.ui.internal.dialog;x-internal:=true,
org.eclipse.jpt.jpadiagrameditor.ui.internal.facade;x-internal:=true,
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JpaArtifactFactory.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JpaArtifactFactory.java
index 8e3631b..9e90dbc 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JpaArtifactFactory.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JpaArtifactFactory.java
@@ -27,8 +27,10 @@ import java.util.ListIterator;
import java.util.Locale;
import java.util.Properties;
import java.util.Set;
+
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.emf.transaction.RecordingCommand;
@@ -59,9 +61,12 @@ import org.eclipse.jpt.common.core.resource.java.JavaResourceAttribute;
import org.eclipse.jpt.common.core.resource.java.JavaResourceCompilationUnit;
import org.eclipse.jpt.common.core.resource.java.JavaResourceType;
import org.eclipse.jpt.common.core.resource.java.NestableAnnotation;
+import org.eclipse.jpt.common.ui.internal.utility.SynchronousUiCommandExecutor;
+import org.eclipse.jpt.common.utility.command.Command;
import org.eclipse.jpt.common.utility.internal.iterables.SubListIterableWrapper;
import org.eclipse.jpt.jpa.core.JpaFile;
import org.eclipse.jpt.jpa.core.JpaProject;
+import org.eclipse.jpt.jpa.core.JpaProjectManager;
import org.eclipse.jpt.jpa.core.MappingKeys;
import org.eclipse.jpt.jpa.core.context.AttributeMapping;
import org.eclipse.jpt.jpa.core.context.Embeddable;
@@ -1466,20 +1471,24 @@ public class JpaArtifactFactory {
inverseJPAName = rel.getInverseAttributeName();
}
}
- ICompilationUnit cu = fp.getCompilationUnit(jpt);
- renameAttribute(cu, oldName, newName, fp, this.isMethodAnnotated(jpt));
- refreshEntityModel(fp, jpt);
+// ICompilationUnit cu = fp.getCompilationUnit(jpt);
+// renameAttribute(cu, oldName, newName, fp, this.isMethodAnnotated(jpt));
+// refreshEntityModel(fp, jpt);
+// JavaPersistentAttribute newAt = jpt.getAttributeNamed(newName);
+// if (newAt == null) {
+// //TODO this is wrong, should not need to do any of these updates or syncs.
+// //should be changing the dali model synchronously so that all the syncs/updates are completed
+// //take a look at the JpaProjectManager.execute(Command, ExtendedCommandExecutor)
+// jpt.getJavaResourceType().getJavaResourceCompilationUnit().synchronizeWithJavaSource();
+// jpt.update();
+// jpt.synchronizeWithResourceModel();
+// newAt = jpt.getAttributeNamed(newName);
+// }
+ Command renameAttr = new RenameAttributeCommand(jpt, oldName, newName, fp);
+ getJpaProjectManager().execute(renameAttr, SynchronousUiCommandExecutor.instance());
+
JavaPersistentAttribute newAt = jpt.getAttributeNamed(newName);
if (newAt == null) {
- //TODO this is wrong, should not need to do any of these updates or syncs.
- //should be changing the dali model synchronously so that all the syncs/updates are completed
- //take a look at the JpaProjectManager.execute(Command, ExtendedCommandExecutor)
- jpt.getJavaResourceType().getJavaResourceCompilationUnit().synchronizeWithJavaSource();
- jpt.update();
- jpt.synchronizeWithResourceModel();
- newAt = jpt.getAttributeNamed(newName);
- }
- if (newAt == null) {
JPADiagramEditorPlugin.logError("The attribute " + newName + " could not be resolved", new NullPointerException()); //$NON-NLS-1$ //$NON-NLS-2$
}
fp.addRemoveIgnore(jpt, oldAt.getName());
@@ -1513,6 +1522,40 @@ public class JpaArtifactFactory {
return newAt;
}
+
+ private class RenameAttributeCommand implements Command {
+
+ private JavaPersistentType jpt;
+ private String oldName;
+ private String newName;
+ private IJPAEditorFeatureProvider fp;
+
+
+ public RenameAttributeCommand(JavaPersistentType jpt, String oldName,
+ String newName, IJPAEditorFeatureProvider fp){
+
+ super();
+ this.jpt = jpt;
+ this.oldName = oldName;
+ this.newName = newName;
+ this.fp = fp;
+
+ }
+
+ public void execute() {
+ ICompilationUnit cu = this.fp.getCompilationUnit(this.jpt);
+ try {
+ renameAttribute(cu, this.oldName, this.newName, this.fp, isMethodAnnotated(this.jpt));
+ } catch (InterruptedException e) {
+ JPADiagramEditorPlugin.logError("Cannot rename attribute", e); //$NON-NLS-1$
+ }
+ }
+
+ }
+
+ private JpaProjectManager getJpaProjectManager() {
+ return (JpaProjectManager) ResourcesPlugin.getWorkspace().getAdapter(JpaProjectManager.class);
+ }
private void updateRelation(JavaPersistentType jpt,
IJPAEditorFeatureProvider fp, IRelation rel) {