diff options
author | Thomas Schindl | 2011-04-19 20:14:11 +0000 |
---|---|---|
committer | Thomas Schindl | 2011-04-19 20:14:11 +0000 |
commit | 6c84dff301d92f5ab2187bbad77633a5c75096c2 (patch) | |
tree | 13d636479ffadeb7864fb04674a879fd82981514 | |
parent | c2d33b6193f69dafb8abfd59a1faafcf48060316 (diff) | |
download | org.eclipse.e4.tools-6c84dff301d92f5ab2187bbad77633a5c75096c2.tar.gz org.eclipse.e4.tools-6c84dff301d92f5ab2187bbad77633a5c75096c2.tar.xz org.eclipse.e4.tools-6c84dff301d92f5ab2187bbad77633a5c75096c2.zip |
Bug 337223 - [Model] Missing NLS-Support for various Model-Attributesv20110419-1630
2 files changed, 53 insertions, 26 deletions
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/ControlFactory.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/ControlFactory.java index 6e678f3a..1218ca93 100644 --- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/ControlFactory.java +++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/ControlFactory.java @@ -10,6 +10,7 @@ ******************************************************************************/ package org.eclipse.e4.tools.emf.ui.internal.common.component; +import java.lang.reflect.InvocationTargetException; import java.util.Arrays; import java.util.List; import java.util.Map.Entry; @@ -49,6 +50,7 @@ import org.eclipse.emf.databinding.edit.EMFEditProperties; import org.eclipse.emf.databinding.edit.IEMFEditListProperty; import org.eclipse.emf.databinding.edit.IEMFEditValueProperty; import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EOperation; import org.eclipse.emf.ecore.EStructuralFeature; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.edit.command.AddCommand; @@ -713,17 +715,29 @@ public class ControlFactory { } public static String getLocalizedLabel(ProjectOSGiTranslationProvider translationProvider, MUILabel element, String locale) { + return getLocalizedValue(translationProvider, (MApplicationElement) element, UiPackageImpl.Literals.UI_LABEL__LABEL, UiPackageImpl.Literals.UI_LABEL___GET_LOCALIZED_LABEL, locale); + } + + public static String getLocalizedValue(ProjectOSGiTranslationProvider translationProvider, MApplicationElement element, EStructuralFeature feature, EOperation operation, String locale) { + EObject eo = (EObject) element; if (translationProvider == null) { - if (element.getLocalizedLabel() != null && element.getLocalizedLabel().trim().length() > 0) { - return element.getLocalizedLabel(); + try { + String value = (String) eo.eInvoke(operation, null); + if (value != null && value.trim().length() > 0) { + return value; + } + } catch (InvocationTargetException e) { + // TODO Auto-generated catch block + e.printStackTrace(); } } - if (element.getLabel() != null && element.getLabel().trim().length() > 0) { - String label = element.getLabel(); - return tr(translationProvider, locale, label); + String value = (String) eo.eGet(feature); + if (value != null && value.trim().length() > 0) { + return tr(translationProvider, locale, value); } return null; + } public static String tr(ProjectOSGiTranslationProvider translationProvider, String locale, String label) { diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/properties/ExternalizeStringHandler.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/properties/ExternalizeStringHandler.java index e6525b7f..1ea30b80 100644 --- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/properties/ExternalizeStringHandler.java +++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/properties/ExternalizeStringHandler.java @@ -20,11 +20,14 @@ import org.eclipse.e4.tools.emf.ui.internal.Messages; import org.eclipse.e4.tools.emf.ui.internal.ResourceProvider; import org.eclipse.e4.tools.services.IResourcePool; import org.eclipse.e4.tools.services.Translation; -import org.eclipse.e4.ui.model.application.ui.MUILabel; +import org.eclipse.e4.ui.model.application.commands.impl.CommandsPackageImpl; +import org.eclipse.e4.ui.model.application.descriptor.basic.impl.BasicPackageImpl; import org.eclipse.e4.ui.model.application.ui.impl.UiPackageImpl; +import org.eclipse.e4.ui.model.application.ui.menu.impl.MenuPackageImpl; import org.eclipse.e4.ui.services.IServiceConstants; import org.eclipse.emf.common.command.Command; import org.eclipse.emf.common.util.TreeIterator; +import org.eclipse.emf.ecore.EAttribute; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EStructuralFeature; import org.eclipse.emf.ecore.util.EcoreUtil; @@ -76,7 +79,9 @@ public class ExternalizeStringHandler { Composite container = (Composite) super.createDialogArea(parent); Table t = new Table(container, SWT.BORDER | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL | SWT.CHECK); - t.setLayoutData(new GridData(GridData.FILL_BOTH)); + GridData gd = new GridData(GridData.FILL_BOTH); + gd.heightHint = t.getItemHeight() * 15; + t.setLayoutData(gd); t.setHeaderVisible(true); t.setLinesVisible(true); @@ -147,16 +152,27 @@ public class ExternalizeStringHandler { List<String> ids = new ArrayList<String>(); + List<EStructuralFeature> translatedFeatures = new ArrayList<EStructuralFeature>(); + translatedFeatures.add(UiPackageImpl.Literals.UI_LABEL__LABEL); + translatedFeatures.add(UiPackageImpl.Literals.UI_LABEL__TOOLTIP); + translatedFeatures.add(CommandsPackageImpl.Literals.COMMAND__COMMAND_NAME); + translatedFeatures.add(CommandsPackageImpl.Literals.COMMAND__DESCRIPTION); + translatedFeatures.add(CommandsPackageImpl.Literals.CATEGORY__NAME); + translatedFeatures.add(CommandsPackageImpl.Literals.CATEGORY__DESCRIPTION); + translatedFeatures.add(org.eclipse.e4.ui.model.application.ui.basic.impl.BasicPackageImpl.Literals.PART__DESCRIPTION); + translatedFeatures.add(BasicPackageImpl.Literals.PART_DESCRIPTOR__DESCRIPTION); + translatedFeatures.add(MenuPackageImpl.Literals.MENU_ELEMENT__MNEMONICS); + while (it.hasNext()) { EObject o = it.next(); - if (o instanceof MUILabel) { - MUILabel l = (MUILabel) o; - if (l.getLabel() != null && l.getLabel().startsWith("%")) { //$NON-NLS-1$ - ids.add(l.getLabel()); - } - if (l.getTooltip() != null && l.getTooltip().startsWith("%")) { //$NON-NLS-1$ - ids.add(l.getTooltip()); + for (EAttribute a : o.eClass().getEAllAttributes()) { + if (translatedFeatures.contains(a)) { + String v = (String) o.eGet(a); + + if (v != null && v.startsWith("%")) { //$NON-NLS-1$ + ids.add(v); + } } } } @@ -169,18 +185,15 @@ public class ExternalizeStringHandler { it = EcoreUtil.getAllContents(list); while (it.hasNext()) { EObject o = it.next(); - if (o instanceof MUILabel) { - MUILabel l = (MUILabel) o; - if (l.getLabel() != null && l.getLabel().trim().length() != 0 && !l.getLabel().startsWith("%")) { //$NON-NLS-1$ - String id = findId(ids, o.eClass().getName().toLowerCase() + ".label"); //$NON-NLS-1$ - entries.add(new Entry(o, UiPackageImpl.Literals.UI_LABEL__LABEL, id, l.getLabel())); - ids.add(id); - } - if (l.getTooltip() != null && l.getTooltip().trim().length() != 0 && !l.getTooltip().startsWith("%")) { //$NON-NLS-1$ - String id = findId(ids, o.eClass().getName().toLowerCase() + ".tooltip"); //$NON-NLS-1$ - entries.add(new Entry(o, UiPackageImpl.Literals.UI_LABEL__TOOLTIP, id, l.getTooltip())); - ids.add(id); + for (EAttribute a : o.eClass().getEAllAttributes()) { + if (translatedFeatures.contains(a)) { + String v = (String) o.eGet(a); + if (v != null && v.trim().length() > 0 && !v.startsWith("%")) { //$NON-NLS-1$ + String id = findId(ids, o.eClass().getName().toLowerCase() + "." + a.getName().toLowerCase()); //$NON-NLS-1$ + entries.add(new Entry(o, a, id, v)); + ids.add(id); + } } } } @@ -206,7 +219,7 @@ public class ExternalizeStringHandler { try { IFile f = getBasePropertyFile(); - StringBuilder b = new StringBuilder(System.getProperty("line.separator")); + StringBuilder b = new StringBuilder(System.getProperty("line.separator")); //$NON-NLS-1$ for (Object o : els) { Entry e = (Entry) o; b.append(e.key + " = " + e.value + System.getProperty("line.separator")); //$NON-NLS-1$//$NON-NLS-2$ |