diff options
author | Nicolas FAUVERGUE | 2016-11-24 11:20:54 +0000 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org | 2016-11-29 10:57:50 +0000 |
commit | b3141df23ca644573f8b2813ad8859722d418bd9 (patch) | |
tree | 6db261c6f918988a7117bfe93731af4ca17f0723 /plugins/infra/onefile/org.eclipse.papyrus.infra.onefile | |
parent | 6d4f41d7e479bfa607ffde18b16fe8ebdae561c2 (diff) | |
download | org.eclipse.papyrus-b3141df23ca644573f8b2813ad8859722d418bd9.tar.gz org.eclipse.papyrus-b3141df23ca644573f8b2813ad8859722d418bd9.tar.xz org.eclipse.papyrus-b3141df23ca644573f8b2813ad8859722d418bd9.zip |
Bug 496905: [Diagram][ModelExplorer][Table][Dialog] Papyrus must integrate
the internationalization feature provided by UML.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=496905
Commit of infra for internationalization.
Change-Id: I1b1859bf111e1ef7a7522212fbe639cf2bd13890
Signed-off-by: Nicolas FAUVERGUE <nicolas.fauvergue@all4tec.net>
Diffstat (limited to 'plugins/infra/onefile/org.eclipse.papyrus.infra.onefile')
4 files changed, 110 insertions, 10 deletions
diff --git a/plugins/infra/onefile/org.eclipse.papyrus.infra.onefile/META-INF/MANIFEST.MF b/plugins/infra/onefile/org.eclipse.papyrus.infra.onefile/META-INF/MANIFEST.MF index 41670ccc965..a9e86595a7e 100644 --- a/plugins/infra/onefile/org.eclipse.papyrus.infra.onefile/META-INF/MANIFEST.MF +++ b/plugins/infra/onefile/org.eclipse.papyrus.infra.onefile/META-INF/MANIFEST.MF @@ -4,7 +4,8 @@ Export-Package: org.eclipse.papyrus.infra.onefile.model, org.eclipse.papyrus.infra.onefile.utils Require-Bundle: org.eclipse.papyrus.infra.core;bundle-version="[2.0.0,3.0.0)", org.eclipse.core.resources;bundle-version="[3.11.0,4.0.0)";visibility:=reexport, - org.eclipse.core.runtime;bundle-version="[3.12.0,4.0.0)";visibility:=reexport + org.eclipse.core.runtime;bundle-version="[3.12.0,4.0.0)";visibility:=reexport, + org.eclipse.papyrus.infra.internationalization;bundle-version="[1.0.0,2.0.0)" Bundle-Vendor: %providerName Bundle-ActivationPolicy: lazy Bundle-Version: 2.0.0.qualifier diff --git a/plugins/infra/onefile/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/model/impl/PapyrusFile.java b/plugins/infra/onefile/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/model/impl/PapyrusFile.java index e7888b7cfa7..f5fc561112a 100644 --- a/plugins/infra/onefile/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/model/impl/PapyrusFile.java +++ b/plugins/infra/onefile/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/model/impl/PapyrusFile.java @@ -8,10 +8,15 @@ * * Contributors: * Tristan Faure (Atos Origin Integration) tristan.faure@atosorigin.com - Initial API and implementation + * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 496905 + * *****************************************************************************/ package org.eclipse.papyrus.infra.onefile.model.impl; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.Locale; import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IFile; @@ -19,6 +24,8 @@ import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.Platform; +import org.eclipse.papyrus.infra.core.Activator; +import org.eclipse.papyrus.infra.internationalization.utils.PropertiesFilesUtils; import org.eclipse.papyrus.infra.onefile.model.IPapyrusFile; import org.eclipse.papyrus.infra.onefile.utils.OneFileUtils; @@ -44,12 +51,39 @@ public class PapyrusFile implements IPapyrusFile { public IResource[] getAssociatedResources() { ArrayList<IResource> files = new ArrayList<IResource>(); try { - for (IResource res : file.getParent().members()) { - if (res instanceof IFile && OneFileUtils.withoutFileExtension(file).equals(OneFileUtils.withoutFileExtension(res))) { - files.add(res); + for (final IResource res : file.getParent().members()) { + if (res instanceof IFile){ + final String resourceWithoutExtension = OneFileUtils.withoutFileExtension(res); + final String fileWithoutExtension = OneFileUtils.withoutFileExtension(file); + if(fileWithoutExtension.equals(resourceWithoutExtension)) { + files.add(res); + }else if(res.getFileExtension().equals(PropertiesFilesUtils.PROPERTIES_FILE_EXTENSION) && resourceWithoutExtension.startsWith(fileWithoutExtension)){ + String possibleLocale = resourceWithoutExtension.substring(fileWithoutExtension.length()); + if(possibleLocale.startsWith("_")){ //$NON-NLS-1$ + possibleLocale = possibleLocale.substring(1); + Locale localeFound = null; + + // Check about possible locale in available locales + final Iterator<Locale> availableLocales = Arrays.asList(Locale.getAvailableLocales()) + .iterator(); + while (availableLocales.hasNext() && null == localeFound) { + final Locale currentAvailableLocale = availableLocales.next(); + + if (currentAvailableLocale.toString().equals(possibleLocale)) { + localeFound = currentAvailableLocale; + } + } + + // The file contains a locale, load it + if (null != localeFound) { + files.add(res); + } + } + } } } - } catch (CoreException e) { + } catch (final CoreException e) { + Activator.log.error("The file members cannot be found", e); //$NON-NLS-1$ } return files.toArray(new IResource[] {}); } diff --git a/plugins/infra/onefile/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/model/impl/SubResourceFile.java b/plugins/infra/onefile/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/model/impl/SubResourceFile.java index 3ddcf35ad8d..a6722120821 100644 --- a/plugins/infra/onefile/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/model/impl/SubResourceFile.java +++ b/plugins/infra/onefile/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/model/impl/SubResourceFile.java @@ -8,12 +8,15 @@ * * Contributors: * Tristan Faure (Atos Origin Integration) tristan.faure@atosorigin.com - Initial API and implementation + * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 496905 + * *****************************************************************************/ package org.eclipse.papyrus.infra.onefile.model.impl; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.Platform; +import org.eclipse.papyrus.infra.internationalization.utils.PropertiesFilesUtils; import org.eclipse.papyrus.infra.onefile.model.IPapyrusFile; import org.eclipse.papyrus.infra.onefile.model.ISubResourceFile; @@ -41,8 +44,18 @@ public class SubResourceFile implements ISubResourceFile { @Override public String toString() { + String result = subResource.getName(); String fileExtension = subResource.getFileExtension(); - return fileExtension != null ? fileExtension : subResource.getName(); + if(null != fileExtension){ + result = fileExtension; + if(fileExtension.equals(PropertiesFilesUtils.PROPERTIES_FILE_EXTENSION)){ + final String resourceWithoutExtension = subResource.getName().substring(0, subResource.getName().lastIndexOf('.')); //$NON-NLS-1$ + if(!resourceWithoutExtension.equals(parent.getText())){ + result = subResource.getName().substring(parent.getText().length()); + } + } + } + return result; } public IFile getFile() { diff --git a/plugins/infra/onefile/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/utils/OneFileUtils.java b/plugins/infra/onefile/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/utils/OneFileUtils.java index 9a3ab4ef4bb..0c23c91750f 100644 --- a/plugins/infra/onefile/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/utils/OneFileUtils.java +++ b/plugins/infra/onefile/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/utils/OneFileUtils.java @@ -9,11 +9,16 @@ * Contributors: * Tristan Faure (Atos Origin Integration) tristan.faure@atosorigin.com - Initial API and implementation * Christian W. Damus - bug 485220 + * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 496905 * *****************************************************************************/ package org.eclipse.papyrus.infra.onefile.utils; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IFile; @@ -21,6 +26,7 @@ import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.Path; import org.eclipse.papyrus.infra.core.resource.sasheditor.DiModel; +import org.eclipse.papyrus.infra.internationalization.utils.PropertiesFilesUtils; import org.eclipse.papyrus.infra.onefile.model.IPapyrusFile; import org.eclipse.papyrus.infra.onefile.model.PapyrusModelHelper; @@ -54,10 +60,7 @@ public class OneFileUtils { if (parent == null || parent.getType() == IResource.ROOT) { return null; } - String substring = fileName; - if (fileName.indexOf('.') > 0) { - substring = fileName.substring(0, fileName.lastIndexOf('.')); - } + final String substring = getFileNameForDi(fileName); IFile file = parent.getFile(new Path(substring + "." + DiModel.DI_FILE_EXTENSION)); if (file.exists()) { return file; @@ -66,6 +69,55 @@ public class OneFileUtils { } /** + * The file name for di search in parent container. + * + * @param fileName + * The initial file name. + * @return The base of the di to search in the parent container. + */ + protected static String getFileNameForDi(final String fileName) { + String result = fileName; + if (fileName.indexOf('.') > 0) { + // Manage the properties files which contains languages + final String extension = fileName.substring(fileName.lastIndexOf('.') + 1); + String fileNameWithoutExtension = fileName.substring(0, fileName.lastIndexOf('.')); + + // For the properties file with underscore in name, we need to check if a locale is available in the name + // If this is true, the file name is the name without the locale name + // Example: projectName_en_US.properties must return projectName + if (extension.equals(PropertiesFilesUtils.PROPERTIES_FILE_EXTENSION) && fileNameWithoutExtension.contains("_")) { + boolean localeFound = false; + // Get the available locales + final List<Locale> availableLocales = Arrays.asList(Locale.getAvailableLocales()); + String substring = fileNameWithoutExtension; + + // Loop until no underscore in the name or if a locale is found + while (substring.contains("_") && !localeFound) { //$NON-NLS-1$ + // Remove the first part of the name to check the possible locale + substring = substring.substring(substring.indexOf("_") + 1); //$NON-NLS-1$ + + final Iterator<Locale> localesIterator = availableLocales.iterator(); + + // Loop on available locales + while (localesIterator.hasNext() && !localeFound) { + final Locale currentAvailableLocale = localesIterator.next(); + + // The available locale is corresponding to the substring of the file name + if (currentAvailableLocale.toString().equals(substring)) { + localeFound = true; + // Get the initial name without the locale as string + fileNameWithoutExtension = fileNameWithoutExtension.substring(0, fileNameWithoutExtension.length() - substring.length() - 1); + } + } + } + } + + result = fileNameWithoutExtension; + } + return result; + } + + /** * check if the element has children or not * * @param element |