diff options
| author | Christian W. Damus | 2016-07-05 21:29:02 +0000 |
|---|---|---|
| committer | Christian W. Damus | 2016-07-05 22:50:13 +0000 |
| commit | 74f8d20230a92668b9f4564fcf00906809e07c88 (patch) | |
| tree | eaaaf097373853fd81865c250c7d2b984d7ec2a4 | |
| parent | 80b6288c1b031c8e95e0b8f46548cab4c4cf45a7 (diff) | |
| download | org.eclipse.papyrus-74f8d20230a92668b9f4564fcf00906809e07c88.tar.gz org.eclipse.papyrus-74f8d20230a92668b9f4564fcf00906809e07c88.tar.xz org.eclipse.papyrus-74f8d20230a92668b9f4564fcf00906809e07c88.zip | |
Bug 497342: [ControlMode] LoadResourceSnippet makes changes without a transaction
https://bugs.eclipse.org/bugs/show_bug.cgi?id=497342
Don't attempt to execute a command that records no changes.
Change-Id: I32f41f1ce28637f20268e036dc9eea7cdb94ca66
(cherry picked from commit 71ea8394cfc80ef8c2f7f6c2f35ff902be153c75)
2 files changed, 56 insertions, 26 deletions
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/commands/LoadDiagramCommand.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/commands/LoadDiagramCommand.java index 4c7b74f71f9..9294831ddf4 100644 --- a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/commands/LoadDiagramCommand.java +++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/commands/LoadDiagramCommand.java @@ -8,7 +8,7 @@ *
* Contributors:
* CEA LIST - Initial API and implementation
- * Christian W. Damus - bug 485220
+ * Christian W. Damus - bugs 485220, 497342
*
*****************************************************************************/
@@ -31,45 +31,66 @@ import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForResource; */
public class LoadDiagramCommand implements Runnable {
- private IPageManager pageManager;
+ private final IPageManager pageManager;
/**
* URI of the resource which the diagram is based on.
*/
- private URI uri;
+ private final URI uri;
/**
- * Constructor.
- *
+ * Initializes me as a no-op.
*/
public LoadDiagramCommand() {
- super();
+ this(null, null);
}
/**
- *
- * Constructor.
+ * Initializes me with a page manager inferred from the {@code resource}.
*
- * @param pageManager
- * @param uriOfDiagram
+ * @param resource
+ * the resource in which there may be diagrams for me to reload
+ * in the page manager
*/
public LoadDiagramCommand(Resource resource) {
+ this(resource, getPageManager(resource));
+ }
+
+ private static IPageManager getPageManager(Resource resource) {
+ IPageManager result = null;
try {
- pageManager = ServiceUtilsForResource.getInstance().getService(IPageManager.class, resource);
+ result = ServiceUtilsForResource.getInstance().getService(IPageManager.class, resource);
} catch (ServiceException e) {
// nothing to do
}
- this.uri = resource.getURI();
-
+ return result;
}
/**
- * @see org.eclipse.emf.common.command.CompoundCommand#execute()
+ * Initializes me.
*
+ * @param resource
+ * the resource in which there may be diagrams for me to reload
+ * in the page manager
+ * @param pageManager
+ * the page manager in which to reload them, or {@code null} if none
+ *
+ * @since 1.2
+ */
+ public LoadDiagramCommand(Resource resource, IPageManager pageManager) {
+ super();
+
+ this.pageManager = pageManager;
+ this.uri = resource.getURI();
+ }
+
+ /**
+ * Reloads hte pages associated with my resource, if any and if there is a
+ * page manager.
*/
public void run() {
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/listener/LoadResourceSnippet.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/listener/LoadResourceSnippet.java index a7847f05444..92f7d447de6 100644 --- a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/listener/LoadResourceSnippet.java +++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/listener/LoadResourceSnippet.java @@ -22,7 +22,10 @@ import org.eclipse.papyrus.infra.core.resource.IModelSetSnippet; import org.eclipse.papyrus.infra.core.resource.ModelSet; import org.eclipse.papyrus.infra.core.resource.ResourceAdapter; import org.eclipse.papyrus.infra.core.sasheditor.di.contentprovider.internal.PageManagerImpl; +import org.eclipse.papyrus.infra.core.sashwindows.di.service.IPageManager; +import org.eclipse.papyrus.infra.core.services.ServiceException; import org.eclipse.papyrus.infra.core.utils.TransactionHelper; +import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForResource; import org.eclipse.papyrus.infra.services.controlmode.commands.LoadDiagramCommand; @@ -67,21 +70,27 @@ public class LoadResourceSnippet implements IModelSetSnippet { */ private class LoadResourceAdapter extends ResourceAdapter { - /** - * @see org.eclipse.papyrus.infra.core.resource.ResourceAdapter#handleResourceLoaded(org.eclipse.emf.ecore.resource.Resource) - * - * @param resource - */ @Override protected void handleResourceLoaded(Resource resource) { - EditingDomain editingDomain = TransactionUtil.getEditingDomain(resource); - final LoadDiagramCommand loadCommand = new LoadDiagramCommand(resource); + IPageManager pageManager = null; + try { - TransactionHelper.run(editingDomain, loadCommand); - } catch (InterruptedException e) { - // Nothing to do - } catch (RollbackException e) { - // Nothing to do + pageManager = ServiceUtilsForResource.getInstance().getIPageManager(resource); + } catch (ServiceException e) { + // No editor. That's okay + } + + // If we have no page manager, then there's no editor and so nothing to do + if (pageManager != null) { + EditingDomain editingDomain = TransactionUtil.getEditingDomain(resource); + final LoadDiagramCommand loadCommand = new LoadDiagramCommand(resource, pageManager); + try { + TransactionHelper.run(editingDomain, loadCommand); + } catch (InterruptedException e) { + // Nothing to do + } catch (RollbackException e) { + // Nothing to do + } } } } |
