Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian W. Damus2016-07-25 08:53:08 -0400
committerChristian W. Damus2016-07-25 09:35:52 -0400
commit538414e9a14f42b9e6c81eeb7b32d9827cbd295c (patch)
treec598b62620534417b68d4ef6b068a0fe1018ee0e /plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode
parentfdedf3cee58b53362ecb1078b8b45c6b8e7d353a (diff)
downloadorg.eclipse.papyrus-538414e9a14f42b9e6c81eeb7b32d9827cbd295c.tar.gz
org.eclipse.papyrus-538414e9a14f42b9e6c81eeb7b32d9827cbd295c.tar.xz
org.eclipse.papyrus-538414e9a14f42b9e6c81eeb7b32d9827cbd295c.zip
Bug 498414: [Profile] Profile are corrupt at the reopen
https://bugs.eclipse.org/bugs/show_bug.cgi?id=498414 Don't attempt to start a write transaction for the re-loading of diagram editors when there are no such editors needing re-loading. Change-Id: Ic978c3fbceb6f868a2236829a36927b6f6c288c3 (cherry picked from commit 8c0b2fc558860628f7492d7079765cea61ad3819)
Diffstat (limited to 'plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode')
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/commands/LoadDiagramCommand.java42
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/listener/LoadResourceSnippet.java23
2 files changed, 46 insertions, 19 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 d0722c26f73..0a0dddc9e5e 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,13 +8,15 @@
*
* Contributors:
* CEA LIST - Initial API and implementation
- * Christian W. Damus - bugs 485220, 497342
+ * Christian W. Damus - bugs 485220, 497342, 498414
*
*****************************************************************************/
package org.eclipse.papyrus.infra.services.controlmode.commands;
+import java.util.Collections;
import java.util.List;
+import java.util.Objects;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
@@ -94,19 +96,35 @@ public class LoadDiagramCommand implements Runnable {
*/
@Override
public void run() {
+ List<?> pagesToReload = getPagesToReload();
+ if (!pagesToReload.isEmpty()) {
+ pagesToReload.forEach(pageManager::reloadPage);
+ }
+
+ }
- if (pageManager != null) {
- URI uriTrimResource = uri.trimFragment().trimFileExtension();
- // retrieve open pages related to this URI
- List<Object> pagesID = pageManager.getAssociatedPages(uriTrimResource);
- if (pagesID.size() > 0) {
- for (Object pageID : pagesID) {
- if (pageID != null) {
- pageManager.reloadPage(pageID);
- }
- }
- }
+ /**
+ * Queries whether I have any pages to reload. If I have none to reload,
+ * then I don't need to be executed.
+ *
+ * @return whether I have any pages to reload
+ * @since 1.3
+ */
+ public boolean canExecute() {
+ return !getPagesToReload().isEmpty();
+ }
+
+ private List<?> getPagesToReload() {
+ List<?> result;
+
+ if (pageManager == null) {
+ result = Collections.EMPTY_LIST;
+ } else {
+ // Retrieve open pages related to our URI (in the abstract, without extension)
+ result = pageManager.getAssociatedPages(uri.trimFragment().trimFileExtension());
+ result.removeIf(Objects::isNull);
}
+ return result;
}
}
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 92f7d447de6..89a1a26751f 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
@@ -8,7 +8,7 @@
*
* Contributors:
* CĂ©line Janssens (ALL4TEC) celine.janssens@all4tec.net - Initial API and implementation
- * Christian W. Damus - bugs 485220, 497342
+ * Christian W. Damus - bugs 485220, 497342, 498414
*
*****************************************************************************/
@@ -26,6 +26,7 @@ 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.ControlModePlugin;
import org.eclipse.papyrus.infra.services.controlmode.commands.LoadDiagramCommand;
@@ -44,6 +45,7 @@ public class LoadResourceSnippet implements IModelSetSnippet {
*
* @param startingModel
*/
+ @Override
public void start(ModelSet startingModel) {
adapter = new LoadResourceAdapter();
startingModel.eAdapters().add(adapter);
@@ -55,6 +57,7 @@ public class LoadResourceSnippet implements IModelSetSnippet {
*
* @param stoppingModel
*/
+ @Override
public void dispose(ModelSet stoppingModel) {
stoppingModel.eAdapters().remove(adapter);
adapter = null;
@@ -84,12 +87,18 @@ public class LoadResourceSnippet implements IModelSetSnippet {
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
+
+ // Nor is there anything to do if we have no diagrams to reload
+ if (loadCommand.canExecute()) {
+ try {
+ TransactionHelper.run(editingDomain, loadCommand);
+ } catch (InterruptedException e) {
+ // Nothing to do
+ ControlModePlugin.log.error(e);
+ } catch (RollbackException e) {
+ // Nothing to do
+ ControlModePlugin.log.error(e);
+ }
}
}
}

Back to the top