diff options
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 |