diff options
author | Pauline DEVILLE | 2019-03-11 08:46:27 +0000 |
---|---|---|
committer | Pauline DEVILLE | 2019-03-13 08:24:22 +0000 |
commit | d3c1a69fd2c45be880e7342dc2edbcc6ec7898a6 (patch) | |
tree | 87d3a801b1b6fff6743be241db2b73c16c33d86c | |
parent | 8c610474fdccfe67457d5ec517d0358c6541e7a7 (diff) | |
download | org.eclipse.papyrus-d3c1a69fd2c45be880e7342dc2edbcc6ec7898a6.tar.gz org.eclipse.papyrus-d3c1a69fd2c45be880e7342dc2edbcc6ec7898a6.tar.xz org.eclipse.papyrus-d3c1a69fd2c45be880e7342dc2edbcc6ec7898a6.zip |
Bug 545246 - [Tools] PackageUtil getUserModel fails in case of
internationalization
- Return UML model root based on editor URI
Signed-off-by: Ansgar Radermacher <ansgar.radermacher@cea.fr>
Signed-off-by: Pauline DEVILLE <pauline.deville@cea.fr>
Change-Id: Iea87bf42c0c372e378f8a5e90856b0bd70f044e6
-rw-r--r-- | plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/PackageUtil.java | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/PackageUtil.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/PackageUtil.java index 3398c030256..0d23096a7e8 100644 --- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/PackageUtil.java +++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/PackageUtil.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2008, 2014 CEA LIST and others. + * Copyright (c) 2008, 2014, 2019 CEA LIST and others. * * * All rights reserved. This program and the accompanying materials @@ -14,6 +14,7 @@ * Yann TANGUY (CEA LIST) yann.tanguy@cea.fr * Christian W. Damus (CEA) - bug 402525 * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 496905 + * Ansgar Radermacher (CEA) - bug 545246 (getUserModel fails in case of internationalization) * *****************************************************************************/ package org.eclipse.papyrus.uml.tools.utils; @@ -61,6 +62,12 @@ import org.eclipse.uml2.uml.UMLPackage; public class PackageUtil { /** + * Extension of UML models (also declared in class UmlModel. This class is not accessible here, + * since oep.uml.tools depends on oep.uml.tools.utils, but not vice versa + */ + public static final String UML_EXT = "uml"; //$NON-NLS-1$ + + /** * Apply a profile and every subprofiles to a package. Also import types defined in profile * * @param profileToApply @@ -617,8 +624,7 @@ public class PackageUtil { } /** - * Return the top element of the model that is currently edited. This function is based on the - * assumption that the user model is the first resource that is loaded into the model set. + * Return the top element of the model that is currently edited. * Use this function instead of Utils.getTop (or getModel) if you want to avoid navigating to the * root of an imported model. * @@ -627,21 +633,16 @@ public class PackageUtil { public static Package getUserModel(ExecutionEvent event) { ServiceUtilsForHandlers serviceUtils = ServiceUtilsForHandlers.getInstance(); try { - // IPath fn = serviceUtils.getModelSet().getFilenameWithoutExtension(); - EList<Resource> resources = serviceUtils.getModelSet(event).getResources(); - if (resources.size() >= 3) { - // check first three resources (di, notation, uml) - for (int i = 0; i < 3; i++) { - Resource userResource = resources.get(i); - if (userResource.getContents().size() > 0) { - EObject topEObj = userResource.getContents().get(0); - if ((topEObj instanceof Package) && (!(topEObj instanceof Profile))) { - return (Package) topEObj; - } - } + URI uri = serviceUtils.getModelSet(event).getURIWithoutExtension().appendFileExtension(UML_EXT); + Resource userResource = serviceUtils.getModelSet(event).getResource(uri, false); + if (userResource != null && userResource.getContents().size() > 0) { + EObject topEObj = userResource.getContents().get(0); + if ((topEObj instanceof Package) && (!(topEObj instanceof Profile))) { + return (Package) topEObj; } } } catch (ServiceException e) { + Activator.log.error(e); } return null; } |