Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 354663

Summary: Cannot have an instance based user supplied message class for i18n.
Product: z_Archived Reporter: David Marsh <dmarsh26>
Component: WindowBuilderAssignee: Konstantin Scheglov <Konstantin.Scheglov>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: clayberg
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
Report for when messages class is non static and generates exception stacktrace.
none
Example that demonstrates that even with annotation cannot display text, get <dynamic> instead. none

Description David Marsh CLA 2011-08-12 14:52:30 EDT
Build Identifier: 20110218-0911

WindowBuilder expects a static class with static entries for i18n. It should be possible to use an arbitrary class for i18n and just pick the resource bundles up with the @wbp.nls.resourceBundle annotation or similar should allow the code to work with any approach.

Reproducible: Always

Steps to Reproduce:
1. Create a custom messages class that wraps a resource bundle, the class should not be static / singleton. It should not have static getString().
2. Inject an instance of the messages class into your view / dialog.
3. Use view / dialog class to get messages, firstly without certain static fields in class WindowBuilder editor will not launch at all, it will crash with a stacktrace. If you make fields instance based and ensure some static fields exist, WindowBuilder will show <dynamic> instead of the correct string. Only if whole class is static does it work. This is not great for IOC and TDD. It also does not make it easy to inject a locale specific class at runtime.
Comment 1 David Marsh CLA 2011-08-12 14:53:58 EDT
Created attachment 201421 [details]
Report for when messages class is non static and generates exception stacktrace.
Comment 2 David Marsh CLA 2011-08-12 15:43:42 EDT
Appears stacktrace is an application issue, please ignore !
Comment 3 David Marsh CLA 2011-08-12 15:56:53 EDT
Created attachment 201429 [details]
Example that demonstrates that even with annotation cannot display text, get <dynamic> instead.
Comment 4 David Marsh CLA 2011-08-12 15:58:52 EDT
Please ignore first bug report zip file, example does not allow reproduce.

There is still the <dynamic> issue though.
Comment 5 Konstantin Scheglov CLA 2011-08-15 13:27:11 EDT
If you want to render this, your should tell WindowBuilder how to create value for "messages" contructor argument.
Add following JavaDoc to the TestDialog constructor.

    /**
     * @wbp.eval.method.parameter messages new packageB.Messages()
     */
(just 'new Messages()' also works) 

I think that our support for (old) standard Eclipse NLS pattern works as expected.

You want support for another NLS pattern.
That is OK, we support contributing NLS patterns from other plugins and binding them to the toolkits.

  See how other NLS patterns are implemented and add support for yours.
  Here are two pieces from plugin.xml files of Core and Swing plugins.
  First contributes NLS patterns and second binds it to the Swing toolkit.

	<!-- ======================================================== -->
	<!-- NLS sources -->
	<!-- ======================================================== -->
	<extension point="org.eclipse.wb.core.nlsSources">
		<description id="org.eclipse.wb.core.nls.bundle.eclipse.old.EclipseSource"
			source="org.eclipse.wb.internal.core.nls.bundle.eclipse.old.EclipseSource"
			composite="org.eclipse.wb.internal.core.nls.bundle.eclipse.old.EclipseSourceNewComposite"/>
	</extension>

	<extension point="org.eclipse.wb.core.nlsSources">
		<binding toolkit="org.eclipse.wb.swing"
			description="org.eclipse.wb.core.nls.bundle.eclipse.old.EclipseSource"/>
	</extension>
Comment 6 Eric Clayberg CLA 2011-08-16 00:04:53 EDT
The key point here is that WB is working as expected. It supports multiple different popular i18n patterns. It is not possible to support arbitrary, custom patterns however without additional information. WB provides an extension point which can be used to teach the tool about the custom pattern you want to use.