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

Bug 317304

Summary: @Preference Annotation not injected when preference node changed
Product: [Eclipse Project] e4 Reporter: Artur Kronenberg <artur.kronenberg>
Component: UIAssignee: Project Inbox <e4.ui-inbox>
Status: RESOLVED INVALID QA Contact: Oleg Besedin <ob1.eclipse>
Severity: normal    
Priority: P3 CC: artur.kronenberg, ob1.eclipse, pwebster
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:
Attachments:
Description Flags
project to test the @Preference behavior none

Description Artur Kronenberg CLA 2010-06-18 10:39:49 EDT
Created attachment 172223 [details]
project to test the @Preference behavior 

Hi,

it seems like annotation a method with the @Inject and @Preference("key") annotations is not being called when the preference is changed.

Steps to reproduce:

Create a method and annotate it with the @Inject and @Preference annotation

@Inject
	public void preferenceChanged(@Preference("key") final String value) {
		System.out.println(value);
	}

Create code to change the preference later in your program.

Start program ans see if the new preference is being printed. 

I attach an example project to test this behavior.

Kind regards,
Artur
Comment 1 Oleg Besedin CLA 2010-06-18 14:09:37 EDT
We track InstanceScope, not DefaultScope. In the example try this:

Preferences node = new InstanceScope() //DefaultScope()
	.getNode("test.project"); //"org.eclipsecon.e4rover.client");

and it will work. 

To see where the DefaultScope chimes in, you can add a constructor:

	@Inject
	public TestView() {
		Preferences node = new DefaultScope().getNode("test.project");		node.put("key", "2010");
	}
Comment 2 Oleg Besedin CLA 2010-06-18 14:12:59 EDT
Or to use a really modern way to set preferences value:

	@Inject
	public void createControl(final Composite composite, @Preference final IEclipsePreferences node) {
...
		store.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				node.put("key", toStoreText.getText());
			}
		});

	}