Results 1 to 10 of 10

Thread: Updating old code: what happened with ListBinder.MODEL_KEY in v0.2 ?

Hybrid View

  1. #1
    Join Date
    Mar 2005
    Location
    Brazil
    Posts
    40

    Default Updating old code: what happened with ListBinder.MODEL_KEY in v0.2 ?

    Hi,

    I'm migrating from a very old, previous version of 0.1 to the head of the project and I'm experiencing some problems. One thing I can't get to work is the ListBinder.

    Previously, to create a JList I did the follow:
    Code:
    final SwingBindingFactory factory = (SwingBindingFactory) getBindingFactory();
    this.selectedPCsObservableList = factory
      .createBoundListModel(LineForm.SELECTED_PCS);
    
    Map<String, Object> context = new HashMap<String, Object>();
    context.put(AbstractListBinder.SELECTABLE_ITEMS_KEY, null);
    context.put(ListBinder.RENDERER_KEY, new BeanPropertyValueListRenderer(
      "code"));
    context.put(ListBinder.MODEL_KEY, this.selectedPCsObservableList);
    
    final Binding nodes = factory.createBinding(JList.class,
    LineForm.SELECTED_PCS, context);
    this.jlSelectedPCs = (JList) nodes.getControl();
    But ListBinder.MODEL_KEY doesn't exist anymore, and everytime I select one item in the list, instead of been selected, it disappears.
    The new code I'm trying is the follow:
    Code:
    final SwingBindingFactory factory = (SwingBindingFactory) getBindingFactory();
    this.selectedPCsObservableList = factory
      .createBoundListModel(LineForm.SELECTED_PCS);
    
    final Binding nodes = factory.createBoundList(LineForm.SELECTED_PCS,
    this.selectedPCsObservableList, "code",
    ListSelectionModel.SINGLE_SELECTION);
    I've tried some other signatures of SwingBindingFactory.createBoundList but them doesn't work as well.

    What should I do to keep the previous behaviour of JList?

    Thanks,

    Mauro.

  2. #2
    Join Date
    May 2005
    Posts
    394

    Default

    I had some similar problems, but Matthias helped me and I 've documented them in /src/site/user/upgrading.apt (the SVN version).

    If it's not in there and you find a solution, could you provide a bit of text which I can add there if other users have this problem?

  3. #3
    Join Date
    Apr 2006
    Location
    Germany, Berlin
    Posts
    61

    Default

    please use

    ListBinder.SELECTABLE_ITEMS_KEY instead of ListBinder.MODEL_KEY. SELECTABLE_ITEMS_KEY now accepts any collection type including ListModel or ValueModel.
    ___
    Mathias

  4. #4
    Join Date
    Mar 2005
    Location
    Brazil
    Posts
    40

    Default

    Hi,

    Thanks for the replies! I've fixed the problem.
    I was doing right, the problem is the deprecated SwingBindingFactory.createBoundListModel(...), it should be avoided. The BufferedCollectionValueModel created by this method causes the strange "desapearing behaviour".
    Maybe this method should be removed. The only problem is that I don't know other Model with the same behaviour of BufferedCollectionValueModel.
    The great insight of BufferedCollectionValueModel is that when a form is commited the differences in the list are computed and the ValueObject is updated by consequence.
    I've tried to reproduce this behaviour with ListListModel, ValueHolder and DynamicListModel but them just commit the selected items, so I have to compute the differences manually.

    There's a good way to avoid this workaround?

    Thanks,

    Mauro Ransolin.

  5. #5
    Join Date
    Apr 2006
    Location
    Germany, Berlin
    Posts
    61

    Default

    IMO BufferedCollectionValueModel does a lot of (maybe unnecessary) things if only the changes of a collection should be "commited". BTW it also contains hacks to support some special use case like SortedSet ...

    I've not tested it but that should work without the use of BufferedCollectionValueModel to modify an existing collection:

    Code:
    Collection getSelection() {
      return mySelection; // no copy needed for this
    }
    
    void setSelection(Collection selection) {
      mySelection.retainAll(selection); // removes any "deselected" value
    
      // optional step if mySelection is not a Set
      selection.removeAll(mySelection); // removes all existing selected elements - the given collection can be modified without side effects if only used for bindings
    
      mySelection.addAll(selection); // add all new "selected" values
    }
    But I'm still not sure if I really understand the usecase for BufferedCollectionValueModel ...
    ___
    Mathias

  6. #6
    Join Date
    Mar 2005
    Location
    Brazil
    Posts
    40

    Default

    Hi Mathias,

    Thanks for the reply.

    My use case is the follow:
    In a screen, on the left side is a list with all possible values to be choosen. On the right side is another list with 'choosen' values (not graphicaly selected, but choosen by the user).
    The user have 2 commands, one add values to choosen list, other to remove. The user change the list of choosen values by adding and removing.
    Previously to V 0.2.0 when a form had been commited all the values of 'choosen' collection were commited, without the need of been selected.
    Now, it's necessary to force the selection of all elements of the list before commiting. This happens to be because the list now commits the selected values only.
    What I'm looking for is a easy method to keep the previous behaviour without the need of workarrounds like force the selection of all values. Furthermore, to force the selection would be a problem if the selection mode is single_selection.

    Thanks,

    Mauro.

  7. #7
    Join Date
    Jan 2006
    Location
    Vilnius, Lithuania
    Posts
    68

    Default Try using ShuttleList

    Hi Mauro,

    Your described use case sounds like you could use a ShuttleList component. It is in the sandbox, package org.sprinframework.richclient.components, together with a ShuttleListBinder and ShuttleListBinding. Have a look at that stuff. I have not used it myself yet , so I'd be interested to hear whether it helped you.

    Andrius

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •