efxclipse Deselection service??? [message #1710994] |
Mon, 12 October 2015 08:19 |
Ali Karimi Messages: 36 Registered: October 2015 |
Member |
|
|
Hey there,
i am pretty new to eclipse 4 so please bare with me, if i am missing an easy solution to my problem.
In short: I am using Eclipse DI to track the current ACTIVE_SELECTION inside my application. What i want to know is, is there any best practice way to get an event of DESELECTION?
Here my scenario:
I have a ListView and DetailsView. When the user selects an item in the ListView, i am using the ESelectionService to set the selection in the active context. My DetailsView has two textfields and is controlled by a DetailsViewController which responds to changes of the active selection using DI (e.g. setSelection(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) ... ).
The DetailsViewController conforms to the master-detail pattern by using a WritableValue as master and data binding between my model and the ui parts.
Now when the user deselects the ListView by clicking on any other part of my application i would like to clear the DetailsView. How to do this in an elegant way? Of cause i can fire some kind of custom event and call clear on the two textfields of my DetailsView but this does not seem to be the most elegant way?
One thing to mention is that may application has multiple models where each can be set to be the active_selection. Each model has its own ListView and DetailsView. When selecting one model i would like to clear the currently selected model, by resetting its ListView and DetailsView. At first glance, i though setting master.setValue(null) would be the right approach, but this does not clear the MODEL.FIELD_ID since it is a long value binding? (see the following code snippets for more information on this).
Here some details about my implementation.
Model class
public class Model {
public static final String FIELD_ID = "id";
public static final String FIELD_NAME = "name";
protected long id = -1;
protected String name = "Unknown";
public Model(final long id, final String name) {
this.id = id;
this.name = name;
}
@Override
public String getName() {
return name;
}
@Override
public long getId() {
return id;
}
}
DetailsViewController class
@SuppressWarnings("restriction")
public class ModelSystemDetailPartController implements Initializable {
private final IObservableValue master = new WritableValue();
@FXML
GridPane modelsystemroot;
@FXML
TextField identity;
@FXML
TextField name;
@Override
public void initialize(final URL location, final ResourceBundle resources) {
final IJFXBeanValueProperty uiTextProperty = JFXBeanProperties.value("text");
final DataBindingContext ctx = new DataBindingContext();
final IObservableValue oIdentity = uiTextProperty.observe(identity);
final IObservableValue oFieldId = BeanProperties.value(Model.FIELD_ID).observeDetail(master);
final UpdateValueStrategy modelTotarget = new UpdateValueStrategy();
modelTotarget.setConverter(NumberToStringConverter.fromLong(true));
ctx.bindValue(oIdentity, oFieldId, new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), modelTotarget);
final IObservableValue oName = uiTextProperty.observe(name);
final IObservableValue oFieldName = BeanProperties.value(Model.FIELD_NAME).observeDetail(master);
ctx.bindValue(oName, oFieldName, new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), null);
}
@Inject
public void setModel(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) final Model modelSystem) {
if (modelSystem != null) {
master.setValue(modelSystem);
}
} else {
// although there is a binding, this does not clear the identity textfield. This textfield is bind to the Model.FIELD_ID. Is this releated to a binding long (model) to String (textfield in ui) ???
master.setValue(null);
// This code does not seems to be the correct way
// if (identity != null && name != null) {
// if (!identity.getText().isEmpty() && !name.getText().isEmpty()) {
// identity.clear();
// name.clear();
// }
// }
}
}
}
Thanks in advance
|
|
|
Re: efxclipse Deselection service??? [message #1711116 is a reply to message #1710994] |
Tue, 13 October 2015 07:58 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
a) Questions on e(fx)clipse are probably better asked at e(fx)clipse
forum
b) Setting master to null is the correct way and if the ID-Field is not
cleared this looks like a bug (maybe in the javafx-properties)
Try to create a simple test-case (*) I can use to reproduce und file a
bug against https://bugs.eclipse.org/bugs/enter_bug.cgi?product=Efxclipse
Tom
(*)With simple I mean it should only hold a JavaFX-TextField, a
master-value and the detail binding.
On 12.10.15 15:30, Ali Karimi wrote:
> Hey there,
>
> i am pretty new to eclipse 4 so please bare with me, if i am missing an
> easy solution to my problem.
>
> In short: I am using Eclipse DI to track the current ACTIVE_SELECTION
> inside my application. What i want to know is, is there any best
> practice way to get an event of DESELECTION?
>
> Here my scenario: I have a ListView and DetailsView. When the user
> selects an item in the ListView, i am using the ESelectionService to set
> the selection in the active context. My DetailsView has two textfields
> and is controlled by a DetailsViewController which responds to changes
> of the active selection using DI (e.g. setSelection(@Optional
> @Named(IServiceConstants.ACTIVE_SELECTION) ... ).
> The DetailsViewController conforms to the master-detail pattern by using
> a WritableValue as master and data binding between my model and the ui
> parts.
> Now when the user deselects the ListView by clicking on any other part
> of my application i would like to clear the DetailsView. How to do this
> in an elegant way? Of cause i can fire some kind of custom event and
> call clear on the two textfields of my DetailsView but this does not
> seem to be the most elegant way?
> One thing to mention is that may application has multiple models where
> each can be set to be the active_selection. Each model has its own
> ListView and DetailsView. When selecting one model i would like to clear
> the currently selected model, by resetting its ListView and DetailsView.
> At first glance, i though setting master.setValue(null) would be the
> right approach, but this does not clear the MODEL.FIELD_ID since it is a
> long value binding? (see the following code snippets for more
> information on this).
>
> Here some details about my implementation.
>
> Model class
>
> public class Model {
> public static final String FIELD_ID = "id";
> public static final String FIELD_NAME = "name";
> protected long id = -1;
> protected String name = "Unknown";
> public Model(final long id, final String name) {
> this.id = id;
> this.name = name;
> }
>
> @Override
> public String getName() {
> return name;
> }
>
> @Override
> public long getId() {
> return id;
> }
> }
>
>
> DetailsViewController class
>
> @SuppressWarnings("restriction")
> public class ModelSystemDetailPartController implements Initializable {
> private final IObservableValue master = new WritableValue();
>
> @FXML
> GridPane modelsystemroot;
>
> @FXML
> TextField identity;
>
> @FXML
> TextField name;
>
> @Override
> public void initialize(final URL location, final ResourceBundle
> resources) {
> final IJFXBeanValueProperty uiTextProperty =
> JFXBeanProperties.value("text");
> final DataBindingContext ctx = new DataBindingContext();
>
> final IObservableValue oIdentity = uiTextProperty.observe(identity);
> final IObservableValue oFieldId =
> BeanProperties.value(Model.FIELD_ID).observeDetail(master);
> final UpdateValueStrategy modelTotarget = new UpdateValueStrategy();
> modelTotarget.setConverter(NumberToStringConverter.fromLong(true));
> ctx.bindValue(oIdentity, oFieldId, new
> UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), modelTotarget);
>
> final IObservableValue oName = uiTextProperty.observe(name);
> final IObservableValue oFieldName =
> BeanProperties.value(Model.FIELD_NAME).observeDetail(master);
> ctx.bindValue(oName, oFieldName, new
> UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), null);
> }
>
> @Inject
> public void setModel(@Optional
> @Named(IServiceConstants.ACTIVE_SELECTION) final Model modelSystem) {
> if (modelSystem != null) {
> master.setValue(modelSystem);
> }
> } else {
> // although there is a binding, this does not clear the identity
> textfield. This textfield is bind to the Model.FIELD_ID. Is this
> releated to a binding long (model) to String (textfield in ui) ???
> master.setValue(null);
> // This code does not seems to be the correct way
> // if (identity != null && name != null) {
> // if (!identity.getText().isEmpty() &&
> !name.getText().isEmpty()) {
> // identity.clear();
> // name.clear();
> // }
> // }
> }
> }
> }
>
>
>
> Thanks in advance
|
|
|
|
Powered by
FUDForum. Page generated in 0.02857 seconds