@ContextValue problem [message #1771526] |
Sat, 26 August 2017 14:01  |
Eclipse User |
|
|
|
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!
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02843 seconds