diff options
author | Christian W. Damus | 2014-02-25 23:31:55 +0000 |
---|---|---|
committer | Christian W. Damus | 2014-02-25 23:31:55 +0000 |
commit | b445cdea6a2ee1321e569876cd3b2a27fdba66ca (patch) | |
tree | 1cade6c0ac4e912e31b7907536c3aa7d58c136de /plugins/infra | |
parent | edd3306fe2372730c8f6cf4d5ebede0bd1a5e088 (diff) | |
parent | 68e107f65621e9e3c6b05f88ad44873efdc4ceb1 (diff) | |
download | org.eclipse.papyrus-b445cdea6a2ee1321e569876cd3b2a27fdba66ca.tar.gz org.eclipse.papyrus-b445cdea6a2ee1321e569876cd3b2a27fdba66ca.tar.xz org.eclipse.papyrus-b445cdea6a2ee1321e569876cd3b2a27fdba66ca.zip |
Merge branch 'refs/heads/master' into bugs/323802-readonly
Conflicts:
plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/EMFHelper.java
Diffstat (limited to 'plugins/infra')
9 files changed, 275 insertions, 246 deletions
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ModelSet.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ModelSet.java index ab35daa7cf7..9593f16a68b 100644 --- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ModelSet.java +++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ModelSet.java @@ -1,7 +1,7 @@ /***************************************************************************** * Copyright (c) 2008, 2013 CEA LIST and others. * - * + * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -61,7 +61,7 @@ import com.google.common.base.Optional; /** * This class is used to manage a set of {@link IModel}. - * + * * <h2>>Usage</h2> * <ul> * <li>First, register associated model. A loader can be used.</li> @@ -69,16 +69,16 @@ import com.google.common.base.Optional; * <li>Then, it is possible to get associated models</li> * <li>Finally, call save()</li> * </ul> - * + * * Please note that indirectly referenced models are loaded on demand. If a * model contains a cross reference towards another model (e.g. an import in * case of UML) the referenced resource does not appear initially in the set. * However, it is added once the referenced model is resolved. - * + * * TODO Modify ModelSetSnippet in order to inform them of model addition. - * + * * @author cedric dumoulin - * + * */ public class ModelSet extends ResourceSetImpl { @@ -115,18 +115,18 @@ public class ModelSet extends ResourceSetImpl { */ protected Set<URI> toDeleteOnSave = new HashSet<URI>(); - /** list of listeners of resources to know if the resource are loaded or not */ + /** list of listeners of resources to know if the resource are loaded or not */ protected ArrayList<IResourceLoadStateListener> resourceLoadStateListeners; /** map of resource loaded in the resource set, with resource as the key and a boolean indicating if the resource is loaded or not has the valuer */ protected Map<Resource, Boolean> resourcesToLoadState = new HashMap<Resource, Boolean>(); - - + + /** - * + * * Constructor. - * + * */ public ModelSet() { registerModel(additional); @@ -144,7 +144,7 @@ public class ModelSet extends ResourceSetImpl { * Register the specified model under its associated key. The key is defined * in the model itself. It is usually the model type from * (ModelPackage.eCONTENT_TYPE). - * + * * @param model * the model */ @@ -164,7 +164,7 @@ public class ModelSet extends ResourceSetImpl { /** * Get a model by its key. TODO throw an exception if not found. - * + * * @param key * the key * @return the model @@ -175,7 +175,7 @@ public class ModelSet extends ResourceSetImpl { /** * Get a model by its key. TODO throw an exception if not found. - * + * * @param key * the key * @return the model @@ -213,7 +213,8 @@ public class ModelSet extends ResourceSetImpl { throw e; } } - return setResourceOptions(r); + + return r != null && r.isLoaded() ? r : setResourceOptions(r); } @Override @@ -246,7 +247,7 @@ public class ModelSet extends ResourceSetImpl { /** * @deprecated please use {@link #getAssociatedResource(EObject, String, boolean)} instead - * + * * @param modelElement * @param associatedResourceExtension * @return @@ -258,7 +259,7 @@ public class ModelSet extends ResourceSetImpl { /** * @deprecated please use {@link #getAssociatedResource(Resource, String, boolean)} instead - * + * * @param modelResource * @param associatedResourceExtension * @return @@ -270,7 +271,7 @@ public class ModelSet extends ResourceSetImpl { /** * Retrieve and load the associated resource which have the given extension. - * + * * @param modelElement * @param associatedResourceExtension * @param loadOnDemand @@ -286,7 +287,7 @@ public class ModelSet extends ResourceSetImpl { /** * Retrieve and load the associated resource which have the given extension. - * + * * @param modelResource * @param associatedResourceExtension * @param loadOnDemand @@ -305,12 +306,15 @@ public class ModelSet extends ResourceSetImpl { /** * This method is called by getResource, createResource and demandLoad before returning * the resource to the caller so we can set options on the resource. - * + * * @param r * , can be null * @return the same resource for convenience */ protected Resource setResourceOptions(Resource r) { + if(r != null && r.getURI() != null && r.getURI().toString().contains("Robot")) { + System.out.println("Break"); + } if(r != null && isTrackingModification() && !r.isTrackingModification()) { r.setTrackingModification(true); } @@ -326,7 +330,7 @@ public class ModelSet extends ResourceSetImpl { /** * Create the transactional editing domain. - * + * * @return the transactional editing domain */ public synchronized TransactionalEditingDomain getTransactionalEditingDomain() { @@ -342,7 +346,7 @@ public class ModelSet extends ResourceSetImpl { /** * @return the filenameWithoutExtension - * + * * @deprecated Use the {@link #getURIWithoutExtension()} API, instead. */ @Deprecated @@ -387,11 +391,11 @@ public class ModelSet extends ResourceSetImpl { /** * Create all the associated models. This creates the models, regardless if * they already exist. - * + * * @param newFile * The file from which path is extracted to create the new * resources - * + * * @deprecated Use the {@link #createModels(URI)} API, instead. */ @Deprecated @@ -402,7 +406,7 @@ public class ModelSet extends ResourceSetImpl { /** * Create all the associated models. This creates the models, regardless if * they already exist. - * + * * @param newFile * The file from which path is extracted to create the new * resources @@ -424,9 +428,9 @@ public class ModelSet extends ResourceSetImpl { /** * Create the model specified by the identifiers. Other models are * untouched, unless they are sharing something with specified models. - * + * * This creates the models, regardless if they already exist. - * + * * @param newFile * The file from which path is extracted to create the new * resources @@ -448,7 +452,7 @@ public class ModelSet extends ResourceSetImpl { /** * Load only the specified model. ModelSetSnippets are not called. Model is * loaded using the ModelSet Path. - * + * * @param modelIdentifier * the model identifier * @param file @@ -468,7 +472,7 @@ public class ModelSet extends ResourceSetImpl { /** * Import only the specified model. ModelSetSnippets are not called. - * + * * @param modelIdentifier * the model identifier * @param file @@ -489,7 +493,7 @@ public class ModelSet extends ResourceSetImpl { /** * Load all the associated models from a handle on one of the associated * file. - * + * * @param file * The file to load (no matter the extension) * @deprecated Use the {@link #loadModels(URI)} API, instead. @@ -506,7 +510,7 @@ public class ModelSet extends ResourceSetImpl { /** * Load all the associated models from a URI identifying one of the associated * files. - * + * * @param uri * The URI to load (no matter the extension) */ @@ -517,7 +521,7 @@ public class ModelSet extends ResourceSetImpl { ModelMultiException exceptions = null; List<IModel> orderedModelsForLoading = getOrderedModelsForLoading(); - + // Walk all registered models for(IModel model : orderedModelsForLoading) { // Try to load each model. Catch exceptions in order to load other @@ -544,8 +548,9 @@ public class ModelSet extends ResourceSetImpl { } /** - * Returns the models to be loaded, in order according to their dependencies - * @return the models to be loaded, in order according to their dependencies + * Returns the models to be loaded, in order according to their dependencies + * + * @return the models to be loaded, in order according to their dependencies */ protected List<IModel> getOrderedModelsForLoading() { return ModelUtils.getOrderedModelsForLoading(models); @@ -555,14 +560,14 @@ public class ModelSet extends ResourceSetImpl { * Import specified models into the ModelSet. The models are imported using * the specified IFile. After import, the models are associated with the * ModelSet Path. - * + * * @param modelIdentifiers * The model to import from the specified IFile. * @param file * The IFile used to import the model. * @throws ModelException * If an error occur during import. - * + * * @deprecated Use the {@link #importModels(ModelIdentifiers, URI)} API, instead */ @Deprecated @@ -575,7 +580,7 @@ public class ModelSet extends ResourceSetImpl { * Import specified models into the ModelSet. The models are imported using * the specified IFile. After import, the models are associated with the * ModelSet Path. - * + * * @param modelIdentifiers * The model to import from the specified IFile. * @param file @@ -602,14 +607,14 @@ public class ModelSet extends ResourceSetImpl { * Import only the specified model. ModelSetSnippets are not called. An * import can be performed after model are loaded. Normally, it should not * be done before a model is loaded. - * + * * @param modelIdentifier * the model identifier * @param file * the file * @throws ModelException * @returns The loaded model. - * + * * @deprecated Use the {@link #importModel(String, URI)} API, instead. */ @Deprecated @@ -622,7 +627,7 @@ public class ModelSet extends ResourceSetImpl { * Import only the specified model. ModelSetSnippets are not called. An * import can be performed after model are loaded. Normally, it should not * be done before a model is loaded. - * + * * @param modelIdentifier * the model identifier * @param file @@ -655,7 +660,7 @@ public class ModelSet extends ResourceSetImpl { /** * Save the resources. - * + * * @param monitor * The monitor. * @throws IOException @@ -728,19 +733,19 @@ public class ModelSet extends ResourceSetImpl { protected void handleResourcesToDelete() { Iterator<URI> uriIterator = getResourcesToDeleteOnSave().iterator(); while(uriIterator.hasNext()) { - URI uri = (URI)uriIterator.next(); - - if (validateDeleteResource(uri)) { - if (deleteResource(uri)) { + URI uri = uriIterator.next(); + + if(validateDeleteResource(uri)) { + if(deleteResource(uri)) { uriIterator.remove(); } } } } - + protected boolean validateDeleteResource(URI uri) { boolean result = true; - + Resource resource = getResource(uri, false); if(resource != null) { String warMessage = "The resource " + resource.getURI().lastSegment() + " was about to deleted but was still contained in the resource set. The will not be deleted"; @@ -748,19 +753,19 @@ public class ModelSet extends ResourceSetImpl { result = false; } - + return result; } - + protected boolean deleteResource(URI uri) { boolean result = false; - + try { getURIConverter().delete(uri, null); result = true; } catch (IOException e) { Activator.log.error(e); - + // hope it's a file that we can delete from the workspace! IFile file = getFile(uri); if(file != null && file.exists()) { @@ -772,19 +777,19 @@ public class ModelSet extends ResourceSetImpl { } } } - + return result; } /** * Finds the file corresponding to the specified URI, using a URI converter * if necessary (and provided) to normalize it. - * + * * @param uri * a URI * @param converter * an optional URI converter (may be <code>null</code>) - * + * * @return the file, if available in the workspace */ protected IFile getFile(URI uri) { @@ -838,12 +843,12 @@ public class ModelSet extends ResourceSetImpl { /** * The resources are already loaded, but we want to save them under another * name. - * + * * @param path * the path * @throws IOException * Signals that an I/O exception has occurred. - * + * * @deprecated Use the {@link #saveAs(URI)} API, instead. */ @Deprecated @@ -854,7 +859,7 @@ public class ModelSet extends ResourceSetImpl { /** * The resources are already loaded, but we want to save them under another * name. - * + * * @param path * the path * @throws IOException @@ -882,8 +887,8 @@ public class ModelSet extends ResourceSetImpl { snippets.performDispose(this); snippets.clear(); - - // FIXME RS: handle the unload ordering as indicated in the model extension point + + // FIXME RS: handle the unload ordering as indicated in the model extension point // Walk all registered models for(IModel model : models.values()) { if(!(model instanceof AdditionalResourcesModel)) { @@ -926,16 +931,18 @@ public class ModelSet extends ResourceSetImpl { /** * Obtains my internal API adapter. - * + * * @return my internal API adapter */ public Internal getInternal() { return new Internal() { + @Override public void setPrimaryModelResourceURI(URI uri) { setURIWithoutExtension(uri.trimFileExtension()); } + @Override public void registerModel(IModel model, boolean force) { if(force) { doRegisterModel(model); @@ -949,7 +956,7 @@ public class ModelSet extends ResourceSetImpl { /** * Add a {@link IModelSetSnippet}. A snippet allows to add code that will * perform additional operations on the ModelSet. - * + * * @param snippet * The snippet to add. */ @@ -959,11 +966,11 @@ public class ModelSet extends ResourceSetImpl { /** * A list of {@link IModelSetSnippet}. - * + * * Used by Models to maintain their list of Snippets. - * + * * @author cedric dumoulin - * + * */ public class ModelSetSnippetList extends ArrayList<IModelSetSnippet> { @@ -972,7 +979,7 @@ public class ModelSet extends ResourceSetImpl { /** * Call the start method on all registered snippets. - * + * * @param modelsManager * The model that is starting */ @@ -984,7 +991,7 @@ public class ModelSet extends ResourceSetImpl { /** * Call the start method on all registered snippets. - * + * * @param modelsManager * The model that is stopping */ @@ -1003,10 +1010,10 @@ public class ModelSet extends ResourceSetImpl { /** * Sets the {@link ModelSet}'s primary resource URI. - * + * * @param uri * the URI - * + * * @see ModelSet#createModels(URI) * @see ModelSet#saveAs(URI) */ @@ -1015,7 +1022,7 @@ public class ModelSet extends ResourceSetImpl { /** * Register a model with the option to force it (in case a more specific * implementation of the model is already registered). - * + * * @param model * a model to register * @param force @@ -1025,7 +1032,7 @@ public class ModelSet extends ResourceSetImpl { } /** - * + * * @param target */ public void saveCopy(IPath targetPathWithoutExtension) { @@ -1045,36 +1052,37 @@ public class ModelSet extends ResourceSetImpl { model.saveCopy(targetPathWithoutExtension, targetMap); } } - + public boolean addResourceLoadStateListener(IResourceLoadStateListener listener) { return resourceLoadStateListeners.add(listener); } - + public boolean removeResourceLoadStateListener(IResourceLoadStateListener listener) { return resourceLoadStateListeners.remove(listener); } - + public void notifyResourceLoadState(Resource resource, boolean newState) { - if(resourceLoadStateListeners !=null) { + if(resourceLoadStateListeners != null) { for(IResourceLoadStateListener listener : resourceLoadStateListeners) { try { listener.notifyLoadStateChanged(resource, newState); - } catch(Throwable e) { + } catch (Throwable e) { Activator.log.error(e); } } } } - + public boolean isUserModelResource(URI uri) { return uri.isPlatformResource() || uri.isFile(); } - + public class ResourceAddRemoveTracker implements Adapter { /** * {@inheritDoc} */ + @Override public void notifyChanged(Notification notification) { // if notification = add, add many or remove/remove many resource(s) to list of resources, process.. if(RESOURCE_SET__RESOURCES == notification.getFeatureID(ResourceSet.class)) { @@ -1083,33 +1091,34 @@ public class ModelSet extends ResourceSetImpl { Object object = notification.getNewValue(); if(object instanceof Resource) { resourcesToLoadState.put(((Resource)object), ((Resource)object).isLoaded()); - } + } break; case Notification.REMOVE: object = notification.getNewValue(); if(object instanceof Resource) { - resourcesToLoadState.remove(((Resource)object)); - } + resourcesToLoadState.remove((object)); + } break; case Notification.ADD_MANY: - + break; - + case Notification.REMOVE_MANY: - + + break; + + default: + // nothing to do break; - - default: - // nothing to do - break; } - + } } /** * {@inheritDoc} */ + @Override public Notifier getTarget() { return ModelSet.this; } @@ -1117,6 +1126,7 @@ public class ModelSet extends ResourceSetImpl { /** * {@inheritDoc} */ + @Override public void setTarget(Notifier newTarget) { // nothing here } @@ -1124,9 +1134,10 @@ public class ModelSet extends ResourceSetImpl { /** * {@inheritDoc} */ + @Override public boolean isAdapterForType(Object type) { return false; } - + } } diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/sasheditor/DiModel.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/sasheditor/DiModel.java index 994e4a145ca..ebfd4abe0f2 100644 --- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/sasheditor/DiModel.java +++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/sasheditor/DiModel.java @@ -1,19 +1,16 @@ /**
- *
+ *
*/
package org.eclipse.papyrus.infra.core.resource.sasheditor;
-import java.util.Map;
-
-import org.eclipse.emf.ecore.xmi.XMIResource;
-import org.eclipse.papyrus.infra.core.resource.AbstractBaseModel;
-import org.eclipse.papyrus.infra.core.resource.IModel;
/**
* @author dumoulin
- *
+ *
+ * @deprecated Use {@link SashModel} instead
*/
-public class DiModel extends AbstractBaseModel implements IModel {
+@Deprecated
+public class DiModel {
/**
* File extension used for notation.
@@ -30,38 +27,4 @@ public class DiModel extends AbstractBaseModel implements IModel { */
public static final String MODEL_ID = "org.eclipse.papyrus.infra.core.resource.sasheditor.SashModel"; //$NON-NLS-1$
- /**
- * Get the file extension used for this model.
- *
- * @see org.eclipse.papyrus.infra.core.resource.AbstractBaseModel#getModelFileExtension()
- *
- * @return
- */
- @Override
- protected String getModelFileExtension() {
- return MODEL_FILE_EXTENSION;
- }
-
- /**
- * Get the identifier used to register this model.
- *
- * @see org.eclipse.papyrus.infra.core.resource.AbstractBaseModel#getIdentifier()
- *
- * @return
- */
- @Override
- public String getIdentifier() {
- return MODEL_FILE_EXTENSION;
- }
-
- @Override
- protected Map<Object, Object> getSaveOptions() {
- Map<Object, Object> saveOptions = super.getSaveOptions();
-
- saveOptions.put(XMIResource.OPTION_USE_XMI_TYPE, Boolean.FALSE);
- saveOptions.put(XMIResource.OPTION_SAVE_TYPE_INFORMATION, Boolean.FALSE);
-
- return saveOptions;
- }
-
}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/sasheditor/DiModelUtils.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/sasheditor/DiModelUtils.java index b909472e632..3c410693165 100644 --- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/sasheditor/DiModelUtils.java +++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/sasheditor/DiModelUtils.java @@ -1,5 +1,5 @@ /**
- *
+ *
*/
package org.eclipse.papyrus.infra.core.resource.sasheditor;
@@ -11,16 +11,16 @@ import org.eclipse.papyrus.infra.core.resource.ModelSet; /**
* Set of utility methods linked to Di resource.
- *
+ *
* @author cedric dumoulin
- *
+ *
*/
public class DiModelUtils {
/**
* Returns the related di file. Warning : this method is here for historical
* reasons. It should be removed asap.
- *
+ *
* @param file
* A file (di, model or notation).
* @return The associated DI file.
@@ -32,11 +32,11 @@ public class DiModelUtils { return null;
}
IFile diFile;
- if(DiModel.DI_FILE_EXTENSION.equalsIgnoreCase(file.getFileExtension())) {
+ if(SashModel.MODEL_FILE_EXTENSION.equalsIgnoreCase(file.getFileExtension())) {
diFile = file;
} else {
// Find the correct file
- IPath diPath = file.getFullPath().removeFileExtension().addFileExtension(DiModel.DI_FILE_EXTENSION);
+ IPath diPath = file.getFullPath().removeFileExtension().addFileExtension(SashModel.MODEL_FILE_EXTENSION);
diFile = file.getParent().getFile(diPath.makeRelativeTo(file.getParent().getFullPath()));
}
return diFile;
@@ -44,12 +44,12 @@ public class DiModelUtils { /**
* Returns the DI Resource associated to the model set. May be null.
- *
+ *
* @param modelSet
* @return
*/
public static Resource getDiResource(ModelSet modelSet) {
- IModel diModel = modelSet.getModel(DiModel.MODEL_ID);
+ IModel diModel = modelSet.getModel(SashModel.MODEL_ID);
if(diModel instanceof SashModel) {
return ((SashModel)diModel).getResource();
}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/utils/EMFHelper.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/utils/EMFHelper.java index 9c6337f672d..d8d8a0790b0 100644 --- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/utils/EMFHelper.java +++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/utils/EMFHelper.java @@ -1,6 +1,6 @@ /*****************************************************************************
* Copyright (c) 2010, 2013 CEA LIST.
- *
+ *
* 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
@@ -10,7 +10,7 @@ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
* Christian W. Damus (CEA) - filter out EObjects that are Resources (CDO)
* Christian W. Damus (CEA) - Support read-only state at object level (CDO)
- *
+ *
*****************************************************************************/
package org.eclipse.papyrus.infra.core.utils;
@@ -23,17 +23,17 @@ import org.eclipse.emf.ecore.util.ECrossReferenceAdapter; /**
* @deprecated Please use {@link org.eclipse.papyrus.infra.emf.utils.EMFHelper} instead
- * (which inherit this one) for architectural reason.
+ * (which inherit this one) for architectural reason.
*/
@Deprecated
public class EMFHelper {
/**
* Gets the usages.
- *
+ *
* @param source
* the source
- *
+ *
* @return the usages or null if there is no usages
*/
public static Collection<Setting> getUsages(EObject source) {
@@ -56,7 +56,7 @@ public class EMFHelper { }
}
- return crossReferencer.getInverseReferences(source, true);
+ return crossReferencer.getInverseReferences(source, false);
}
}
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/EMFHelper.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/EMFHelper.java index 594b111e94d..99f66309b39 100644 --- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/EMFHelper.java +++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/EMFHelper.java @@ -42,6 +42,7 @@ import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.URIConverter;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.xmi.XMIResource;
import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
import org.eclipse.emf.edit.domain.EditingDomain;
@@ -764,4 +765,42 @@ public class EMFHelper { }
return result;
}
+
+ /**
+ * Returns the given element, reloaded into the resource set of the context element,
+ * or the source element itself if not possible.
+ *
+ * Use this method for e.g. loading an element from a shared resource set into another resource set
+ * (Apply a registered profile/library, drop an element from the project explorer, ...)
+ *
+ * @param element
+ * @param contextElement
+ * @return
+ */
+ public static <T extends EObject> T reloadIntoContext(T element, EObject contextElement) {
+ ResourceSet sourceResourceSet = getResourceSet(element);
+ ResourceSet loadingContext = getResourceSet(contextElement);
+
+ if(sourceResourceSet == loadingContext || loadingContext == null) {
+ return element;
+ }
+
+ URI sourceURI = EcoreUtil.getURI(element);
+ EObject result = loadingContext.getEObject(sourceURI, true);
+
+ return (T)result;
+ }
+
+ /**
+ * Returns the resourceSet owning this eObject, or null if it is detached
+ *
+ * @param eObject
+ */
+ public static ResourceSet getResourceSet(EObject eObject) {
+ if(eObject == null || eObject.eResource() == null) {
+ return null;
+ }
+
+ return eObject.eResource().getResourceSet();
+ }
}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/advice/GMFDiagramDuplicateEditHelperAdvice.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/advice/GMFDiagramDuplicateEditHelperAdvice.java index 202080c4135..7868a3d49df 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/advice/GMFDiagramDuplicateEditHelperAdvice.java +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/advice/GMFDiagramDuplicateEditHelperAdvice.java @@ -1,6 +1,6 @@ /*****************************************************************************
* Copyright (c) 2011 CEA LIST.
- *
+ *
* 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
@@ -24,7 +24,6 @@ import java.util.Set; import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature.Setting;
import org.eclipse.emf.ecore.resource.Resource;
@@ -41,10 +40,9 @@ import org.eclipse.gmf.runtime.emf.type.core.requests.DuplicateElementsRequest; import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.infra.core.resource.ModelSet;
-import org.eclipse.papyrus.infra.core.resource.sasheditor.DiModel;
+import org.eclipse.papyrus.infra.core.resource.sasheditor.SashModel;
import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageManager;
import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.core.utils.EditorUtils;
import org.eclipse.papyrus.infra.emf.commands.IPapyrusDuplicateCommandConstants;
import org.eclipse.papyrus.infra.emf.utils.BusinessModelResolver;
import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForResource;
@@ -70,7 +68,7 @@ public class GMFDiagramDuplicateEditHelperAdvice extends AbstractEditHelperAdvic Set<Object> duplicatedObjects = ((Set<Object>)additional);
EObject object = getDuplicatedEObject(request);
- if(object == null || object.eResource()==null) {
+ if(object == null || object.eResource() == null) {
return super.getBeforeDuplicateCommand(request);
}
@@ -142,7 +140,7 @@ public class GMFDiagramDuplicateEditHelperAdvice extends AbstractEditHelperAdvic /**
* Returns the EObject to be duplicated
- *
+ *
* @return the EObject to be duplicated
*/
protected EObject getDuplicatedEObject(DuplicateElementsRequest request) {
@@ -168,7 +166,7 @@ public class GMFDiagramDuplicateEditHelperAdvice extends AbstractEditHelperAdvic /**
* Constructs a new duplicate EObjects command with the specified label and
* list of EObjects.
- *
+ *
* @param editingDomain
* the editing domain through which model changes are made
* @param label
@@ -184,7 +182,7 @@ public class GMFDiagramDuplicateEditHelperAdvice extends AbstractEditHelperAdvic /**
* Constructs a new duplicate EObjects command with the specified label and
* list of EObjects.
- *
+ *
* @param editingDomain
* the editing domain through which model changes are made
* @param label
@@ -204,7 +202,7 @@ public class GMFDiagramDuplicateEditHelperAdvice extends AbstractEditHelperAdvic * list of EObjects. Also sets the list of affected files to be the files,
* where the targetContainer is stored. Target container specifies the
* eObject into which the duplicated eObjects will be added.
- *
+ *
* @param editingDomain
* the editing domain through which model changes are made
* @param label
@@ -235,15 +233,15 @@ public class GMFDiagramDuplicateEditHelperAdvice extends AbstractEditHelperAdvic EObject duplicateDiagram = copier.get(diagramToDuplicate);
Resource targetResource = getNotationResourceForDiagram(((Diagram)duplicateDiagram).getElement(), getEditingDomain());
Resource diTargetResource = getDiResourceForDiagram(((Diagram)duplicateDiagram).getElement(), getEditingDomain());
-
+
if(targetResource != null) {
targetResource.getContents().add(duplicateDiagram);
-
- if(diTargetResource !=null) {
+
+ if(diTargetResource != null) {
try {
- IPageManager pageManager = ServiceUtilsForResource.getInstance().getIPageManager(diTargetResource);
- pageManager.addPage(duplicateDiagram);
- } catch(ServiceException e) {
+ IPageManager pageManager = ServiceUtilsForResource.getInstance().getIPageManager(diTargetResource);
+ pageManager.addPage(duplicateDiagram);
+ } catch (ServiceException e) {
Activator.log.error(e);
}
} else {
@@ -255,11 +253,11 @@ public class GMFDiagramDuplicateEditHelperAdvice extends AbstractEditHelperAdvic if(targetResource != null) {
Activator.log.error("It was not possible to find the Resource with the source diagram", null);
targetResource.getContents().add(duplicateDiagram);
- if(diTargetResource !=null) {
+ if(diTargetResource != null) {
try {
- IPageManager pageManager = ServiceUtilsForResource.getInstance().getIPageManager(diTargetResource);
- pageManager.addPage(duplicateDiagram);
- } catch(ServiceException e) {
+ IPageManager pageManager = ServiceUtilsForResource.getInstance().getIPageManager(diTargetResource);
+ pageManager.addPage(duplicateDiagram);
+ } catch (ServiceException e) {
Activator.log.error(e);
}
} else {
@@ -279,7 +277,7 @@ public class GMFDiagramDuplicateEditHelperAdvice extends AbstractEditHelperAdvic /**
* Returns the notation resource where to add the new diagram
- *
+ *
* @param eObject
* the semantic object linked to the diagram or the diagram itself.
* @param domain
@@ -295,25 +293,27 @@ public class GMFDiagramDuplicateEditHelperAdvice extends AbstractEditHelperAdvic } else {
semanticObject = (EObject)object;
}
-
+
Resource containerResource = semanticObject.eResource();
- if(containerResource == null) {
+ if(containerResource == null) {
return null;
}
// retrieve the model set from the container resource
ResourceSet resourceSet = containerResource.getResourceSet();
-
+
if(resourceSet instanceof ModelSet) {
ModelSet modelSet = (ModelSet)resourceSet;
Resource destinationResource = modelSet.getAssociatedResource(semanticObject, NotationModel.NOTATION_FILE_EXTENSION, true);
return destinationResource;
- } else throw new RuntimeException("Resource Set is not a ModelSet or is null");
+ } else {
+ throw new RuntimeException("Resource Set is not a ModelSet or is null");
+ }
}
-
+
/**
* Returns the di resource where to add the new diagram
- *
+ *
* @param eObject
* the semantic object linked to the diagram or the diagram itself.
* @param domain
@@ -328,21 +328,23 @@ public class GMFDiagramDuplicateEditHelperAdvice extends AbstractEditHelperAdvic } else {
semanticObject = (EObject)object;
}
-
+
Resource containerResource = semanticObject.eResource();
- if(containerResource == null) {
+ if(containerResource == null) {
return null;
}
// retrieve the model set from the container resource
ResourceSet resourceSet = containerResource.getResourceSet();
-
+
if(resourceSet instanceof ModelSet) {
ModelSet modelSet = (ModelSet)resourceSet;
- Resource destinationResource = modelSet.getAssociatedResource(semanticObject, DiModel.DI_FILE_EXTENSION, true);
+ Resource destinationResource = modelSet.getAssociatedResource(semanticObject, SashModel.MODEL_FILE_EXTENSION, true);
return destinationResource;
- } else throw new RuntimeException("Resource Set is not a ModelSet or is null");
+ } else {
+ throw new RuntimeException("Resource Set is not a ModelSet or is null");
+ }
}
-
+
/**
* Copier for diagrams, where only views and internal references are duplicated, not the semantic elements themselves.
*/
@@ -356,7 +358,7 @@ public class GMFDiagramDuplicateEditHelperAdvice extends AbstractEditHelperAdvic /**
* Creates a new {@link DiagramCopier}
- *
+ *
* @param semanticObjects
* list of semantic objects already copied, to which new views should be related.
*/
@@ -366,7 +368,7 @@ public class GMFDiagramDuplicateEditHelperAdvice extends AbstractEditHelperAdvic /**
* Overrides the get to look in the map of duplicated semantic objects in case the element was not found in this map
- *
+ *
* {@inheritDoc}
*/
@Override
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/NotationHelper.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/NotationHelper.java index e138812175e..6f1d4dbb9c0 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/NotationHelper.java +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/NotationHelper.java @@ -17,14 +17,14 @@ import org.eclipse.gmf.runtime.notation.View; /**
* A Helper class related to the GMF Notation metamodel.
- *
+ *
* @author Camille Letavernier
*/
public class NotationHelper {
/**
* Retrieves the GMF View associated to the source object
- *
+ *
* @param source
* the source
* @return the resolved view, or null if it cannot be found
@@ -51,7 +51,7 @@ public class NotationHelper { * Tests whether the given View is a reference to an external element.
* A view is an external reference if its graphical container is different from its semantic
* container (i.e. self.element.eContainer() != self.primaryView.eContainer().element)
- *
+ *
* @param diagramElement
* @return
*/
@@ -81,6 +81,7 @@ public class NotationHelper { return false;
}
- return parentSemanticElement != semanticElement.eContainer();
+ //Relax the constraints for elements displayed on themselves (e.g. Frame in Composite Structure Diagram)
+ return parentSemanticElement != semanticElement.eContainer() && parentSemanticElement != semanticElement;
}
}
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 index 16ea2cb5d20..c99e64275fc 100644 --- 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 @@ -1,6 +1,6 @@ /***************************************************************************** * Copyright (c) 2010, 2013 ATOS ORIGIN, CEA LIST, and others. - * + * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -10,7 +10,7 @@ * Tristan Faure (ATOS ORIGIN INTEGRATION) tristan.faure@atosorigin.com - Initial API and implementation * Christian W. Damus (CEA) - manage models by URI, not IFile (CDO) * Christian W. Damus (CEA LIST) - support control mode in CDO resources - * + * *****************************************************************************/ package org.eclipse.papyrus.infra.services.resourceloading.strategies; @@ -26,7 +26,7 @@ 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.editor.IMultiDiagramEditor; import org.eclipse.papyrus.infra.core.resource.ModelSet; import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageManager; import org.eclipse.papyrus.infra.core.services.ServiceException; @@ -53,9 +53,9 @@ 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 { @@ -97,7 +97,7 @@ public class AskUserStrategy implements ILoadingStrategy { /** * @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 @@ -106,7 +106,7 @@ public class AskUserStrategy implements ILoadingStrategy { // pathmap resource are always loaded boolean result = !modelSet.isUserModelResource(uri); URI initialURI = modelSet.getURIWithoutExtension(); - // if no listener is registered, a listener is added on the editor to remove the notifications + // 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); @@ -135,7 +135,7 @@ public class AskUserStrategy implements ILoadingStrategy { /** * Create the ask notification to the user - * + * * @param modelSet * @param initialURI * @param trimFragment @@ -153,7 +153,7 @@ public class AskUserStrategy implements ILoadingStrategy { /** * Add a listener closing the uri parameter - * + * * @param initialURI */ private void addClosingEditorListener(URI initialURI) { @@ -167,7 +167,7 @@ public class AskUserStrategy implements ILoadingStrategy { /** * Remember that an uri has already be asked - * + * * @param initialURI * , the uri opened by the editor * @param guessed @@ -183,7 +183,7 @@ public class AskUserStrategy implements ILoadingStrategy { /** * Check if the uri is already asked - * + * * @param initialURI * , the uri opened by the editor * @param toLoad @@ -201,7 +201,7 @@ public class AskUserStrategy implements ILoadingStrategy { /** * 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 @@ -222,20 +222,20 @@ public class AskUserStrategy implements ILoadingStrategy { /** * Get the current editor - * + * * @return */ - protected CoreMultiDiagramEditor getCurrentEditor() { + protected IMultiDiagramEditor getCurrentEditor() { IEditorPart editor = getEditor(); - if(editor instanceof CoreMultiDiagramEditor) { - return (CoreMultiDiagramEditor)editor; + if(editor instanceof IMultiDiagramEditor) { + return (IMultiDiagramEditor)editor; } return null; } /** * Create the notification with Yes/No/Yes For All/No For All option - * + * * @param message * , the message to display * @param uri @@ -256,7 +256,7 @@ public class AskUserStrategy implements ILoadingStrategy { /** * NO for all registers the NoForAll URI and do nothing - * + * * @param uri * @param modelSet * @param initialURI @@ -295,7 +295,7 @@ public class AskUserStrategy implements ILoadingStrategy { /** * 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 @@ -315,7 +315,7 @@ public class AskUserStrategy implements ILoadingStrategy { return new RefreshRunnable(modelSet, uri, initialURI, true, true) { @Override - public void run(CoreMultiDiagramEditor editor) { + public void run(IMultiDiagramEditor editor) { List<INotification> list = notifications.get(getInitialURI()); if(list != null) { for(INotification n : notifications.get(getInitialURI())) { @@ -355,7 +355,7 @@ public class AskUserStrategy implements ILoadingStrategy { /** * No runnable does not accept the URI asked - * + * * @param uri * @param modelSet * @param initialURI @@ -379,7 +379,7 @@ public class AskUserStrategy implements ILoadingStrategy { /** * Yes registers the URI and refresh the tab to take in account the loaded elements - * + * * @param uri * @param modelSet * @param initialURI @@ -391,7 +391,7 @@ public class AskUserStrategy implements ILoadingStrategy { /** * Register the notification created to the URI open by the editor - * + * * @param initialURI * @param notification */ @@ -434,9 +434,9 @@ public class AskUserStrategy implements ILoadingStrategy { /** * 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 { @@ -516,7 +516,7 @@ public class AskUserStrategy implements ILoadingStrategy { protected void manageRefresh(IEditorReference ref, IEditorPart part) { addAuthorized(initialURI, uri); if(part != null) { - getRunnable().run((CoreMultiDiagramEditor)part); + getRunnable().run((IMultiDiagramEditor)part); } else { addPageListener(new EditorActivateListener(ref, modelSet, uri, initialURI, getRunnable())); } @@ -535,7 +535,7 @@ public class AskUserStrategy implements ILoadingStrategy { /** * Add a page listener - * + * * @param listener * @return */ @@ -550,7 +550,7 @@ public class AskUserStrategy implements ILoadingStrategy { /** * Register a listener of the perspective to know when the editor is finally closed - * + * * @param listener * @return */ @@ -564,7 +564,7 @@ public class AskUserStrategy implements ILoadingStrategy { /** * Unregister a perspective listener - * + * * @param listener * @return */ @@ -592,20 +592,20 @@ public class AskUserStrategy implements ILoadingStrategy { protected static URI getURI(final IEditorInput input) { URI result; - + IFile file = (IFile)input.getAdapter(IFile.class); if((file != null) && (file.getFullPath() != null)) { result = URI.createPlatformResourceURI(file.getFullPath().removeFileExtension().toString(), true); } else { - result = (URI) input.getAdapter(URI.class); + result = (URI)input.getAdapter(URI.class); } return result; } - + /** * Notification containing the {@link URI} loaded - * + * */ public class EncapsulatedNotification implements INotification { @@ -633,9 +633,9 @@ public class AskUserStrategy implements ILoadingStrategy { /** * An empty {@link IPartListener} implementation - * + * * @author tfaure - * + * */ private class EditorAdapter implements IPartListener { @@ -658,9 +658,9 @@ public class AskUserStrategy implements ILoadingStrategy { /** * Listener which is notifid when an editor is activated - * + * * @author tfaure - * + * */ private class EditorActivateListener extends EditorAdapter { @@ -675,8 +675,8 @@ public class AskUserStrategy implements ILoadingStrategy { @Override public void partActivated(IWorkbenchPart part) { - if(reference.getPart(false) == part && part instanceof CoreMultiDiagramEditor) { - refreshRunnable.run((CoreMultiDiagramEditor)part); + if(reference.getPart(false) == part && part instanceof IMultiDiagramEditor) { + refreshRunnable.run((IMultiDiagramEditor)part); removePageListener(this); } } @@ -685,20 +685,20 @@ public class AskUserStrategy implements ILoadingStrategy { /** * 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; - + if(part instanceof IMultiDiagramEditor) { + IMultiDiagramEditor editor = (IMultiDiagramEditor)part; + URI uri = getURI(editor.getEditorInput()); - if (uri != null) { + if(uri != null) { uri = uri.trimFileExtension(); addPerspectiveListener(new EditorClosePerspectiveListener(uri)); removePageListener(this); @@ -711,9 +711,9 @@ public class AskUserStrategy implements ILoadingStrategy { /** * A perspective listener which choices of an user - * + * * @author tfaure - * + * */ protected class EditorClosePerspectiveListener implements IPerspectiveListener { @@ -744,9 +744,9 @@ public class AskUserStrategy implements ILoadingStrategy { /** * A runnable refreshing resource and/or pages - * + * * @author tfaure - * + * */ public class RefreshRunnable { @@ -770,7 +770,7 @@ public class AskUserStrategy implements ILoadingStrategy { this.refreshTab = refreshTab; } - public void run(CoreMultiDiagramEditor editor) { + public void run(IMultiDiagramEditor editor) { final Set<URI> alreadyLoaded = new HashSet<URI>(); try { pageMngr = editor.getServicesRegistry().getService(IPageManager.class); 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 index 1a8fb06f784..b72d2528e05 100644 --- 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 @@ -1,7 +1,7 @@ /*****************************************************************************
* 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
@@ -27,20 +27,16 @@ 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.emf.ecore.resource.URIConverter;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gef.util.EditPartUtilities;
import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramGraphicalViewer;
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.editor.IMultiDiagramEditor;
import org.eclipse.papyrus.infra.core.resource.ModelSet;
import org.eclipse.papyrus.infra.core.resource.sasheditor.DiModel;
import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageManager;
-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.gmfdiag.common.model.NotationModel;
import org.eclipse.papyrus.infra.services.resourceloading.Activator;
@@ -77,8 +73,8 @@ public class LoadingUtils { IProgressMonitor monitor = dialog.getProgressMonitor();
IEditorPart editor = getEditor();
- if(editor instanceof CoreMultiDiagramEditor) {
- CoreMultiDiagramEditor core = (CoreMultiDiagramEditor)editor;
+ if(editor instanceof IMultiDiagramEditor) {
+ IMultiDiagramEditor core = (IMultiDiagramEditor)editor;
try {
IPageManager pageMngr = core.getServicesRegistry().getService(IPageManager.class);
List<Object> allPages = pageMngr.allPages();
@@ -150,7 +146,7 @@ public class LoadingUtils { * path of resources to unload without file extension
*/
public static void unloadResourcesFromModelSet(ModelSet modelSet, URI uriWithoutFileExtension) {
- unloadResourcesFromModelSet(modelSet, uriWithoutFileExtension, true);
+ unloadResourcesFromModelSet(modelSet, uriWithoutFileExtension, false);
}
/**
@@ -210,12 +206,23 @@ public class LoadingUtils { // (registered libraries in the model set have different URIs - e.g. due to a pathmap -
// although they point to the same location).
// TODO: Use a single detection mechanism in ResourceUpdateService and here
- String unloadPlatformString = uriWithoutFileExtension.toPlatformString(true);
- URIConverter uriConverter = modelSet.getURIConverter();
+ String unloadPlatformString;
+ if(uriWithoutFileExtension.isPlatform()) {
+ unloadPlatformString = uriWithoutFileExtension.toPlatformString(true);
+ } else {
+ unloadPlatformString = URI.decode(uriWithoutFileExtension.toString());
+ }
+ //URIConverter uriConverter = modelSet.getURIConverter();
// unload resource
for(Resource res : new ArrayList<Resource>(modelSet.getResources())) {
- URI normalizedURI = uriConverter.normalize(res.getURI());
- String platformString = normalizedURI.trimFileExtension().toPlatformString(true);
+ URI normalizedURI = res.getURI();
+ String platformString;
+ if(normalizedURI.isPlatform()) {
+ platformString = normalizedURI.trimFileExtension().toPlatformString(true);
+ } else {
+ platformString = URI.decode(normalizedURI.trimFileExtension().toString());
+ }
+
if((platformString != null) && platformString.equals(unloadPlatformString)) {
// unload this resource
modelSet.getResources().remove(res);
@@ -248,7 +255,13 @@ public class LoadingUtils { // refresh page's diagram if needed
Diagram diag = ((Diagram)eobject);
if(pageMngr.isOpen(diag)) {
- Object part = ((IDiagramGraphicalViewer)core.getAdapter(IDiagramGraphicalViewer.class)).getEditPartRegistry().get(diag);
+
+ IDiagramGraphicalViewer graphicalViewer = (IDiagramGraphicalViewer)core.getAdapter(IDiagramGraphicalViewer.class);
+ if(graphicalViewer == null) {
+ continue;
+ }
+
+ Object part = graphicalViewer.getEditPartRegistry().get(diag);
if(part instanceof GraphicalEditPart) {
// refresh nodes
for(Object child : EditPartUtilities.getAllChildren((GraphicalEditPart)part)) {
|