Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian W. Damus2016-08-18 10:06:02 -0400
committerChristian W. Damus2016-08-18 14:32:46 -0400
commitd5dd02046b7fdbc1623aff18f3b020b5ed32e26c (patch)
tree180d4ba25902fe94236fe330c97adb041b9120d6 /plugins/infra/services
parent0a22a1df17f4546cac744f098832811068aa08a1 (diff)
downloadorg.eclipse.papyrus-d5dd02046b7fdbc1623aff18f3b020b5ed32e26c.tar.gz
org.eclipse.papyrus-d5dd02046b7fdbc1623aff18f3b020b5ed32e26c.tar.xz
org.eclipse.papyrus-d5dd02046b7fdbc1623aff18f3b020b5ed32e26c.zip
Bug 499661: Exception about missing write transaction when iterating over a potential unloaded model element
https://bugs.eclipse.org/bugs/show_bug.cgi?id=499661 The listener for loading of resources was still causing problems, triggering re-loading of editor pages in situations where it doesn't need to. Moreover, this listener was implemented in the wrong component: its purpose is solely to re-load an "unloaded resource" editor tab as created by the UI for the selective resource loading service. Therefore, it is this UI bundle that now provides the listener and this listener now further restricts its reload behaviour to the case only when the editor page being reloaded is one of the "unloaded resource" pages that it had created, itself. To maintain API compatibility, the LoadDiagramCommand, with its previous fixes, is retained in the control-mode bundle but is now deprecated. The listener snippet that used it is moved to the resource-loading service bundle (it was not API) along with a new implementation of the LoadDiagramCommand that is also not API. (cherry-picked from streams/2.0-maintenance) Change-Id: I06ebcd232fd07cdc64db5a5b371940020716ac36
Diffstat (limited to 'plugins/infra/services')
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/plugin.xml7
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/commands/LoadDiagramCommand.java6
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading.ui/.classpath2
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading.ui/.settings/org.eclipse.jdt.core.prefs6
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading.ui/META-INF/MANIFEST.MF4
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading.ui/plugin.xml7
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading.ui/pom.xml2
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading.ui/src/org/eclipse/papyrus/infra/services/resourceloading/internal/ui/UIPlugin.java18
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading.ui/src/org/eclipse/papyrus/infra/services/resourceloading/internal/ui/editor/LoadDiagramCommand.java149
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading.ui/src/org/eclipse/papyrus/infra/services/resourceloading/internal/ui/editor/LoadResourceSnippet.java (renamed from plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/listener/LoadResourceSnippet.java)17
10 files changed, 183 insertions, 35 deletions
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/plugin.xml b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/plugin.xml
index 0d3cd935be1..f1264b55313 100644
--- a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/plugin.xml
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/plugin.xml
@@ -39,13 +39,6 @@
startKind="startup">
</serviceFactory>
</extension>
- <extension
- point="org.eclipse.papyrus.infra.core.model">
- <modelSetSnippet
- classname="org.eclipse.papyrus.infra.services.controlmode.listener.LoadResourceSnippet"
- description="Snippet to attach listener on the resourceSet">
- </modelSetSnippet>
- </extension>
<extension
point="org.eclipse.ui.commands">
<command
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 0a0dddc9e5e..4288417f4b1 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 - bugs 485220, 497342, 498414
+ * Christian W. Damus - bugs 485220, 497342, 498414, 499661
*
*****************************************************************************/
@@ -29,8 +29,10 @@ import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForResource;
* Command to load the diagram related to a resource URI
*
* @author Céline JANSSENS
- *
+ *
+ * @deprecated As of version 1.3, this class is no longer used by the Control-Mode framework.
*/
+@Deprecated
public class LoadDiagramCommand implements Runnable {
private final IPageManager pageManager;
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading.ui/.classpath b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading.ui/.classpath
index 64c5e31b7a2..eca7bdba8f0 100644
--- a/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading.ui/.classpath
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading.ui/.classpath
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading.ui/.settings/org.eclipse.jdt.core.prefs b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading.ui/.settings/org.eclipse.jdt.core.prefs
index c585cc455ae..b3aa6d60f94 100644
--- a/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading.ui/.settings/org.eclipse.jdt.core.prefs
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading.ui/.settings/org.eclipse.jdt.core.prefs
@@ -1,10 +1,10 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
-org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.source=1.5
+org.eclipse.jdt.core.compiler.source=1.8
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading.ui/META-INF/MANIFEST.MF b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading.ui/META-INF/MANIFEST.MF
index ccf8f10f335..4008fabaf41 100644
--- a/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading.ui/META-INF/MANIFEST.MF
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading.ui/META-INF/MANIFEST.MF
@@ -7,13 +7,13 @@ Require-Bundle: org.eclipse.emf.common.ui;bundle-version="[2.10.0,3.0.0)",
org.eclipse.gmf.runtime.notation;bundle-version="[1.8.0,2.0.0)"
Bundle-Vendor: %providerName
Bundle-ActivationPolicy: lazy
-Bundle-Version: 1.2.0.qualifier
+Bundle-Version: 1.2.100.qualifier
Bundle-Localization: plugin
Bundle-Name: %pluginName
Bundle-Activator: org.eclipse.papyrus.infra.services.resourceloading.internal.ui.UIPlugin
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.eclipse.papyrus.infra.services.resourceloading.ui;singleton:=true
-Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Export-Package: org.eclipse.papyrus.infra.services.resourceloading.internal.ui;x-internal:=true,
org.eclipse.papyrus.infra.services.resourceloading.internal.ui.editor;x-internal:=true,
org.eclipse.papyrus.infra.services.resourceloading.internal.ui.expressions;x-internal:=true,
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading.ui/plugin.xml b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading.ui/plugin.xml
index 9e41302230d..c226431d516 100644
--- a/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading.ui/plugin.xml
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading.ui/plugin.xml
@@ -68,4 +68,11 @@
type="org.eclipse.jface.viewers.IStructuredSelection">
</propertyTester>
</extension>
+ <extension
+ point="org.eclipse.papyrus.infra.core.model">
+ <modelSetSnippet
+ classname="org.eclipse.papyrus.infra.services.resourceloading.internal.ui.editor.LoadResourceSnippet"
+ description="Snippet handling unresolved editor pages when resources are loaded.">
+ </modelSetSnippet>
+ </extension>
</plugin>
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading.ui/pom.xml b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading.ui/pom.xml
index 1d40d989c48..6ed755844dc 100644
--- a/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading.ui/pom.xml
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading.ui/pom.xml
@@ -7,6 +7,6 @@
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>org.eclipse.papyrus.infra.services.resourceloading.ui</artifactId>
- <version>1.2.0-SNAPSHOT</version>
+ <version>1.2.100-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading.ui/src/org/eclipse/papyrus/infra/services/resourceloading/internal/ui/UIPlugin.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading.ui/src/org/eclipse/papyrus/infra/services/resourceloading/internal/ui/UIPlugin.java
index 91d892f23fc..c32e4ecdcb4 100644
--- a/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading.ui/src/org/eclipse/papyrus/infra/services/resourceloading/internal/ui/UIPlugin.java
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading.ui/src/org/eclipse/papyrus/infra/services/resourceloading/internal/ui/UIPlugin.java
@@ -8,11 +8,12 @@
*
* Contributors:
* Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
- * Christian W. Damus - bug 485220
+ * Christian W. Damus - bugs 485220, 499661
*
*****************************************************************************/
package org.eclipse.papyrus.infra.services.resourceloading.internal.ui;
+import org.eclipse.papyrus.infra.core.log.LogHelper;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
@@ -27,28 +28,23 @@ public class UIPlugin extends AbstractUIPlugin {
// The shared instance
private static UIPlugin plugin;
+ /** The logging facade. */
+ public static LogHelper log;
+
/**
* The constructor
*/
public UIPlugin() {
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)
- */
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
+
plugin = this;
+ log = new LogHelper(this);
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
- */
@Override
public void stop(BundleContext context) throws Exception {
plugin = null;
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading.ui/src/org/eclipse/papyrus/infra/services/resourceloading/internal/ui/editor/LoadDiagramCommand.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading.ui/src/org/eclipse/papyrus/infra/services/resourceloading/internal/ui/editor/LoadDiagramCommand.java
new file mode 100644
index 00000000000..499a447bf5f
--- /dev/null
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading.ui/src/org/eclipse/papyrus/infra/services/resourceloading/internal/ui/editor/LoadDiagramCommand.java
@@ -0,0 +1,149 @@
+/*****************************************************************************
+ * Copyright (c) 2014, 2016 CEA LIST, Christian W. Damus, and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ * Christian W. Damus - bugs 485220, 497342, 498414, 499661
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.services.resourceloading.internal.ui.editor;
+
+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;
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageModel;
+import org.eclipse.papyrus.infra.core.sasheditor.di.contentprovider.utils.IPageUtils;
+import org.eclipse.papyrus.infra.core.sasheditor.editor.IPage;
+import org.eclipse.papyrus.infra.core.sasheditor.editor.ISashWindowsContainer;
+import org.eclipse.papyrus.infra.core.sashwindows.di.service.IPageManager;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForResource;
+import org.eclipse.papyrus.infra.tools.util.PlatformHelper;
+
+
+/**
+ * Command to load the diagram related to a resource URI
+ *
+ * @author Céline JANSSENS
+ *
+ */
+class LoadDiagramCommand implements Runnable {
+
+ private final IPageManager pageManager;
+ private final ISashWindowsContainer sashContainer;
+
+ /**
+ * URI of the resource which the diagram is based on.
+ */
+ private final URI uri;
+
+ /**
+ * Initializes me with a page manager and sash-windows container inferred
+ * from the {@code resource}.
+ *
+ * @param resource
+ * the resource in which there may be diagrams for me to reload
+ * in the page manager
+ */
+ public LoadDiagramCommand(Resource resource) {
+ this(resource,
+ getService(resource, IPageManager.class),
+ getService(resource, ISashWindowsContainer.class));
+ }
+
+ private static <S> S getService(Resource resource, Class<S> serviceAPI) {
+ S result = null;
+
+ try {
+ result = ServiceUtilsForResource.getInstance().getService(serviceAPI, resource);
+ } catch (ServiceException e) {
+ // nothing to do
+ }
+
+ return result;
+ }
+
+ /**
+ * 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
+ * @param sashContainer
+ * the sash windows container in which to reload them, or {@code null} if none
+ */
+ public LoadDiagramCommand(Resource resource, IPageManager pageManager, ISashWindowsContainer sashContainer) {
+ super();
+
+ this.pageManager = pageManager;
+ this.sashContainer = sashContainer;
+ this.uri = resource.getURI();
+ }
+
+ /**
+ * Reloads hte pages associated with my resource, if any and if there is a
+ * page manager.
+ */
+ @Override
+ public void run() {
+ List<?> pagesToReload = getPagesToReload();
+ if (!pagesToReload.isEmpty()) {
+ pagesToReload.forEach(pageManager::reloadPage);
+ }
+ }
+
+ /**
+ * 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() {
+ List<?> pages = getPagesToReload();
+ return !pages.isEmpty() && pages.stream().allMatch(this::needsReload);
+ }
+
+ 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;
+ }
+
+ private boolean needsReload(Object pageIdentifier) {
+ boolean result = false;
+
+ if (sashContainer != null) {
+ IPage page = IPageUtils.lookupModelPage(sashContainer, pageIdentifier);
+
+ // If there is no page, it needn't be re-loaded
+ result = (page != null) && isUnloadedResourcePage(page);
+ }
+
+ return result;
+ }
+
+ private boolean isUnloadedResourcePage(IPage page) {
+ IPageModel model = PlatformHelper.getAdapter(page, IPageModel.class);
+ return (model != null) && (model instanceof UnloadResourcesEditorModel);
+ }
+}
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.resourceloading.ui/src/org/eclipse/papyrus/infra/services/resourceloading/internal/ui/editor/LoadResourceSnippet.java
index 89a1a26751f..039cacc4bf0 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.resourceloading.ui/src/org/eclipse/papyrus/infra/services/resourceloading/internal/ui/editor/LoadResourceSnippet.java
@@ -12,7 +12,7 @@
*
*****************************************************************************/
-package org.eclipse.papyrus.infra.services.controlmode.listener;
+package org.eclipse.papyrus.infra.services.resourceloading.internal.ui.editor;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.edit.domain.EditingDomain;
@@ -21,13 +21,12 @@ import org.eclipse.emf.transaction.util.TransactionUtil;
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.sasheditor.editor.ISashWindowsContainer;
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;
+import org.eclipse.papyrus.infra.services.resourceloading.internal.ui.UIPlugin;
/**
@@ -66,7 +65,7 @@ public class LoadResourceSnippet implements IModelSetSnippet {
/**
* This Adapter allows to load associated pages of the resources.
- * It uses {@link LoadingPagesHandler} to do so with the help of the {@link PageManagerImpl}.
+ * It uses {@link LoadDiagramCommand} to do so with the help of the {@link IPageManager}.
*
* @author Céline JANSSENS
*
@@ -76,9 +75,11 @@ public class LoadResourceSnippet implements IModelSetSnippet {
@Override
protected void handleResourceLoaded(Resource resource) {
IPageManager pageManager = null;
+ ISashWindowsContainer sashContainer = null;
try {
pageManager = ServiceUtilsForResource.getInstance().getIPageManager(resource);
+ sashContainer = ServiceUtilsForResource.getInstance().getService(ISashWindowsContainer.class, resource);
} catch (ServiceException e) {
// No editor. That's okay
}
@@ -86,7 +87,7 @@ public class LoadResourceSnippet implements IModelSetSnippet {
// 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);
+ final LoadDiagramCommand loadCommand = new LoadDiagramCommand(resource, pageManager, sashContainer);
// Nor is there anything to do if we have no diagrams to reload
if (loadCommand.canExecute()) {
@@ -94,10 +95,10 @@ public class LoadResourceSnippet implements IModelSetSnippet {
TransactionHelper.run(editingDomain, loadCommand);
} catch (InterruptedException e) {
// Nothing to do
- ControlModePlugin.log.error(e);
+ UIPlugin.log.error(e);
} catch (RollbackException e) {
// Nothing to do
- ControlModePlugin.log.error(e);
+ UIPlugin.log.error(e);
}
}
}

Back to the top