Hi
I'm am playing with @ContextValue following the recipe here:
https://wiki.eclipse.org/Efxclipse/Runtime/Recipes#Injected_value_as_an_observable
My goal is to have a property in the application or perspective scope to keep track of a currently selected element. In simplest terms: There is a master part where you can select a HistoryEvent and a detail part where the properties of the selected element should be displayed.
The setup of the master part looks like this:
@PostConstruct
void postContruct(BorderPane parent, @ContextValue("selection.HistoryEvent") Property<HistoryEvent> selectedEvent) {
TableView<HistoryEvent> table = createTableView();
controlsPane.setCenter(parent);
selectedEvent.bind(table.getSelectionModel().selectedItemProperty());
}
This gives me an exception during creation:
Caused by: java.lang.RuntimeException: A bound value cannot be set.
at javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:141)
at org.eclipse.fx.core.di.context.internal.PropertyAdapterProvider$2.call(PropertyAdapterProvider.java:60)
at org.eclipse.fx.core.di.context.internal.EclipseContextBoundValue.setCurrentValue(EclipseContextBoundValue.java:87)
...
so it seams, as if the newly created Property selectedEvent has already been bound somewhere.
Am I using this wrong? Should it be:
table.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
selectedEvent.setValue(newValue);
});
Or should I create the Property in an AddOn and put it in the context myself?
Greetings
Christoph