Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 94301 Details for
Bug 222309
Review of the metadata translation support
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Patch for UI query and dialog to get translated IU properties.
222309Patch1.txt (text/plain), 12.19 KB, created by
Dave Stevenson
on 2008-03-31 20:05:51 EDT
(
hide
)
Description:
Patch for UI query and dialog to get translated IU properties.
Filename:
MIME Type:
Creator:
Dave Stevenson
Created:
2008-03-31 20:05:51 EDT
Size:
12.19 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.equinox.p2.metadata.generator >Index: src/org/eclipse/equinox/internal/provisional/p2/metadata/generator/MetadataGeneratorHelper.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.equinox/p2/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/internal/provisional/p2/metadata/generator/MetadataGeneratorHelper.java,v >retrieving revision 1.39 >diff -u -r1.39 MetadataGeneratorHelper.java >--- src/org/eclipse/equinox/internal/provisional/p2/metadata/generator/MetadataGeneratorHelper.java 28 Mar 2008 14:37:14 -0000 1.39 >+++ src/org/eclipse/equinox/internal/provisional/p2/metadata/generator/MetadataGeneratorHelper.java 31 Mar 2008 23:44:09 -0000 >@@ -69,6 +69,7 @@ > * of strings from a specified IU in a specified locale > * @see RequiredCapability#getNamespace() > * @see ProvidedCapability#getNamespace() >+ * TODO: this should be in API, probably in IInstallableUnit > */ > public static final String NAMESPACE_IU_LOCALIZATION = "org.eclipse.equinox.p2.localization"; //$NON-NLS-1$ > >@@ -293,37 +294,6 @@ > return MetadataFactory.createInstallableUnit(iu); > } > >- /* >- * @param bd >- * @param manifestLocalizations map from locale to translated properties >- * @return installableUnitFragment >- */ >- // private static IInstallableUnitFragment createLocalizationFragmentOfBundle(BundleDescription bd, Map manifestLocalizations) { >- // InstallableUnitFragmentDescription fragment = new MetadataFactory.InstallableUnitFragmentDescription(); >- // String fragmentId = makeBundleLocalizationFragmentId(bd.getSymbolicName()); >- // fragment.setId(fragmentId); >- // fragment.setVersion(bd.getVersion()); >- // >- // RequiredCapability[] hostReqs = new RequiredCapability[] {MetadataFactory.createRequiredCapability(NAMESPACE_ECLIPSE_TYPE, bd.getSymbolicName(), new VersionRange(bd.getVersion(), true, bd.getVersion(), true), null, false, false, false)}; >- // fragment.setHost(hostReqs); >- // >- // fragment.setSingleton(true); >- // >- // ArrayList providedCapabilities = new ArrayList(manifestLocalizations.size()); >- // for (Iterator iter = manifestLocalizations.keySet().iterator(); iter.hasNext();) { >- // Locale locale = (Locale) iter.next(); >- // Properties translatedStrings = (Properties) manifestLocalizations.get(locale); >- // Enumeration propertyKeys = translatedStrings.propertyNames(); >- // while (propertyKeys.hasMoreElements()) { >- // String nextKey = (String) propertyKeys.nextElement(); >- // fragment.setProperty(locale.toString() + '.' + nextKey, translatedStrings.getProperty(nextKey)); >- // } >- // providedCapabilities.add(makeTranslationCapability(bd.getSymbolicName(), locale)); >- // } >- // fragment.setCapabilities((ProvidedCapability[]) providedCapabilities.toArray(new ProvidedCapability[providedCapabilities.size()])); >- // >- // return MetadataFactory.createInstallableUnitFragment(fragment); >- // } > public static void createHostLocalizationFragment(IInstallableUnit bundleIU, BundleDescription bd, String hostId, String[] hostBundleManifestValues, Set localizationIUs) { > Map hostLocalizations = getHostLocalizations(new File(bd.getLocation()), hostBundleManifestValues); > if (hostLocalizations != null) { >#P org.eclipse.equinox.p2.ui >Index: src/org/eclipse/equinox/internal/provisional/p2/ui/query/IUPropertyUtils.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.equinox/p2/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/query/IUPropertyUtils.java,v >retrieving revision 1.2 >diff -u -r1.2 IUPropertyUtils.java >--- src/org/eclipse/equinox/internal/provisional/p2/ui/query/IUPropertyUtils.java 28 Mar 2008 00:05:30 -0000 1.2 >+++ src/org/eclipse/equinox/internal/provisional/p2/ui/query/IUPropertyUtils.java 31 Mar 2008 23:44:10 -0000 >@@ -13,39 +13,83 @@ > import java.util.*; > import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; > import org.eclipse.equinox.internal.p2.ui.ProvUIActivator; >-import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit; >-import org.eclipse.equinox.internal.provisional.p2.metadata.query.InstallableUnitQuery; >+import org.eclipse.equinox.internal.provisional.p2.metadata.*; >+import org.eclipse.equinox.internal.provisional.p2.metadata.query.IUPropertyQuery; > import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager; > import org.eclipse.equinox.internal.provisional.p2.query.Collector; > > public class IUPropertyUtils { > >+ // TODO: these constants should come from API, eg. IInstallableUnit or ??? > static final Locale DEFAULT_LOCALE = new Locale("df", "LT"); //$NON-NLS-1$//$NON-NLS-2$ >+ static final String NAMESPACE_IU_LOCALIZATION = "org.eclipse.equinox.p2.localization"; //$NON-NLS-1$ > > public static String getIUProperty(IInstallableUnit iu, String propertyKey, Locale locale) { > String value = iu.getProperty(propertyKey); > if (value == null || value.length() <= 1 || value.charAt(0) != '%') > return value; > // else have a localizable property >- String actualKey = value.substring(1); >- String localizationBundles[] = buildLocalizationVariants(iu, locale); >+ final String actualKey = value.substring(1); // Strip off the % >+ final List locales = buildLocaleVariants(locale); >+ final IInstallableUnit theUnit = iu; >+ >+ Collector hostLocalizationCollector = new Collector() { >+ public boolean accept(Object object) { >+ boolean haveHost = false; >+ boolean haveLocale = false; >+ if (object instanceof IInstallableUnitFragment) { >+ IInstallableUnitFragment fragment = (IInstallableUnitFragment) object; >+ RequiredCapability[] hosts = fragment.getHost(); >+ for (int i = 0; i < hosts.length; i++) { >+ RequiredCapability nextHost = hosts[i]; >+ if (IInstallableUnit.NAMESPACE_IU_ID.equals(nextHost.getNamespace()) && // >+ theUnit.getId().equals(nextHost.getName()) && // >+ nextHost.getRange() != null && // >+ nextHost.getRange().isIncluded(theUnit.getVersion())) { >+ haveHost = true; >+ break; >+ } >+ } >+ >+ if (haveHost) { >+ ProvidedCapability[] provides = fragment.getProvidedCapabilities(); >+ for (int j = 0; j < provides.length && !haveLocale; j++) { >+ ProvidedCapability nextProvide = provides[j]; >+ if (NAMESPACE_IU_LOCALIZATION.equals(nextProvide.getNamespace())) { >+ String providedLocale = nextProvide.getName(); >+ if (providedLocale != null) { >+ for (Iterator iter = locales.iterator(); iter.hasNext();) { >+ if (providedLocale.equals(iter.next())) { >+ haveLocale = true; >+ break; >+ } >+ } >+ } >+ } >+ } >+ } >+ } >+ return (haveHost && haveLocale ? super.accept(object) : false); >+ } >+ }; > > IMetadataRepositoryManager repoMgr = (IMetadataRepositoryManager) ServiceHelper.getService(ProvUIActivator.getContext(), IMetadataRepositoryManager.class.getName()); >- >- for (int i = 0; i < localizationBundles.length; i++) { >- InstallableUnitQuery iuQuery = new InstallableUnitQuery(localizationBundles[i]); >- Collector collected = repoMgr.query(iuQuery, new Collector(), null); >- if (!collected.isEmpty()) { >- for (Iterator iter = collected.iterator(); iter.hasNext();) { >- IInstallableUnit localizationIU = (IInstallableUnit) iter.next(); >- String translation = localizationIU.getProperty(actualKey); >+ IUPropertyQuery iuQuery = new IUPropertyQuery(IInstallableUnit.PROP_TYPE_FRAGMENT, "true"); //$NON-NLS-1$ >+ Collector collected = repoMgr.query(iuQuery, hostLocalizationCollector, null); >+ if (!collected.isEmpty()) { >+ String translation = null; >+ for (Iterator iter = collected.iterator(); iter.hasNext() && translation == null;) { >+ IInstallableUnit localizationIU = (IInstallableUnit) iter.next(); >+ for (Iterator jter = locales.iterator(); jter.hasNext();) { >+ String localeKey = makeLocalizedKey(actualKey, (String) jter.next()); >+ translation = localizationIU.getProperty(localeKey); > if (translation != null) > return translation; > } > } > } > >- String defaultKey = DEFAULT_LOCALE.toString() + '.' + actualKey; >+ String defaultKey = makeLocalizedKey(actualKey, DEFAULT_LOCALE.toString()); > String defaultValue = iu.getProperty(defaultKey); > if (defaultValue != null) > return defaultValue; >@@ -53,25 +97,26 @@ > return value; > } > >- private static final String TRANSLATED_PROPERTIES_NAME = "_translated_properties"; //$NON-NLS-1$ >- > /** > */ >- private static String[] buildLocalizationVariants(IInstallableUnit iu, Locale locale) { >- String id = iu.getId().toString(); >+ private static List buildLocaleVariants(Locale locale) { > String nl = locale.toString(); > ArrayList result = new ArrayList(4); > int lastSeparator; > while (true) { >- result.add(id + '_' + nl + TRANSLATED_PROPERTIES_NAME); >+ result.add(nl); > lastSeparator = nl.lastIndexOf('_'); > if (lastSeparator == -1) > break; > nl = nl.substring(0, lastSeparator); > } >- // Add the empty suffix last (most general) >- result.add(id + TRANSLATED_PROPERTIES_NAME); >- return (String[]) result.toArray(new String[result.size()]); >+ // Add the default locale (most general) >+ result.add(DEFAULT_LOCALE); >+ return result; >+ } >+ >+ private static String makeLocalizedKey(String actualKey, String localeImage) { >+ return localeImage + '.' + actualKey; > } > > } >Index: src/org/eclipse/equinox/internal/provisional/p2/ui/dialogs/IUGeneralInfoPropertyPage.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.equinox/p2/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/dialogs/IUGeneralInfoPropertyPage.java,v >retrieving revision 1.5 >diff -u -r1.5 IUGeneralInfoPropertyPage.java >--- src/org/eclipse/equinox/internal/provisional/p2/ui/dialogs/IUGeneralInfoPropertyPage.java 29 Feb 2008 04:36:44 -0000 1.5 >+++ src/org/eclipse/equinox/internal/provisional/p2/ui/dialogs/IUGeneralInfoPropertyPage.java 31 Mar 2008 23:44:10 -0000 >@@ -54,18 +54,18 @@ > layout.marginHeight = 0; > composite.setLayout(layout); > composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); >- //addField(composite, ProvUIMessages.IUGeneralInfoPropertyPage_NameLabel, iu.getProperty(IInstallableUnit.PROP_NAME)); >- addField(composite, ProvUIMessages.IUGeneralInfoPropertyPage_NameLabel, IUPropertyUtils.getIUProperty(iu, IInstallableUnit.PROP_NAME, Locale.getDefault())); >+ Locale currentLocale = Locale.getDefault(); >+ addField(composite, ProvUIMessages.IUGeneralInfoPropertyPage_NameLabel, IUPropertyUtils.getIUProperty(iu, IInstallableUnit.PROP_NAME, currentLocale)); > addField(composite, ProvUIMessages.IUGeneralInfoPropertyPage_IdentifierLabel, iu.getId()); > addField(composite, ProvUIMessages.IUGeneralInfoPropertyPage_VersionLabel, iu.getVersion().toString()); >- //addField(composite, ProvUIMessages.IUGeneralInfoPropertyPage_ProviderLabel, iu.getProperty(IInstallableUnit.PROP_PROVIDER)); >- addField(composite, ProvUIMessages.IUGeneralInfoPropertyPage_ProviderLabel, IUPropertyUtils.getIUProperty(iu, IInstallableUnit.PROP_PROVIDER, Locale.getDefault())); >- addField(composite, ProvUIMessages.IUGeneralInfoPropertyPage_ContactLabel, iu.getProperty(IInstallableUnit.PROP_CONTACT)); >+ addField(composite, ProvUIMessages.IUGeneralInfoPropertyPage_ProviderLabel, IUPropertyUtils.getIUProperty(iu, IInstallableUnit.PROP_PROVIDER, currentLocale)); >+ addField(composite, ProvUIMessages.IUGeneralInfoPropertyPage_ContactLabel, IUPropertyUtils.getIUProperty(iu, IInstallableUnit.PROP_CONTACT, currentLocale)); > > } > > private void createDescriptionSection(Composite parent, IInstallableUnit iu) { >- String description = iu.getProperty(IInstallableUnit.PROP_DESCRIPTION); >+ Locale currentLocale = Locale.getDefault(); >+ String description = IUPropertyUtils.getIUProperty(iu, IInstallableUnit.PROP_DESCRIPTION, currentLocale); > if (description != null && description.length() > 0) { > Group group = new Group(parent, SWT.NONE); > group.setText(ProvUIMessages.IUGeneralInfoPropertyPage_DescriptionLabel);
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 222309
:
93829
| 94301 |
99221
|
99406
|
100028
|
100281