Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 317304 - @Preference Annotation not injected when preference node changed
Summary: @Preference Annotation not injected when preference node changed
Status: RESOLVED INVALID
Alias: None
Product: e4
Classification: Eclipse Project
Component: UI (show other bugs)
Version: unspecified   Edit
Hardware: PC Mac OS X - Carbon (unsup.)
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Oleg Besedin CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-06-18 10:39 EDT by Artur Kronenberg CLA
Modified: 2010-06-18 14:12 EDT (History)
3 users (show)

See Also:


Attachments
project to test the @Preference behavior (11.83 KB, application/zip)
2010-06-18 10:39 EDT, Artur Kronenberg CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
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());
			}
		});

	}