NAME

Rui::Model::SelectionInList - selection in a list


SYNOPSIS

  $selectionInList = Rui::Model::SelectionInList->new(
     list            => Rui::Model::List->new(data => qw[ a b c ]),
     selection       => Rui::Model::Value->new(value => 'a'),
  );
  $selectionInList = Rui::Model::SelectionInList->new(
     data            => [qw( a b c )],
     selectedItem    => 'a',
     attach          => 0, # not needed because 0 is default
  );
  $selectionInList = Rui::Model::SelectionInList->new(
     data            => [qw( a b c )],
     selectedIndex   => 0,
     events          => {
        List_RangeAdded   => $listener,
        List_RangeRemoved => $listener,
        List_RangeChanged => $listener,
        List_Change       => $listener,
        Selection_Change  => $listener,
     },
  );
  $firstItemInList = $selectionInList->list->get(0);     # 'a'
  $selectedIndex = $selectionInList->selectedIndex;      # 0
  $selectionInList->selectedItem('b');                   # selection='b'
  $selectionInList->selection(Rui::Model::Value->new);   # selection undefined
  $selectionInList->selectedIndex(1);                    # selection='b'
  $selectionInList->list->remove(1);                     # selection='a'
  $self->addBeforeSelection('foo');                      # selection='foo'
  $self->addAfterSelection('bar');                       # selection='bar'
  $self->removeSelection;                                # selection='foo'
  $selectionInList->list(Rui::Model::List->new);         # selection undefined


SUPERCLASS

the Rui::Model::Base manpage


REQUIRES

the Rui::Model::Value manpage, the Rui::Model::List manpage


EVENTS

List_Change
the Rui::Event::Value manpage. The entire list has changed.

Selection_Change
the Rui::Event::Value manpage. The selection has changed.

List_RangeAdded
List_RangeRemoved
List_RangeChanged
the Rui::Event::List manpage. The list has been modified. $event->index is the first index of change in the list, $event->size is the number of relevant elements. The selection in list propagates all list events.


DESCRIPTION

A model of a list and a selection from it. Provides a simple interface for managing the list and the selection.

The selection is automatically changd when it has become invalid because of certain changes to the list. These list events can cause me to change the selection:

The selection is advanced to the new item when calling addBefore/AfterSelection().