Partially sorted columns in a ListView

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Partially sorted columns in a ListView

Dmitry Zamotkin-3
Hello all,

I've just modified ListView and ListViewColumn classes to make possible
excluding a column from sorting. For example, I have a long list with only
same values in a column, and sort on it can be a very overextended. Please,
judge the code below:

| package |
package := Package name: 'ListViewColumnSorting'.
package paxVersion: 0;
 basicComment: ''.

package basicPackageVersion: ''.

"Add the package scripts"
package basicScriptAt: #preinstall put: 'Object subclass: #ListViewColumn
 instanceVariableNames: ''text width alignment getTextBlock
getSortValueBlock getContentsBlock compareBlock parent getImageBlock
isAutoResize getInfoTipBlock customDrawBlock hasSorting''
 classVariableNames: ''''
 poolDictionaries: ''''
 classInstanceVariableNames: '''''.

"Add the class names, loose method names, global names, resource names"
package classNames
 yourself.

package methodNames
 add: #ListView -> #sortOnColumn:;
 add: #ListViewColumn -> #hasSorting;
 add: #ListViewColumn -> #hasSorting:;
 add: 'ListViewColumn class' -> #publishedAspectsOfInstances;
 add: 'ListViewColumn class' -> #stbConvertFrom:;
 add: 'ListViewColumn class' -> #stbVersion;
 yourself.

package globalNames
 yourself.

package resourceNames
 yourself.

"Binary Global Names"
package binaryGlobalNames: (Set new
 yourself).
"Resource Names"
package allResourceNames: (Set new
 yourself).

"Add the prerequisite names"
package setPrerequisites: (IdentitySet new
 add: 'Development System';
 add: 'Dolphin';
 yourself).

package!

"Class Definitions"!

"Loose Methods"!

!ListView methodsFor!

sortOnColumn: aListViewColumn
 "Sorts the receiver according to the sort block in aListViewColumn"

 aListViewColumn hasSorting ifFalse: [ ^ self ]. "inserted line"

 Cursor wait showWhile: [
  self presenter beSorted: aListViewColumn rowSortBlock]! !
!ListView categoriesFor: #sortOnColumn:!columns!public!sorting! !

!ListViewColumn methodsFor!

hasSorting

 hasSorting isNil ifTrue: [ hasSorting := true ].
 ^hasSorting!

hasSorting: aBoolean
 hasSorting := aBoolean! !
!ListViewColumn categoriesFor: #hasSorting!accessing!public! !
!ListViewColumn categoriesFor: #hasSorting:!accessing!public! !

!ListViewColumn class methodsFor!

publishedAspectsOfInstances
 "Answer a Set of the aspects published by  instances of the receiver"

 ^super publishedAspectsOfInstances
  add: (Aspect autostring: #text);
  add: (Aspect integer: #width);
  add: (Aspect block: #getContentsBlock);
  add: (Aspect block: #getImageBlock);
  add: (Aspect block: #getTextBlock);
  add: (Aspect block: #sortBlock);
  add: (Aspect choice: #alignment from: #(left center right));
  add: (Aspect boolean: #isAutoResize);
  add: (Aspect block: #getInfoTipBlock);
  add: (Aspect block: #customDrawBlock);
  add: (Aspect block: #hasSorting); "inserted line"
  yourself!

stbConvertFrom: anSTBClassFormat
 "Convert from earlier version resource.
 Version changes:
  1: Add a getImageBlock instance variable.
  2: Addsan isAutoResize instance variable.
  3: Add getInfoTipBlock instance variable.
  4: Add customDrawBlock instance variable."

 ^[:data | | newInstance ver |
  newInstance := self basicNew.
  1 to: data size do: [:i | newInstance instVarAt: i put: (data at: i)].
  ver := anSTBClassFormat version.
  ver < 1 ifTrue: ["Leave the new getImageBlock inst. var. nilled"].
  ver < 2 ifTrue: [newInstance instVarAt: 10 put: false].
  ver < 3 ifTrue: ["Leave the getInfoTipBlock inst. var. nilled"].
  ver < 4 ifTrue: ["Leave the new customDrawBlock inst. var. nilled"].
  ver < 4.01 ifTrue: []. "inserted line"

  newInstance]!

stbVersion
 "Answer the current binary filer version number for instances of the
receiver."

 ^4.01 "inserted line"
! !
!ListViewColumn class categoriesFor:
#publishedAspectsOfInstances!constants!development!public! !
!ListViewColumn class categoriesFor: #stbConvertFrom:!binary filing!public!
!
!ListViewColumn class categoriesFor: #stbVersion!binary filing!public! !

"End of package definition"!


"Binary Globals"!

"Resources"!


--
Dmitry Zamotkin
























begin 666 ListViewColumnSorting.pac
M?"!P86-K86=E('P-"G!A8VMA9V4@.CT@4&%C:V%G92!N86UE.B G3&ES=%9I
M97=#;VQU;6Y3;W)T:6YG)RX-"G!A8VMA9V4@<&%X5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