Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra')
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/Activator.java66
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/ControledResourceAdapter.java291
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/HistoryRoutingManager.java90
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/HistoryRoutingUtils.java79
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/ILoadingStrategy.java42
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/ILoadingStrategyExtension.java34
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/IProxyManager.java47
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/IStrategyChooser.java30
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/Messages.java48
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/OnDemandLoadingModelSet.java95
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/OnDemandLoadingModelSetServiceFactory.java68
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/editor/UnloadResourcesEditorFactory.java41
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/editor/UnloadResourcesEditorModel.java148
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/impl/ProxyManager.java284
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/messages.properties18
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/strategies/AskUserStrategy.java827
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/strategies/LoadAllResources.java34
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/strategies/LoadControlledResources.java52
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/strategies/LoadCurrentResource.java31
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/strategies/Messages.java41
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/strategies/messages.properties13
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/util/LoadingTester.java147
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/util/LoadingUtils.java348
23 files changed, 2874 insertions, 0 deletions
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/Activator.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/Activator.java
new file mode 100644
index 00000000000..bcd7027f39b
--- /dev/null
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/Activator.java
@@ -0,0 +1,66 @@
+package org.eclipse.papyrus.infra.services.resourceloading;
+
+import org.eclipse.core.runtime.Plugin;
+import org.eclipse.core.runtime.Status;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends Plugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.papyrus.infra.services.resourceloading"; //$NON-NLS-1$
+
+ // The shared instance
+ private static Activator plugin;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /*
+ * (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;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
+ */
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+ /**
+ * Log an error
+ *
+ * @param e
+ * error to log
+ */
+ public static void logError(Exception e) {
+ Status err = new Status(Status.ERROR, PLUGIN_ID, e.getMessage(), e);
+ getDefault().getLog().log(err);
+ }
+
+}
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/ControledResourceAdapter.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/ControledResourceAdapter.java
new file mode 100644
index 00000000000..2f99c83eb2e
--- /dev/null
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/ControledResourceAdapter.java
@@ -0,0 +1,291 @@
+/*****************************************************************************
+ * Copyright (c) 2010 ATOS ORIGIN.
+ *
+ * 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:
+ * Tristan Faure (ATOS ORIGIN INTEGRATION) tristan.faure@atosorigin.com - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.services.resourceloading;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.emf.common.notify.Adapter;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.common.notify.Notifier;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.InternalEObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.util.InternalEList;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.resource.sasheditor.SashModel;
+import org.eclipse.papyrus.infra.services.controlmode.mm.history.ControledResource;
+
+/**
+ * This adapter maintains a map linking url and the corresponding ControledResource
+ *
+ * @author tfaure
+ *
+ */
+public class ControledResourceAdapter implements Adapter.Internal {
+
+ /**
+ * The map accesed
+ */
+ private Map<String, List<ControledResource>> resources = new HashMap<String, List<ControledResource>>();
+
+ private ModelSet modelSet = null;
+
+ public ControledResourceAdapter(ModelSet modelSet) {
+ this.modelSet = modelSet;
+ manageAllControledResources();
+ modelSet.eAdapters().add(this);
+ }
+
+ protected void put(ControledResource controled) {
+ List<ControledResource> list = resources.get(controled.getResourceURL());
+ if(list == null) {
+ list = new LinkedList<ControledResource>();
+ resources.put(controled.getResourceURL(), list);
+ addAdapter(controled);
+ }
+ list.add(controled);
+ }
+
+ public void manageAllControledResources() {
+ for(Resource r : modelSet.getResources()) {
+ addResource(r);
+ }
+ }
+
+ protected void addResource(Resource r) {
+ if(SashModel.MODEL_FILE_EXTENSION.equals(r.getURI().fileExtension())) {
+ for(EObject e : r.getContents()) {
+ if(e instanceof ControledResource) {
+ ControledResource root = (ControledResource)e;
+ if(root != null) {
+ put(root);
+ for(Iterator<EObject> i = root.eAllContents(); i.hasNext();) {
+ EObject eobject = i.next();
+ if(eobject instanceof ControledResource) {
+ put((ControledResource)eobject);
+ }
+ }
+ }
+
+ }
+ }
+ if(!r.eAdapters().contains(this)) {
+ r.eAdapters().add(this);
+ }
+ }
+ }
+
+ public List<ControledResource> getControledResource(String locationURL) {
+ List<ControledResource> list = resources.get(locationURL);
+ if(list == null) {
+ return Collections.emptyList();
+ }
+ return list;
+ }
+
+
+ public void notifyChanged(Notification notification) {
+ Notifier aNotifier = (Notifier)notification.getNotifier();
+ if(aNotifier instanceof EObject) {
+ switch(notification.getEventType()) {
+ case Notification.ADD:
+ addControledResource(notification.getNewValue());
+ break;
+ case Notification.ADD_MANY:
+ List<?> list = (List<?>)notification.getNewValue();
+ for(Object o : list) {
+ addControledResource(o);
+ }
+ break;
+ case Notification.REMOVE:
+ removeControledResource(notification.getOldValue());
+ break;
+ case Notification.REMOVE_MANY:
+ List<?> list2 = (List<?>)notification.getOldValue();
+ for(Object o : list2) {
+ removeControledResource(o);
+ }
+ break;
+ default:
+ break;
+ }
+ } else if(aNotifier instanceof Resource) {
+ switch(notification.getFeatureID(Resource.class)) {
+ case Resource.RESOURCE__IS_LOADED:
+ addResource((Resource)aNotifier);
+ break;
+ }
+
+ } else if(aNotifier instanceof ModelSet) {
+ if(notification.getNewValue() instanceof Resource) {
+ Resource r = ((Resource)notification.getNewValue());
+ if(!r.eAdapters().contains(this)) {
+ r.eAdapters().add(this);
+ }
+ setTarget((Resource)notification.getNewValue());
+ }
+ }
+ }
+
+ protected void addControledResource(Object o) {
+ if(o instanceof ControledResource) {
+ ControledResource o2 = (ControledResource)o;
+ put(o2);
+ }
+ }
+
+ protected void removeControledResource(Object o) {
+ if(o instanceof ControledResource) {
+ ControledResource res = (ControledResource)o;
+ List<ControledResource> list = resources.get(res.getResourceURL());
+ if(list != null) {
+ list.remove(res);
+ if(list.isEmpty()) {
+ resources.remove(res.getResourceURL());
+ }
+ }
+ }
+
+ }
+
+ public Notifier getTarget() {
+ return modelSet;
+ }
+
+ public boolean isAdapterForType(Object type) {
+ return false;
+ }
+
+ /**
+ * Handles installation of the adapter on an EObject by adding the adapter
+ * to each of the directly contained objects.
+ */
+ protected void setTarget(EObject target) {
+ for(@SuppressWarnings("unchecked")
+ Iterator<EObject> i = (Iterator<EObject>)((InternalEList<?>)target.eContents()).basicIterator(); i.hasNext();) {
+ Notifier notifier = i.next();
+ addAdapter(notifier);
+ }
+ }
+
+ protected void addAdapter(Notifier notifier) {
+ List<Adapter> eAdapters = notifier.eAdapters();
+ if(!eAdapters.contains(this)) {
+ eAdapters.add(this);
+ }
+ }
+
+ /**
+ * Handles installation of the adapter by adding the adapter to each of the
+ * directly contained objects.
+ */
+ public void setTarget(Notifier target) {
+ if(target instanceof EObject) {
+ setTarget((EObject)target);
+ } else if(target instanceof Resource) {
+ setTarget((Resource)target);
+ } else if(target instanceof ResourceSet) {
+ setTarget((ResourceSet)target);
+ }
+ }
+
+ /**
+ * Handles installation of the adapter on a Resource by adding the adapter
+ * to each of the directly contained objects.
+ */
+ protected void setTarget(Resource target) {
+ List<EObject> contents = target.getContents();
+ for(int i = 0, size = contents.size(); i < size; ++i) {
+ Notifier notifier = contents.get(i);
+ addAdapter(notifier);
+ }
+ }
+
+ /**
+ * Handles installation of the adapter on a ResourceSet by adding the
+ * adapter to each of the directly contained objects.
+ */
+ protected void setTarget(ResourceSet target) {
+ List<Resource> resources = target.getResources();
+ for(int i = 0; i < resources.size(); ++i) {
+ Notifier notifier = resources.get(i);
+ addAdapter(notifier);
+ }
+ }
+
+ /**
+ * Handles undoing the installation of the adapter by removing the adapter
+ * to each of the directly contained objects.
+ */
+ public void unsetTarget(Notifier target) {
+ if(target instanceof EObject) {
+ unsetTarget((EObject)target);
+ } else if(target instanceof Resource) {
+ unsetTarget((Resource)target);
+ } else if(target instanceof ResourceSet) {
+ unsetTarget((ResourceSet)target);
+ }
+ }
+
+ /**
+ * Handles undoing the installation of the adapter from an EObject by
+ * removing the adapter to each of the directly contained objects.
+ */
+ protected void unsetTarget(EObject target) {
+ for(@SuppressWarnings("unchecked")
+ Iterator<InternalEObject> i = (Iterator<InternalEObject>)((InternalEList<?>)target.eContents()).basicIterator(); i.hasNext();) {
+ // Don't remove the adapter if the object is in a different resource
+ // and that resource (and hence all its contents) are being cross
+ // referenced.
+ //
+ InternalEObject internalEObject = i.next();
+ Resource eDirectResource = internalEObject.eDirectResource();
+ if(eDirectResource == null || !eDirectResource.eAdapters().contains(this)) {
+ removeAdapter(internalEObject);
+ }
+ }
+ }
+
+ /**
+ * Handles undoing the installation of the adapter from a Resource by
+ * removing the adapter to each of the directly contained objects.
+ */
+ protected void unsetTarget(Resource target) {
+ List<EObject> contents = target.getContents();
+ for(int i = 0, size = contents.size(); i < size; ++i) {
+ Notifier notifier = contents.get(i);
+ removeAdapter(notifier);
+ }
+ }
+
+ protected void removeAdapter(Notifier notifier) {
+ notifier.eAdapters().remove(this);
+ }
+
+ /**
+ * Handles undoing the installation of the adapter from a ResourceSet by
+ * removing the adapter to each of the directly contained objects.
+ */
+ protected void unsetTarget(ResourceSet target) {
+ List<Resource> resources = target.getResources();
+ for(int i = 0; i < resources.size(); ++i) {
+ Notifier notifier = resources.get(i);
+ removeAdapter(notifier);
+ }
+ }
+}
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/HistoryRoutingManager.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/HistoryRoutingManager.java
new file mode 100644
index 00000000000..d7dd6f5bc2f
--- /dev/null
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/HistoryRoutingManager.java
@@ -0,0 +1,90 @@
+/*****************************************************************************
+ * Copyright (c) 2010 ATOS ORIGIN.
+ *
+ * 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:
+ * Tristan Faure (ATOS ORIGIN INTEGRATION) tristan.faure@atosorigin.com - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.services.resourceloading;
+
+import java.util.List;
+
+import org.eclipse.emf.common.notify.Notifier;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.services.controlmode.history.HistoryModel;
+import org.eclipse.papyrus.infra.services.controlmode.history.utils.HistoryUtils;
+import org.eclipse.papyrus.infra.services.controlmode.mm.history.ControledResource;
+
+/**
+ * This manager navigates in the history to access to controlled resources
+ *
+ * @author tfaure
+ *
+ */
+public class HistoryRoutingManager {
+
+ private ControledResourceAdapter adapter;
+
+ private final IProxyManager proxyManager;
+
+ public HistoryRoutingManager(IProxyManager proxyManager) {
+ this.proxyManager = proxyManager;
+ }
+
+ /**
+ * Returns the eobject navigating through the history
+ *
+ * @param modelSet
+ * @param resourceURI
+ * @param fragment
+ * @return
+ */
+ public EObject getEObject(ModelSet modelSet, String resourceURI, String fragment) {
+ adapter = HistoryRoutingUtils.getControledResourceAdapter(modelSet);
+ EObject result = null;
+ HistoryModel historyModel = HistoryUtils.getHistoryModel(modelSet);
+ if(historyModel != null) {
+ List<ControledResource> res = adapter.getControledResource(resourceURI);
+ if(res != null) {
+ for(ControledResource controled : res) {
+ for(ControledResource child : controled.getChildren()) {
+ URI locationURI = URI.createURI(child.getResourceURL());
+ URI toGet = locationURI.resolve(HistoryUtils.getURIFullPath(child.eResource().getURI()));
+ Resource resource = modelSet.getResource(toGet, proxyManager.loadResource(locationURI));
+ if(resource != null) {
+ result = resource.getEObject(fragment);
+ if(result != null) {
+ break;
+ } else {
+ result = getEObject(modelSet, child.getResourceURL(), fragment);
+ if(result != null) {
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Unload the routing manager dropping the ControledResourceAdapter
+ */
+ public void unload() {
+ if(adapter != null) {
+ Notifier resSet = adapter.getTarget();
+ resSet.eAdapters().remove(adapter);
+ adapter = null;
+ }
+ }
+
+}
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/HistoryRoutingUtils.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/HistoryRoutingUtils.java
new file mode 100644
index 00000000000..ee8c742a6fe
--- /dev/null
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/HistoryRoutingUtils.java
@@ -0,0 +1,79 @@
+/*****************************************************************************
+ * Copyright (c) 2010 ATOS ORIGIN.
+ *
+ * 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:
+ * Tristan Faure (ATOS ORIGIN INTEGRATION) tristan.faure@atosorigin.com - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.services.resourceloading;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.emf.common.notify.Adapter;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.resource.sasheditor.SashModel;
+import org.eclipse.papyrus.infra.core.resource.sasheditor.SashModelUtils;
+import org.eclipse.papyrus.infra.services.controlmode.history.HistoryModel;
+import org.eclipse.papyrus.infra.services.controlmode.history.utils.HistoryUtils;
+import org.eclipse.papyrus.infra.services.controlmode.mm.history.ControledResource;
+
+
+/**
+ * The Class HistoryRoutingUtils.
+ */
+public class HistoryRoutingUtils {
+
+ /**
+ * Retrieves all the URIs of the controlled resources of the initial resource uri
+ *
+ * @param model
+ * , the history model
+ * @param initialURI
+ * , the uri to check
+ * @return
+ */
+ public static Set<String> getAllControledURIs(ModelSet set, HistoryModel model, URI initialURI, boolean loadCorrespondantDI) {
+ Set<String> result = new HashSet<String>();
+ String path = HistoryUtils.getURIFullPath(SashModelUtils.getInitialURI(set)).toString();
+ if(model != null && initialURI != null) {
+ ControledResourceAdapter adapter = getControledResourceAdapter(set);
+ set.getResource(URI.createURI(path.concat(initialURI.trimFragment().trimFileExtension().appendFileExtension(SashModel.MODEL_FILE_EXTENSION).toString())), loadCorrespondantDI);
+ List<ControledResource> elements = adapter.getControledResource(initialURI.toString());
+ for(ControledResource c : elements) {
+ for(ControledResource child : c.getChildren()) {
+ URI childURI = URI.createURI(child.getResourceURL());
+ result.add(childURI.toString());
+ result.addAll(getAllControledURIs(set, model, childURI, loadCorrespondantDI));
+ }
+ }
+ }
+ return result;
+ }
+
+ /**
+ * get the controled resource adapter from the given {@link ModelSet} if it is not found it is installed
+ *
+ * @param set
+ * @return
+ */
+ public static ControledResourceAdapter getControledResourceAdapter(ModelSet set) {
+ ControledResourceAdapter adapter = null;
+ for(Adapter a : set.eAdapters()) {
+ if(a instanceof ControledResourceAdapter) {
+ adapter = (ControledResourceAdapter)a;
+ }
+ }
+ if(adapter == null) {
+ adapter = new ControledResourceAdapter(set);
+ }
+ return adapter;
+ }
+
+}
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/ILoadingStrategy.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/ILoadingStrategy.java
new file mode 100644
index 00000000000..318b89fee94
--- /dev/null
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/ILoadingStrategy.java
@@ -0,0 +1,42 @@
+/*****************************************************************************
+ * Copyright (c) 2010 Atos Origin.
+ *
+ *
+ * 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:
+ * Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.services.resourceloading;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+
+/**
+ * The Interface ILoadingStrategy that manages several strategies to load the model
+ */
+public interface ILoadingStrategy {
+
+ /**
+ * Check if the resource from the uri need to be loaded according to the strategy.
+ *
+ * @param modelSet
+ * @param uri
+ * @return true if resource must be loaded, return false otherwise
+ */
+ boolean loadResource(ModelSet modelSet, URI uri);
+
+ // AR : additional resources (types, profiles ...)
+ // parents : set of elements containing the current selection
+ // currents : the resource opened
+ // children : the resources bellow the current selection
+
+ // strategy 1: all : AR U parents U currents U children -> done
+ // strategy 2: only one : AR U currents -> done
+ // strategy 3: bellow : AR U children U currents
+ // strategy 4: ask the user the needed resources he wants to load (need an UI)
+}
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/ILoadingStrategyExtension.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/ILoadingStrategyExtension.java
new file mode 100644
index 00000000000..3559fdf227d
--- /dev/null
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/ILoadingStrategyExtension.java
@@ -0,0 +1,34 @@
+/*****************************************************************************
+ * Copyright (c) 2010 Atos Origin.
+ *
+ *
+ * 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:
+ * Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.services.resourceloading;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+
+/**
+ * The Interface ILoadingStrategyExtension.
+ */
+public interface ILoadingStrategyExtension {
+
+ /**
+ * Check if the resource from the uri need to be loaded, no matter which strategy is set.
+ *
+ * @param modelSet
+ * the model set
+ * @param uri
+ * the uri of the eObject
+ * @return true if resource must be loaded irrespective of strategy, return false otherwise
+ */
+ boolean loadResource(ModelSet modelSet, URI uri);
+}
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/IProxyManager.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/IProxyManager.java
new file mode 100644
index 00000000000..74b359609ea
--- /dev/null
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/IProxyManager.java
@@ -0,0 +1,47 @@
+/*****************************************************************************
+ * Copyright (c) 2010 ATOS ORIGIN.
+ *
+ * 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:
+ * Tristan Faure (ATOS ORIGIN INTEGRATION) tristan.faure@atosorigin.com - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.services.resourceloading;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+
+
+/**
+ * Interface providing services to load resources and resolves Proxies
+ *
+ * @author tfaure
+ *
+ */
+public interface IProxyManager {
+
+ /**
+ * Release the different resources to free memory
+ */
+ void dispose();
+
+ /**
+ * Returns an eobject from a strategy, the implementation manages itself its resources
+ *
+ * @param uri
+ * @return
+ */
+ EObject getEObjectFromStrategy(URI uri);
+
+ /**
+ * Returns true if the proxy manager will load the resource located at the URI
+ *
+ * @param uri
+ * @return
+ */
+ boolean loadResource(URI uri);
+
+}
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/IStrategyChooser.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/IStrategyChooser.java
new file mode 100644
index 00000000000..4ed3c9a0388
--- /dev/null
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/IStrategyChooser.java
@@ -0,0 +1,30 @@
+/*****************************************************************************
+ * Copyright (c) 2010 Atos Origin.
+ *
+ *
+ * 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:
+ * Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.services.resourceloading;
+
+
+/**
+ * The Interface IStrategyChooser that provides the current loading strategy to the proxy manager.
+ * Proxy manager load the resource if needed, according to the current strategy
+ */
+public interface IStrategyChooser {
+
+ /**
+ * Gets the current strategy ID.
+ * Proxy manager load the resource if needed, according to the current strategy
+ *
+ * @return the current strategy id
+ */
+ int getCurrentStrategy();
+}
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/Messages.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/Messages.java
new file mode 100644
index 00000000000..d7ac519fc33
--- /dev/null
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/Messages.java
@@ -0,0 +1,48 @@
+/*****************************************************************************
+ * Copyright (c) 2011 Atos Origin.
+ *
+ *
+ * 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:
+ * Vincent Hemery (Atos) vincent.hemery@atos.net - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.services.resourceloading;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ * This class handles messages internationalization
+ *
+ * @author vhemery
+ */
+public class Messages extends NLS {
+
+ private static final String BUNDLE_NAME = "org.eclipse.papyrus.infra.services.resourceloading.messages"; //$NON-NLS-1$
+
+ /** Error message */
+ public static String LoadingUtils_ErrorMessage;
+
+ /** Error popup title */
+ public static String LoadingUtils_ErrorTitle;
+
+ /** Load models task name */
+ public static String LoadingUtils_LoadModelsTask;
+
+ /** Resfresh pages task name */
+ public static String LoadingUtils_RefreshPagesTask;
+
+ /** Unload models task name */
+ public static String LoadingUtils_UnloadModelsTask;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/OnDemandLoadingModelSet.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/OnDemandLoadingModelSet.java
new file mode 100644
index 00000000000..f08d4c9185a
--- /dev/null
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/OnDemandLoadingModelSet.java
@@ -0,0 +1,95 @@
+/**
+ *
+ */
+package org.eclipse.papyrus.infra.services.resourceloading;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.resource.ModelsReader;
+import org.eclipse.papyrus.infra.core.resource.notation.NotationUtils;
+import org.eclipse.papyrus.infra.core.resource.sasheditor.SashModelUtils;
+import org.eclipse.papyrus.infra.core.resource.uml.UmlUtils;
+import org.eclipse.papyrus.infra.core.utils.DiResourceSet;
+import org.eclipse.papyrus.infra.services.resourceloading.impl.ProxyManager;
+
+
+/**
+ * A {@link ModelSet} allowing to load models on demand.
+ * Also, this implementation allows to have loading strategies.
+ *
+ * TODO extends {@link ModelSet} rather than {@link DiResourceSet}. This can be done once
+ * DiResourceSet is not referenced anywhere.
+ *
+ * @author cedric dumoulin
+ * @author emilien perico
+ *
+ */
+public class OnDemandLoadingModelSet extends DiResourceSet {
+
+ /** Set that enables to always load the uri with any strategy. */
+ private Set<URI> uriLoading = new HashSet<URI>();
+
+ /**
+ * The proxy manager that loads the model according to a specific strategy.
+ */
+ private IProxyManager proxyManager;
+
+ /**
+ *
+ * Constructor.
+ *
+ */
+ public OnDemandLoadingModelSet() {
+ super();
+ // Register declared models
+ ModelsReader reader = new ModelsReader();
+ reader.readModel(this);
+ proxyManager = new ProxyManager(this);
+ }
+
+
+
+ @Override
+ public void unload() {
+ super.unload();
+ proxyManager.dispose();
+ }
+
+
+
+ /**
+ * @see org.eclipse.emf.ecore.resource.impl.ResourceSetImpl#getEObject(org.eclipse.emf.common.util.URI, boolean)
+ */
+ @Override
+ public EObject getEObject(URI uri, boolean loadOnDemand) {
+ //return super.getEObject(uri, loadOnDemand);
+
+ URI resourceURI = uri.trimFragment();
+ // for performance reasons, we check the three initial resources first
+ // TODO not use getUMLModel
+ if(resourceURI.equals(UmlUtils.getUmlModel(this).getResourceURI()) || resourceURI.equals(NotationUtils.getNotationModel(this).getResourceURI()) || resourceURI.equals(SashModelUtils.getSashModel(this).getResourceURI()) || uriLoading.contains(resourceURI)) {
+ // do not manage eObject of the current resources
+ return super.getEObject(uri, loadOnDemand);
+ } else if(loadOnDemand) {
+ return proxyManager.getEObjectFromStrategy(uri);
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Enables to add an URI that will be always loaded.
+ * It is not listening at the current loading strategy and always load the specified URI if needed.
+ *
+ * @param alwaysLoadedUri
+ * the always loaded uri
+ */
+ public void forceUriLoading(URI alwaysLoadedUri) {
+ uriLoading.add(alwaysLoadedUri);
+ }
+
+}
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/OnDemandLoadingModelSetServiceFactory.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/OnDemandLoadingModelSetServiceFactory.java
new file mode 100644
index 00000000000..20b97bd4f7b
--- /dev/null
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/OnDemandLoadingModelSetServiceFactory.java
@@ -0,0 +1,68 @@
+/**
+ *
+ */
+package org.eclipse.papyrus.infra.services.resourceloading;
+
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.services.IServiceFactory;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.eclipse.papyrus.infra.core.utils.DiResourceSet;
+import org.eclipse.papyrus.infra.services.controlmode.history.HistoryModel;
+import org.eclipse.papyrus.infra.services.controlmode.history.utils.HistoryUtils;
+import org.eclipse.papyrus.infra.services.controlmode.mm.history.ControledResource;
+import org.eclipse.papyrus.infra.services.controlmode.mm.history.historyFactory;
+
+
+/**
+ * A service starting the ModelSet
+ *
+ * @author cedric dumoulin
+ *
+ */
+public class OnDemandLoadingModelSetServiceFactory implements IServiceFactory {
+
+ /** The ModelSet */
+ private ModelSet service;
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.core.services.IService#init(org.eclipse.papyrus.infra.core.services.ServicesRegistry)
+ *
+ * @param servicesRegistry
+ * @throws ServiceException
+ */
+ public void init(ServicesRegistry servicesRegistry) throws ServiceException {
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.core.services.IService#startService()
+ *
+ * @throws ServiceException
+ */
+ public void startService() throws ServiceException {
+
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.core.services.IService#disposeService()
+ *
+ * @throws ServiceException
+ */
+ public void disposeService() throws ServiceException {
+ if(service != null)
+ service.unload();
+ }
+
+ /**
+ * Create the service served by this factory.
+ */
+ public Object createServiceInstance() {
+ // Create the appropriate service.
+ service = new OnDemandLoadingModelSet();
+ return service;
+ }
+
+}
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/editor/UnloadResourcesEditorFactory.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/editor/UnloadResourcesEditorFactory.java
new file mode 100644
index 00000000000..3f9a6e7f9d7
--- /dev/null
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/editor/UnloadResourcesEditorFactory.java
@@ -0,0 +1,41 @@
+package org.eclipse.papyrus.infra.services.resourceloading.editor;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.InternalEObject;
+import org.eclipse.papyrus.infra.core.extension.diagrameditor.EditorDescriptor;
+import org.eclipse.papyrus.infra.core.extension.diagrameditor.IPluggableEditorFactory;
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageModel;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+
+
+public class UnloadResourcesEditorFactory implements IPluggableEditorFactory {
+
+ private EditorDescriptor editorDescriptor;
+
+ private ServicesRegistry serviceRegistry;
+
+ public IPageModel createIPageModel(Object pageIdentifier) {
+ URI uri = null;
+ if(pageIdentifier instanceof InternalEObject) {
+ InternalEObject internal = (InternalEObject)pageIdentifier;
+ uri = internal.eProxyURI();
+ }
+ return new UnloadResourcesEditorModel(uri);
+ }
+
+ public boolean isPageModelFactoryFor(Object pageIdentifier) {
+ boolean result = false;
+ if(pageIdentifier instanceof EObject) {
+ EObject eObjectPageIdentifier = (EObject)pageIdentifier;
+ result = eObjectPageIdentifier.eIsProxy();
+ }
+ return result;
+ }
+
+ public void init(ServicesRegistry serviceRegistry, EditorDescriptor editorDescriptor) {
+ this.editorDescriptor = editorDescriptor;
+ this.serviceRegistry = serviceRegistry;
+ }
+
+}
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/editor/UnloadResourcesEditorModel.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/editor/UnloadResourcesEditorModel.java
new file mode 100644
index 00000000000..c83b38fc413
--- /dev/null
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/editor/UnloadResourcesEditorModel.java
@@ -0,0 +1,148 @@
+package org.eclipse.papyrus.infra.services.resourceloading.editor;
+
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IEditorModel;
+import org.eclipse.papyrus.infra.widgets.toolbox.notification.builders.NotificationBuilder;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IEditorSite;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.part.EditorActionBarContributor;
+import org.eclipse.ui.part.EditorPart;
+
+
+/**
+ * A simple model that can be used as editor in tests.
+ *
+ * @author cedric dumoulin
+ *
+ */
+public class UnloadResourcesEditorModel implements IEditorModel {
+
+
+ private String name;
+
+ private final URI uri;
+
+ public UnloadResourcesEditorModel(URI uri) {
+ this.uri = uri;
+ name = "unresolved tab";
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageModel#getTabTitle()
+ *
+ * @return
+ */
+ public String getTabTitle() {
+ return name;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageModel#getTabIcon()
+ *
+ * @return
+ */
+ public Image getTabIcon() {
+ return null;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageModel#getRawModel()
+ *
+ * @return
+ */
+ public Object getRawModel() {
+ // TODO Auto-generated method stub
+ return this;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IEditorModel#createIEditorPart()
+ *
+ * @return
+ * @throws PartInitException
+ */
+ public IEditorPart createIEditorPart() throws PartInitException {
+ return new UnloadResourcesEditorPart(uri);
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IEditorModel#getActionBarContributor()
+ *
+ * @return
+ */
+ public EditorActionBarContributor getActionBarContributor() {
+ return null;
+ }
+
+ /**
+ * A class implementing a fake editor.
+ *
+ * @author dumoulin
+ *
+ */
+ public static class UnloadResourcesEditorPart extends EditorPart {
+
+ private final URI unloadedUri;
+
+ public UnloadResourcesEditorPart(URI uri) {
+ unloadedUri = uri;
+ }
+
+ @Override
+ public void doSave(IProgressMonitor monitor) {
+ }
+
+ @Override
+ public void doSaveAs() {
+ }
+
+ @Override
+ public void init(IEditorSite site, IEditorInput input) throws PartInitException {
+ setSite(site);
+ setInput(input);
+ setPartName(input.getName());
+ }
+
+ @Override
+ public boolean isDirty() {
+ return false;
+ }
+
+ @Override
+ public boolean isSaveAsAllowed() {
+ return false;
+ }
+
+ @Override
+ public void createPartControl(Composite parent) {
+ Composite compo = new Composite(parent, SWT.NONE);
+ compo.setLayout(new GridLayout(2, false));
+ Image image = NotificationBuilder.getSWTImage(SWT.ICON_INFORMATION, parent.getShell());
+ Label label = new Label(compo, SWT.NONE);
+ label.setImage(image);
+ label.setLayoutData(new GridData(SWT.CENTER, SWT.TOP, false, false));
+ Text t = new Text(compo, SWT.None);
+ t.setText("This diagram is contained in an unresolved resource : " + unloadedUri.trimFragment().toString());
+ t.setLayoutData(new GridData(GridData.FILL_BOTH));
+ t.setEditable(false);
+ label.setBackground(t.getBackground());
+ compo.setBackground(t.getBackground());
+ }
+
+ @Override
+ public void setFocus() {
+ }
+
+ }
+}
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/impl/ProxyManager.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/impl/ProxyManager.java
new file mode 100644
index 00000000000..02b0e530004
--- /dev/null
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/impl/ProxyManager.java
@@ -0,0 +1,284 @@
+/*****************************************************************************
+ * Copyright (c) 2010 Atos Origin.
+ *
+ *
+ * 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:
+ * Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.services.resourceloading.impl;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.MissingResourceException;
+import java.util.Set;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.emf.common.CommonPlugin;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.papyrus.infra.core.Activator;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.resource.sasheditor.SashModel;
+import org.eclipse.papyrus.infra.services.resourceloading.HistoryRoutingManager;
+import org.eclipse.papyrus.infra.services.resourceloading.ILoadingStrategy;
+import org.eclipse.papyrus.infra.services.resourceloading.ILoadingStrategyExtension;
+import org.eclipse.papyrus.infra.services.resourceloading.IProxyManager;
+import org.eclipse.papyrus.infra.services.resourceloading.IStrategyChooser;
+
+/**
+ * The Class ProxyManager that manages the proxy resolving according to a specific strategy.
+ */
+public class ProxyManager implements IProxyManager {
+
+ // === Manage strategies
+
+ /** extension point ID for loading strategy */
+ private static final String LOADING_STRATEGY_EXTENSION_POINT_ID = "org.eclipse.papyrus.infra.services.resourceloading.loadingStrategy";
+
+ /** element ID for the loading strategy element */
+ private static final String LOADING_STRATEGY_ELEMENT_ID = "loadingStrategy";
+
+ /** attribute ID for identification of the strategy */
+ private static final String LOADING_STRATEGY_ID = "id";
+
+ /** attribute ID for the description of the strategy */
+ private static final String LOADING_STRATEGY_DESCRIPTION_ID = "description";
+
+ /** attribute ID for the implementation of the strategy */
+ private static final String STRATEGY_ID = "strategy";
+
+ // ==== Manage strategy extensions (for UML profile)
+
+ /** extension point ID for strategy extensions */
+ private static final String STRATEGY_EXTENDER_EXTENSION_POINT_ID = "org.eclipse.papyrus.infra.services.resourceloading.loadingStrategyExtender";
+
+ /** element ID for the loading strategy extension element */
+ private static final String STRATEGY_EXTENDER_ELEMENT_ID = "strategyExtender";
+
+ /** attribute ID for the implementation of the strategy extension */
+ private static final String STRATEGY_EXTENSION_ID = "strategyExtension";
+
+ // === Manage strategy chooser extension
+
+ /** extension point ID for strategy chooser extension */
+ private static final String STRATEGY_CHOOSER_EXTENSION_POINT_ID = "org.eclipse.papyrus.infra.services.resourceloading.currentStrategyChooser";
+
+ /** attribute ID for the implementation of the strategy chooser extension used in preferences */
+ private static final String STRATEGY_CHOOSER_CHOOSER_ATTRIBUTE = "chooser";
+
+ private static IStrategyChooser strategyChooser = getStrategyChooser();
+
+ // ===
+
+ /** The strategies id and descriptions for preferences */
+ private static Map<Integer, String> strategiesAndDescriptions = new HashMap<Integer, String>();
+
+ /** custom commands from extensions */
+ private static Map<Integer, ILoadingStrategy> availableStrategies = getLoadingStrategies();
+
+ /** custom commands from strategy extensions */
+ private static Set<ILoadingStrategyExtension> strategyExtensions = getLoadingStrategyExtensions();
+
+ private ModelSet modelSet;
+
+ private HistoryRoutingManager routeManager = new HistoryRoutingManager(this);
+
+ public ProxyManager(ModelSet modelSet) {
+ super();
+ this.modelSet = modelSet;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.infra.services.resourceloading.IProxyManager#loadResource(URI)
+ */
+ public boolean loadResource(URI uri) {
+ boolean result = availableStrategies.get(getCurrentStrategy()).loadResource(modelSet, uri);
+ Iterator<ILoadingStrategyExtension> iterator = strategyExtensions.iterator();
+ while(!result && iterator.hasNext()) {
+ ILoadingStrategyExtension extension = (ILoadingStrategyExtension)iterator.next();
+ result = extension.loadResource(modelSet, uri.trimFragment());
+ }
+ return result;
+ }
+
+ /**
+ * Gets the eobject according to the strategy.
+ *
+ * @param uri
+ * the specified uri to load
+ * @return the resolved eobject or the proxy, depending on the loading strategy
+ * @throws MissingResourceException
+ * the missing resource exception
+ */
+ public EObject getEObjectFromStrategy(URI uri) throws MissingResourceException {
+ // ask the strategy if the resource of the uri must be loaded
+ URI trimFragment = uri.trimFragment();
+ boolean loadOnDemand = loadResource(trimFragment);
+ // accept to recover object, either if strategy provides it, or if it has already been loaded anyway
+ Resource resource = modelSet.getResource(trimFragment, loadOnDemand);
+ if(resource != null) {
+ String fragment = uri.fragment();
+ EObject object = resource.getEObject(fragment);
+ if(object != null) {
+ // object find in the resource
+ return object;
+ }
+ // use HistoryRoutingManager to explore routes in di resource historic
+ else {
+ String fileExtension = uri.fileExtension();
+ Resource diResource = null;
+ String resourceName = "";
+ if(SashModel.MODEL_FILE_EXTENSION.equals(fileExtension)) {
+ // proxy is in DI resource
+ diResource = modelSet.getResource(trimFragment, loadOnDemand);
+ resourceName = trimFragment.toString();
+ } else {
+ // retrieve the DI resource from the uri to get the historic
+ URI newURI = trimFragment.trimFileExtension().appendFileExtension(SashModel.MODEL_FILE_EXTENSION);
+ diResource = modelSet.getResource(newURI.trimFragment(), loadOnDemand);
+ resourceName = newURI.trimFragment().toString();
+ }
+ if(diResource != null) {
+ // call the HistoryRoutingManager to get the EObject
+ // we assume di/notation are at the same level in folder hierarchy
+ EObject eobject = routeManager.getEObject(modelSet, uri.lastSegment().toString(), fragment);
+ if(eobject == null) {
+ throw new MissingResourceException(CommonPlugin.INSTANCE.getString("_UI_StringResourceNotFound_exception", new Object[]{ resourceName }), getClass().getName(), resourceName);
+ }
+ return eobject;
+
+ } else {
+ // resource di not found
+ // warn the user, ask him to select the resource
+ throw new MissingResourceException(CommonPlugin.INSTANCE.getString("_UI_StringResourceNotFound_exception", new Object[]{ resourceName }), getClass().getName(), resourceName);
+ }
+ }
+ } else if(loadOnDemand) {
+ // resource not found
+ // warn the user, ask him to select a resource to search in
+ // or ask to search in the entire resource set
+ // or use a proxy
+ // strategy used for the specified resource only
+ throw new MissingResourceException(CommonPlugin.INSTANCE.getString("_UI_StringResourceNotFound_exception", new Object[]{ trimFragment.toString() }), getClass().getName(), trimFragment.toString());
+ } else {
+ // we just want to manage a proxy for this object
+ return null;
+ }
+ }
+
+ /**
+ * Gets the current strategy.
+ *
+ * @return the current strategy, strategy 0 (load all resources) is loaded by default if null
+ */
+ private static int getCurrentStrategy() {
+ if(strategyChooser == null) {
+ return 0;
+ }
+ return strategyChooser.getCurrentStrategy();
+ }
+
+ /**
+ * Gets the all strategies.
+ *
+ * @return the all strategies
+ */
+ public static Map<Integer, String> getAllStrategies() {
+ return strategiesAndDescriptions;
+ }
+
+ /**
+ * Gets the available strategies from extensions
+ *
+ * @return the strategies
+ */
+ private static Map<Integer, ILoadingStrategy> getLoadingStrategies() {
+ Map<Integer, ILoadingStrategy> strategies = new HashMap<Integer, ILoadingStrategy>();
+ IConfigurationElement[] extensions = Platform.getExtensionRegistry().getConfigurationElementsFor(LOADING_STRATEGY_EXTENSION_POINT_ID);
+ for(IConfigurationElement element : extensions) {
+ if(LOADING_STRATEGY_ELEMENT_ID.equals(element.getName())) {
+ try {
+ // use description in extension to define preferences from the extensions
+ int id = Integer.valueOf(element.getAttribute(LOADING_STRATEGY_ID));
+ String description = element.getAttribute(LOADING_STRATEGY_DESCRIPTION_ID);
+ ILoadingStrategy strategy = (ILoadingStrategy)element.createExecutableExtension(STRATEGY_ID);
+ strategies.put(id, strategy);
+ strategiesAndDescriptions.put(id, description);
+ } catch (CoreException e1) {
+ Activator.log.error(e1.getMessage(), e1);
+ e1.printStackTrace();
+ } catch (NumberFormatException e2) {
+ Activator.log.error(e2.getMessage(), e2);
+ e2.printStackTrace();
+ }
+ }
+ }
+ return strategies;
+ }
+
+ /**
+ * Gets the strategy extensions
+ *
+ * @return the strategy extensions
+ */
+ private static Set<ILoadingStrategyExtension> getLoadingStrategyExtensions() {
+ Set<ILoadingStrategyExtension> strategies = new HashSet<ILoadingStrategyExtension>();
+ IConfigurationElement[] extensions = Platform.getExtensionRegistry().getConfigurationElementsFor(STRATEGY_EXTENDER_EXTENSION_POINT_ID);
+ for(IConfigurationElement element : extensions) {
+ if(STRATEGY_EXTENDER_ELEMENT_ID.equals(element.getName())) {
+ try {
+ ILoadingStrategyExtension strategyExtension = (ILoadingStrategyExtension)element.createExecutableExtension(STRATEGY_EXTENSION_ID);
+ strategies.add(strategyExtension);
+ } catch (CoreException e) {
+ Activator.log.error(e.getMessage(), e);
+ e.printStackTrace();
+ }
+ }
+ }
+ return strategies;
+ }
+
+ /**
+ * There is only one Strategy chooser chosen in extension registry.
+ *
+ * @return
+ */
+ public static IStrategyChooser getStrategyChooser() {
+ IStrategyChooser result = null;
+ IConfigurationElement[] element = Platform.getExtensionRegistry().getConfigurationElementsFor(STRATEGY_CHOOSER_EXTENSION_POINT_ID);
+ if(element.length > 0) {
+ IConfigurationElement e = element[0];
+ try {
+ result = (IStrategyChooser)e.createExecutableExtension(STRATEGY_CHOOSER_CHOOSER_ATTRIBUTE);
+ } catch (CoreException e1) {
+ Activator.log.error(e1.getMessage(), e1);
+ e1.printStackTrace();
+ }
+ }
+ return result;
+ }
+
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.infra.services.resourceloading.IProxyManager#dispose()
+ */
+ public void dispose() {
+ routeManager.unload();
+ }
+
+}
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/messages.properties b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/messages.properties
new file mode 100644
index 00000000000..f22195b08d8
--- /dev/null
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/messages.properties
@@ -0,0 +1,18 @@
+##########################################################################################
+# Copyright (c) 2011 Atos.
+#
+#
+# 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:
+# Vincent Hemery (Atos) vincent.hemery@atos.net - Initial API and implementation
+#
+########################################################################################
+LoadingUtils_ErrorMessage=Unable to load resource %s
+LoadingUtils_ErrorTitle=Error
+LoadingUtils_LoadModelsTask=Load models
+LoadingUtils_RefreshPagesTask=Refresh Pages
+LoadingUtils_UnloadModelsTask=Unload models
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/strategies/AskUserStrategy.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/strategies/AskUserStrategy.java
new file mode 100644
index 00000000000..c4bb17a4c0e
--- /dev/null
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/strategies/AskUserStrategy.java
@@ -0,0 +1,827 @@
+/*****************************************************************************
+ * Copyright (c) 2010 ATOS ORIGIN.
+ *
+ * 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:
+ * Tristan Faure (ATOS ORIGIN INTEGRATION) tristan.faure@atosorigin.com - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.services.resourceloading.strategies;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.papyrus.infra.core.editor.CoreMultiDiagramEditor;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageMngr;
+import org.eclipse.papyrus.infra.core.sasheditor.di.contentprovider.DiSashModelMngr;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.services.resourceloading.ILoadingStrategy;
+import org.eclipse.papyrus.infra.widgets.toolbox.notification.INotification;
+import org.eclipse.papyrus.infra.widgets.toolbox.notification.NotificationRunnable;
+import org.eclipse.papyrus.infra.widgets.toolbox.notification.Type;
+import org.eclipse.papyrus.infra.widgets.toolbox.notification.builders.IContext;
+import org.eclipse.papyrus.infra.widgets.toolbox.notification.builders.NotificationBuilder;
+import org.eclipse.swt.SWT;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IEditorReference;
+import org.eclipse.ui.IPartListener;
+import org.eclipse.ui.IPerspectiveDescriptor;
+import org.eclipse.ui.IPerspectiveListener;
+import org.eclipse.ui.IWindowListener;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * The strategy which ask user if the resource has to be loaded or not
+ *
+ * @author tfaure
+ *
+ */
+public class AskUserStrategy implements ILoadingStrategy {
+
+ /**
+ * the uris linked to the uri of an editor already guessed to the user
+ */
+ private Map<URI, Set<URI>> alreadyGuessed = new HashMap<URI, Set<URI>>();
+
+ /**
+ * the uris linked to the uri of an editor already authorized
+ */
+ Map<URI, Set<URI>> authorized = new HashMap<URI, Set<URI>>();
+
+ /**
+ * The extensions needed to load for each resource
+ */
+ Map<URI, Map<URI, Set<String>>> mappingURIExtensions = new HashMap<URI, Map<URI, Set<String>>>();
+
+ /**
+ * Listeners triggered when the editors are closed
+ */
+ Map<URI, EditorCloseListener> listeners = new HashMap<URI, AskUserStrategy.EditorCloseListener>();
+
+ /**
+ * All the notifications created for each editor
+ */
+ Map<URI, List<INotification>> notifications = new HashMap<URI, List<INotification>>();
+
+ /**
+ * Constant URI for Yes For All Option
+ */
+ public static final URI YesForAllURI = URI.createURI(Messages.AskUserStrategy_YES_FOR_ALL_URI);
+
+ /**
+ * Constant URI for No For All Option
+ */
+ private static final URI NoForAllURI = URI.createURI(Messages.AskUserStrategy_NO_FOR_ALL_URI);
+
+ /**
+ * @see org.eclipse.papyrus.infra.services.resourceloading.ILoadingStrategy#loadResource(org.eclipse.papyrus.infra.core.resource.ModelSet,
+ * org.eclipse.emf.common.util.URI)
+ *
+ * @param modelSet
+ * @param uri
+ * @return
+ */
+ public boolean loadResource(ModelSet modelSet, URI uri) {
+ // pathmap resource are always loaded
+ boolean result = !uri.isPlatform() && !uri.isFile();
+ URI initialURI = URI.createPlatformResourceURI(modelSet.getFilenameWithoutExtension().toString(), true);
+ // if no listener is registered, a listener is added on the editor to remove the notifications
+ // when the editor is closed the listener removes too the choices made by the user.
+ addClosingEditorListener(initialURI);
+
+ // all the verification are made with the uri without the file extension
+ // each load is performed for a set of resources
+ URI trimFileExtensionAndFragment = uri.trimFragment().trimFileExtension();
+ if(!result) {
+ result = initialURI.equals(trimFileExtensionAndFragment);
+ }
+ if(!result) {
+ manageExtensions(initialURI, uri);
+ Set<URI> uris = authorized.get(initialURI);
+ if(uris != null && (uris.contains(YesForAllURI) || uris.contains(trimFileExtensionAndFragment))) {
+ result = true;
+ }
+ if(uris != null && (uris.contains(NoForAllURI))) {
+ // in this case always false !
+ return false;
+ }
+ if(!result) {
+ manageGuess(modelSet, initialURI, trimFileExtensionAndFragment);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Create the ask notification to the user
+ *
+ * @param modelSet
+ * @param initialURI
+ * @param trimFragment
+ */
+ protected void manageGuess(ModelSet modelSet, URI initialURI, URI trimFragment) {
+ if(!alreadyGuessed(initialURI, trimFragment) && !alreadyGuessed(initialURI, YesForAllURI) && !alreadyGuessed(initialURI, NoForAllURI)) {
+ String message = new StringBuffer(Messages.AskUserStrategy_MESSAGE_PART_1).append(initialURI.lastSegment()).append(Messages.AskUserStrategy_MESSAGE_PART_2).append(trimFragment.toString()).append(Messages.AskUserStrategy_MESSAGE_PART3).toString();
+ addGuessed(initialURI, trimFragment);
+ NotificationBuilder builder = getNotification(message, trimFragment, modelSet, initialURI);
+ INotification notification = builder.run();
+ addNotification(initialURI, new EncapsulatedNotification(notification, trimFragment));
+ // notification
+ }
+ }
+
+ /**
+ * Add a listener closing the uri parameter
+ *
+ * @param initialURI
+ */
+ private void addClosingEditorListener(URI initialURI) {
+ if(!listeners.containsKey(initialURI)) {
+ EditorCloseListener value = new EditorCloseListener();
+ if(addPageListener(value)) {
+ listeners.put(initialURI, value);
+ }
+ }
+ }
+
+ /**
+ * Remember that an uri has already be asked
+ *
+ * @param initialURI
+ * , the uri opened by the editor
+ * @param guessed
+ */
+ private void addGuessed(URI initialURI, URI guessed) {
+ Set<URI> set = alreadyGuessed.get(initialURI);
+ if(set == null) {
+ set = new HashSet<URI>();
+ alreadyGuessed.put(initialURI, set);
+ }
+ set.add(guessed);
+ }
+
+ /**
+ * Check if the uri is already asked
+ *
+ * @param initialURI
+ * , the uri opened by the editor
+ * @param toLoad
+ * , the uri to load
+ * @return
+ */
+ private boolean alreadyGuessed(URI initialURI, URI toLoad) {
+ Set<URI> guessed = alreadyGuessed.get(initialURI);
+ if(guessed != null) {
+ return guessed.contains(toLoad);
+ }
+ return false;
+ }
+
+ /**
+ * The extensions are saved to load all the specified resource if the user
+ * wants to load a set of resources
+ *
+ * @param uri
+ * , the file to load
+ * @param trimFragment
+ */
+ private void manageExtensions(URI initialURI, URI toLoad) {
+ Map<URI, Set<String>> map = mappingURIExtensions.get(initialURI);
+ if(map == null) {
+ map = new HashMap<URI, Set<String>>();
+ mappingURIExtensions.put(initialURI, map);
+ }
+ Set<String> extensions = map.get(toLoad.trimFileExtension());
+ if(extensions == null) {
+ extensions = new HashSet<String>();
+ map.put(toLoad.trimFileExtension(), extensions);
+ }
+ extensions.add(toLoad.fileExtension());
+ }
+
+ /**
+ * Get the current editor
+ *
+ * @return
+ */
+ protected CoreMultiDiagramEditor getCurrentEditor() {
+ IEditorPart editor = getEditor();
+ if(editor instanceof CoreMultiDiagramEditor) {
+ return (CoreMultiDiagramEditor)editor;
+ }
+ return null;
+ }
+
+ /**
+ * Create the notification with Yes/No/Yes For All/No For All option
+ *
+ * @param message
+ * , the message to display
+ * @param uri
+ * , the uri to load
+ * @param modelSet
+ * , the model set of the editor
+ * @param initialURI
+ * , the uri opened by the editor
+ * @return a {@link NotificationBuilder} to build
+ */
+ protected NotificationBuilder getNotification(String message, final URI uri, final ModelSet modelSet, final URI initialURI) {
+ NotificationRunnable yes = getYesRunnable(uri, modelSet, initialURI);
+ NotificationRunnable no = getNoRunnable(uri, modelSet, initialURI);
+ NotificationRunnable yesForAll = getYesForAllRunnable(uri, modelSet, initialURI);
+ NotificationRunnable noForAll = getNoForAllRunnable(uri, modelSet, initialURI);
+ return new NotificationBuilder().setType(Type.QUESTION).setAsynchronous(true).setTemporary(false).setMessage(message).setHTML(true).setAsynchronous(true).setTitle(Messages.AskUserStrategy_LOAD_RESOURCE + uri.toString()).addAction(yes).addAction(no).addAction(yesForAll).addAction(noForAll);
+ }
+
+ /**
+ * NO for all registers the NoForAll URI and do nothing
+ * @param uri
+ * @param modelSet
+ * @param initialURI
+ * @return
+ */
+ protected LoadAndRefreshRunnable getNoForAllRunnable(final URI uri, final ModelSet modelSet, final URI initialURI) {
+ return new LoadAndRefreshRunnable(initialURI, uri, modelSet, Messages.AskUserStrategy_NO_FOR_ALL) {
+
+ @Override
+ public void run(IContext context) {
+ addGuessed(getInitialURI(), NoForAllURI);
+ super.run(context);
+ }
+
+ @Override
+ protected void manageRefresh(IEditorReference ref, IEditorPart part) {
+ addAuthorized(getInitialURI(), NoForAllURI);
+
+ List<INotification> list = notifications.get(getInitialURI());
+ if(list != null) {
+ for(INotification n : notifications.get(getInitialURI())) {
+ if(n != getNotification()) {
+ n.delete();
+ }
+ }
+ }
+ // DO NOTHING
+ }
+
+ @Override
+ public int getActionValue() {
+ return SWT.NO;
+ }
+ };
+ }
+
+ /**
+ * Yes for All registers Yes For All URI and refresh the tabs to take in account the loaded elements
+ * @param uri
+ * @param modelSet
+ * @param initialURI
+ * @return
+ */
+ protected LoadAndRefreshRunnable getYesForAllRunnable(final URI uri, final ModelSet modelSet, final URI initialURI) {
+ return new LoadAndRefreshRunnable(initialURI, uri, modelSet, Messages.AskUserStrategy_0) {
+
+ @Override
+ public void run(IContext context) {
+ addGuessed(getInitialURI(), YesForAllURI);
+ super.run(context);
+ }
+
+ @Override
+ RefreshRunnable getRunnable() {
+ return new RefreshRunnable(modelSet, uri, initialURI, true, true) {
+
+ @Override
+ public void run(CoreMultiDiagramEditor editor) {
+ List<INotification> list = notifications.get(getInitialURI());
+ if(list != null) {
+ for(INotification n : notifications.get(getInitialURI())) {
+ if(n instanceof EncapsulatedNotification) {
+ EncapsulatedNotification encapsulated = (EncapsulatedNotification)n;
+ new RefreshRunnable(modelSet, encapsulated.getURIToLoad(), getInitialURI(), false, false).run(editor);
+ }
+ }
+ }
+ new RefreshRunnable(modelSet, null, getInitialURI(), true, true).run(editor);
+ };
+ };
+
+ }
+
+ @Override
+ protected void manageRefresh(IEditorReference ref, IEditorPart part) {
+ addAuthorized(getInitialURI(), YesForAllURI);
+ INotification currentNotification = getNotification();
+ List<INotification> list = notifications.get(getInitialURI());
+ if(list != null) {
+ for(INotification n : notifications.get(getInitialURI())) {
+ if(n != currentNotification) {
+ n.delete();
+ }
+ }
+ }
+ super.manageRefresh(ref, part);
+ }
+
+ @Override
+ public int getActionValue() {
+ return SWT.YES;
+ }
+ };
+ }
+
+ /**
+ * No runnable does not accept the URI asked
+ * @param uri
+ * @param modelSet
+ * @param initialURI
+ * @return
+ */
+ protected LoadAndRefreshRunnable getNoRunnable(final URI uri, final ModelSet modelSet, final URI initialURI) {
+ return new LoadAndRefreshRunnable(initialURI, uri, modelSet, Messages.AskUserStrategy_NO) {
+
+ @Override
+ protected void manageRefresh(IEditorReference ref, IEditorPart part) {
+ // DO NOTHING
+ // inheritance for close listener
+ }
+
+ @Override
+ public int getActionValue() {
+ return SWT.NO;
+ }
+ };
+ }
+
+ /**
+ * Yes registers the URI and refresh the tab to take in account the loaded elements
+ * @param uri
+ * @param modelSet
+ * @param initialURI
+ * @return
+ */
+ protected LoadAndRefreshRunnable getYesRunnable(final URI uri, final ModelSet modelSet, final URI initialURI) {
+ return new LoadAndRefreshRunnable(initialURI, uri, modelSet, Messages.AskUserStrategy_YES);
+ }
+
+ /**
+ * Register the notification created to the URI open by the editor
+ * @param initialURI
+ * @param notification
+ */
+ protected void addNotification(URI initialURI, INotification notification) {
+ List<INotification> notifs = notifications.get(initialURI);
+ if(notifs == null) {
+ notifs = new LinkedList<INotification>();
+ notifications.put(initialURI, notifs);
+ }
+ notifs.add(notification);
+ }
+
+ protected IEditorPart getEditor() {
+ IWorkbenchWindow activeWorkbenchWindow = getActiveWorkbenchWindow();
+ if(activeWorkbenchWindow != null) {
+ IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
+ if(activePage != null) {
+ return activePage.getActiveEditor();
+ }
+ }
+ return null;
+ }
+
+ protected IWorkbenchWindow getActiveWorkbenchWindow() {
+ IWorkbench workbench = PlatformUI.getWorkbench();
+ if(workbench != null) {
+ return workbench.getActiveWorkbenchWindow();
+ }
+ return null;
+ }
+
+ protected IWorkbenchPage getActivePage() {
+ IWorkbenchWindow activeWorkbenchWindow = getActiveWorkbenchWindow();
+ if(activeWorkbenchWindow != null) {
+ return activeWorkbenchWindow.getActivePage();
+ }
+ return null;
+ }
+
+ /**
+ * A basic runnable managing the load of a resource and a refresh of the tabs
+ * If the editor is not opened or activated some listeners will be triggered to launch the refresh
+ *
+ * @author tfaure
+ *
+ */
+ private class LoadAndRefreshRunnable implements NotificationRunnable {
+
+ protected URI initialURI;
+
+ protected URI uri;
+
+ protected ModelSet modelSet;
+
+ protected final String label;
+
+ protected IContext theContext;
+
+ public LoadAndRefreshRunnable(URI initialURI, URI uri, ModelSet modelSet, String label) {
+ this(initialURI, uri, modelSet, label, false);
+ }
+
+ public LoadAndRefreshRunnable(URI initialURI, URI uri, ModelSet modelSet, String label, boolean refreshAll) {
+ this.initialURI = initialURI;
+ this.uri = uri;
+ this.modelSet = modelSet;
+ this.label = label;
+ }
+
+ public URI getInitialURI() {
+ return initialURI;
+ }
+
+ public void run(IContext context) {
+ context.put(IContext.ACTION_ID, getActionValue());
+ theContext = context;
+ IWorkbenchPage activePage = getActivePage();
+ if(activePage != null) {
+ // search the editor which opened the given URI
+ for(IEditorReference ref : activePage.getEditorReferences()) {
+ try {
+ IFile file = (IFile)ref.getEditorInput().getAdapter(IFile.class);
+ if(file != null) {
+ URI createPlatformResourceURI = URI.createPlatformResourceURI(file.getFullPath().removeFileExtension().toString(), true);
+ if(createPlatformResourceURI != null && createPlatformResourceURI.equals(initialURI)) {
+ IEditorPart part = (IEditorPart)ref.getPart(false);
+ manageRefresh(ref, part);
+ // add the uris to load in authorized list
+ }
+ }
+ } catch (PartInitException e) {
+ e.printStackTrace();
+ }
+ }
+ } else {
+ PlatformUI.getWorkbench().addWindowListener(new IWindowListener() {
+
+ public void windowOpened(IWorkbenchWindow window) {
+ }
+
+ public void windowDeactivated(IWorkbenchWindow window) {
+ }
+
+ public void windowClosed(IWorkbenchWindow window) {
+ }
+
+ public void windowActivated(IWorkbenchWindow window) {
+ if(window.getActivePage() != null) {
+ run(new IContext.Context());
+ PlatformUI.getWorkbench().removeWindowListener(this);
+ }
+ }
+ });
+ }
+ }
+
+ public int getActionValue() {
+ return SWT.YES;
+ }
+
+ public INotification getNotification() {
+ return new EncapsulatedNotification((INotification)theContext.get(IContext.NOTIFICATION_OBJECT), uri);
+ }
+
+ protected void manageRefresh(IEditorReference ref, IEditorPart part) {
+ addAuthorized(initialURI, uri);
+ if(part != null) {
+ getRunnable().run((CoreMultiDiagramEditor)part);
+ } else {
+ addPageListener(new EditorActivateListener(ref, modelSet, uri, initialURI, getRunnable()));
+ }
+ }
+
+ RefreshRunnable getRunnable() {
+ return new RefreshRunnable(modelSet, uri, initialURI, false, true);
+
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ }
+
+ /**
+ * Add a page listener
+ * @param listener
+ * @return
+ */
+ protected boolean addPageListener(IPartListener listener) {
+ IWorkbenchPage page = getActivePage();
+ if(page != null) {
+ page.addPartListener(listener);
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Register a listener of the perspective to know when the editor is finally closed
+ * @param listener
+ * @return
+ */
+ protected boolean addPerspectiveListener(IPerspectiveListener listener) {
+ if(PlatformUI.getWorkbench() != null && PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null) {
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().addPerspectiveListener(listener);
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Unregister a perspective listener
+ * @param listener
+ * @return
+ */
+ protected void removePerspectiveListener(IPerspectiveListener listener) {
+ if(PlatformUI.getWorkbench() != null && PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null) {
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().removePerspectiveListener(listener);
+ }
+ }
+
+ protected void removePageListener(IPartListener listener) {
+ IWorkbenchPage page = getActivePage();
+ if(page != null) {
+ page.removePartListener(listener);
+ }
+ }
+
+ protected void addAuthorized(URI initial, URI toAutorized) {
+ Set<URI> uris = authorized.get(initial);
+ if(uris == null) {
+ uris = new HashSet<URI>();
+ authorized.put(initial, uris);
+ }
+ uris.add(toAutorized);
+ }
+
+ /**
+ * Notification containing the {@link URI} loaded
+ *
+ */
+ public class EncapsulatedNotification implements INotification {
+
+ private final INotification notification;
+
+ private final URI uri;
+
+ public EncapsulatedNotification(INotification notification, URI uri) {
+ this.notification = notification;
+ this.uri = uri;
+ }
+
+ public void delete() {
+ this.notification.delete();
+ }
+
+ public boolean isDeleted() {
+ return this.notification.isDeleted();
+ }
+
+ public URI getURIToLoad() {
+ return uri;
+ }
+ }
+
+ /**
+ * An empty {@link IPartListener} implementation
+ * @author tfaure
+ *
+ */
+ private class EditorAdapter implements IPartListener {
+
+ public void partActivated(IWorkbenchPart part) {
+ }
+
+ public void partBroughtToTop(IWorkbenchPart part) {
+ }
+
+ public void partClosed(IWorkbenchPart part) {
+ }
+
+ public void partDeactivated(IWorkbenchPart part) {
+ }
+
+ public void partOpened(IWorkbenchPart part) {
+ }
+
+ }
+
+ /**
+ * Listener which is notifid when an editor is activated
+ * @author tfaure
+ *
+ */
+ private class EditorActivateListener extends EditorAdapter {
+
+ private final IEditorReference reference;
+
+ private final RefreshRunnable refreshRunnable;
+
+ public EditorActivateListener(IEditorReference reference, ModelSet set, URI uri, URI initialURI, RefreshRunnable refreshRunnable) {
+ this.reference = reference;
+ this.refreshRunnable = refreshRunnable;
+ }
+
+ @Override
+ public void partActivated(IWorkbenchPart part) {
+ if(reference.getPart(false) == part && part instanceof CoreMultiDiagramEditor) {
+ refreshRunnable.run((CoreMultiDiagramEditor)part);
+ removePageListener(this);
+ }
+ }
+
+ }
+
+ /**
+ * Listener which is notifid when an editor is closed
+ * @author tfaure
+ *
+ */
+ private class EditorCloseListener extends EditorAdapter {
+
+ @Override
+ public void partClosed(IWorkbenchPart part) {
+ super.partClosed(part);
+ if(part instanceof CoreMultiDiagramEditor) {
+ CoreMultiDiagramEditor editor = (CoreMultiDiagramEditor)part;
+ IFile file = (IFile)editor.getEditorInput().getAdapter(IFile.class);
+ if(file != null) {
+ if(file.getFullPath() != null) {
+ final URI uri = URI.createPlatformResourceURI(file.getFullPath().removeFileExtension().toString(), true);
+ addPerspectiveListener(new EditorClosePerspectiveListener(uri));
+ removePageListener(this);
+ listeners.remove(uri);
+ }
+ }
+ }
+ }
+
+ }
+
+ /**
+ * A perspective listener which choices of an user
+ * @author tfaure
+ *
+ */
+ protected class EditorClosePerspectiveListener implements IPerspectiveListener {
+
+ private final URI uri;
+
+ public EditorClosePerspectiveListener(URI uri) {
+ this.uri = uri;
+ }
+
+ public void perspectiveActivated(IWorkbenchPage page, IPerspectiveDescriptor perspective) {
+ }
+
+ public void perspectiveChanged(IWorkbenchPage page, IPerspectiveDescriptor perspective, String changeId) {
+ authorized.remove(uri);
+ mappingURIExtensions.remove(uri);
+ alreadyGuessed.remove(uri);
+ List<INotification> list = notifications.get(uri);
+ if(list != null) {
+ for(INotification n : list) {
+ n.delete();
+ }
+ }
+ notifications.remove(uri);
+ removePerspectiveListener(this);
+ }
+
+ }
+
+ /**
+ * A runnable refreshing resource and/or pages
+ *
+ * @author tfaure
+ *
+ */
+ public class RefreshRunnable {
+
+ protected DiSashModelMngr sashModelMngr;
+
+ protected IPageMngr pageMngr;
+
+ protected URI uri;
+
+ protected final ModelSet modelSet;
+
+ protected final URI initialURI;
+
+ private final boolean refreshAll;
+
+ private final boolean refreshTab;
+
+ public RefreshRunnable(ModelSet modelSet, URI uriToLoad, URI initialURI, boolean refreshAll, boolean refreshTab) {
+ this.modelSet = modelSet;
+ uri = uriToLoad;
+ this.initialURI = initialURI;
+ this.refreshAll = refreshAll;
+ this.refreshTab = refreshTab;
+ }
+
+ public void run(CoreMultiDiagramEditor editor) {
+ final Set<URI> alreadyLoaded = new HashSet<URI>();
+ try {
+ sashModelMngr = editor.getServicesRegistry().getService(DiSashModelMngr.class);
+ pageMngr = sashModelMngr.getIPageMngr();
+ List<Object> allPages = sashModelMngr.getIPageMngr().allPages();
+ // the uri is added after getting all the pages. If it is done
+ // before, the eobjects are resolved
+ NotificationBuilder error = NotificationBuilder.createAsyncPopup(Messages.AskUserStrategy_ERROR, String.format(Messages.AskUserStrategy_UNABLE_TO_LOAD, uri != null ? uri.toString() : Messages.AskUserStrategy_12)).setType(Type.ERROR).setDelay(2000);
+ // load associated resources
+ // the extensions needed for each element are saved so it is not needed to check filesystem
+ Set<String> extensions = getExtensions();
+ if(extensions != null) {
+ for(String s : extensions) {
+ try {
+ if(s != null) {
+ URI uriToLoad = URI.createURI(uri.toString());
+ if(s != null) {
+ uriToLoad = uriToLoad.appendFileExtension(s);
+ }
+ // the resource is loaded only if it is needed
+ if(!alreadyLoaded.contains(uriToLoad)) {
+ Resource r = modelSet.getResource(uriToLoad, true);
+ alreadyLoaded.add(uriToLoad);
+ if(r == null) {
+ error.run();
+ }
+ }
+ }
+ } catch (Exception re) {
+ error.run();
+ re.printStackTrace();
+ }
+ }
+ }
+ // refresh tabs
+ for(Object o : allPages) {
+ if(o instanceof EObject) {
+ EObject eobject = (EObject)o;
+ URI eobjectURI = EcoreUtil.getURI(eobject);
+ if(refreshAll || (refreshTab && eobjectURI.trimFileExtension().trimFragment().equals(uri))) {
+ // TODO improve this when an update is created
+ pageMngr.closePage(o);
+ pageMngr.openPage(eobject);
+ }
+ }
+ }
+
+ } catch (ServiceException e1) {
+ e1.printStackTrace();
+ }
+
+ }
+
+ public Set<String> getExtensions() {
+ Map<URI, Set<String>> map = mappingURIExtensions.get(initialURI);
+ if(map != null) {
+ return map.get(uri);
+ }
+ return null;
+ }
+
+ public IWorkbenchPage getActivePage() {
+ IWorkbench workbench = PlatformUI.getWorkbench();
+ if(workbench != null) {
+ IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow();
+ if(activeWorkbenchWindow != null) {
+ if(activeWorkbenchWindow.getActivePage() != null) {
+ return activeWorkbenchWindow.getActivePage();
+ }
+ }
+ }
+ return null;
+ }
+
+ }
+}
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/strategies/LoadAllResources.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/strategies/LoadAllResources.java
new file mode 100644
index 00000000000..475dd2e3b7f
--- /dev/null
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/strategies/LoadAllResources.java
@@ -0,0 +1,34 @@
+/*****************************************************************************
+ * Copyright (c) 2010 Atos Origin.
+ *
+ *
+ * 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:
+ * Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.services.resourceloading.strategies;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.services.resourceloading.ILoadingStrategy;
+
+
+/**
+ * Default strategy that load all the resources
+ */
+public class LoadAllResources implements ILoadingStrategy {
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean loadResource(ModelSet modelSet, URI uri) {
+ // whatever is the uri, the resource is loaded
+ return true;
+ }
+
+}
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/strategies/LoadControlledResources.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/strategies/LoadControlledResources.java
new file mode 100644
index 00000000000..f47c51b516d
--- /dev/null
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/strategies/LoadControlledResources.java
@@ -0,0 +1,52 @@
+/*****************************************************************************
+ * Copyright (c) 2010 Atos Origin.
+ *
+ *
+ * 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:
+ * Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.services.resourceloading.strategies;
+
+import java.util.Set;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.resource.sasheditor.SashModelUtils;
+import org.eclipse.papyrus.infra.services.controlmode.history.HistoryModel;
+import org.eclipse.papyrus.infra.services.controlmode.history.utils.HistoryUtils;
+import org.eclipse.papyrus.infra.services.resourceloading.HistoryRoutingUtils;
+import org.eclipse.papyrus.infra.services.resourceloading.ILoadingStrategy;
+
+
+public class LoadControlledResources implements ILoadingStrategy {
+
+ /**
+ * {@inheritDoc} Loads additional resources (types, profiles, etc)
+ * The controlled resources from the current one are loaded
+ * Other resources used from references are not loaded
+ */
+ public boolean loadResource(ModelSet modelSet, URI uri) {
+ boolean result = !uri.isPlatform() && !uri.isFile();
+ if(!result) {
+ URI initialURI = SashModelUtils.getInitialURI(modelSet).trimFileExtension().appendFileExtension(uri.fileExtension());
+ URI uriInitialTrimFragment = initialURI.trimFragment();
+ URI uritrimFragment = uri.trimFragment();
+ result = uritrimFragment.equals(uriInitialTrimFragment);
+ // if !result it is necessary to navigate into the history to find if the uri searched is a controlled
+ if(!result) {
+ HistoryModel model = HistoryUtils.getHistoryModel(modelSet);
+ URI path = HistoryUtils.getURIFullPath(uriInitialTrimFragment);
+ URI resolve = URI.createURI(HistoryUtils.resolve(path, uriInitialTrimFragment));
+ Set<String> allControled = HistoryRoutingUtils.getAllControledURIs(modelSet, model, resolve, true);
+ result = allControled.contains(HistoryUtils.resolve(path, uritrimFragment).toString());
+ }
+ }
+ return result;
+ }
+}
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/strategies/LoadCurrentResource.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/strategies/LoadCurrentResource.java
new file mode 100644
index 00000000000..e7ff17b2a8a
--- /dev/null
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/strategies/LoadCurrentResource.java
@@ -0,0 +1,31 @@
+/*****************************************************************************
+ * Copyright (c) 2010 Atos Origin.
+ *
+ *
+ * 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:
+ * Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.services.resourceloading.strategies;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.services.resourceloading.ILoadingStrategy;
+
+
+public class LoadCurrentResource implements ILoadingStrategy {
+
+ /**
+ * {@inheritDoc} Only loads additional resources (types, profiles, etc) and the current opened resource
+ * Controlled resources from the current one are not loaded
+ */
+ public boolean loadResource(ModelSet modelSet, URI uri) {
+ return (!uri.isPlatform() && !uri.isFile());
+ }
+
+}
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/strategies/Messages.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/strategies/Messages.java
new file mode 100644
index 00000000000..f67582807da
--- /dev/null
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/strategies/Messages.java
@@ -0,0 +1,41 @@
+package org.eclipse.papyrus.infra.services.resourceloading.strategies;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+
+ private static final String BUNDLE_NAME = "org.eclipse.papyrus.infra.services.resourceloading.strategies.messages"; //$NON-NLS-1$
+
+ public static String AskUserStrategy_0;
+
+ public static String AskUserStrategy_12;
+
+ public static String AskUserStrategy_ERROR;
+
+ public static String AskUserStrategy_LOAD_RESOURCE;
+
+ public static String AskUserStrategy_MESSAGE_PART_1;
+
+ public static String AskUserStrategy_MESSAGE_PART_2;
+
+ public static String AskUserStrategy_MESSAGE_PART3;
+
+ public static String AskUserStrategy_NO;
+
+ public static String AskUserStrategy_NO_FOR_ALL;
+
+ public static String AskUserStrategy_NO_FOR_ALL_URI;
+
+ public static String AskUserStrategy_UNABLE_TO_LOAD;
+
+ public static String AskUserStrategy_YES;
+
+ public static String AskUserStrategy_YES_FOR_ALL_URI;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/strategies/messages.properties b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/strategies/messages.properties
new file mode 100644
index 00000000000..0d70f650ff3
--- /dev/null
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/strategies/messages.properties
@@ -0,0 +1,13 @@
+AskUserStrategy_0=Yes for all
+AskUserStrategy_12=
+AskUserStrategy_ERROR=Error
+AskUserStrategy_LOAD_RESOURCE=Load resource
+AskUserStrategy_MESSAGE_PART_1=<form><p>The editor opening the file
+AskUserStrategy_MESSAGE_PART_2=\ is trying to open an external resource:</p><p>
+AskUserStrategy_MESSAGE_PART3=</p><p>Do you want to load it ?</p></form>
+AskUserStrategy_NO=No
+AskUserStrategy_NO_FOR_ALL=No for all
+AskUserStrategy_NO_FOR_ALL_URI=papyrus://NoForAll
+AskUserStrategy_UNABLE_TO_LOAD=Unable to load resource %s
+AskUserStrategy_YES=Yes
+AskUserStrategy_YES_FOR_ALL_URI=papyrus://YesForAll
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/util/LoadingTester.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/util/LoadingTester.java
new file mode 100644
index 00000000000..755898687f8
--- /dev/null
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/util/LoadingTester.java
@@ -0,0 +1,147 @@
+/*****************************************************************************
+ * Copyright (c) 2011 Atos.
+ *
+ *
+ * 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:
+ * Vincent Hemery (Atos) vincent.hemery@atos.net - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.services.resourceloading.util;
+
+import java.util.Iterator;
+
+import org.eclipse.core.expressions.PropertyTester;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
+import org.eclipse.gmf.runtime.notation.Edge;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.resource.notation.NotationUtils;
+
+/**
+ * This class provides test to perform on resources to know their loading status.
+ */
+public class LoadingTester extends PropertyTester {
+
+ /** property to test if the selected elements are in loaded resources (at least one other than the opened one) */
+ public static final String IS_ALL_LOADED = "isAllLoaded"; //$NON-NLS-1$
+
+ /** property to test if the selected elements are in not loaded resources */
+ public static final String IS_ALL_NOTLOADED = "isAllNotLoaded"; //$NON-NLS-1$
+
+ /**
+ * Test a property
+ *
+ * @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object)
+ *
+ * @param receiver
+ * @param property
+ * @param args
+ * @param expectedValue
+ * @return
+ */
+ public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
+ if(IS_ALL_LOADED.equals(property) && receiver instanceof IStructuredSelection) {
+ boolean answer = isInLoadedResource((IStructuredSelection)receiver);
+ return new Boolean(answer).equals(expectedValue);
+ }
+ if(IS_ALL_NOTLOADED.equals(property) && receiver instanceof IStructuredSelection) {
+ boolean answer = isInNotLoadedResource((IStructuredSelection)receiver);
+ return new Boolean(answer).equals(expectedValue);
+ }
+ return false;
+ }
+
+ /**
+ * Tests the selection in order to know if it is in a loaded resource
+ *
+ * @param selection
+ * selected elements
+ * @return <code>true</code> if all selected elements are in loaded resources ; <code>false</code otherwise or if empty selection
+ */
+ private boolean isInLoadedResource(IStructuredSelection selection) {
+ if(!selection.isEmpty()) {
+ boolean atLeastOneInSubmodel = false;
+ URI mainURI = null;
+ Iterator<?> iter = selection.iterator();
+ while(iter.hasNext()) {
+ Object obj = iter.next();
+ if(obj instanceof IAdaptable) {
+ View view = (View)((IAdaptable)obj).getAdapter(View.class);
+ EObject eObject;
+ if(view != null) {
+ eObject = view.getElement();
+ } else {
+ eObject = (EObject)((IAdaptable)obj).getAdapter(EObject.class);
+ }
+ if(eObject != null && !eObject.eIsProxy()) {
+ // test that there is at least one not loaded resource object
+ if(!atLeastOneInSubmodel) {
+ Resource containingResource = eObject.eResource();
+ if(mainURI == null && containingResource != null && containingResource.getResourceSet() instanceof ModelSet) {
+ mainURI = NotationUtils.getNotationModel((ModelSet)containingResource.getResourceSet()).getResourceURI().trimFileExtension();
+ }
+ if(mainURI != null) {
+ URI uriTrim = containingResource.getURI().trimFileExtension();
+ atLeastOneInSubmodel = !uriTrim.equals(mainURI);
+ }
+ }
+ continue;
+ }
+ }
+ // a step failed
+ return false;
+ }
+ return atLeastOneInSubmodel;
+ }
+ return false;
+ }
+
+ /**
+ * Tests the selection in order to know if it is in a not loaded resource
+ *
+ * @param selection
+ * selected elements
+ * @return <code>true</code> if all selected elements are in not loaded resources ; <code>false</code otherwise or if empty selection
+ */
+ private boolean isInNotLoadedResource(IStructuredSelection selection) {
+ if(!selection.isEmpty()) {
+ Iterator<?> iter = selection.iterator();
+ while(iter.hasNext()) {
+ Object obj = iter.next();
+ if(obj instanceof IAdaptable) {
+ View view = (View)((IAdaptable)obj).getAdapter(View.class);
+ EObject eObject;
+ if(view != null) {
+ eObject = view.getElement();
+ } else {
+ eObject = (EObject)((IAdaptable)obj).getAdapter(EObject.class);
+ }
+ if(eObject != null && eObject.eIsProxy()) {
+ continue;
+ } else if(view instanceof Edge) {
+ View target = ((Edge)view).getTarget();
+ if(target != null && ViewUtil.resolveSemanticElement(target) == null) {
+ // there is a backslash decorator
+ continue;
+ }
+ }
+ }
+ // a step failed
+ return false;
+ }
+ return true;
+ }
+ return false;
+ }
+
+}
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/util/LoadingUtils.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/util/LoadingUtils.java
new file mode 100644
index 00000000000..66795f80efe
--- /dev/null
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/util/LoadingUtils.java
@@ -0,0 +1,348 @@
+/*****************************************************************************
+ * Copyright (c) 2011 Atos Origin.
+ *
+ *
+ * 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:
+ * Vincent Hemery (Atos) vincent.hemery@atos.net - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.services.resourceloading.util;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.InternalEObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.GraphicalEditPart;
+import org.eclipse.gef.util.EditPartUtilities;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
+import org.eclipse.papyrus.infra.core.editor.CoreMultiDiagramEditor;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.resource.notation.NotationModel;
+import org.eclipse.papyrus.infra.core.resource.sasheditor.DiModel;
+import org.eclipse.papyrus.infra.core.resource.uml.UmlModel;
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageMngr;
+import org.eclipse.papyrus.infra.core.sasheditor.di.contentprovider.DiSashModelMngr;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.services.resourceloading.Activator;
+import org.eclipse.papyrus.infra.services.resourceloading.Messages;
+import org.eclipse.papyrus.infra.widgets.toolbox.notification.Type;
+import org.eclipse.papyrus.infra.widgets.toolbox.notification.builders.NotificationBuilder;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * This class provides utility methods for model loading
+ *
+ * @author vhemery
+ */
+public class LoadingUtils {
+
+ /**
+ * Load corresponding resources in model set for all its existing models.
+ *
+ * @param modelSet
+ * the model set
+ * @param uriWithoutFileExtension
+ * path of resources to load without file extension
+ */
+ public static void loadResourcesInModelSet(ModelSet modelSet, URI uriWithoutFileExtension) {
+ // initiate progress dialog
+ ProgressMonitorDialog dialog = new ProgressMonitorDialog(Display.getCurrent().getActiveShell());
+ dialog.open();
+ IProgressMonitor monitor = dialog.getProgressMonitor();
+
+ IEditorPart editor = getEditor();
+ if(editor instanceof CoreMultiDiagramEditor) {
+ CoreMultiDiagramEditor core = (CoreMultiDiagramEditor)editor;
+ try {
+ DiSashModelMngr sashModelMngr = core.getServicesRegistry().getService(DiSashModelMngr.class);
+ IPageMngr pageMngr = sashModelMngr.getIPageMngr();
+ List<Object> allPages = pageMngr.allPages();
+ // mark progress
+ monitor.beginTask(Messages.LoadingUtils_RefreshPagesTask, allPages.size());
+ // the uri is added after getting all the pages. If it is done before, the eobjects are resolved
+ NotificationBuilder error = NotificationBuilder.createAsyncPopup(Messages.LoadingUtils_ErrorTitle, String.format(Messages.LoadingUtils_ErrorMessage, uriWithoutFileExtension.toString())).setType(Type.ERROR).setDelay(2000);
+ for(Object o : allPages) {
+ // refresh pages to display proxy diagrams
+ if(o instanceof EObject) {
+ EObject eobject = (EObject)o;
+ if(eobject.eIsProxy()) {
+ InternalEObject internal = (InternalEObject)eobject;
+ URI uriProxy = internal.eProxyURI();
+ URI trimFragment = uriProxy.trimFragment();
+ if(uriWithoutFileExtension.equals(trimFragment.trimFileExtension())) {
+ try {
+ Resource r = modelSet.getResource(trimFragment, true);
+ if(r != null) {
+ EObject newEObject = r.getEObject(uriProxy.fragment());
+ if(pageMngr.isOpen(newEObject)) {
+ pageMngr.closePage(newEObject);
+ pageMngr.openPage(newEObject);
+ }
+ } else {
+ error.run();
+ }
+ } catch (Exception e) {
+ error.run();
+ Activator.logError(e);
+ }
+ }
+ }
+ }
+ // mark progress
+ monitor.worked(1);
+ }
+ Set<String> extensions = getExtensions(modelSet);
+ // mark progress
+ monitor.beginTask(Messages.LoadingUtils_LoadModelsTask, extensions.size());
+ for(String s : extensions) {
+ try {
+ URI uriToLoad = uriWithoutFileExtension.appendFileExtension(s);
+ Resource r = modelSet.getResource(uriToLoad, true);
+ if(r == null) {
+ error.run();
+ }
+ } catch (Exception re) {
+ error.run();
+ Activator.logError(re);
+ }
+ // mark progress
+ monitor.worked(1);
+ }
+ } catch (ServiceException e) {
+ Activator.logError(e);
+ }
+ }
+ // mark progress
+ monitor.done();
+ dialog.close();
+ }
+
+ /**
+ * Unload corresponding resources from model set for all its existing models.
+ *
+ * @param modelSet
+ * the model set
+ * @param uriWithoutFileExtension
+ * path of resources to unload without file extension
+ */
+ public static void unloadResourcesFromModelSet(ModelSet modelSet, URI uriWithoutFileExtension) {
+ unloadResourcesFromModelSet(modelSet, uriWithoutFileExtension, true);
+ }
+
+ /**
+ * Unload corresponding resources from model set for all its existing models.
+ *
+ * @param modelSet
+ * the model set
+ * @param uriWithoutFileExtension
+ * path of resources to unload without file extension
+ * @param refreshDiagramsWithProxies
+ * true if we must refresh necessary diagrams, false to skip it.
+ */
+ public static void unloadResourcesFromModelSet(ModelSet modelSet, URI uriWithoutFileExtension, boolean refreshDiagramsWithProxies) {
+ // initiate progress dialog
+ ProgressMonitorDialog dialog = new ProgressMonitorDialog(Display.getCurrent().getActiveShell());
+ dialog.open();
+ IProgressMonitor monitor = dialog.getProgressMonitor();
+
+ IEditorPart editor = getEditor();
+ if(editor instanceof CoreMultiDiagramEditor) {
+ CoreMultiDiagramEditor core = (CoreMultiDiagramEditor)editor;
+ try {
+ DiSashModelMngr sashModelMngr = core.getServicesRegistry().getService(DiSashModelMngr.class);
+ IPageMngr pageMngr = sashModelMngr.getIPageMngr();
+ List<Object> allPages = pageMngr.allPages();
+ List<URI> pagesURIToOpen = new ArrayList<URI>(allPages.size());
+ List<URI> pagesURIToRefresh = new ArrayList<URI>(allPages.size());
+ if(refreshDiagramsWithProxies) {
+ // mark progress
+ monitor.beginTask(Messages.LoadingUtils_RefreshPagesTask, allPages.size());
+ for(Object o : allPages) {
+ // refresh pages to cancel display of proxified elements
+ if(o instanceof EObject) {
+ EObject eobject = (EObject)o;
+ if(!eobject.eIsProxy()) {
+ URI trimFragment = eobject.eResource().getURI();
+ String frag = eobject.eResource().getURIFragment(eobject);
+ if(uriWithoutFileExtension.equals(trimFragment.trimFileExtension())) {
+ // diagram was in unloaded resource. Refresh it.
+ if(pageMngr.isOpen(eobject)) {
+ pageMngr.closePage(eobject);
+ pagesURIToOpen.add(trimFragment.appendFragment(frag));
+ }
+ } else if(pageMngr.isOpen(eobject)) {
+ // diagram is still loaded but may display proxified elements
+ pagesURIToRefresh.add(trimFragment.appendFragment(frag));
+ }
+ }
+ }
+ // mark progress
+ monitor.worked(1);
+ }
+ }
+ // mark progress
+ monitor.beginTask(Messages.LoadingUtils_UnloadModelsTask, modelSet.getResources().size());
+ // unload resource
+ for(Resource res : new ArrayList<Resource>(modelSet.getResources())) {
+ if(res.getURI().trimFileExtension().equals(uriWithoutFileExtension)) {
+ // unload this resource
+ modelSet.getResources().remove(res);
+ res.unload();
+ res.eAdapters().clear();
+ }
+ // mark progress
+ monitor.worked(1);
+ }
+ // // mark progress
+ // monitor.beginTask("Resolve", 1);
+ // EcoreUtil.resolveAll(modelSet);
+ // monitor.worked(1);
+
+ if(refreshDiagramsWithProxies) {
+ // mark progress
+ monitor.beginTask(Messages.LoadingUtils_RefreshPagesTask, allPages.size());
+ // reopen pages from proxies and refresh necessary pages
+ for(Object page : allPages) {
+ if(page instanceof EObject) {
+ EObject eobject = (EObject)page;
+ if(eobject.eIsProxy()) {
+ // reopen page from proxy if needed
+ InternalEObject internal = (InternalEObject)eobject;
+ URI uriProxy = internal.eProxyURI();
+ if(pagesURIToOpen.contains(uriProxy)) {
+ pageMngr.openPage(eobject);
+ }
+ } else if(eobject instanceof Diagram) {
+ // refresh page's diagram if needed
+ Diagram diag = ((Diagram)eobject);
+ if(pageMngr.isOpen(diag)) {
+ Object part = core.getDiagramGraphicalViewer().getEditPartRegistry().get(diag);
+ if(part instanceof GraphicalEditPart) {
+ // refresh nodes
+ for(Object child : EditPartUtilities.getAllChildren((GraphicalEditPart)part)) {
+ if(child instanceof EditPart) {
+ ((EditPart)child).refresh();
+ }
+ }
+ // refresh edges
+ for(Object child : EditPartUtilities.getAllNestedConnectionEditParts((GraphicalEditPart)part)) {
+ if(child instanceof EditPart) {
+ ((EditPart)child).refresh();
+ }
+ }
+ }
+ }
+ }
+ }
+ // mark progress
+ monitor.worked(1);
+ }
+ }
+ } catch (ServiceException e) {
+ Activator.logError(e);
+ }
+ }
+ // mark progress
+ monitor.done();
+ dialog.close();
+ }
+
+ /**
+ * Common extensions
+ * TODO get rid of listing all model's extensions and find a way to deduce them from model set. Then, delete this attribute.
+ *
+ * @see #getExtensions(ModelSet)
+ */
+ private static final Set<String> COMMON_EXTENSIONS = new HashSet<String>();
+ static {
+ COMMON_EXTENSIONS.add(UmlModel.UML_FILE_EXTENSION);
+ COMMON_EXTENSIONS.add(NotationModel.NOTATION_FILE_EXTENSION);
+ COMMON_EXTENSIONS.add(DiModel.DI_FILE_EXTENSION);
+ }
+
+ /**
+ * Get list of file extensions existing for this model set
+ *
+ * @param modelSet
+ * model set to find common extensions for
+ * @return extensions list to explore
+ */
+ private static Set<String> getExtensions(ModelSet modelSet) {
+ return COMMON_EXTENSIONS;
+ }
+
+ /**
+ * Get currently opened editor
+ *
+ * @return editor
+ */
+ public static IEditorPart getEditor() {
+ IEditorPart editor = null;
+ IWorkbench workbench = PlatformUI.getWorkbench();
+ if(workbench != null) {
+ IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow();
+ if(activeWorkbenchWindow != null) {
+ IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
+ if(activePage != null) {
+ editor = activePage.getActiveEditor();
+ }
+ }
+ }
+ return editor;
+ }
+
+ /**
+ * Get File from a URI
+ *
+ * @param uri
+ * the URI to transform
+ * @return the corresponding file
+ */
+ public static IFile getFile(URI uri) {
+ IPath path = getPath(uri);
+ if(path != null) {
+ return ResourcesPlugin.getWorkspace().getRoot().getFile(path);
+ }
+ return null;
+ }
+
+ /**
+ * Get Path from a URI
+ *
+ * @param uri
+ * the URI to transform
+ * @return the corresponding path
+ */
+ public static IPath getPath(URI uri) {
+ String scheme = uri.scheme();
+ IPath path = null;
+ if("platform".equals(scheme)) { //$NON-NLS-1$
+ path = Path.fromPortableString(uri.toPlatformString(true));
+ } else if("file".equals(scheme)) { //$NON-NLS-1$
+ path = Path.fromPortableString(uri.toFileString());
+ }
+ return path;
+ }
+}

Back to the top