uqbar-project / arena

MMVC framework
http://arena.uqbar-project.org/
4 stars 2 forks source link

Unify Adapters & Transformers Controllers #18

Closed fdodino closed 8 years ago

fdodino commented 9 years ago

Original problem:

The biggest problem here is in table columns. Theres a bindContentsToProperty "or" bindContentsToTransformer

Using the latter will not create any binding. Arena looses information on which property are you using from the object, therefore, it won't refresh the cell when the model changes.

'What steps will reproduce the problem?'

  1. Create a Table, bound to a list of Objects
  2. Change a property of an object in the list, without changing the list iself.

Table cell should actualize its contents, but it does not (unless the whole list changes).

The best approach for this is to have something really similar to transformers in bindings for other controls.

Column<Account> column = ...

Binding binding = column.bindContentProperty("amountOfMoney")
binding.setTransformer[ Double d |  "$" + d ]

In this way there's still a binding there, so it will be updated automatically upon a change on that property. But it still allows the user to change the way it's been seen.

Also note that in this case the transformer works on the value of the property. While the current transformer works on the object that's one of the item on the list

[ Account a |  "$" + a.getAmountOfMoney() ]

Note: Arena 3.5.1 has a setTransformer method, but Transformer needs to conform a <String, String> conversion. See example below:

bindContentsToProperty("recibeResumenCuenta").transformer = [ recibe | if (recibe) "SI" else "NO"] does not work,

java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean
    at ar.edu.celulares.ui.BuscarCelularesWindow$10$1.transform(BuscarCelularesWindow.java:1)
    at org.uqbar.lacar.ui.impl.jface.tables.JFaceLabelProviderBuilder$1.transform(JFaceLabelProviderBuilder.java:85)
    at org.uqbar.lacar.ui.impl.jface.tables.JFaceLabelProviderBuilder$1.transform(JFaceLabelProviderBuilder.java:82)

you should ask

bindContentsToProperty("recibeResumenCuenta").transformer = [ recibe | if (recibe == "true") "SI" else "NO"]

Same situation rises if you define a Transformer class:

BooleanToSiNoTransformer implements Transformer<String, String>

is ok while

BooleanToSiNoTransformer implements Transformer<Boolean, String>

does not compile.

fdodino commented 8 years ago

Fixed in 3.6.1-SNAPSHOT. Problem was here:

ColumnsLabelProvider
public Transformer<R, Object> getDelegatingTransformer(final int columnIndex) {
        return new Transformer<R, Object>() {
            @Override
            public Object transform(R element) {
                return ColumnsLabelProvider.this.decorated.getColumnText(element, columnIndex);
            }
        };
    }

Instead of calling getColumnText, we now use getColumnValue,a new method in ObservableMapProvider.

fdodino commented 8 years ago

Original problem also solved (pushing soon new example ejemplosWidget-ui-arena)