Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » e(fx)clipse » Table column and composition relation binding(Table column and composition relation binding)
Table column and composition relation binding [message #1485429] Mon, 24 November 2014 08:26 Go to next message
David Ponzo is currently offline David PonzoFriend
Messages: 14
Registered: November 2014
Junior Member
Hi.

I am using e(fx) in order to bind a table to a class "A". This class"A" contains simple attributs (as double) and a composition relation with a multiplicity * to a class "B".
In one of the column of my table , I would like to display a concatenation of the attributs of my class B. In other terms, when one instance of the list(of B) is update,
I would like to be be notify and update one cell of the column with the concatenation of the attributs of the instances of the list.
I do not see anything in e(fx) which let me do that. In there a solution ?

Thanks a lot.
Re: Table column and composition relation binding [message #1485764 is a reply to message #1485429] Mon, 24 November 2014 14:24 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Can you provide a bit more context? What binding technology are you
talking about? EMF-Edit? Eclipse-Databinding?

Tom

On 24.11.14 14:57, David Ponzo wrote:
> Hi.
>
> I am using e(fx) in order to bind a table to a class "A". This class"A"
> contains simple attributs (as double) and a composition relation with a
> multiplicity * to a class "B". In one of the column of my table , I
> would like to display a concatenation of the attributs of my class B. In
> other terms, when one instance of the list(of B) is update,
> I would like to be be notify and update one cell of the column with the
> concatenation of the attributs of the instances of the list.
> I do not see anything in e(fx) which let me do that. In there a solution ?
>
> Thanks a lot.
Re: Table column and composition relation binding [message #1485785 is a reply to message #1485764] Mon, 24 November 2014 14:41 Go to previous messageGo to next message
David Ponzo is currently offline David PonzoFriend
Messages: 14
Registered: November 2014
Junior Member
Hi tom,

I am using Eclipse-Databinding.
Re: Table column and composition relation binding [message #1485803 is a reply to message #1485785] Mon, 24 November 2014 15:03 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Can you show us some code?

Tom

On 24.11.14 15:41, David Ponzo wrote:
> Hi tom,
>
> I am using Eclipse-Databinding.
Re: Table column and composition relation binding [message #1485860 is a reply to message #1485803] Mon, 24 November 2014 16:02 Go to previous messageGo to next message
David Ponzo is currently offline David PonzoFriend
Messages: 14
Registered: November 2014
Junior Member
Well , I hoped some code of you Smile

However you can fin below my implementation of the need I was expecting to find in e(fx). I hope it will make my purpose more clear :

 
import java.util.ArrayList;
import java.util.List;

import javafx.beans.Observable;
import javafx.beans.binding.Bindings;
import javafx.beans.binding.StringExpression;
import javafx.beans.property.Property;
import javafx.beans.value.ObservableValue;
import javafx.util.Callback;

import org.eclipse.core.databinding.conversion.IConverter;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.databinding.property.value.IValueProperty;
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.fx.core.databinding.AdapterFactory;

// TODO: Auto-generated Javadoc
/**
 * The Class CallBackMultiRelationWithCriteria.
 *
 * @param <T> the generic type
 */
public class CallBackMultiRelationWithCriteria<T> implements Callback<Object, Object> {

    /** The master value property. */
    private final IValueProperty masterValueProperty;

    /** The detail value property. */
    private final IValueProperty detailValueProperty;

    /** The converter. */
    private final IConverter converter;

    /**
     * Instantiates a new call back.
     *
     * @param masterValueProperty the master value property
     * @param detailValueProperty the detail value property
     * @param converter the converter
     */
    public CallBackMultiRelationWithCriteria(IValueProperty masterValueProperty, IValueProperty detailValueProperty, IConverter converter) {
        this.masterValueProperty = masterValueProperty;
        this.detailValueProperty = detailValueProperty;
        this.converter = converter;
    }

    /**
     * {@inheritDoc}
     */
    @SuppressWarnings({ "unchecked" })
    @Override
    public ObservableValue<T> call(Object valueSource) {
        final IObservableValue masterValueObs = this.masterValueProperty.observe(valueSource);

        // When the attribute is a reference with a multiplicity >1
        final Object masterValue = masterValueObs.getValue();

        if (masterValue instanceof EObjectContainmentEList<?>) {

            final EObjectContainmentEList<?> e = (EObjectContainmentEList<?>) masterValue;

            final List<Observable> dependencies = new ArrayList<>();
            // We wrap the EMF property into a javafx
            // property for each element of the list
            for (final Object value : e) {
                final IObservableValue observableValue = this.detailValueProperty.observe(value);
                final ObservableValue<T> tmp = AdapterFactory.adapt(observableValue);
                dependencies.add(tmp);
            }

            // When the previous EMF property change, the javafx
            // property change and so the String expression is
            // recompute.The new computation consist in a new
            // conversion and the addition of a delimiter
            final StringExpression se = Bindings.createStringBinding(() -> {
                final StringBuilder sb = new StringBuilder();
                for (int i = 0; i < e.size(); i++) {

                    final Object containement = e.get(i);

                    if (containement instanceof Property) {
                        sb.append(((Property<?>) containement).getValue());
                    }
                    else {
                        final T value = ((T) containement);
                        final String valueConvert = this.converter.convert(value).toString();
                        sb.append(valueConvert);
                    }

                    if ((i + 1) < e.size()) {
                        sb.append("\n ");
                    }
                }
                return sb.toString();
            }, dependencies.toArray(new Observable[dependencies.size()]));

            return (ObservableValue<T>) se;
        }

        return null;
    }

}
Re: Table column and composition relation binding [message #1485974 is a reply to message #1485860] Mon, 24 November 2014 18:12 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
I was more after how you are using the stuff to setup TableColumns but
let me see if I understand the problem domain appropriately.

We have a model:

Person
+ friends : List<Person>
+ name: String

and we want a table to display:

--------------------------
| Name | Friends |
==========================
| Tom | Mike, Steve |
--------------------------
| Steve | Mike, Tom |
--------------------------
| Mike | Steve, Tom |
--------------------------

Is that correct? So we want the Friends columns to update:
* if the list of friends changes
* if one of the names in of the displayed friends changes

Is this correct?

Tom

On 24.11.14 17:02, David Ponzo wrote:
> Well , I hoped some code of you :)
>
> However you can fin below my implementation of the need I was expecting
> to find in e(fx). I hope it will make my purpose more clear :
>
>
>
> import java.util.ArrayList;
> import java.util.List;
>
> import javafx.beans.Observable;
> import javafx.beans.binding.Bindings;
> import javafx.beans.binding.StringExpression;
> import javafx.beans.property.Property;
> import javafx.beans.value.ObservableValue;
> import javafx.util.Callback;
>
> import org.eclipse.core.databinding.conversion.IConverter;
> import org.eclipse.core.databinding.observable.value.IObservableValue;
> import org.eclipse.core.databinding.property.value.IValueProperty;
> import org.eclipse.emf.ecore.util.EObjectContainmentEList;
> import org.eclipse.fx.core.databinding.AdapterFactory;
>
> // TODO: Auto-generated Javadoc
> /**
> * The Class CallBackMultiRelationWithCriteria.
> *
> * @param <T> the generic type
> */
> public class CallBackMultiRelationWithCriteria<T> implements
> Callback<Object, Object> {
>
> /** The master value property. */
> private final IValueProperty masterValueProperty;
>
> /** The detail value property. */
> private final IValueProperty detailValueProperty;
>
> /** The converter. */
> private final IConverter converter;
>
> /**
> * Instantiates a new call back.
> *
> * @param masterValueProperty the master value property
> * @param detailValueProperty the detail value property
> * @param converter the converter
> */
> public CallBackMultiRelationWithCriteria(IValueProperty
> masterValueProperty, IValueProperty detailValueProperty, IConverter
> converter) {
> this.masterValueProperty = masterValueProperty;
> this.detailValueProperty = detailValueProperty;
> this.converter = converter;
> }
>
> /**
> * {@inheritDoc}
> */
> @SuppressWarnings({ "unchecked" })
> @Override
> public ObservableValue<T> call(Object valueSource) {
> final IObservableValue masterValueObs =
> this.masterValueProperty.observe(valueSource);
>
> // When the attribute is a reference with a multiplicity >1
> final Object masterValue = masterValueObs.getValue();
>
> if (masterValue instanceof EObjectContainmentEList<?>) {
>
> final EObjectContainmentEList<?> e =
> (EObjectContainmentEList<?>) masterValue;
>
> final List<Observable> dependencies = new ArrayList<>();
> // We wrap the EMF property into a javafx
> // property for each element of the list
> for (final Object value : e) {
> final IObservableValue observableValue =
> this.detailValueProperty.observe(value);
> final ObservableValue<T> tmp =
> AdapterFactory.adapt(observableValue);
> dependencies.add(tmp);
> }
>
> // When the previous EMF property change, the javafx
> // property change and so the String expression is
> // recompute.The new computation consist in a new
> // conversion and the addition of a delimiter
> final StringExpression se = Bindings.createStringBinding(() -> {
> final StringBuilder sb = new StringBuilder();
> for (int i = 0; i < e.size(); i++) {
>
> final Object containement = e.get(i);
>
> if (containement instanceof Property) {
> sb.append(((Property<?>) containement).getValue());
> }
> else {
> final T value = ((T) containement);
> final String valueConvert =
> this.converter.convert(value).toString();
> sb.append(valueConvert);
> }
>
> if ((i + 1) < e.size()) {
> sb.append("\n ");
> }
> }
> return sb.toString();
> }, dependencies.toArray(new Observable[dependencies.size()]));
>
> return (ObservableValue<T>) se;
> }
>
> return null;
> }
>
> }
>
Re: Table column and composition relation binding [message #1486695 is a reply to message #1485974] Tue, 25 November 2014 08:13 Go to previous messageGo to next message
David Ponzo is currently offline David PonzoFriend
Messages: 14
Registered: November 2014
Junior Member
Yes this is correct. (The elements of the list can be different type than the class Person)
Re: Table column and composition relation binding [message #1498485 is a reply to message #1486695] Thu, 04 December 2014 12:41 Go to previous messageGo to next message
David Ponzo is currently offline David PonzoFriend
Messages: 14
Registered: November 2014
Junior Member
Any idea ?
Re: Table column and composition relation binding [message #1505074 is a reply to message #1498485] Tue, 09 December 2014 20:29 Go to previous message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
I have not yet had time to think about it in detail.

Tom

On 04.12.14 13:41, David Ponzo wrote:
> Any idea ?
Previous Topic:Standalone StyledTextArea
Next Topic:problem following e(fx)clipse tutorial 1 step 9
Goto Forum:
  


Current Time: Wed Feb 05 11:38:46 GMT 2025

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

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

Back to the top