Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » e(fx)clipse » Using @ContextValue with JavaFX Properties
Using @ContextValue with JavaFX Properties [message #1387148] Tue, 24 June 2014 12:45 Go to next message
Christoph Keimel is currently offline Christoph KeimelFriend
Messages: 482
Registered: December 2010
Location: Germany
Senior Member
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
Re: Using @ContextValue with JavaFX Properties [message #1391037 is a reply to message #1387148] Mon, 30 June 2014 11:04 Go to previous message
Christoph Keimel is currently offline Christoph KeimelFriend
Messages: 482
Registered: December 2010
Location: Germany
Senior Member
I debugged the issue today. The problem is that the Property created with the PropertyAdapter will be set, when the value changes in the context. This is called right away when the binding is set up. I'm not sure, but it seems like this could be an unnecessary round trip.

Value of Property is set => ContextBoundValue.publish => ContextBoundValue OnValueChange => Property.set()

I created a bug to find a solution for this:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=438541
Previous Topic:EList &lt;-&gt; ListProperty databinding
Next Topic:Sources
Goto Forum:
  


Current Time: Fri Apr 19 17:06:32 GMT 2024

Powered by FUDForum. Page generated in 0.02000 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top