MultipleItemSelectionWidget.st
author Claus Gittinger <cg@exept.de>
Thu, 14 Sep 2000 17:48:28 +0200
changeset 1838 833893f82202
parent 1837 67fd7ad3d699
child 1840 87591034ff12
permissions -rw-r--r--
*** empty log message ***

"{ Package: 'stx:libwidg2' }"

ApplicationModel subclass:#MultipleItemSelectionWidget
	instanceVariableNames:'possibleItemsLabelHolder possibleItemListSelection
		listOfPossibleItems selectedItemListSelection
		removeButtonLabelHolder addButtonLabelHolder
		selectedItemsLabelHolder listOfSelectedItems
		canAddItemToSelection canRemoveItemFromSelection
		canAddAllItemsToSelection canRemoveAllItemsFromSelection'
	classVariableNames:''
	poolDictionaries:''
	category:'Views-Lists'
!

!MultipleItemSelectionWidget class methodsFor:'documentation'!

documentation
"
    Replacement for a multiSelectionInList widget;
    allows construction of a list by adding/removing items.

    For use in a UI-spec, add a subCanvas, and bind the exported aspects to
    your applications aspects.

    [author:]
         (cg@smc1)

    [see also:]

    [instance variables:]

    [class variables:]
"
!

examples
"
                                                                [exBegin]
        |box|

        box := MultipleItemSelectionWidget new.
        box listOfPossibleItems value:#('one' 'two' 'three' 'four' 'five').  
        box listOfSelectedItems value:#().  
        box open.
        box listOfSelectedItems inspect
                                                                [exEnd]


                                                                [exBegin]
        |box|

        box := MultipleItemSelectionWidget new.
        box listOfPossibleItems value:#('one' 'two' 'three' 'four' 'five') asSortedCollection.  
        box listOfSelectedItems value:#() asSortedCollection.  
        box open.
        box listOfSelectedItems inspect
                                                                [exEnd]
"
! !

!MultipleItemSelectionWidget class methodsFor:'interface specs'!

windowSpec
    "This resource specification was automatically generated
     by the UIPainter of ST/X."

    "Do not manually edit this!! If it is corrupted,
     the UIPainter may not be able to read the specification."

    "
     UIPainter new openOnClass:MultipleItemSelectionWidget andSelector:#windowSpec
     MultipleItemSelectionWidget new openInterface:#windowSpec
     MultipleItemSelectionWidget open
    "

    <resource: #canvas>

    ^ 
     #(#FullSpec
        #name: #windowSpec
        #window: 
       #(#WindowSpec
          #label: 'NewApplication'
          #name: 'NewApplication'
          #min: #(#Point 10 10)
          #max: #(#Point 1280 1024)
          #bounds: #(#Rectangle 12 22 312 322)
        )
        #component: 
       #(#SpecCollection
          #collection: #(
           #(#LabelSpec
              #label: 'Selected'
              #name: 'SelectedLabel'
              #layout: #(#LayoutFrame 0 0 0 0 0 0.5 25 0)
              #translateLabel: true
              #labelChannel: #selectedItemsLabelHolder
            )
           #(#SequenceViewSpec
              #name: 'SelectedList'
              #layout: #(#LayoutFrame 0 0 25 0 -20 0.5 0 1)
              #tabable: true
              #model: #selectedItemListSelection
              #hasHorizontalScrollBar: true
              #hasVerticalScrollBar: true
              #miniScrollerHorizontal: true
              #miniScrollerVertical: true
              #isMultiSelect: true
              #doubleClickSelector: #removeItemsFromSelection
              #valueChangeSelector: #showInfoForItem:
              #useIndex: false
              #sequenceList: #listOfSelectedItems
            )
           #(#LabelSpec
              #label: 'Not Selected'
              #name: 'NotSelectedLabel'
              #layout: #(#LayoutFrame 0 0.5 0 0 0 1 25 0)
              #translateLabel: true
              #labelChannel: #possibleItemsLabelHolder
            )
           #(#SequenceViewSpec
              #name: 'NotSelectedList'
              #layout: #(#LayoutFrame 20 0.5 25 0 0 1 0 1)
              #tabable: true
              #model: #possibleItemListSelection
              #hasHorizontalScrollBar: true
              #hasVerticalScrollBar: true
              #miniScrollerHorizontal: true
              #miniScrollerVertical: true
              #isMultiSelect: true
              #doubleClickSelector: #addItemsToSelection
              #valueChangeSelector: #showInfoForItem:
              #useIndex: false
              #sequenceList: #listOfPossibleItems
            )
           #(#VerticalPanelViewSpec
              #name: 'VerticalPanel1'
              #layout: #(#LayoutFrame -20 0.5 25 0 20 0.5 5 0.5)
              #horizontalLayout: #fitSpace
              #verticalLayout: #center
              #horizontalSpace: 3
              #verticalSpace: 3
              #component: 
             #(#SpecCollection
                #collection: #(
                 #(#ActionButtonSpec
                    #label: '<<<'
                    #name: 'AddButton'
                    #translateLabel: true
                    #labelChannel: #addButtonLabelHolder
                    #resizeForLabel: false
                    #tabable: true
                    #model: #addItemsToSelection
                    #enableChannel: #canAddItemToSelection
                    #actionValue: ''
                    #useDefaultExtent: true
                  )
                 #(#ActionButtonSpec
                    #label: '>>>'
                    #name: 'RemoveButton'
                    #translateLabel: true
                    #labelChannel: #removeButtonLabelHolder
                    #resizeForLabel: false
                    #tabable: true
                    #model: #removeItemsFromSelection
                    #enableChannel: #canRemoveItemFromSelection
                    #useDefaultExtent: true
                  )
                 )
               
              )
            )
           #(#VerticalPanelViewSpec
              #name: 'VerticalPanel2'
              #layout: #(#LayoutFrame -20 0.5 5 0.5 20 0.5 -10 1)
              #horizontalLayout: #fitSpace
              #verticalLayout: #center
              #horizontalSpace: 3
              #verticalSpace: 3
              #component: 
             #(#SpecCollection
                #collection: #(
                 #(#ActionButtonSpec
                    #label: 'All'
                    #name: 'AddAllButton'
                    #translateLabel: true
                    #labelChannel: #addButtonLabelHolder
                    #resizeForLabel: false
                    #tabable: true
                    #model: #addAllItemsToSelection
                    #enableChannel: #canAddAllItemsToSelection
                    #useDefaultExtent: true
                  )
                 #(#ActionButtonSpec
                    #label: 'None'
                    #name: 'RemoveAllButton'
                    #translateLabel: true
                    #labelChannel: #removeButtonLabelHolder
                    #resizeForLabel: false
                    #tabable: true
                    #model: #removeAllItemsFromSelection
                    #enableChannel: #canRemoveAllItemsFromSelection
                    #actionValue: ''
                    #useDefaultExtent: true
                  )
                 )
               
              )
            )
           )
         
        )
      )
! !

!MultipleItemSelectionWidget class methodsFor:'plugIn spec'!

aspectSelectors
    "This resource specification was automatically generated
     by the UIPainter of ST/X."

    "Do not manually edit this. If it is corrupted,
     the UIPainter may not be able to read the specification."

    "Return a description of exported aspects;
     these can be connected to aspects of an embedding application
     (if this app is embedded in a subCanvas)."

    ^ #(
        #addButtonLabelHolder
        #listOfPossibleItems
        #listOfSelectedItems
        #possibleItemsLabelHolder
        #removeButtonLabelHolder
        #selectedItemsLabelHolder
      ).

! !

!MultipleItemSelectionWidget methodsFor:'actions'!

addAllItemsToSelection
    "add all items from unselected to the selected list"

    self listOfSelectedItems value:(self listOfSelectedItems value copy addAll:self listOfPossibleItems value; yourself).
    self listOfPossibleItems value:(self listOfPossibleItems value copy removeAll; yourself).


!

addItemsToSelection
    "add selected items from left list to the right list"

    |sel|

    sel := self possibleItemListSelection value.
    sel size > 0 ifTrue:[
        self listOfSelectedItems value:(self listOfSelectedItems value copy addAll:sel; yourself).
        self listOfPossibleItems value:(self listOfPossibleItems value copy removeAll:sel; yourself).

        self possibleItemListSelection value:#()
    ]


!

removeAllItemsFromSelection
    "remove all items from selected to the unselected list"

    self listOfPossibleItems value:(self listOfSelectedItems value copy addAll:self listOfPossibleItems value; yourself).
    self listOfSelectedItems value:(self listOfSelectedItems value copy removeAll; yourself).

!

removeItemsFromSelection
    "remove selected items from right list to the left list"

    |sel|

    sel := self selectedItemListSelection value.
    sel size > 0 ifTrue:[
        self listOfPossibleItems value:(self listOfPossibleItems value copy addAll:sel; yourself).
        self listOfSelectedItems value:(self listOfSelectedItems value copy removeAll:sel; yourself).

        self selectedItemListSelection value:#()
    ]
!

showInfoForItem:anArgument
! !

!MultipleItemSelectionWidget methodsFor:'aspects'!

canAddAllItemsToSelection
    canAddAllItemsToSelection isNil ifTrue:[
       canAddAllItemsToSelection := BlockValue with:[:m | m value size > 0]
                                    argument:self listOfPossibleItems 
    ].
    ^ canAddAllItemsToSelection.
!

canAddItemToSelection
    "automatically generated by UIPainter ..."

    "*** the code below creates a default model when invoked."
    "*** (which may not be the one you wanted)"
    "*** Please change as required and accept it in the browser."

    canAddItemToSelection isNil ifTrue:[
       canAddItemToSelection := BlockValue with:[:m | m value size > 0]
                                    argument:self possibleItemListSelection 
    ].
    ^ canAddItemToSelection.
!

canRemoveAllItemsFromSelection
    canRemoveAllItemsFromSelection isNil ifTrue:[
       canRemoveAllItemsFromSelection := BlockValue with:[:m | m value size > 0]
                                    argument:self listOfSelectedItems 
    ].
    ^ canRemoveAllItemsFromSelection.
!

canRemoveItemFromSelection
    "automatically generated by UIPainter ..."

    "*** the code below creates a default model when invoked."
    "*** (which may not be the one you wanted)"
    "*** Please change as required and accept it in the browser."

    canRemoveItemFromSelection isNil ifTrue:[
       canRemoveItemFromSelection := BlockValue with:[:m | m value size > 0]
                                    argument:self selectedItemListSelection 
    ].
    ^ canRemoveItemFromSelection.
!

listOfPossibleItems
    "automatically generated by UIPainter ..."

    "*** the code below creates a default model when invoked."
    "*** (which may not be the one you wanted)"
    "*** Please change as required and accept it in the browser."

    listOfPossibleItems isNil ifTrue:[
       listOfPossibleItems := #() asValue.
    ].
    ^ listOfPossibleItems.
!

listOfPossibleItems:aValueHolder
   listOfPossibleItems := aValueHolder.
!

listOfSelectedItems
    "automatically generated by UIPainter ..."

    "*** the code below creates a default model when invoked."
    "*** (which may not be the one you wanted)"
    "*** Please change as required and accept it in the browser."

    listOfSelectedItems isNil ifTrue:[
       listOfSelectedItems := #() asValue.
    ].
    ^ listOfSelectedItems.
!

listOfSelectedItems:aValueHolder
   listOfSelectedItems := aValueHolder.
!

possibleItemListSelection
    "automatically generated by UIPainter ..."

    "*** the code below creates a default model when invoked."
    "*** (which may not be the one you wanted)"
    "*** Please change as required and accept it in the browser."

    possibleItemListSelection isNil ifTrue:[
       possibleItemListSelection := #() asValue.
    ].
    ^ possibleItemListSelection.
!

selectedItemListSelection
    "automatically generated by UIPainter ..."

    "*** the code below creates a default model when invoked."
    "*** (which may not be the one you wanted)"
    "*** Please change as required and accept it in the browser."

    selectedItemListSelection isNil ifTrue:[
       selectedItemListSelection := #() asValue.
    ].
    ^ selectedItemListSelection.
! !

!MultipleItemSelectionWidget methodsFor:'aspects - look'!

addButtonLabelHolder
    "automatically generated by UIPainter ..."

    "*** the code below creates a default model when invoked."
    "*** (which may not be the one you wanted)"
    "*** Please change as required and accept it in the browser."

    addButtonLabelHolder isNil ifTrue:[
       addButtonLabelHolder :=  ValueHolder new.
    ].
    ^ addButtonLabelHolder.
!

addButtonLabelHolder:aValueHolder
    addButtonLabelHolder := aValueHolder

!

possibleItemsLabelHolder
    "automatically generated by UIPainter ..."

    "*** the code below creates a default model when invoked."
    "*** (which may not be the one you wanted)"
    "*** Please change as required and accept it in the browser."

    possibleItemsLabelHolder isNil ifTrue:[
       possibleItemsLabelHolder :=  ValueHolder new.
    ].
    ^ possibleItemsLabelHolder.
!

possibleItemsLabelHolder:aValueHolder
    possibleItemsLabelHolder := aValueHolder

!

removeButtonLabelHolder
    "automatically generated by UIPainter ..."

    "*** the code below creates a default model when invoked."
    "*** (which may not be the one you wanted)"
    "*** Please change as required and accept it in the browser."

    removeButtonLabelHolder isNil ifTrue:[
       removeButtonLabelHolder :=  ValueHolder new.
    ].
    ^ removeButtonLabelHolder.
!

removeButtonLabelHolder:aValueHolder
    removeButtonLabelHolder := aValueHolder

!

selectedItemsLabelHolder
    "automatically generated by UIPainter ..."

    "*** the code below creates a default model when invoked."
    "*** (which may not be the one you wanted)"
    "*** Please change as required and accept it in the browser."

    selectedItemsLabelHolder isNil ifTrue:[
       selectedItemsLabelHolder :=  ValueHolder new.
    ].
    ^ selectedItemsLabelHolder.
!

selectedItemsLabelHolder:aValueHolder
    selectedItemsLabelHolder := aValueHolder
! !

!MultipleItemSelectionWidget class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libwidg2/MultipleItemSelectionWidget.st,v 1.2 2000-09-14 15:48:28 cg Exp $'
! !