Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian W. Damus2015-10-30 22:40:00 +0000
committerGerrit Code Review @ Eclipse.org2015-10-30 23:21:23 +0000
commit42be40ff6bcbe50ff50158f7884d6460938d4662 (patch)
tree87d7dedc27c618d81ba2458f02e2f401369828cd /plugins/infra/core
parentd17ead3770131535dcee4260403d31279d1893e1 (diff)
downloadorg.eclipse.papyrus-42be40ff6bcbe50ff50158f7884d6460938d4662.tar.gz
org.eclipse.papyrus-42be40ff6bcbe50ff50158f7884d6460938d4662.tar.xz
org.eclipse.papyrus-42be40ff6bcbe50ff50158f7884d6460938d4662.zip
Bug 481149: [ModelSet] Model snippets added after a model has loaded are never started
https://bugs.eclipse.org/bugs/show_bug.cgi?id=481149 Ensure that model snippets are started as soon as they are added, if the model has already been loaded. Also fix the omission of snippet starting on creation (not loading) of a new model.
Diffstat (limited to 'plugins/infra/core')
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/AbstractBaseModel.java13
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/AbstractDynamicModel.java18
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/AbstractModel.java32
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/IModel.java7
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/additional/AdditionalResourcesModel.java10
5 files changed, 63 insertions, 17 deletions
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/AbstractBaseModel.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/AbstractBaseModel.java
index c9b798632be..b93d8b805e3 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/AbstractBaseModel.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/AbstractBaseModel.java
@@ -1,6 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2010, 2014 CEA LIST, Christian W. Damus, and others.
- *
+ * Copyright (c) 2010, 2015 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
@@ -12,6 +11,7 @@
* Christian W. Damus (CEA) - manage models by URI, not IFile (CDO)
* Christian W. Damus (CEA) - bug 437052
* Christian W. Damus - bug 399859
+ * Christian W. Damus - bug 481149
*
*****************************************************************************/
package org.eclipse.papyrus.infra.core.resource;
@@ -35,7 +35,7 @@ import org.eclipse.emf.ecore.xmi.impl.URIHandlerImpl.PlatformSchemeAware;
import org.eclipse.papyrus.infra.core.Activator;
/**
- * An abstract implmeentation of model. This class should be subclassed to fit
+ * An abstract implementation of model. This class should be subclassed to fit
* the required model.
*
* @author cedric dumoulin
@@ -124,6 +124,9 @@ public abstract class AbstractBaseModel extends AbstractModel implements IVersio
resource = getModelManager().createResource(resourceURI);
}
configureResource(resource);
+
+ // And start snippets
+ startSnippets();
}
protected void configureResource(Resource resource) {
@@ -186,7 +189,7 @@ public abstract class AbstractBaseModel extends AbstractModel implements IVersio
configureResource(resource);
// call registered snippets
- snippets.performStart(this);
+ startSnippets();
}
/**
@@ -257,7 +260,7 @@ public abstract class AbstractBaseModel extends AbstractModel implements IVersio
@Override
public void unload() {
// call registered snippets
- snippets.performDispose(this);
+ stopSnippets();
// Do unloading
if (resource != null) {
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/AbstractDynamicModel.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/AbstractDynamicModel.java
index 9a2097107a2..fcecfdd5e32 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/AbstractDynamicModel.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/AbstractDynamicModel.java
@@ -1,6 +1,17 @@
-/**
+/*****************************************************************************
+ * Copyright (c) 2010, 2015 LIFL, 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:
+ * LIFL - Initial API and implementation
+ * Christian W. Damus - bug 481149
+ *
+ *****************************************************************************/
+
package org.eclipse.papyrus.infra.core.resource;
import java.io.IOException;
@@ -56,8 +67,9 @@ public abstract class AbstractDynamicModel<T extends EObject> extends AbstractBa
}
// The resource do not exist, crate it.
createModel(fullPathWithoutExtension);
+
// call registered snippets
- snippets.performStart(this);
+ startSnippets();
}
/**
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/AbstractModel.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/AbstractModel.java
index 4d9940c47a5..a11561b9a58 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/AbstractModel.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/AbstractModel.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
+ * Copyright (c) 2013, 2015 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
@@ -9,6 +9,7 @@
* Contributors:
* Remi Schnekenburger (CEA LIST) - Initial API and implementation
* Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Bug 436952
+ * Christian W. Damus - bug 481149
*
*****************************************************************************/
package org.eclipse.papyrus.infra.core.resource;
@@ -33,6 +34,8 @@ public abstract class AbstractModel implements IModel {
/** List of attached snippets */
protected ModelSnippetList snippets = new ModelSnippetList();
+ private boolean snippetsStarted;
+
/** list of Models (referenced by identifiers) that should be loaded before this one can be loaded */
protected List<String> afterLoadModelIdentifiers;
@@ -76,7 +79,10 @@ public abstract class AbstractModel implements IModel {
*/
@Override
public void addModelSnippet(IModelSnippet snippet) {
- snippets.add(snippet);
+ if (snippets.add(snippet) && snippetsStarted) {
+ // Snippets have already started, so start this one, too
+ snippet.start(this);
+ }
}
/**
@@ -114,6 +120,8 @@ public abstract class AbstractModel implements IModel {
@Override
public void unload() {
this.modelSet = null;
+
+ stopSnippets();
snippets.clear();
}
@@ -133,4 +141,24 @@ public abstract class AbstractModel implements IModel {
// Nothing to do
}
+
+ /**
+ * Starts my registered snippets.
+ */
+ protected void startSnippets() {
+ if (!snippetsStarted) {
+ snippetsStarted = true;
+ snippets.performStart(this);
+ }
+ }
+
+ /**
+ * Stops my registered snippets.
+ */
+ protected void stopSnippets() {
+ if (snippetsStarted) {
+ snippetsStarted = false;
+ snippets.performDispose(this);
+ }
+ }
}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/IModel.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/IModel.java
index 2e4d9ed0ca3..837eca7ede3 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/IModel.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/IModel.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2010, 2013 CEA LIST and others.
+ * Copyright (c) 2010, 2015 CEA LIST, Christian W. Damus, and others.
*
*
* All rights reserved. This program and the accompanying materials
@@ -11,6 +11,7 @@
* CEA LIST - Initial API and implementation
* Christian W. Damus (CEA) - manage models by URI, not IFile (CDO)
* Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Bug 436952
+ * Christian W. Damus - bug 481149
*
*
*****************************************************************************/
@@ -141,7 +142,9 @@ public interface IModel {
/**
* Add a snippet to this model. The snippet is called just after model is
* initialized, and before it is disposed or unloaded. Snippet can be shared
- * among models.
+ * among models. If this model's snippets have already been started (the
+ * model was previously loaded), then this new {@code snippet} is started
+ * also.
*
* @param snippet
* The snippet to add.
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/additional/AdditionalResourcesModel.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/additional/AdditionalResourcesModel.java
index b674258142f..df98aa77d7f 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/additional/AdditionalResourcesModel.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/additional/AdditionalResourcesModel.java
@@ -1,6 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2010, 2014 Atos Origin, CEA LIST, and others.
- *
+ * Copyright (c) 2010, 2015 Atos Origin, 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
@@ -13,6 +12,7 @@
* Christian W. Damus (CEA LIST) - support control mode in CDO resources
* Christian W. Damus (CEA) - bug 437052
* Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Bug 436952
+ * Christian W. Damus - bug 481149
*
*
*****************************************************************************/
@@ -67,13 +67,13 @@ public class AdditionalResourcesModel extends AbstractModel implements IModel {
@Deprecated
public void loadModel(IPath path) {
// call registered snippets
- snippets.performStart(this);
+ startSnippets();
}
@Override
public void loadModel(URI uri) {
// call registered snippets
- snippets.performStart(this);
+ startSnippets();
}
@Override
@@ -122,7 +122,7 @@ public class AdditionalResourcesModel extends AbstractModel implements IModel {
@Override
public void unload() {
// call registered snippets
- snippets.performDispose(this);
+ stopSnippets();
// Unload remaining resources
for (int i = 0; i < modelSet.getResources().size(); i++) {

Back to the top