MultipleItemSelectionWidget.st
author Claus Gittinger <cg@exept.de>
Tue, 10 Dec 2002 12:05:10 +0100
changeset 2404 2b7591c982ac
parent 1863 b4130d1fea7d
child 2520 83dce5294ade
permissions -rw-r--r--
category change

"{ Package: 'stx:libwidg2' }"

ApplicationModel subclass:#MultipleItemSelectionWidget
	instanceVariableNames:'possibleItemsLabelHolder possibleItemListSelection
		listOfPossibleItems selectedItemListSelection
		removeButtonLabelHolder addButtonLabelHolder
		selectedItemsLabelHolder listOfSelectedItems
		canAddItemToSelection canRemoveItemFromSelection
		canAddAllItemsToSelection canRemoveAllItemsFromSelection
		enableChannel'
	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
	      #enableChannel: #enableChannel
	    )
	   #(#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
	      #enableChannel: #enableChannel
	    )
	   #(#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
	#enableChannel
      ).
! !

!MultipleItemSelectionWidget methodsFor:'actions'!

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

    |newSel|

    newSel := self listOfSelectedItems value asOrderedCollection
	      , self listOfPossibleItems value asOrderedCollection.

    self listOfSelectedItems value:newSel asSortedCollection.
    self listOfPossibleItems value:(#() asSortedCollection).
!

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

    |sel t|

    sel := self possibleItemListSelection value.
    sel size > 0 ifTrue:[
	t := self listOfSelectedItems value copy.
	t addAll:sel.
	self listOfSelectedItems value:t.

	t := self listOfPossibleItems value copy.
	t removeAll:sel.
	self listOfPossibleItems value:t.

	self possibleItemListSelection value:#()
    ]
!

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

    |newRem|

    newRem := self listOfSelectedItems value asOrderedCollection
	      , self listOfPossibleItems value asOrderedCollection.

    self listOfPossibleItems value:newRem asSortedCollection.
    self listOfSelectedItems value:(#() asSortedCollection).
!

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

    |sel t|

    sel := self selectedItemListSelection value.
    sel size > 0 ifTrue:[
	t := self listOfPossibleItems value copy.
	t addAll:sel.
	self listOfPossibleItems value:t.

	t := self listOfSelectedItems value copy.
	t removeAll:sel.
	self listOfSelectedItems value:t.

	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.
!

enableChannel
    enableChannel isNil ifTrue:[
       enableChannel := true asValue 
    ].
    ^ enableChannel.
!

enableChannel:aChannel
    enableChannel := aChannel
!

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.5 2002-12-10 11:02:27 cg Exp $'
! !