From VisualWorks®, 7.6 of February 1, 2008 on February 1, 2008 at 12:49:35 pm (Dialog confirm: 'You are filing-in a Parcel source file!\\While this is possible it will not have\the same effect as loading the parcel.\None of the Parcel''s prerequisites will\be loaded and none of its load actions\will be performed.\\Are you sure you want to file-in?' withCRs) ifFalse: [self error: 'Parcel file-in abandoned. Choose terminate or close.'] <class> <name>ListDragDropExample</name> <environment>Examples</environment> <super>UI.ApplicationModel</super> <private>false</private> none numberList dropType <imports></imports> <category>Drag Drop-Examples</category> <attributes> <package>DragDrop-List-Example</package> </attributes> </class> <comment> Examples.ListDragDropExample
ListDragDropExample combines behavior and definitions common to the ListDDExample and MultiListDDExample list drag-drop example classes. Instance Variables: dropType <ValueHolder on:Symbol> Selector for choice of drop method that determines drop feedback shown in list. numberList <MultiSelectionInList> List model for items available to select, sort, replace, and remove.
</comment> <class> <name>ListDDExample</name> <environment>Examples</environment> <super>Examples.ListDragDropExample</super> <private>false</private> none <imports></imports> <category>Drag Drop-Examples</category> <attributes> <package>DragDrop-List-Example</package> </attributes> </class> <comment> Examples.ListDDExample
ListDDExample demonstrates how drag-drop may be used to sort, replace, and insert selected items from a source list widget to a destination list widget. Only a single item in the ListDDExample list may be selected at a time. The source and destination list may belong in the same ListDDExample application window or be from another ListDDExample or MultiListDDExample application window. Items dragged from its list will be removed upon drop to another list or will be copied if the <Shift> key is held during drag. The drop action performed for items dragged to a ListDDExample list is selectable by three radio buttons as either Insert only Replace only Insert or Replace Try dragging and dropping items between multiple ListDDExample or MultiListDDExample windows.
</comment> <class> <name>MultiListDDExample</name> <environment>Examples</environment> <super>Examples.ListDragDropExample</super> <private>false</private> none <imports></imports> <category>Drag Drop-Examples</category> <attributes> <package>DragDrop-List-Example</package> </attributes> </class> <comment> Examples.MultiListDDExample
MultiListDDExample demonstrates how drag-drop may be used to sort, replace, and insert selected items from a source list widget to a destination list widget. One or more items in the MultiListDDExample list may be selected at a time. The source and destination list may belong in the same MultiListDDExample application window or be from another ListDDExample or MultiListDDExample application window. Items dragged from its list will be removed upon drop to another list or will be copied if the <Shift> key is held during drag. The drop action performed for items dragged to a MultiListDDExample list is selectable by three radio buttons as either Insert only Replace only Insert or Replace Try dragging and dropping items between multiple ListDDExample or MultiListDDExample windows.
</comment> <methods> Examples.ListDragDropExample <category>drag and drop</category>
doDrag: aController "Drag the currently selected change. Include all available information so that the drop target can use whatever it needs." | data | data := DragDropData new. data contextWindow: builder window. data contextWidget: aController view. data contextApplication: self. data clientData: self numberList. (DragDropManager withDropSource: DropSource new withData: data) doDragDrop
dragEnter: aDragContext "A drag has entered the list. If the receiver is happy to accept a drag then fill-in the appropriate data and answer that dragging should continue." (aDragContext data contextApplication isKindOf: ListDragDropExample) ifFalse: [^#dropEffectNone]. aDragContext dropTarget clientData: (self initialDropState: (self widgetAt: #List1)). ^aDragContext shiftDown ifTrue: [#dropEffectCopy] ifFalse: [#dropEffectMove]
dragExit: aDragContext "A drag has left the list" ^#dropEffectNone
dragOver: aDragContext "A drag is over the list view. Enable a drop if the drag originated in this application" ^(aDragContext data contextApplication isKindOf: ListDragDropExample) ifTrue: [(self widgetAt: #List1) perform: self dropType value with: aDragContext with: true. aDragContext shiftDown ifTrue: [#dropEffectCopy] ifFalse: [#dropEffectMove]] ifFalse: [#dropEffectNone]
drop: aDragContext "A drop has occurred on the list. Remove the object(s) dragged from its source and place it in the drop target at position targetIndex." ^aDragContext data clientData selectionIndex isInteger ifTrue:[self dropSingle: aDragContext] ifFalse:[self dropMultiple: aDragContext]
wantToDrag: treeController ^self numberList list notEmpty
</methods> <methods> Examples.ListDragDropExample <category>aspects</category>
dropType ^dropType isNil ifTrue: [dropType := #showInsertDropFeedbackIn:allowScrolling: asValue] ifFalse: [dropType]
numberList ^numberList isNil ifTrue: [numberList := SelectionInList with: (1 to:100) asList] ifFalse: [numberList]
</methods> <methods> Examples.ListDragDropExample <category>private</category>
initialDropState: aListView "Answer the initial state of aListView when a drag has begun within its bounds. The state will be used to re-establish the appearance of aListView when a drag leaves." | dict | dict := IdentityDictionary new. aListView hasFocus: true. ^dict
</methods> <methods> Examples.ListDragDropExample <category>accessing</category>
multiSelectApp ^MultiListDDExample new
singleSelectApp ^ListDDExample new
</methods> <methods> Examples.ListDragDropExample <category>actions</category>
spawn self class open
</methods> <methods> Examples.ListDDExample <category>drag and drop</category>
dropMultiple: aDragContext | targetIndex targetView source dragObjects | targetView := self widgetAt: #List1. source := aDragContext data clientData. targetIndex := targetView targetIndex. dragObjects := source selections. aDragContext shiftDown ifFalse: ["Remove objects from source for a move drag" source list removeAll: source selections]. targetIndex isInteger ifTrue: ["Replace selection" self numberList list removeAtIndex: targetIndex]. self numberList list addAll: dragObjects beforeIndex: targetIndex ceiling. self numberList selectionIndex: targetIndex ceiling. ^#dropEffectNone
dropSingle: aDragContext "A drop has occurred on the list. Remove the object dragged from its source and place it in the drop target in position targetIndex." | targetIndex sourceIndex dragObject targetView sourceView source | targetView := self widgetAt: #List1. sourceView := aDragContext data contextWidget. source := aDragContext data clientData. sourceIndex := source selectionIndex. targetIndex := targetView targetIndex. dragObject := aDragContext shiftDown ifTrue: ["Leave in source for a copy drag" source selection] ifFalse: ["Remove from source for a move drag" (sourceView = targetView and: [targetIndex > sourceIndex]) ifTrue: ["The target and source are the same list. Reorder the targetIndex" targetIndex := targetIndex - 1]. source list removeAtIndex: sourceIndex]. targetIndex isInteger ifTrue: ["Replace" self numberList list at: targetIndex put: dragObject] ifFalse: ["Insert" self numberList list add: dragObject beforeIndex: targetIndex ceiling]. self numberList selectionIndex: targetIndex ceiling. ^#dropEffectNone
</methods> <methods> Examples.MultiListDDExample <category>drag and drop</category>
dropMultiple: aDragContext | targetIndex targetView source dragObjects sourceView | targetView := self widgetAt: #List1. sourceView := aDragContext data contextWidget. source := aDragContext data clientData. targetIndex := targetView targetIndex. dragObjects := source selections. aDragContext shiftDown ifFalse: ["Remove objects from source for a move drag" targetView = sourceView ifTrue: [targetIndex := source selectionIndexes inject: targetIndex into: [:sofar :each | each < targetIndex ifTrue: [sofar - 1] ifFalse: [sofar]]]. "Remove by index instead by value to prevent removing any prior duplicate" (source selectionIndexes asSortedCollection: [:a :b | a > b]) do: [:each | source list removeAtIndex: each]]. targetIndex isInteger ifTrue: ["Replace selection" self numberList list removeAtIndex: targetIndex]. targetIndex := targetIndex ceiling. self numberList list addAll: dragObjects beforeIndex: targetIndex. self numberList selectionIndexes: (targetIndex to: targetIndex + dragObjects size - 1) asSet. ^#dropEffectNone
dropSingle: aDragContext "A drop has occurred on the list. Remove the object dragged from its source and place it in the drop target in position targetIndex." | targetIndex dragObject targetView source | targetView := self widgetAt: #List1. source := aDragContext data clientData. targetIndex := targetView targetIndex. dragObject := source selection. aDragContext shiftDown ifFalse: ["Remove from source for a move drag" source list removeAtIndex: source selectionIndex]. targetIndex isInteger ifTrue: ["Replace" self numberList list at: targetIndex put: dragObject] ifFalse: ["Insert" self numberList list add: dragObject beforeIndex: targetIndex ceiling]. self numberList selectionIndexes: (Set with: targetIndex ceiling). ^#dropEffectNone
</methods> <methods> Examples.MultiListDDExample <category>aspects</category>
numberList ^numberList isNil ifTrue: [numberList := MultiSelectionInList with: (1 to:100) asList] ifFalse: [numberList]
</methods> <methods> Examples.ListDragDropExample class <category>interface specs</category>
windowSpec "Tools.UIPainter new openOnClass: self andSelector: #windowSpec" <resource: #canvas> ^#(#{UI.FullSpec} #window: #(#{UI.WindowSpec} #label: 'List Drag/Drop Examples' #bounds: #(#{Graphics.Rectangle} 640 512 1089 813 ) ) #component: #(#{UI.SpecCollection} #collection: #( #(#{UI.SubCanvasSpec} #layout: #(#{Graphics.LayoutFrame} 5 0 25 0 -2 0.5 -5 1 ) #name: #Subcanvas1 #majorKey: #{ListDDExample} #minorKey: #windowSpec #clientKey: #singleSelectApp ) #(#{UI.SubCanvasSpec} #layout: #(#{Graphics.LayoutFrame} 2 0.5 25 0 -5 1 -5 1 ) #name: #Subcanvas2 #majorKey: #{MultiListDDExample} #minorKey: #windowSpec #clientKey: #multiSelectApp ) #(#{UI.LabelSpec} #layout: #(#{Core.Point} 5 5 ) #name: #Label2 #label: 'Single selection' ) #(#{UI.LabelSpec} #layout: #(#{Graphics.LayoutOrigin} 0 0.505568 5 0 ) #name: #Label3 #label: 'Multi-selection' ) ) ) )
</methods> <methods> Examples.ListDDExample class <category>interface specs</category>
windowSpec "Tools.UIPainter new openOnClass: self andSelector: #windowSpec" <resource: #canvas> ^#(#{UI.FullSpec} #window: #(#{UI.WindowSpec} #properties: #(#{UI.PropertyListDictionary} #sizeType #specifiedSize #positionType #cascade #openType #advanced ) #label: 'Single Select Drag/Drop Reordering' #min: #(#{Core.Point} 208 162 ) #max: #(#{Core.Point} 0 0 ) #bounds: #(#{Graphics.Rectangle} 640 512 886 788 ) ) #component: #(#{UI.SpecCollection} #collection: #( #(#{UI.SequenceViewSpec} #properties: #(#{UI.PropertyListDictionary} #dragOkSelector #wantToDrag: #dragEnterSelector #dragEnter: #dragOverSelector #dragOver: #dragStartSelector #doDrag: #dropSelector #drop: #dragExitSelector #dragExit: ) #layout: #(#{Graphics.LayoutFrame} 10 0 20 0 -10 1 -85 1 ) #name: #List1 #model: #numberList #multipleSelections: false #useModifierKeys: true #selectionType: #highlight ) #(#{UI.RadioButtonSpec} #layout: #(#{Graphics.LayoutOrigin} 25 0 -68 1 ) #name: #RadioButton1 #model: #dropType #label: 'Insert' #select: #showInsertDropFeedbackIn:allowScrolling: ) #(#{UI.RadioButtonSpec} #layout: #(#{Graphics.LayoutOrigin} 25 0 -48 1 ) #name: #RadioButton2 #model: #dropType #label: 'Insert or Replace' #select: #showInsertReplaceDropFeedbackIn:allowScrolling: ) #(#{UI.RadioButtonSpec} #layout: #(#{Graphics.LayoutOrigin} 25 0 -28 1 ) #name: #RadioButton3 #model: #dropType #label: 'Replace' #select: #showReplaceDropFeedbackIn:allowScrolling: ) #(#{UI.GroupBoxSpec} #layout: #(#{Graphics.LayoutFrame} 10 0 -85 1 140 0 -5 1 ) #name: #GroupBox1 #label: 'Drop Action' ) #(#{UI.LabelSpec} #layout: #(#{Core.Point} 8 0 ) #name: #Label1 #label: 'Hold <Shift> to drag a copy' ) #(#{UI.ActionButtonSpec} #layout: #(#{UI.AlignmentOrigin} -10 1 -5 1 1 1 ) #name: #ActionButton1 #model: #spawn #label: 'Spawn' #defaultable: true ) ) ) )
</methods> <methods> Examples.MultiListDDExample class <category>interface specs</category>
windowSpec "Tools.UIPainter new openOnClass: self andSelector: #windowSpec" <resource: #canvas> ^#(#{UI.FullSpec} #window: #(#{UI.WindowSpec} #properties: #(#{UI.PropertyListDictionary} #sizeType #specifiedSize #positionType #cascade #openType #advanced ) #label: 'Multi Select Drag/Drop Reordering' #min: #(#{Core.Point} 208 162 ) #max: #(#{Core.Point} 0 0 ) #bounds: #(#{Graphics.Rectangle} 640 512 886 788 ) ) #component: #(#{UI.SpecCollection} #collection: #( #(#{UI.SequenceViewSpec} #properties: #(#{UI.PropertyListDictionary} #dragOkSelector #wantToDrag: #dragEnterSelector #dragEnter: #dragOverSelector #dragOver: #dragStartSelector #doDrag: #dropSelector #drop: #dragExitSelector #dragExit: ) #layout: #(#{Graphics.LayoutFrame} 10 0 20 0 -10 1 -85 1 ) #name: #List1 #model: #numberList #multipleSelections: true #useModifierKeys: true #selectionType: #highlight ) #(#{UI.RadioButtonSpec} #layout: #(#{Graphics.LayoutOrigin} 25 0 -68 1 ) #name: #RadioButton1 #model: #dropType #label: 'Insert' #select: #showInsertDropFeedbackIn:allowScrolling: ) #(#{UI.RadioButtonSpec} #layout: #(#{Graphics.LayoutOrigin} 25 0 -48 1 ) #name: #RadioButton2 #model: #dropType #label: 'Insert or Replace' #select: #showInsertReplaceDropFeedbackIn:allowScrolling: ) #(#{UI.RadioButtonSpec} #layout: #(#{Graphics.LayoutOrigin} 25 0 -28 1 ) #name: #RadioButton3 #model: #dropType #label: 'Replace' #select: #showReplaceDropFeedbackIn:allowScrolling: ) #(#{UI.GroupBoxSpec} #layout: #(#{Graphics.LayoutFrame} 10 0 -85 1 140 0 -5 1 ) #name: #GroupBox1 #label: 'Drop Action' ) #(#{UI.LabelSpec} #layout: #(#{Core.Point} 8 0 ) #name: #Label1 #label: 'Hold <Shift> to drag a copy' ) #(#{UI.ActionButtonSpec} #layout: #(#{UI.AlignmentOrigin} -10 1 -5 1 1 1 ) #name: #ActionButton1 #model: #spawn #label: 'Spawn' #defaultable: true ) ) ) )
</methods> "Imported Classes:" self error: 'Attempting to file-in parcel imports. Choose terminate or close' <class> <name>ApplicationModel</name> <environment>UI</environment> <super>UI.Model</super> <private>false</private> none builder uiSession eventHandlers savedWindowInformation <imports></imports> <category>UIBuilder-Framework</category> <attributes> <package>UIBuilder-Framework</package> </attributes> </class>