On Wed, Mar 7, 2012 at 6:40 PM, Stéphane Ducasse
<[email protected]> wrote:
> Alexis
>
> send it t the list so that we all learn.
>

sorry, bad reflex on my part I guess. So here they are, as changesets.

SimpleGridExample :

Generates a tabular view on Person instances where cells are editable.
Modified to
a) reduce the number of items to 100 (down from 1000 -- takes several
seconds to build on my machine)
b) set the age of the Person randomly (was just the value of the
sequential counter over Persons)
c) add a read-only text column with a comment about the age, one of
the comments being rather long.
As it stands, it uses "theme newTextIn:text:" in
SimpleGridNodeExample>>ageComment and works OK. Replace it by "theme
builder newLabel:" and see the effect I was describing.

MixedTreeGridExample :

A generalized version of what I was looking into, which is a tabular
view with a hierarchy in the first column. I haven't made it clear in
the example code, but it is possible to display tabular cells at *any*
level of expansion, not only the last one. This now uses theme
newTextIn:text: throughout and works exactly as intended. The code is
commented.

Regards,
A.
'From Pharo1.4a of ''16 June 2011'' [Latest update: #14284] on 7 March 2012 at 11:15:28 am'!

!SimpleGridNodeExample methodsFor: 'as yet unclassified' stamp: 'AlexisParseghian 3/7/2012 11:13'!
ageComment
	"with self theme builder newLabel: the text is not properly clipped and pushes the next column to
	the right regardless of column boundaries"
	"^ self theme builder newLabel: "
	^ self theme newTextIn: self text: 
		((item age > 60) 
			ifTrue: [ 'This is a senior citizen and an overly long comment' ]
			ifFalse: [
				(item age < 12) ifTrue: [ 'Still a kid' ] ifFalse: [ 'Not too old' ] ] )! !

!SimpleGridNodeExample methodsFor: 'as yet unclassified' stamp: 'AlainPlantec 2/2/2010 08:36'!
ageMorph
	^ (UITheme current
				newTextEntryIn: World
				for: self 
				get: #age
				set: #age:
				class: Integer
				getEnabled: nil
				help: nil) color: Color transparent! !


!SimpleGridExample methodsFor: 'as yet unclassified' stamp: 'AlexisParseghian 3/6/2012 12:59'!
rootItems
	| rand |
	rand := Random seed: 1000.
	^ rootItems ifNil: [rootItems := (1 to: 100)
		collect: [:i | PersonDataExample
				firstName: 'Person' , i asString
				secondName: 'Person' , i asString , ' second name'
				age: (rand nextInt: 100)
				married: false] ]! !

!SimpleGridExample methodsFor: 'as yet unclassified' stamp: 'AlexisParseghian 3/6/2012 13:10'!
treeMorph
	| treeMorph oddColor evenColor |
	treeMorph := (self treeMorphClass on: self)
		beCheckList;
		beMultiple;
		columns: {MorphTreeColumn new startWidth: 100;
						rowMorphGetSelector: #firstNameMorph;
						headerButtonLabel: 'First name' font:  nil.
					MorphTreeColumn new startWidth: 150;
						rowMorphGetSelector: #secondNameMorph;
						headerButtonLabel: 'Second name' font:  nil.
					MorphTreeColumn new startWidth: 50;
						rowMorphGetSelector: #ageMorph;
						headerButtonLabel: 'Age' font:  nil.
					MorphTreeColumn new startWidth: 100;
						rowMorphGetSelector: #ageComment;
						headerButtonLabel: 'Comment' font: nil.
					MorphTreeColumn new startWidth: 50;
						rowMorphGetSelector: #marriedMorph;
					 	headerButtonLabel: 'Married' font: nil};
		columnInset: 3;
		rowInset: 1;
		preferedPaneColor: Color white;
		rowColorForEven:  Color veryLightGray muchLighter odd: Color white .
	^ treeMorph ! !

'From Pharo1.4a of ''16 June 2011'' [Latest update: #14284] on 7 March 2012 at 10:55:38 am'!
MorphTreeModel subclass: #MixedTreeGridExample
	instanceVariableNames: ''
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Morphic-MorphTreeWidget-Examples'!

!MixedTreeGridExample commentStamp: 'AlexisParseghian 3/7/2012 10:32' prior: 0!
MixedTreeGridExample new open

This example implements the strictest minimum required to show a multi-column grid with a hierarchical tree in the first column.
#rootItems provides a collection of items to show ; here it's the list of packages in the system. How to show them is provided by the class returned by #rootNodeClassFromItem:. See MixedTreeGridPkgNodeExample for the first level (packages).!

MorphTreeNodeModel subclass: #MixedTreeGridMethodNodeExample
	instanceVariableNames: ''
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Morphic-MorphTreeWidget-Examples'!

!MixedTreeGridMethodNodeExample commentStamp: 'AlexisParseghian 3/7/2012 10:47' prior: 0!
Instances of this class are used to display the tabular data in MixedTreeGridExample's tree morph. They correspond to the last level of expansion in the first column's hierarchical view. In opposition to the previous levels' nodes (MixedTreeGridClassNodeExample, MixedTreeGridPkgNodeExample), it is the first column (hierarchical view) that returns nil and the other columns that return a theme-based morph to display in the corresponding column.!

MorphTreeNodeModel subclass: #MixedTreeGridPkgNodeExample
	instanceVariableNames: ''
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Morphic-MorphTreeWidget-Examples'!

!MixedTreeGridPkgNodeExample commentStamp: 'AlexisParseghian 3/7/2012 10:38' prior: 0!
Instances of this class are used by MixedTreeGridExample's tree to display its first-level (packages) items. Accessors for all of the columns defined in the tree morph must be implemented but may return nil. 
#childrenItems return the collection of items to display when a given first-level item is expanded : here classes in a given package. #childNodeClassFromItem: returns the class used to display earch item returned by #childrenItem ; this is the nth-level equivalent of #rootItems/#rootNodeClassFromItem:!

MorphTreeNodeModel subclass: #MixedTreeGridClassNodeExample
	instanceVariableNames: ''
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Morphic-MorphTreeWidget-Examples'!

!MixedTreeGridClassNodeExample commentStamp: 'AlexisParseghian 3/7/2012 10:44' prior: 0!
Instances of this class are used by MixedTreeGridExample's tree morph to display second-level items (classes) in its first column when a first-level item (package) is expanded.!


!MixedTreeGridExample methodsFor: 'as yet unclassified' stamp: 'AlexisParseghian 3/7/2012 10:33'!
rootItems
	"return a collection of items to show"
	^ PackageOrganizer default packages! !

!MixedTreeGridExample methodsFor: 'as yet unclassified' stamp: 'AlexisParseghian 3/7/2012 10:33'!
rootNodeClassFromItem: anItem
	"return the class used to show each item returned by rootItems"
	^ MixedTreeGridPkgNodeExample! !

!MixedTreeGridExample methodsFor: 'user interface' stamp: 'AlexisParseghian 3/7/2012 01:02'!
open
	(self treeMorph buildContents;
		embeddedInMorphicWindowLabeled: 'Mixed Tree and Grid example') openInWorld.! !

!MixedTreeGridExample methodsFor: 'user interface' stamp: 'AlexisParseghian 3/7/2012 01:19'!
treeMorph
	| tree |
	tree := (MorphTreeMorph on: self)
		columns: {
			MorphTreeColumn new
				rowMorphGetSelector: #hierachyColumn;
				headerButtonLabel: 'Hierarchy' font: nil.
			MorphTreeColumn new
				rowMorphGetSelector: #category;
				headerButtonLabel: 'Category' font: nil.
			MorphTreeColumn new
				rowMorphGetSelector: #methodName;
				headerButtonLabel: 'Selector' font: nil.
			MorphTreeColumn new
				rowMorphGetSelector: #linesCount;
				headerButtonLabel: 'Lines' font: nil
		};
		columnInset: 3.
	^ tree! !


!MixedTreeGridMethodNodeExample methodsFor: 'user interface' stamp: 'AlexisParseghian 3/7/2012 10:51'!
category
	"use theme newTextIn:text: or other theme-provided morphs ; others might not be properly clipped 
	to the column width, and/or respect the tree morph's inset specifications. See instance methods of UITheme
	in package Polymorph-Widgets-Themes for what kind of morphs can be properly shown."
	^ self theme newTextIn: self text: self item category! !

!MixedTreeGridMethodNodeExample methodsFor: 'user interface' stamp: 'AlexisParseghian 3/7/2012 10:47'!
hierachyColumn
	"do not show anything in the hierarchical view at this level"
	^ nil! !

!MixedTreeGridMethodNodeExample methodsFor: 'user interface' stamp: 'AlexisParseghian 3/7/2012 01:39'!
linesCount
	^ self theme newTextIn: self text: self item asString lineCount printString! !

!MixedTreeGridMethodNodeExample methodsFor: 'user interface' stamp: 'AlexisParseghian 3/7/2012 01:34'!
methodName
	^ self theme newTextIn: self text: self item selector! !


!MixedTreeGridPkgNodeExample methodsFor: 'accessing' stamp: 'AlexisParseghian 3/7/2012 01:16'!
childNodeClassFromItem: anItem
	^ MixedTreeGridClassNodeExample! !

!MixedTreeGridPkgNodeExample methodsFor: 'accessing' stamp: 'AlexisParseghian 3/7/2012 01:15'!
childrenItems
	^ self item classes! !

!MixedTreeGridPkgNodeExample methodsFor: 'user interface' stamp: 'AlexisParseghian 3/7/2012 01:19'!
category
	^ nil! !

!MixedTreeGridPkgNodeExample methodsFor: 'user interface' stamp: 'AlexisParseghian 3/7/2012 01:15'!
hierachyColumn
	^ self theme newTextIn: self text: self item packageName! !

!MixedTreeGridPkgNodeExample methodsFor: 'user interface' stamp: 'AlexisParseghian 3/7/2012 01:14'!
linesCount
	^ nil! !

!MixedTreeGridPkgNodeExample methodsFor: 'user interface' stamp: 'AlexisParseghian 3/7/2012 01:13'!
methodName
	^ nil! !


!MixedTreeGridClassNodeExample methodsFor: 'user interface' stamp: 'AlexisParseghian 3/7/2012 01:22'!
category
	^ nil! !

!MixedTreeGridClassNodeExample methodsFor: 'user interface' stamp: 'AlexisParseghian 3/7/2012 01:22'!
hierachyColumn
	^ self theme newTextIn: self text: self item printString! !

!MixedTreeGridClassNodeExample methodsFor: 'user interface' stamp: 'AlexisParseghian 3/7/2012 01:23'!
linesCount
	^ nil! !

!MixedTreeGridClassNodeExample methodsFor: 'user interface' stamp: 'AlexisParseghian 3/7/2012 01:23'!
methodName
	^ nil! !

!MixedTreeGridClassNodeExample methodsFor: 'as yet unclassified' stamp: 'AlexisParseghian 3/7/2012 01:25'!
childNodeClassFromItem: anItem
	^ MixedTreeGridMethodNodeExample! !

!MixedTreeGridClassNodeExample methodsFor: 'as yet unclassified' stamp: 'AlexisParseghian 3/7/2012 01:27'!
childrenItems
	^ self item methods! !


!MixedTreeGridPkgNodeExample reorganize!
('accessing' childNodeClassFromItem: childrenItems)
('user interface' category hierachyColumn linesCount methodName)
!


!MixedTreeGridExample reorganize!
('as yet unclassified' rootItems rootNodeClassFromItem:)
('user interface' open treeMorph)
!

Reply via email to