Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas FAUVERGUE2016-12-12 12:43:54 +0000
committerGerrit Code Review @ Eclipse.org2016-12-14 09:02:43 +0000
commit421a002124a0d73377fffca5a398bd1f3a90dfcd (patch)
treeb388ebe00d47b5266519d9f839605aae96658213 /plugins/infra
parentb735b34b43c8d647670361d98b85333e14b83764 (diff)
downloadorg.eclipse.papyrus-421a002124a0d73377fffca5a398bd1f3a90dfcd.tar.gz
org.eclipse.papyrus-421a002124a0d73377fffca5a398bd1f3a90dfcd.tar.xz
org.eclipse.papyrus-421a002124a0d73377fffca5a398bd1f3a90dfcd.zip
Bug 509067: [Internationalization] Manage the properties files with a
proper Resource https://bugs.eclipse.org/bugs/show_bug.cgi?id=509067 - Manage the properties by their own Resource - Fix bug with Diagrams/Tables in sub elements (Load + edit + save) Change-Id: I16c453ab7cc808a940bde9e84f36380e288efb26 Signed-off-by: Nicolas FAUVERGUE <nicolas.fauvergue@cea.fr>
Diffstat (limited to 'plugins/infra')
-rw-r--r--plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.readonly/src/org/eclipse/papyrus/infra/internationalization/internal/readonly/InternationalizationPropertiesReadOnlyHandler.java4
-rw-r--r--plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/src/org/eclipse/papyrus/infra/internationalization/utils/utils/LabelInternationalization.java61
-rw-r--r--plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/src/org/eclipse/papyrus/infra/internationalization/utils/utils/LabelInternationalizationPreferencesUtils.java20
-rw-r--r--plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/src/org/eclipse/papyrus/infra/internationalization/utils/utils/LabelInternationalizationUtils.java54
-rw-r--r--plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/META-INF/MANIFEST.MF5
-rw-r--r--plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/helper/InternationalizationResourceHelper.java39
-rw-r--r--plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/modelresource/InternationalizationModelResource.java245
-rw-r--r--plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/resource/InternationalizationResource.java305
-rw-r--r--plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/resource/InternationalizationResourceFactory.java45
-rw-r--r--plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/utils/EntryPartLabelSynchronizer.java4
-rw-r--r--plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/utils/InternationalizationKeyResolver.java153
-rw-r--r--plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/utils/InternationalizationResourceOptionsConstants.java50
-rw-r--r--plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/utils/PreferencePartLabelSynchronizer.java4
-rw-r--r--plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/utils/QualifiedNameUtils.java58
14 files changed, 870 insertions, 177 deletions
diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.readonly/src/org/eclipse/papyrus/infra/internationalization/internal/readonly/InternationalizationPropertiesReadOnlyHandler.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.readonly/src/org/eclipse/papyrus/infra/internationalization/internal/readonly/InternationalizationPropertiesReadOnlyHandler.java
index 04c13621aad..f18bdb91511 100644
--- a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.readonly/src/org/eclipse/papyrus/infra/internationalization/internal/readonly/InternationalizationPropertiesReadOnlyHandler.java
+++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.readonly/src/org/eclipse/papyrus/infra/internationalization/internal/readonly/InternationalizationPropertiesReadOnlyHandler.java
@@ -20,6 +20,7 @@ import org.eclipse.papyrus.infra.core.resource.AbstractReadOnlyHandler;
import org.eclipse.papyrus.infra.core.resource.ModelSet;
import org.eclipse.papyrus.infra.core.resource.ReadOnlyAxis;
import org.eclipse.papyrus.infra.internationalization.modelresource.InternationalizationPreferenceModel;
+import org.eclipse.papyrus.infra.internationalization.utils.PropertiesFilesUtils;
import com.google.common.base.Optional;
@@ -74,7 +75,8 @@ public class InternationalizationPropertiesReadOnlyHandler extends AbstractReadO
for (URI uri : uris) {
if (InternationalizationPreferenceModel.INTERNATIONALIZATION_PREFERENCE_FILE_EXTENSION
.equals(uri.fileExtension())
- || InternationalizationPreferenceModel.NOTATION_FILE_EXTENSION.equals(uri.fileExtension())) {
+ || InternationalizationPreferenceModel.NOTATION_FILE_EXTENSION.equals(uri.fileExtension())
+ || (uri.isPlatform() && PropertiesFilesUtils.PROPERTIES_FILE_EXTENSION.equals(uri.fileExtension()))) {
knownWritableCount++;
}
}
diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/src/org/eclipse/papyrus/infra/internationalization/utils/utils/LabelInternationalization.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/src/org/eclipse/papyrus/infra/internationalization/utils/utils/LabelInternationalization.java
index 257cca4d333..f1a6370d237 100644
--- a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/src/org/eclipse/papyrus/infra/internationalization/utils/utils/LabelInternationalization.java
+++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/src/org/eclipse/papyrus/infra/internationalization/utils/utils/LabelInternationalization.java
@@ -19,6 +19,7 @@ import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.papyrus.infra.internationalization.common.utils.InternationalizationPreferencesUtils;
+import org.eclipse.papyrus.infra.internationalization.utils.QualifiedNameUtils;
import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
/**
@@ -98,7 +99,7 @@ public class LabelInternationalization {
*/
public String getDiagramLabel(final Diagram diagram, final boolean localize) {
String result = null;
- if (null != diagram.eResource() && InternationalizationPreferencesUtils.getInternationalizationPreference(diagram)) {
+ if (null != diagram.eResource() && getInternationalizationPreference(diagram)) {
result = getDiagramLabelWithoutName(diagram, localize);
}
return null != result ? result : diagram.getName();
@@ -120,6 +121,35 @@ public class LabelInternationalization {
}
/**
+ * This allows to modify the internationalization preference value for the
+ * diagram owner.
+ *
+ * @param eObject
+ * The {@link EObject) corresponding (to get its resource).
+ * @param value
+ * The new preference value.
+ */
+ public void setInternationalizationPreference(final Diagram diagram, final boolean value) {
+ InternationalizationPreferencesUtils.setInternationalizationPreference(QualifiedNameUtils.getOwner(diagram),
+ value);
+ }
+
+ /**
+ * This allows to get the internationalization preference value for the
+ * diagram (but it is the diagram owner because the diagram is in the
+ * notation file).
+ *
+ * @param diagram
+ * The {@link Diagram) corresponding.
+ * @return <code>true</code> if the preference value is set to true,
+ * <code>false</code> otherwise.
+ */
+ public boolean getInternationalizationPreference(final Diagram diagram) {
+ return InternationalizationPreferencesUtils
+ .getInternationalizationPreference(QualifiedNameUtils.getOwner(diagram));
+ }
+
+ /**
* This allows to get the set diagram label command.
*
* @param domain
@@ -186,7 +216,7 @@ public class LabelInternationalization {
*/
public String getTableLabel(final Table table, final boolean localize) {
String result = null;
- if (null != table.eResource() && InternationalizationPreferencesUtils.getInternationalizationPreference(table)) {
+ if (null != table.eResource() && getInternationalizationPreference(table)) {
result = getTableLabelWithoutName(table, localize);
}
return null != result ? result : table.getName();
@@ -208,6 +238,33 @@ public class LabelInternationalization {
}
/**
+ * This allows to modify the internationalization preference value for the
+ * table owner.
+ *
+ * @param eObject
+ * The {@link EObject) corresponding (to get its resource).
+ * @param value
+ * The new preference value.
+ */
+ public void setInternationalizationPreference(final Table table, final boolean value) {
+ InternationalizationPreferencesUtils.setInternationalizationPreference(table.getOwner(), value);
+ }
+
+ /**
+ * This allows to get the internationalization preference value for the
+ * table (but it is the table owner because the diagram is in the notation
+ * file).
+ *
+ * @param diagram
+ * The {@link Diagram) corresponding.
+ * @return <code>true</code> if the preference value is set to true,
+ * <code>false</code> otherwise.
+ */
+ public boolean getInternationalizationPreference(final Table table) {
+ return InternationalizationPreferencesUtils.getInternationalizationPreference(table.getOwner());
+ }
+
+ /**
* This allows to get the set table label command.
*
* @param domain
diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/src/org/eclipse/papyrus/infra/internationalization/utils/utils/LabelInternationalizationPreferencesUtils.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/src/org/eclipse/papyrus/infra/internationalization/utils/utils/LabelInternationalizationPreferencesUtils.java
index 8ef77d9c261..9a5ff43bfcd 100644
--- a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/src/org/eclipse/papyrus/infra/internationalization/utils/utils/LabelInternationalizationPreferencesUtils.java
+++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/src/org/eclipse/papyrus/infra/internationalization/utils/utils/LabelInternationalizationPreferencesUtils.java
@@ -15,7 +15,9 @@ package org.eclipse.papyrus.infra.internationalization.utils.utils;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.papyrus.infra.internationalization.common.utils.InternationalizationPreferencesUtils;
+import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
/**
* Open the label internationalization preferences to the others plugins with the utils plugin.
@@ -29,7 +31,13 @@ public class LabelInternationalizationPreferencesUtils {
* @param value The new preference value.
*/
public static void setInternationalizationPreference(final EObject eObject, final boolean value){
- InternationalizationPreferencesUtils.setInternationalizationPreference(eObject, value);
+ if(eObject instanceof Table){
+ LabelInternationalization.getInstance().setInternationalizationPreference((Table)eObject, value);
+ }else if(eObject instanceof Diagram){
+ LabelInternationalization.getInstance().setInternationalizationPreference((Diagram)eObject, value);
+ }else{
+ InternationalizationPreferencesUtils.setInternationalizationPreference(eObject, value);
+ }
}
/**
@@ -49,7 +57,15 @@ public class LabelInternationalizationPreferencesUtils {
* @return <code>true</code> if the preference value is set to true, <code>false</code> otherwise.
*/
public static boolean getInternationalizationPreference(final EObject eObject){
- return InternationalizationPreferencesUtils.getInternationalizationPreference(eObject);
+ boolean result = false;
+ if(eObject instanceof Table){
+ result = LabelInternationalization.getInstance().getInternationalizationPreference((Table)eObject);
+ }else if(eObject instanceof Diagram){
+ result = LabelInternationalization.getInstance().getInternationalizationPreference((Diagram)eObject);
+ }else{
+ result = InternationalizationPreferencesUtils.getInternationalizationPreference(eObject);
+ }
+ return result;
}
/**
diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/src/org/eclipse/papyrus/infra/internationalization/utils/utils/LabelInternationalizationUtils.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/src/org/eclipse/papyrus/infra/internationalization/utils/utils/LabelInternationalizationUtils.java
index ee57125a72a..fc1c888e554 100644
--- a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/src/org/eclipse/papyrus/infra/internationalization/utils/utils/LabelInternationalizationUtils.java
+++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/src/org/eclipse/papyrus/infra/internationalization/utils/utils/LabelInternationalizationUtils.java
@@ -22,6 +22,7 @@ import org.eclipse.emf.common.command.UnexecutableCommand;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.papyrus.infra.core.resource.ModelSet;
import org.eclipse.papyrus.infra.core.resource.NotFoundException;
import org.eclipse.papyrus.infra.core.services.ServiceException;
@@ -32,6 +33,8 @@ import org.eclipse.papyrus.infra.internationalization.InternationalizationEntry;
import org.eclipse.papyrus.infra.internationalization.common.editor.IInternationalizationEditor;
import org.eclipse.papyrus.infra.internationalization.common.utils.InternationalizationPreferencesUtils;
import org.eclipse.papyrus.infra.internationalization.modelresource.InternationalizationModelResource;
+import org.eclipse.papyrus.infra.internationalization.utils.QualifiedNameUtils;
+import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
/**
* This allows to manage the utils methods for the internationalization.
@@ -80,14 +83,16 @@ public class LabelInternationalizationUtils {
final InternationalizationModelResource internationalizationResource = getInternationalizationModelResource(
eObject.eResource());
+ final EObject parentEObject = getParentEObject(eObject);
+
if (null != internationalizationResource) {
Locale localeToUse = locale;
if (null == localeToUse) {
- localeToUse = InternationalizationPreferencesUtils.getLocalePreference(eObject);
+ localeToUse = InternationalizationPreferencesUtils.getLocalePreference(parentEObject);
}
- internationalizationResource.setValue(eObject.eResource().getURI(), eObject, value, localeToUse);
+ internationalizationResource.setValue(parentEObject.eResource().getURI(), eObject, value, localeToUse);
}
} catch (final Exception e) {
// Do nothing
@@ -111,19 +116,22 @@ public class LabelInternationalizationUtils {
public static Command getSetLabelCommand(final EditingDomain domain, final EObject eObject, final String value,
final Locale locale) {
Command resultCommand = null;
+
+ final EObject parentEObject = getParentEObject(eObject);
+
try {
final InternationalizationModelResource internationalizationResource = getInternationalizationModelResource(
- eObject.eResource());
+ parentEObject.eResource());
if (null != internationalizationResource) {
Locale localeToUse = locale;
if (null == localeToUse) {
- localeToUse = InternationalizationPreferencesUtils.getLocalePreference(eObject);
+ localeToUse = InternationalizationPreferencesUtils.getLocalePreference(parentEObject);
}
- resultCommand = internationalizationResource.getSetValueCommand(domain, eObject.eResource().getURI(),
- eObject, value, localeToUse);
+ resultCommand = internationalizationResource.getSetValueCommand(domain,
+ parentEObject.eResource().getURI(), eObject, value, localeToUse);
}
} catch (final Exception e) {
// Do nothing
@@ -144,13 +152,15 @@ public class LabelInternationalizationUtils {
public static InternationalizationEntry getInternationalizationEntry(final EObject eObject, final Object key) {
InternationalizationEntry resultEntry = null;
+ final EObject parentEObject = getParentEObject(eObject);
+
try {
final InternationalizationModelResource internationalizationResource = getInternationalizationModelResource(
- eObject.eResource());
+ parentEObject.eResource());
if (null != internationalizationResource) {
- resultEntry = internationalizationResource.getEntryForKey(eObject.eResource().getURI(), key,
- InternationalizationPreferencesUtils.getLocalePreference(eObject));
+ resultEntry = internationalizationResource.getEntryForKey(parentEObject.eResource().getURI(), key,
+ InternationalizationPreferencesUtils.getLocalePreference(parentEObject));
}
} catch (final Exception e) {
// Do nothing
@@ -175,18 +185,21 @@ public class LabelInternationalizationUtils {
final Locale locale) {
InternationalizationEntry resultEntry = null;
+ final EObject parentEObject = getParentEObject(eObject);
+
try {
final InternationalizationModelResource internationalizationResource = getInternationalizationModelResource(
- eObject.eResource());
+ parentEObject.eResource());
if (null != internationalizationResource) {
Locale localeToUse = locale;
if (null == localeToUse) {
- localeToUse = InternationalizationPreferencesUtils.getLocalePreference(eObject);
+ localeToUse = InternationalizationPreferencesUtils.getLocalePreference(parentEObject);
}
- resultEntry = internationalizationResource.getEntryForKey(eObject.eResource().getURI(), key, locale);
+ resultEntry = internationalizationResource.getEntryForKey(parentEObject.eResource().getURI(), key,
+ locale);
}
} catch (final Exception e) {
// Do nothing
@@ -256,4 +269,21 @@ public class LabelInternationalizationUtils {
// Do nothing
}
}
+
+ /**
+ * Get the eObject or diagram/table owner if needed.
+ *
+ * @param eObject
+ * The initial EObject.
+ * @return The eObject or diagram/table owner.
+ */
+ protected static EObject getParentEObject(final EObject eObject) {
+ EObject parentEObject = eObject;
+ if (eObject instanceof Table) {
+ parentEObject = ((Table) eObject).getOwner();
+ } else if (eObject instanceof Diagram) {
+ parentEObject = QualifiedNameUtils.getOwner((Diagram) eObject);
+ }
+ return parentEObject;
+ }
}
diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/META-INF/MANIFEST.MF b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/META-INF/MANIFEST.MF
index 1bd0f712dc1..4f283852947 100644
--- a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/META-INF/MANIFEST.MF
+++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/META-INF/MANIFEST.MF
@@ -9,8 +9,10 @@ Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Export-Package: org.eclipse.papyrus.infra.internationalization,
org.eclipse.papyrus.infra.internationalization.commands,
+ org.eclipse.papyrus.infra.internationalization.helper,
org.eclipse.papyrus.infra.internationalization.modelresource,
org.eclipse.papyrus.infra.internationalization.modelsnippet,
+ org.eclipse.papyrus.infra.internationalization.resource,
org.eclipse.papyrus.infra.internationalization.util,
org.eclipse.papyrus.infra.internationalization.utils
Require-Bundle: org.eclipse.emf.ecore;bundle-version="[2.12.0,3.0.0)";visibility:=reexport,
@@ -24,6 +26,7 @@ Require-Bundle: org.eclipse.emf.ecore;bundle-version="[2.12.0,3.0.0)";visibility
org.eclipse.jface;bundle-version="[3.12.0,4.0.0)",
org.eclipse.papyrus.infra.emf.gmf;bundle-version="[1.2.0,2.0.0)",
org.eclipse.help;bundle-version="[3.7.0,4.0.0)",
- org.eclipse.papyrus.infra.doc;bundle-version="[1.2.0,2.0.0)"
+ org.eclipse.papyrus.infra.doc;bundle-version="[1.2.0,2.0.0)",
+ org.eclipse.papyrus.infra.viewpoints.policy;bundle-version="[1.2.0,2.0.0)"
Bundle-ActivationPolicy: lazy
Bundle-Activator: org.eclipse.papyrus.infra.internationalization.Activator
diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/helper/InternationalizationResourceHelper.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/helper/InternationalizationResourceHelper.java
new file mode 100644
index 00000000000..b4112530ead
--- /dev/null
+++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/helper/InternationalizationResourceHelper.java
@@ -0,0 +1,39 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.internationalization.helper;
+
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.papyrus.infra.internationalization.resource.InternationalizationResourceFactory;
+import org.eclipse.papyrus.infra.internationalization.utils.PropertiesFilesUtils;
+
+/**
+ * The internationalization resource helper needed to install the
+ * internationalization support for the properties files resources.
+ */
+public class InternationalizationResourceHelper {
+
+ /**
+ * This allows to install the correct resource fatory corresponding to the
+ * properties files.
+ *
+ * @param resourceSet
+ * The current resource set.
+ */
+ public static void installUMLInternationalizationSupport(final ResourceSet resourceSet) {
+ final InternationalizationResourceFactory factory = new InternationalizationResourceFactory();
+ resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
+ .put(PropertiesFilesUtils.PROPERTIES_FILE_EXTENSION, factory);
+ }
+
+}
diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/modelresource/InternationalizationModelResource.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/modelresource/InternationalizationModelResource.java
index 60baacf8d45..5a27f0324aa 100644
--- a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/modelresource/InternationalizationModelResource.java
+++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/modelresource/InternationalizationModelResource.java
@@ -7,7 +7,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Initial API and implementation
+ * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Initial API and implementation
*
*****************************************************************************/
@@ -15,14 +15,12 @@ package org.eclipse.papyrus.infra.internationalization.modelresource;
import java.io.IOException;
import java.util.Arrays;
-import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
-import java.util.Properties;
import java.util.Set;
import org.eclipse.core.resources.IContainer;
@@ -39,8 +37,7 @@ 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.emf.ecore.resource.URIConverter;
-import org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl;
+import org.eclipse.emf.ecore.xmi.XMLResource;
import org.eclipse.emf.edit.command.AddCommand;
import org.eclipse.emf.edit.command.RemoveCommand;
import org.eclipse.emf.edit.command.SetCommand;
@@ -67,7 +64,11 @@ import org.eclipse.papyrus.infra.internationalization.common.editor.IInternation
import org.eclipse.papyrus.infra.internationalization.common.utils.InternationalizationPreferencesConstants;
import org.eclipse.papyrus.infra.internationalization.common.utils.InternationalizationPreferencesUtils;
import org.eclipse.papyrus.infra.internationalization.common.utils.LocaleNameResolver;
+import org.eclipse.papyrus.infra.internationalization.helper.InternationalizationResourceHelper;
+import org.eclipse.papyrus.infra.internationalization.resource.InternationalizationResource;
import org.eclipse.papyrus.infra.internationalization.utils.EntryPartLabelSynchronizer;
+import org.eclipse.papyrus.infra.internationalization.utils.InternationalizationKeyResolver;
+import org.eclipse.papyrus.infra.internationalization.utils.InternationalizationResourceOptionsConstants;
import org.eclipse.papyrus.infra.internationalization.utils.PreferencePartLabelSynchronizer;
import org.eclipse.papyrus.infra.internationalization.utils.PropertiesFilesUtils;
import org.eclipse.papyrus.infra.internationalization.utils.QualifiedNameUtils;
@@ -87,25 +88,10 @@ public class InternationalizationModelResource extends AbstractModelWithSharedRe
public static final String MODEL_ID = "org.eclipse.papyrus.infra.internationalization.resource.InternationalizationModel"; //$NON-NLS-1$
/**
- * The '_labelDiagram_' prefix of each diagram entry.
+ * This allows to manage the key (resolve the objects by their qualified
+ * name, etc.).
*/
- protected static final String LABEL_DIAGRAM_PREFIX_QN = "_labelDiagram_"; //$NON-NLS-1$
-
- /**
- * The '_labelTable_' prefix of each table entry.
- */
- protected static final String LABEL_TABLE_PREFIX_QN = "_labelTable_"; //$NON-NLS-1$
-
- /**
- * The '_label_' prefix of each entry.
- */
- public static final String LABEL_PREFIX = "_label_"; //$NON-NLS-1$
-
- /**
- * The notation extension file (cannot use the
- * NotationModel.NOTATION_FILE_EXTENSION because of dependencies cycle).
- */
- protected static final String NOTATION_FILE_EXTENSION = "notation"; //$NON-NLS-1$
+ protected InternationalizationKeyResolver keyResolver = null;
/**
* The map of the loaded resource by the initial URI and by locale.
@@ -174,6 +160,27 @@ public class InternationalizationModelResource extends AbstractModelWithSharedRe
/**
* {@inheritDoc}
*
+ * @see org.eclipse.papyrus.infra.core.resource.AbstractModel#init(org.eclipse.papyrus.infra.core.resource.ModelSet)
+ */
+ @Override
+ public void init(final ModelSet modelSet) {
+ super.init(modelSet);
+ InternationalizationResourceHelper.installUMLInternationalizationSupport(modelSet);
+ keyResolver = createKeyResolver();
+ }
+
+ /**
+ * This allows to create the key resolver.
+ *
+ * @return The created key resolver.
+ */
+ protected InternationalizationKeyResolver createKeyResolver() {
+ return InternationalizationKeyResolver.getInstance();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
* @see org.eclipse.papyrus.infra.core.resource.AbstractModelWithSharedResource#loadModel(org.eclipse.emf.common.util.URI)
*/
@Override
@@ -268,9 +275,9 @@ public class InternationalizationModelResource extends AbstractModelWithSharedRe
IContainer parentFolder = null;
if (folderURI.isPlatformResource()) {
final String uriPlatformString = folderURI.toPlatformString(true);
- try{
+ try {
parentFolder = ResourcesPlugin.getWorkspace().getRoot().getProject(uriPlatformString);
- }catch(Exception exception){
+ } catch (Exception exception) {
parentFolder = ResourcesPlugin.getWorkspace().getRoot().getFolder(new Path(uriPlatformString));
}
}
@@ -364,6 +371,15 @@ public class InternationalizationModelResource extends AbstractModelWithSharedRe
startSnippets();
}
+ // Load the resource if not already loaded
+ if (!resource.isLoaded()) {
+ try {
+ resource.load(null);
+ } catch (IOException e) {
+ Activator.log.error("Error during load resource.", e); //$NON-NLS-1$
+ }
+ }
+
loadInternationalizationContent(uri, locale);
}
@@ -410,6 +426,14 @@ public class InternationalizationModelResource extends AbstractModelWithSharedRe
* The locale to manage.
*/
protected void configureResource(final Resource resourceToConfigure, final Locale locale) {
+ if (resourceToConfigure instanceof InternationalizationResource) {
+ final Map<Object, Object> defaultLoadOptions = ((InternationalizationResource) resourceToConfigure)
+ .getDefaultLoadOptions();
+ defaultLoadOptions.put(InternationalizationResourceOptionsConstants.LOAD_SAVE_OPTION_KEY_RESOLVER,
+ keyResolver);
+ defaultLoadOptions.put(InternationalizationResourceOptionsConstants.LOAD_OPTION_LOCALE, locale);
+ defaultLoadOptions.put(InternationalizationResourceOptionsConstants.LOAD_OPTION_URI, resourceURI);
+ }
super.configureResource(resourceToConfigure);
// Add the resource to the resource properties classified by their
// locale
@@ -420,8 +444,8 @@ public class InternationalizationModelResource extends AbstractModelWithSharedRe
}
/**
- * This allows to load internationalization content of properties file into
- * the current resource.
+ * This allows to through the internationalization library to manage
+ * adapters for needed objects.
*
* @param uri
* The URI of the properties file with the extension.
@@ -429,71 +453,16 @@ public class InternationalizationModelResource extends AbstractModelWithSharedRe
* The locale to use.
*/
protected void loadInternationalizationContent(final URI uri, final Locale locale) {
- final Resource resource = getResourceForURIAndLocale(uri, locale);
-
if (null != resource && resource.getContents().isEmpty()) {
- final ResourceBundleAndURI resourceBundleAndURI = PropertiesFilesUtils
- .getResourceBundle(uri.trimFileExtension().appendFileExtension(getModelFileExtension()), locale);
- if (null != resourceBundleAndURI && null != resourceBundleAndURI.getResourceBundle()) {
- // Create the internationalization library to set to the
- // resource contents
- final InternationalizationLibrary library = InternationalizationFactory.eINSTANCE
- .createInternationalizationLibrary();
- final Enumeration<String> keys = resourceBundleAndURI.getResourceBundle().getKeys();
-
- // Loop on existing keys
- while (keys.hasMoreElements()) {
- // Create an entry for each key
- final InternationalizationEntry entry = InternationalizationFactory.eINSTANCE
- .createInternationalizationEntry();
- String key = (String) keys.nextElement();
- if (key.startsWith(LABEL_DIAGRAM_PREFIX_QN)) {
- final String keyWithoutPrefix = key.substring(LABEL_DIAGRAM_PREFIX_QN.length());
- final String qualifiedName = keyWithoutPrefix.substring(0,
- keyWithoutPrefix.indexOf(LABEL_PREFIX));
- final String diagramName = keyWithoutPrefix
- .substring(keyWithoutPrefix.indexOf(LABEL_PREFIX) + LABEL_PREFIX.length());
-
- final Resource notationResource = modelSet.getResource(
- uri.trimFileExtension().appendFileExtension(NOTATION_FILE_EXTENSION), true);
-
- if (null != notationResource && null != notationResource.getContents()
- && !notationResource.getContents().isEmpty()) {
- final Diagram foundDiagram = QualifiedNameUtils.getDiagram(notationResource, diagramName,
- qualifiedName);
- entry.setKey(foundDiagram);
- addModifiedAdapter(foundDiagram, resource);
- }
+ final InternationalizationLibrary library = getModelRoot();
- } else if (key.startsWith(LABEL_TABLE_PREFIX_QN)) {
- final String keyWithoutPrefix = key.substring(LABEL_TABLE_PREFIX_QN.length());
- final String qualifiedName = keyWithoutPrefix.substring(0,
- keyWithoutPrefix.indexOf(LABEL_PREFIX));
- final String tableName = keyWithoutPrefix
- .substring(keyWithoutPrefix.indexOf(LABEL_PREFIX) + LABEL_PREFIX.length());
-
- final Resource umlResource = modelSet.getResource(
- uri.trimFileExtension().appendFileExtension(NOTATION_FILE_EXTENSION), true);
-
- if (null != umlResource && null != umlResource.getContents()
- && !umlResource.getContents().isEmpty()) {
- final Table foundTable = QualifiedNameUtils.getTable(umlResource, tableName, qualifiedName);
- entry.setKey(foundTable);
- addModifiedAdapter(foundTable, resource);
- }
- } else {
- entry.setKey(key);
+ if (null != library) {
+ for (final InternationalizationEntry entry : library.getEntries()) {
+ if (entry.getKey() instanceof EObject) {
+ addModifiedAdapter((EObject) entry.getKey(), resource);
}
- entry.setValue(resourceBundleAndURI.getResourceBundle().getString(key));
- // Add the entry to the library
- library.getEntries().add(entry);
}
-
- final GMFtoEMFCommandWrapper command = new GMFtoEMFCommandWrapper(new AddToResourceCommand(
- ((ModelSet) resource.getResourceSet()).getTransactionalEditingDomain(), resource, library));
- command.execute();
}
- resource.setModified(false);
}
}
@@ -523,6 +492,14 @@ public class InternationalizationModelResource extends AbstractModelWithSharedRe
// Create the resource needed
final Resource resultResource = modelSet.createResource(propertiesURI);
configureResource(resultResource, locale);
+ // Load the resource if not already loaded
+ if (!resultResource.isLoaded()) {
+ try {
+ resultResource.load(null);
+ } catch (IOException e) {
+ Activator.log.error("Error during load resource.", e); //$NON-NLS-1$
+ }
+ }
// Create the internationalization library in the resource content
createInternationalizationContent(resultResource);
@@ -563,7 +540,6 @@ public class InternationalizationModelResource extends AbstractModelWithSharedRe
@Override
public void saveModel() throws IOException {
// Save into the properties files
-
for (final Resource resource : getResources()) {
saveResource(resource);
}
@@ -578,32 +554,17 @@ public class InternationalizationModelResource extends AbstractModelWithSharedRe
* The input output file exception.
*/
protected void saveResource(final Resource resource) throws IOException {
- final ModelSet set = getModelManager();
- if (null != resource && set.shouldSave(resource) && !resource.getContents().isEmpty()) {
- // It is needed to manage the save of properties by a simple output
- // stream because the resource bundle cannot be modified
- final Properties properties = new Properties();
-
- final InternationalizationLibrary library = (InternationalizationLibrary) resource.getContents().get(0);
-
- // Add all the entries into properties (need this properties to save
- // easier the properties file)
- for (final InternationalizationEntry entry : library.getEntries()) {
- if (!deletedObjects.contains(entry.getKey()) && !entry.getValue().isEmpty()) {
- properties.setProperty(getKey(entry), entry.getValue());
- }
+ Map<Object, Object> saveOptions = null;
+ if (resource instanceof XMLResource) {
+ saveOptions = ((XMLResource) resource).getDefaultSaveOptions();
+ if (resource instanceof InternationalizationResource) {
+ saveOptions.put(InternationalizationResourceOptionsConstants.SAVE_OPTION_DELETED_OBJECTS,
+ deletedObjects);
+ saveOptions.put(InternationalizationResourceOptionsConstants.LOAD_SAVE_OPTION_KEY_RESOLVER,
+ keyResolver);
}
-
- final Locale locale = getLocaleForResource(resource);
-
- // Get the URI of properties file used (with locale or not)
- final URI resourceURI = PropertiesFilesUtils.getResourceBundleURIFromResourceURI(resource.getURI(), locale);
-
- // This allows to save the properties into the properties file
- final URIConverter uriConverter = new ExtensibleURIConverterImpl();
- properties.store(uriConverter.createOutputStream(resourceURI), null);
- resource.setModified(false);
}
+ resource.save(saveOptions);
}
/**
@@ -674,36 +635,6 @@ public class InternationalizationModelResource extends AbstractModelWithSharedRe
}
/**
- * This allows to get the entry key (can be override to get element string
- * identifier instead of string key).
- *
- * @param entry
- * The internationalization entry.
- * @return The key as String.
- */
- protected String getKey(final InternationalizationEntry entry) {
- final StringBuilder result = new StringBuilder();
- if (entry.getKey() instanceof Diagram) {
- result.append(LABEL_DIAGRAM_PREFIX_QN);
- final Diagram diagram = (Diagram) entry.getKey();
- final EObject diagramContainer = diagram.getElement();
- result.append(QualifiedNameUtils.getQualifiedName(diagramContainer));
- result.append(LABEL_PREFIX);
- result.append(diagram.getName());
- } else if (entry.getKey() instanceof Table) {
- result.append(LABEL_TABLE_PREFIX_QN);
- final Table table = (Table) entry.getKey();
- final EObject tableContainer = table.getOwner();
- result.append(QualifiedNameUtils.getQualifiedName(tableContainer));
- result.append(LABEL_PREFIX);
- result.append(table.getName());
- } else {
- result.append((String) entry.getKey());
- }
- return result.toString();
- }
-
- /**
* {@inheritDoc}
*
* @see org.eclipse.papyrus.infra.core.resource.AbstractModelWithSharedResource#isModelRoot(org.eclipse.emf.ecore.EObject)
@@ -780,7 +711,7 @@ public class InternationalizationModelResource extends AbstractModelWithSharedRe
*/
public String getValueForEntryKey(final URI uri, final EObject key) {
InternationalizationEntry entry = getEntryForKey(uri, key,
- InternationalizationPreferencesUtils.getLocalePreference(key));
+ InternationalizationPreferencesUtils.getLocalePreference(getParentEObject(key)));
return null != entry ? entry.getValue() : null;
}
@@ -845,7 +776,11 @@ public class InternationalizationModelResource extends AbstractModelWithSharedRe
Command resultCommand = null;
// Get the resource where add/modify the entry corresponding to the key
- final Resource resource = getResourceForURIAndLocale(uri, locale);
+ Resource resource = getResourceForURIAndLocale(uri, locale);
+ if (null == resource) {
+ resource = getResourceForURIAndLocale(uri, new Locale("")); //$NON-NLS-1$
+ }
+
final InternationalizationLibrary library = getModelRoot(resource);
if (null != library) {
@@ -896,7 +831,7 @@ public class InternationalizationModelResource extends AbstractModelWithSharedRe
// the library
resultCommand = new CompoundCommand("Create entry"); //$NON-NLS-1$
((CompoundCommand) resultCommand).append(new CreatePropertiesResourceCommand(uri, entry,
- InternationalizationPreferencesUtils.getLocalePreference(key)));
+ InternationalizationPreferencesUtils.getLocalePreference(getParentEObject(key))));
Command setNameValueCommand = getSetNameValueCommand(domain, (EObject) entry.getKey());
if (null != setNameValueCommand) {
((CompoundCommand) resultCommand).append(setNameValueCommand);
@@ -967,7 +902,8 @@ public class InternationalizationModelResource extends AbstractModelWithSharedRe
Resource resource = getResourceForURIAndLocale(uri, locale);
if (null == resource) {
// If the resource does not exist, create it
- resource = createResource(uri, InternationalizationPreferencesUtils.getLocalePreference(key));
+ resource = createResource(uri,
+ InternationalizationPreferencesUtils.getLocalePreference(getParentEObject(key)));
}
final InternationalizationLibrary library = getModelRoot(resource);
@@ -1203,6 +1139,23 @@ public class InternationalizationModelResource extends AbstractModelWithSharedRe
}
/**
+ * Get the eObject or diagram/table owner if needed.
+ *
+ * @param eObject
+ * The initial EObject.
+ * @return The eObject or diagram/table owner.
+ */
+ protected static EObject getParentEObject(final EObject eObject) {
+ EObject parentEObject = eObject;
+ if (eObject instanceof Table) {
+ parentEObject = ((Table) eObject).getOwner();
+ } else if (eObject instanceof Diagram) {
+ parentEObject = QualifiedNameUtils.getOwner((Diagram) eObject);
+ }
+ return parentEObject;
+ }
+
+ /**
* Returns <code>true</code> if the URI was already loaded,
* <code>false</code> otherwise.
*
diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/resource/InternationalizationResource.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/resource/InternationalizationResource.java
new file mode 100644
index 00000000000..f4ebe534d8b
--- /dev/null
+++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/resource/InternationalizationResource.java
@@ -0,0 +1,305 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.internationalization.resource;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.Vector;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.URIConverter;
+import org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl;
+import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.emf.commands.AddToResourceCommand;
+import org.eclipse.papyrus.infra.emf.gmf.command.GMFtoEMFCommandWrapper;
+import org.eclipse.papyrus.infra.internationalization.Activator;
+import org.eclipse.papyrus.infra.internationalization.InternationalizationEntry;
+import org.eclipse.papyrus.infra.internationalization.InternationalizationFactory;
+import org.eclipse.papyrus.infra.internationalization.InternationalizationLibrary;
+import org.eclipse.papyrus.infra.internationalization.common.utils.LocaleNameResolver;
+import org.eclipse.papyrus.infra.internationalization.utils.InternationalizationKeyResolver;
+import org.eclipse.papyrus.infra.internationalization.utils.InternationalizationResourceOptionsConstants;
+import org.eclipse.papyrus.infra.internationalization.utils.PropertiesFilesUtils;
+import org.eclipse.papyrus.infra.internationalization.utils.ResourceBundleAndURI;
+
+/**
+ * The resource corresponding to the properties files.
+ */
+public class InternationalizationResource extends XMIResourceImpl {
+
+ /**
+ * Constructor.
+ *
+ * @param uri
+ * The uri of the resource.
+ */
+ public InternationalizationResource(final URI uri) {
+ super(uri);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.ecore.resource.impl.ResourceImpl#load(java.util.Map)
+ */
+ @Override
+ public void load(final Map<?, ?> options) throws IOException {
+
+ // Load the key resolver save option if exist
+ final InternationalizationKeyResolver keyResolver = loadKeyResolverOption(options, defaultLoadOptions);
+
+ // Load the URI save option if exist
+ final URI initialURI = loadURIOption(options, defaultLoadOptions);
+
+ // Load the locale save option if exist
+ final Object saveOptionLocale = options != null
+ && options.containsKey(InternationalizationResourceOptionsConstants.LOAD_OPTION_LOCALE)
+ ? options.get(InternationalizationResourceOptionsConstants.LOAD_OPTION_LOCALE)
+ : defaultLoadOptions != null
+ ? defaultLoadOptions
+ .get(InternationalizationResourceOptionsConstants.LOAD_OPTION_LOCALE)
+ : null;
+ Locale locale = null;
+ if (null != saveOptionLocale) {
+ if (saveOptionLocale instanceof Locale) {
+ locale = (Locale) saveOptionLocale;
+ } else if (saveOptionLocale instanceof String) {
+ locale = LocaleNameResolver.getLocaleFromString((String) saveOptionLocale);
+ }
+ }
+
+ // Load the resource from Properties files utils manager
+ final ResourceBundleAndURI resourceBundleAndURI = PropertiesFilesUtils.getResourceBundle(
+ initialURI.trimFileExtension().appendFileExtension(PropertiesFilesUtils.PROPERTIES_FILE_EXTENSION),
+ locale);
+ if (null != resourceBundleAndURI && null != resourceBundleAndURI.getResourceBundle()) {
+ // Create the internationalization library to set to the
+ // resource contents
+ final InternationalizationLibrary library = InternationalizationFactory.eINSTANCE
+ .createInternationalizationLibrary();
+ final Enumeration<String> keys = resourceBundleAndURI.getResourceBundle().getKeys();
+
+ // Loop on existing keys
+ while (keys.hasMoreElements()) {
+ // Create an entry for each key
+
+ final String key = (String) keys.nextElement();
+
+ final InternationalizationEntry entry = keyResolver.createInternationalizationEntryByKey(key,
+ getResourceSet(), initialURI);
+ entry.setValue(resourceBundleAndURI.getResourceBundle().getString(key));
+
+ // Add the entry to the library
+ library.getEntries().add(entry);
+ }
+
+ if (getResourceSet() instanceof ModelSet) {
+ // Add the library to the resource
+ final GMFtoEMFCommandWrapper command = new GMFtoEMFCommandWrapper(new AddToResourceCommand(
+ ((ModelSet) getResourceSet()).getTransactionalEditingDomain(), this, library));
+ command.execute();
+ } else {
+ // Workaround for the non ModelSet resource set.
+ final ResourceSet resourceSet = getResourceSet();
+ resourceSet.getResources().remove(this);
+ getContents().add(library);
+ resourceSet.getResources().add(this);
+ }
+
+ setModified(false);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.ecore.resource.impl.ResourceImpl#save(java.util.Map)
+ */
+ @Override
+ public void save(final Map<?, ?> options) throws IOException {
+
+ // Load the key resolver save option if exist
+ final InternationalizationKeyResolver keyResolver = loadKeyResolverOption(options, defaultSaveOptions);
+
+ // Load the deleted objects save option if exist
+ final Object saveOptionDeletedObjects = options != null
+ && options.containsKey(InternationalizationResourceOptionsConstants.SAVE_OPTION_DELETED_OBJECTS)
+ ? options.get(InternationalizationResourceOptionsConstants.SAVE_OPTION_DELETED_OBJECTS)
+ : defaultSaveOptions != null
+ ? defaultSaveOptions
+ .get(InternationalizationResourceOptionsConstants.SAVE_OPTION_DELETED_OBJECTS)
+ : null;
+ Set<?> deletedObjects = null;
+ if (null != saveOptionDeletedObjects && saveOptionDeletedObjects instanceof Set) {
+ deletedObjects = (Set<?>) saveOptionDeletedObjects;
+ }
+
+ // Load the sort save option if exist
+ final Object saveOptionSort = options != null
+ && options.containsKey(InternationalizationResourceOptionsConstants.SAVE_OPTION_SORT)
+ ? options.get(InternationalizationResourceOptionsConstants.SAVE_OPTION_SORT)
+ : defaultSaveOptions != null
+ ? defaultSaveOptions.get(InternationalizationResourceOptionsConstants.SAVE_OPTION_SORT)
+ : null;
+ boolean sort = false;
+ if (null != saveOptionSort && saveOptionSort instanceof Boolean) {
+ sort = (Boolean) saveOptionSort;
+ }
+
+ // It is needed to manage the save of properties by a simple output
+ // stream because the resource bundle cannot be modified
+ final SortedProperties properties = new SortedProperties(sort);
+
+ if (!getContents().isEmpty()) {
+ for (final EObject content : getContents()) {
+ if (content instanceof InternationalizationLibrary) {
+ final InternationalizationLibrary library = (InternationalizationLibrary) content;
+
+ // Add all the entries into properties (need this properties
+ // to save
+ // easier the properties file)
+ for (final InternationalizationEntry entry : library.getEntries()) {
+ if ((null == deletedObjects || !deletedObjects.contains(entry.getKey()))
+ && !entry.getValue().isEmpty()) {
+ if (null != keyResolver) {
+ properties.setProperty(keyResolver.getKey(entry), entry.getValue());
+ } else {
+ properties.setProperty(entry.getKey().toString(), entry.getValue());
+ }
+ }
+ }
+
+ // This allows to save the properties into the properties
+ // file
+ final URIConverter uriConverter = new ExtensibleURIConverterImpl();
+ properties.store(uriConverter.createOutputStream(getURI()), null);
+ }
+ }
+ }
+ setModified(false);
+ }
+
+ /**
+ * This allows to load the key resolver option.
+ *
+ * @param options
+ * The initial options.
+ * @param defaultOptions
+ * The default options.
+ * @return The key resolver.
+ */
+ protected InternationalizationKeyResolver loadKeyResolverOption(final Map<?, ?> options,
+ final Map<?, ?> defaultOptions) {
+ // Load the key resolver save option if exist
+ Object saveOptionKeyResolver = options != null
+ && options.containsKey(InternationalizationResourceOptionsConstants.LOAD_SAVE_OPTION_KEY_RESOLVER)
+ ? options.get(InternationalizationResourceOptionsConstants.LOAD_SAVE_OPTION_KEY_RESOLVER)
+ : defaultOptions != null
+ ? defaultOptions
+ .get(InternationalizationResourceOptionsConstants.LOAD_SAVE_OPTION_KEY_RESOLVER)
+ : null;
+ InternationalizationKeyResolver keyResolver = null;
+ if (null != saveOptionKeyResolver && saveOptionKeyResolver instanceof InternationalizationKeyResolver) {
+ keyResolver = (InternationalizationKeyResolver) saveOptionKeyResolver;
+ } else {
+ Activator.log.error("The 'keyResolver' option for the internationalization resource must be set.", null); //$NON-NLS-1$
+ }
+
+ return keyResolver;
+ }
+
+ /**
+ * This allows to load the URI option.
+ *
+ * @param options
+ * The initial options.
+ * @param defaultOptions
+ * The default options.
+ * @return The URI option.
+ */
+ protected URI loadURIOption(final Map<?, ?> options, final Map<?, ?> defaultOptions) {
+ // Load the URI save option if exist
+ Object saveOptionURI = options != null
+ && options.containsKey(InternationalizationResourceOptionsConstants.LOAD_OPTION_URI)
+ ? options.get(InternationalizationResourceOptionsConstants.LOAD_OPTION_URI)
+ : defaultOptions != null
+ ? defaultOptions.get(InternationalizationResourceOptionsConstants.LOAD_OPTION_URI)
+ : null;
+ URI initialURI = null;
+ if (null != saveOptionURI && saveOptionURI instanceof URI) {
+ initialURI = (URI) saveOptionURI;
+ } else {
+ Activator.log.error("The initial 'URI' option for the internationalization resource must be set.", null); //$NON-NLS-1$
+ }
+
+ return initialURI;
+ }
+
+ /**
+ * Re-implement the properties because the sort is not enable for a
+ * HashTable
+ */
+ private class SortedProperties extends Properties {
+
+ /**
+ * Serial version.
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Determinates if the sort must be applied.
+ */
+ private boolean sort = false;
+
+ /**
+ * Constructor.
+ *
+ * @param sort
+ * Determinates if the sort must be applied.
+ */
+ public SortedProperties(final boolean sort) {
+ this.sort = sort;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.util.Hashtable#keys()
+ */
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ @Override
+ public Enumeration keys() {
+ Enumeration keysEnum = super.keys();
+ if (sort) {
+ Vector<String> keyList = new Vector<String>();
+ while (keysEnum.hasMoreElements()) {
+ keyList.add((String) keysEnum.nextElement());
+ }
+ Collections.sort(keyList);
+ keysEnum = keyList.elements();
+ }
+ return keysEnum;
+ }
+
+ }
+
+}
diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/resource/InternationalizationResourceFactory.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/resource/InternationalizationResourceFactory.java
new file mode 100644
index 00000000000..6b22fff15fc
--- /dev/null
+++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/resource/InternationalizationResourceFactory.java
@@ -0,0 +1,45 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.internationalization.resource;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.xmi.XMIResource;
+import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
+import org.eclipse.gmf.runtime.emf.core.internal.util.EMFCoreConstants;
+
+/**
+ * The resource factory for the properties files.
+ */
+@SuppressWarnings("restriction")
+public class InternationalizationResourceFactory extends XMIResourceFactoryImpl {
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl#createResource(org.eclipse.emf.common.util.URI)
+ */
+ @Override
+ public Resource createResource(final URI uri) {
+
+ final XMIResource resource = new InternationalizationResource(uri);
+
+ if (!resource.getEncoding().equals(EMFCoreConstants.XMI_ENCODING)) {
+ resource.setEncoding(EMFCoreConstants.XMI_ENCODING);
+ }
+
+ return resource;
+ }
+
+}
diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/utils/EntryPartLabelSynchronizer.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/utils/EntryPartLabelSynchronizer.java
index cc009312427..b52db2ff0c4 100644
--- a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/utils/EntryPartLabelSynchronizer.java
+++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/utils/EntryPartLabelSynchronizer.java
@@ -142,7 +142,7 @@ public class EntryPartLabelSynchronizer {
*/
protected String getTableLabel(final Table table) {
String result = null;
- if (InternationalizationPreferencesUtils.getInternationalizationPreference(table)) {
+ if (InternationalizationPreferencesUtils.getInternationalizationPreference(table.getOwner())) {
result = modelResource.getValueForEntryKey(table.eResource().getURI(), table);
}
return null != result ? result : table.getName();
@@ -159,7 +159,7 @@ public class EntryPartLabelSynchronizer {
*/
protected String getDiagramLabel(final Diagram diagram) {
String result = null;
- if (InternationalizationPreferencesUtils.getInternationalizationPreference(diagram)) {
+ if (InternationalizationPreferencesUtils.getInternationalizationPreference(QualifiedNameUtils.getOwner(diagram))) {
result = modelResource.getValueForEntryKey(diagram.eResource().getURI(), diagram);
}
return null != result ? result : diagram.getName();
diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/utils/InternationalizationKeyResolver.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/utils/InternationalizationKeyResolver.java
new file mode 100644
index 00000000000..c88f69b5105
--- /dev/null
+++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/utils/InternationalizationKeyResolver.java
@@ -0,0 +1,153 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.internationalization.utils;
+
+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.resource.ResourceSet;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.papyrus.infra.internationalization.InternationalizationEntry;
+import org.eclipse.papyrus.infra.internationalization.InternationalizationFactory;
+import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
+
+/**
+ * The internationalization key resolver for the infra elements (Diagrams an Tables).
+ */
+public class InternationalizationKeyResolver {
+
+ /**
+ * The singleton instance.
+ */
+ private static InternationalizationKeyResolver instance;
+
+ /**
+ * The '_labelDiagram_' prefix of each diagram entry.
+ */
+ protected static final String LABEL_DIAGRAM_PREFIX_QN = "_labelDiagram_"; //$NON-NLS-1$
+
+ /**
+ * The '_labelTable_' prefix of each table entry.
+ */
+ protected static final String LABEL_TABLE_PREFIX_QN = "_labelTable_"; //$NON-NLS-1$
+
+ /**
+ * The '_label_' prefix of each entry.
+ */
+ public static final String LABEL_PREFIX = "_label_"; //$NON-NLS-1$
+
+ /**
+ * The notation extension file (cannot use the
+ * NotationModel.NOTATION_FILE_EXTENSION because of dependencies cycle).
+ */
+ protected static final String NOTATION_FILE_EXTENSION = "notation"; //$NON-NLS-1$
+
+ public InternationalizationKeyResolver() {
+ // Do nothing
+ }
+
+ /**
+ * Get the singleton instance (create it if not existing).
+ *
+ * @return The singleton instance.
+ */
+ public static InternationalizationKeyResolver getInstance() {
+ if (null == instance) {
+ instance = new InternationalizationKeyResolver();
+ }
+ return instance;
+ }
+
+ /**
+ * This allows to create an internationalization entry corresponding to the
+ * key in parameter and creating table or diagram reference if possible.
+ *
+ * @param key
+ * The key.
+ * @param resourceSet
+ * The current resource set.
+ * @param uri
+ * The uri of the file to manage.
+ * @return The created internationalization entry.
+ */
+ public InternationalizationEntry createInternationalizationEntryByKey(final String key, final ResourceSet resourceSet,
+ final URI uri) {
+ final InternationalizationEntry entry = InternationalizationFactory.eINSTANCE.createInternationalizationEntry();
+ if (key.startsWith(LABEL_DIAGRAM_PREFIX_QN)) {
+ final String keyWithoutPrefix = key.substring(LABEL_DIAGRAM_PREFIX_QN.length());
+ final String qualifiedName = keyWithoutPrefix.substring(0, keyWithoutPrefix.indexOf(LABEL_PREFIX));
+ final String diagramName = keyWithoutPrefix
+ .substring(keyWithoutPrefix.indexOf(LABEL_PREFIX) + LABEL_PREFIX.length());
+
+ final Resource notationResource = resourceSet
+ .getResource(uri.trimFileExtension().appendFileExtension(NOTATION_FILE_EXTENSION), true);
+
+ if (null != notationResource && null != notationResource.getContents()
+ && !notationResource.getContents().isEmpty()) {
+ final Diagram foundDiagram = QualifiedNameUtils.getDiagram(notationResource, diagramName,
+ qualifiedName);
+ entry.setKey(foundDiagram);
+ }
+
+ } else if (key.startsWith(LABEL_TABLE_PREFIX_QN)) {
+ final String keyWithoutPrefix = key.substring(LABEL_TABLE_PREFIX_QN.length());
+ final String qualifiedName = keyWithoutPrefix.substring(0, keyWithoutPrefix.indexOf(LABEL_PREFIX));
+ final String tableName = keyWithoutPrefix
+ .substring(keyWithoutPrefix.indexOf(LABEL_PREFIX) + LABEL_PREFIX.length());
+
+ final Resource umlResource = resourceSet
+ .getResource(uri.trimFileExtension().appendFileExtension(NOTATION_FILE_EXTENSION), true);
+
+ if (null != umlResource && null != umlResource.getContents() && !umlResource.getContents().isEmpty()) {
+ final Table foundTable = QualifiedNameUtils.getTable(umlResource, tableName, qualifiedName);
+ entry.setKey(foundTable);
+ }
+ } else {
+ entry.setKey(key);
+ }
+
+ return entry;
+ }
+
+ /**
+ * This allows to get the entry key (can be override to get element string
+ * identifier instead of string key).
+ *
+ * @param entry
+ * The internationalization entry.
+ * @return The key as String.
+ */
+ public String getKey(final InternationalizationEntry entry) {
+ final StringBuilder result = new StringBuilder();
+ if (entry.getKey() instanceof Diagram) {
+ result.append(LABEL_DIAGRAM_PREFIX_QN);
+ final Diagram diagram = (Diagram) entry.getKey();
+ final EObject diagramContainer = diagram.getElement();
+ result.append(QualifiedNameUtils.getQualifiedName(diagramContainer));
+ result.append(LABEL_PREFIX);
+ result.append(diagram.getName());
+ } else if (entry.getKey() instanceof Table) {
+ result.append(LABEL_TABLE_PREFIX_QN);
+ final Table table = (Table) entry.getKey();
+ final EObject tableContainer = table.getOwner();
+ result.append(QualifiedNameUtils.getQualifiedName(tableContainer));
+ result.append(LABEL_PREFIX);
+ result.append(table.getName());
+ } else {
+ result.append((String) entry.getKey());
+ }
+ return result.toString();
+ }
+
+}
diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/utils/InternationalizationResourceOptionsConstants.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/utils/InternationalizationResourceOptionsConstants.java
new file mode 100644
index 00000000000..860d5601a90
--- /dev/null
+++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/utils/InternationalizationResourceOptionsConstants.java
@@ -0,0 +1,50 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.internationalization.utils;
+
+/**
+ * This defines the internationalization options constants available for the
+ * internationalization resource load and save.
+ */
+public class InternationalizationResourceOptionsConstants {
+
+ /**
+ * The deleted objects save option which can be used to not serialize the
+ * objects in this set.
+ */
+ public static final String SAVE_OPTION_DELETED_OBJECTS = "internationalizationDeletedObjects"; //$NON-NLS-1$
+
+ /**
+ * The sort save option to determinate if the properties entries must be
+ * sort.
+ */
+ public static final String SAVE_OPTION_SORT = "internationalizationSort"; //$NON-NLS-1$
+
+ /**
+ * The key resolver option which allow to calculate the properties entries
+ * keys.
+ */
+ public static final String LOAD_SAVE_OPTION_KEY_RESOLVER = "internationalizationKeyResolver"; //$NON-NLS-1$
+
+ /**
+ * The locale option to store the locale file to load.
+ */
+ public static final String LOAD_OPTION_LOCALE = "internationalizationLocale"; //$NON-NLS-1$
+
+ /**
+ * The uri of the resource without locale extension.
+ */
+ public static final String LOAD_OPTION_URI = "internationalizationURI"; //$NON-NLS-1$
+
+}
diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/utils/PreferencePartLabelSynchronizer.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/utils/PreferencePartLabelSynchronizer.java
index cc01609c041..cebe9663f89 100644
--- a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/utils/PreferencePartLabelSynchronizer.java
+++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/utils/PreferencePartLabelSynchronizer.java
@@ -146,7 +146,7 @@ public class PreferencePartLabelSynchronizer {
*/
protected String getTableLabel(final Table table) {
String result = null;
- if (InternationalizationPreferencesUtils.getInternationalizationPreference(table)) {
+ if (InternationalizationPreferencesUtils.getInternationalizationPreference(table.getOwner())) {
result = modelResource.getValueForEntryKey(table.eResource().getURI(), table);
}
return null != result ? result : table.getName();
@@ -163,7 +163,7 @@ public class PreferencePartLabelSynchronizer {
*/
protected String getDiagramLabel(final Diagram diagram) {
String result = null;
- if (InternationalizationPreferencesUtils.getInternationalizationPreference(diagram)) {
+ if (InternationalizationPreferencesUtils.getInternationalizationPreference(QualifiedNameUtils.getOwner(diagram))) {
result = modelResource.getValueForEntryKey(diagram.eResource().getURI(), diagram);
}
return null != result ? result : diagram.getName();
diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/utils/QualifiedNameUtils.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/utils/QualifiedNameUtils.java
index c0d1d04accd..a97690b7b70 100644
--- a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/utils/QualifiedNameUtils.java
+++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/utils/QualifiedNameUtils.java
@@ -13,12 +13,16 @@
package org.eclipse.papyrus.infra.internationalization.utils;
+import java.util.List;
+
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.xmi.XMIResource;
import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.gmf.runtime.notation.Style;
import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
+import org.eclipse.papyrus.infra.viewpoints.style.PapyrusViewStyle;
/**
* The utils methods corresponding to the qualified name calculation for the
@@ -47,15 +51,17 @@ public class QualifiedNameUtils {
// Loop until no more parent to calculate qualified name
while (null != parent && !hasNotFoundName) {
- hasNotFoundName = true;
-
- // Get the name feature if existing
- final EStructuralFeature feature = parent.eClass().getEStructuralFeature("name"); //$NON-NLS-1$
- if (null != feature) {
- Object featureValue = parent.eGet(feature);
- if (featureValue instanceof String) {
- result = appendQualifiedName(result, (String) featureValue);
- hasNotFoundName = false;
+ if (parent.eResource().getURI().equals(eObject.eResource().getURI())){
+ hasNotFoundName = true;
+
+ // Get the name feature if existing
+ final EStructuralFeature feature = parent.eClass().getEStructuralFeature("name"); //$NON-NLS-1$
+ if (null != feature) {
+ Object featureValue = parent.eGet(feature);
+ if (featureValue instanceof String) {
+ result = appendQualifiedName(result, (String) featureValue);
+ hasNotFoundName = false;
+ }
}
}
@@ -73,6 +79,40 @@ public class QualifiedNameUtils {
return result.toString();
}
+
+ /**
+ * Get the diagram owner.
+ *
+ * @param diagram
+ * A diagram
+ * @return The diagram owner
+ */
+ public static EObject getOwner(final Diagram diagram) {
+ final PapyrusViewStyle pvs = getPapyrusViewStyle(diagram);
+ if (null != pvs) {
+ final EObject value = pvs.getOwner();
+ if (null != value) {
+ return value;
+ }
+ }
+ return diagram.getElement();
+ }
+
+ /**
+ * Returns the PapyrusViewStyle owned by this diagram (if any)
+ *
+ * @param diagram
+ * @return
+ */
+ @SuppressWarnings("unchecked")
+ public static final PapyrusViewStyle getPapyrusViewStyle(final Diagram diagram) {
+ for (final Style ownedStyle : (List<Style>) diagram.getStyles()) { // Access all styles directly to avoid CSS computation, and use instanceof (Rather than reflexive EMF)
+ if (ownedStyle instanceof PapyrusViewStyle) {
+ return (PapyrusViewStyle) ownedStyle;
+ }
+ }
+ return null;
+ }
/**
* This allows to append a string to the StringBuilder in parameter.

Back to the top