@ContextValue problem [message #1771526] |
Sat, 26 August 2017 18:01 |
Marcelo Ruiz Messages: 80 Registered: April 2017 |
Member |
|
|
Hi Community,
I am having some trouble getting notified of context value updates with @ContextValue. I followed the example posted here: https://wiki.eclipse.org/Efxclipse/Runtime/Recipes#Publishing_to_the_IEclipseContext and I am able to receive only 2 events: the first one is the 'null' value when the property is created and the second one is the first modification to that property. Subsequent modifications are not received. As far as I understand, the use of @ContextValue creates the slot in the IEclipseContext and sets the value as modifiable, preventing the user to declare the dependency to the IEclipseContext. Shouldn't I be notified of changes all the time?
I created the variable in the Perspective where the 2 Parts that need to communicate reside (editing the fragment.e4xmi file and adding the variable name under 'Variables').
The code that publishes changes in the context looks like the following:
@Inject
@ContextValue(value = ContextKeys.SELECTED_SUPPLIERS)
private ContextBoundValue<List<? extends Supplier>> selectedSuppliersCtxValue;
private Subscription subscription;
@PostConstruct
publishToContext() {
subscription = FXObservableUtil.onChange(
model.selectedSuppliersProperty(),
new ListChangeListener<Supplier>() {
@Override
public void onChanged(Change<? extends Supplier> c) {
System.err.println("publishing to context: " + c.getList().toString());
selectedSuppliersCtxValue.publish(c.getList());;
}
});
}
@PreDestroy
public void cleanUpSubscription() {
subscription.dispose();
}
In the receiving end I have the following:
@Inject
@Optional
public void handleSelectedSuppliersContextUpdate(
@ContextValue(value = ContextKeys.SELECTED_SUPPLIERS)
Property<List<? extends Supplier>> selectedSuppliersProperty) {
System.err.println("receiving from context: " + selectedSuppliersProperty.toString());
}
And when I run the program and trigger changes in the model.selectedSuppliersProperty() by manipulating the UI (selecting a different values in a ListView), I get the following output:
receiving from context: ObjectProperty [value: null]
publishing to context: ListProperty [value: [com.example.Supplier@66d116d3]]
receiving from context: ObjectProperty [value: ListProperty [value: [com.example.Supplier@66d116d3]]]
publishing to context: ListProperty [value: []]
publishing to context: ListProperty [value: [com.example.Supplier@927af95]]
publishing to context: ListProperty [value: []]
publishing to context: ListProperty [value: [com.example.Supplier@28d1f4ba]]
So, the first two notifications are fine, but I do not receive anything else afterwards. What is wrong with my code?
As a side note, I found that it is really hard to debug the application when the program being debugged is a graphic application (with a displayed window). I can only press the Function keys to control the debugger, but I am unable to interact with the mouse at all in Eclipse. Is this normal? Is there anything I could do to prevent this?
Thanks!
|
|
|
|
Re: @ContextValue problem [message #1771530 is a reply to message #1771528] |
Sat, 26 August 2017 22:55 |
Marcelo Ruiz Messages: 80 Registered: April 2017 |
Member |
|
|
Thanks for your answer Tom!
For some reason I get a NullPointerException because I receive null in the first call to handleSelectedSuppliersContextUpdate(). Shouldn't that be avoided by the use use of @Optional?
Also, to my surprise, the behavior did not change. Using your code (taking out the toString() method call)the result I get is exactly the same:
receiving from context: null
publishing to context: ListProperty [value: [com.example.Supplier@2a61cc4b]]
receiving from context: ListProperty [value: [com.example.Supplier@2a61cc4b]]
publishing to context: ListProperty [value: []]
publishing to context: ListProperty [value: [com.example.Supplier@6410c383]]
publishing to context: ListProperty [value: []]
publishing to context: ListProperty [value: [com.example.Supplier@2a61cc4b]]
Should I be looking at a different cause for this problem? I am positive the value for the key is typed correctly in my fragment.e4xmi file...
[Updated on: Sat, 26 August 2017 23:10] Report message to a moderator
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04542 seconds