Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » efxclipse Deselection service???
efxclipse Deselection service??? [message #1710994] Mon, 12 October 2015 08:19 Go to next message
Ali Karimi is currently offline Ali KarimiFriend
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 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6566
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
Re: efxclipse Deselection service??? [message #1711149 is a reply to message #1711116] Tue, 13 October 2015 13:09 Go to previous message
Ali Karimi is currently offline Ali KarimiFriend
Messages: 36
Registered: October 2015
Member
Hey,

thank you for your help and of course you are right, next time i will post on the correct forum. However for now lets continue here.

I made a small demo app, demonstrating what i was talking about.
Steps to get the demo up and running (i am using Eclipse Mars and jdk1.8_60):

  1. Download zip
  2. Import Existing projects
  3. Set target platform from the directory deselection.test.app/tp
  4. Run product file from deselection.test.app.product
  5. Select FirstModelA -> First Details will be filled with content
  6. Select SecondModelA -> Second Details will be filled but First Details Id is not cleared
  7. Now click in the background of the FistModelList view - First Detail again are filled but without any selection


Is this correct behavior? I guess no. But maybe i am missing something. When clicking in the background of a ListView there should no selection event be fired, but there is one with the previously selected item as event target.




Previous Topic:disable DND temporarily
Next Topic:Mixing Eclipse DI with Google Guice?
Goto Forum:
  


Current Time: Sat Sep 19 16:31:43 GMT 2020

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

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

Back to the top