Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWim Jongman2012-12-16 16:05:29 +0000
committerWim Jongman2012-12-16 16:05:29 +0000
commit1a2645bd31f382d3f0f412da962ef252ec1e9c65 (patch)
treeecfed47b85451e3c6e9816b1e1e522abd8894058
parent4ff5ab9f28d61738b38d756dc3e84b5f6eac923b (diff)
downloadorg.eclipse.e4.tools-1a2645bd31f382d3f0f412da962ef252ec1e9c65.tar.gz
org.eclipse.e4.tools-1a2645bd31f382d3f0f412da962ef252ec1e9c65.tar.xz
org.eclipse.e4.tools-1a2645bd31f382d3f0f412da962ef252ec1e9c65.zip
Let the resource change listener know that she herself caused the
resource change. This is solved by setting a flag in doSave. If the flag is set during the resource change then the model will not be reloaded which is good. bug 395174: Provide refactoring support for e4xmi files https://bugs.eclipse.org/bugs/show_bug.cgi?id=395174
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/ModelEditor.java23
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/wbm/ApplicationModelEditor.java49
2 files changed, 55 insertions, 17 deletions
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/ModelEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/ModelEditor.java
index 8062ac48..be541f72 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/ModelEditor.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/ModelEditor.java
@@ -310,6 +310,8 @@ public class ModelEditor {
private boolean mod1Down = false;
+ private boolean saving;
+
public ModelEditor(Composite composite, IEclipseContext context, IModelResource modelProvider, IProject project, final IResourcePool resourcePool) {
this.resourcePool = resourcePool;
this.modelProvider = modelProvider;
@@ -1213,11 +1215,28 @@ public class ModelEditor {
@Persist
public void doSave(@Optional IProgressMonitor monitor) {
- if (modelProvider.isSaveable()) {
- modelProvider.save();
+
+ try {
+ setSaving(true);
+ if (modelProvider.isSaveable()) {
+ modelProvider.save();
+ }
+ } finally {
+ setSaving(false);
}
}
+ private void setSaving(boolean saving) {
+ this.saving = saving;
+ }
+
+ /**
+ * @return true if the editor is currently in the progress of saving.
+ */
+ protected boolean isSaving() {
+ return saving;
+ }
+
@Focus
public void setFocus() {
if (clipboardHandler == null) {
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/wbm/ApplicationModelEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/wbm/ApplicationModelEditor.java
index bb9600d5..e05ca64d 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/wbm/ApplicationModelEditor.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/wbm/ApplicationModelEditor.java
@@ -13,6 +13,7 @@
******************************************************************************/
package org.eclipse.e4.tools.emf.ui.internal.wbm;
+import java.io.IOException;
import javax.annotation.PreDestroy;
import javax.inject.Inject;
import javax.inject.Named;
@@ -109,21 +110,15 @@ public class ApplicationModelEditor extends ModelEditor {
hidePart(true);
}
- // if (delta.getKind() == IResourceDelta.CHANGED) {
- // try {
- // resource.unload();
- // resource.load(null);
- // // must be done in ui thread because of databinding
- // sync.syncExec(new Runnable() {
- // public void run() {
- // getModelProvider().replaceRoot(resource.getContents().get(0));
- // // getModelProvider().save(); // avoids dirty state
- // }
- // });
- // } catch (IOException e) {
- // statusDialog(e);
- // }
- // }
+ // If the current model editor is causing this resource change event
+ // then skip the reload.
+ if (!isSaving()) {
+
+ // reload the model if the file has changed
+ if (delta.getKind() == IResourceDelta.CHANGED) {
+ reloadModel();
+ }
+ }
}
private void hidePart(boolean force) {
@@ -131,6 +126,12 @@ public class ApplicationModelEditor extends ModelEditor {
}
};
+ /**
+ * Shows an error dialog based on the passed exception. It should never
+ * occur but if it does, the user can report a problem.
+ *
+ * @param exc
+ */
protected void statusDialog(final Exception exc) {
try {
sync.syncExec(new Runnable() {
@@ -144,4 +145,22 @@ public class ApplicationModelEditor extends ModelEditor {
} catch (Exception e) {
}
}
+
+ /**
+ * Reload the model.
+ */
+ protected void reloadModel() {
+ try {
+ resource.unload();
+ resource.load(null);
+ // must be done in ui thread because of databinding
+ sync.syncExec(new Runnable() {
+ public void run() {
+ getModelProvider().replaceRoot(resource.getContents().get(0));
+ }
+ });
+ } catch (IOException e) {
+ statusDialog(e);
+ }
+ }
} \ No newline at end of file

Back to the top