From VisualWorks®, 7.6 of February 1, 2008 on February 1, 2008 at 12:48:53 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>AdvancedTreeViewExample</name> <environment>Examples</environment> <super>UI.ApplicationModel</super> <private>false</private> none treeView <imports></imports> <category>Examples</category> <attributes> <package>TreeView-Example</package> </attributes> </class> <comment> Examples.AdvancedTreeViewExample
This class demonstrates the use of the TreeView. It uses individually assigned display-blocks to show different icons for opened and closed nodes in the tree. Instance Variables: treeView <SelectionInList> holds the tree's model
</comment> <class> <name>TreeTestNode</name> <environment>Examples</environment> <super>Core.Object</super> <private>false</private> none children editedDisplayString <imports></imports> <category>Examples</category> <attributes> <package>TreeView-Example</package> </attributes> </class> <comment> Examples.TreeTestNode
This class provides the nodes to be displayed in the TreeView Example.
</comment> <class> <name>TreeViewExample</name> <environment>Examples</environment> <super>UI.ApplicationModel</super> <private>false</private> none treeView <imports></imports> <category>Examples</category> <attributes> <package>TreeView-Example</package> </attributes> </class> <comment> Examples.TreeViewExample
To test the TreeView take a look at the class protocol: examples.
</comment> <methods> Examples.AdvancedTreeViewExample <category>actions</category>
doubleClick: aTreeController "Let the tree toggle the state of expandation of the selected node." aTreeController toggleExpand
</methods> <methods> Examples.AdvancedTreeViewExample <category>private</category>
iconFor: aTreeModel at: index ^(aTreeModel isLeafAtIndex: index) ifTrue: ["Leaf node icon" self class noFolder] ifFalse: [(aTreeModel isOpenedAtIndex: index) ifTrue: ["Use the open folder if the node is expanded" self class openFolder] ifFalse: ["Otherwise use the closed folder" self class closedFolder]]
</methods> <methods> Examples.AdvancedTreeViewExample <category>interface opening</category>
postBuildWith: aBuilder | treeViewWidget | super postBuildWith: aBuilder. self treeView list root: Object displayIt: true childrenBlock: [:cls | cls subclasses select: [:ea | ea isMeta not]]. treeViewWidget := (aBuilder componentAt: #treeView) widget. treeViewWidget visualBlock: [:view :index | (view sequence wrapperAt: index) wrappedWithLabel: view displayStringSelector andIcon: (self iconFor: view sequence at: index) attributes: view textStyle]. treeViewWidget selectedVisualBlock: [:view :index | | wrapper | wrapper := (view sequence wrapperAt: index) wrappedWithLabel: view displayStringSelector andIcon: (self iconFor: view sequence at: index) attributes: view textStyle. wrapper component selected setValue: true. wrapper]
</methods> <methods> Examples.AdvancedTreeViewExample <category>aspects</category>
treeView "This method was generated by UIDefiner. Any edits made here may be lost whenever methods are automatically defined. The initialization provided below may have been preempted by an initialize method." ^treeView isNil ifTrue: [treeView := SelectionInTree new] ifFalse: [treeView]
</methods> <methods> Examples.AdvancedTreeViewExample class <category>examples</category>
example "Display the Smalltalk class hierarchy with open, closed and no folder icons with double click support" "self example" self open
</methods> <methods> Examples.TreeTestNode <category>accessing</category>
children ^children isNil ifTrue: [children := Array new] ifFalse: [children]
children: aCollection children := aCollection
childrenImage ^self class perform: (#img , self children size printString) asSymbol
inPlaceEdited: aString editedDisplayString := aString
zeroImage ^self class img0
</methods> <methods> Examples.TreeTestNode <category>printing</category>
displayString | str | str := (String new: 20) writeStream. self printOn: str. str nextPutAll: ' (children: '; nextPutAll: self children size printString; nextPut: $). ^str contents
mayEditedDisplayString ^editedDisplayString isNil ifTrue: ['-not edited yet-'] ifFalse: [editedDisplayString]
printStringInTestApp | str | str := (String new: 20) writeStream. self printOn: str. str nextPutAll: ' ('; nextPutAll: self children size printString; nextPut: $). ^str contents
</methods> <methods> Examples.TreeTestNode class <category>examples</category>
example1 "self example1" | x | x := self new children: (Array with: (self new children: (Array with: self new)) with: self new). ^x
example2 "self example2" | x | x := self new children: (Array with: self example1 with: self example1 with: self example1 with: self example1). ^x
</methods> <methods> Examples.TreeViewExample <category>menu actions</category>
inspectItem | sel | (sel := self treeView selection) isNil ifTrue: [Dialog warn: 'Nothing selected.'] ifFalse: [sel inspect]
</methods> <methods> Examples.TreeViewExample <category>aspects</category>
treeView "This method was generated by UIDefiner. Any edits made here may be lost whenever methods are automatically defined. The initialization provided below may have been preempted by an initialize method." ^treeView isNil ifTrue: [treeView := SelectionInList new] ifFalse: [treeView]
</methods> <methods> Examples.TreeViewExample class <category>examples</category>
example1 "Display the Smalltalk class hierarchy with standard folder icons" "self example1" | app | app := self new. self openOn: app. app treeView list root: Object displayIt: true childrenBlock: [:cls | cls subclasses select: [:ea | ea isMeta not]]
example2 "Display a sample collection of TestNode(s) with standard folder icons" "self example2" | app | app := self new. self openOn: app. app treeView list root: TreeTestNode example2
example3 "Display a sample collection of TestNode(s) without any icons" "self example3" | app | app := self new. self openOn: app withSpec: #testNodesAsTextSpec. app treeView list root: TreeTestNode example2
example4 "Display a sample collection of TestNode(s) with two user defined icons" "self example4" | app | app := self new. self openOn: app withSpec: #testNodesWithIconsSpec. app treeView list root: TreeTestNode example2
example5 "Display a sample collection of TestNode(s) whose display string can be changed via in-place editing" "self example5" | app | app := self new. self openOn: app withSpec: #editingTestNodesSpec. app treeView list root: TreeTestNode example2
example6 "Display the collection class hierarchy with standard folder icons but without lines." "self example6" | app | app := self new. self openOn: app. app treeView list root: Collection displayIt: true childrenBlock: [:cls | cls subclasses select: [:ea | ea isMeta not]]. (app builder componentAt: #treeView) widget noLinesAndImages
</methods> <methods> Examples.AdvancedTreeViewExample class <category>resources</category>
closedFolder "UIMaskEditor new openOnClass: self andSelector: #closedFolder" <resource: #image> ^CachedImage on: (Image extent: 16@13 depth: 3 bitsPerPixel: 4 palette: (MappedPalette withColors: ((Array new: 5) at: 1 put: ColorValue black; at: 2 put: ColorValue yellow; at: 3 put: ColorValue white; at: 4 put: (ColorValue scaledRed: 4227 scaledGreen: 4227 scaledBlue: 4227); at: 5 put: (ColorValue scaledRed: 6077 scaledGreen: 6077 scaledBlue: 6077); yourself)) usingBits: #[34 35 51 51 34 34 34 34 34 52 20 20 50 34 34 34 35 65 65 65 67 51 51 50 35 34 34 34 34 34 34 48 35 33 65 65 65 65 65 48 35 36 20 20 20 20 20 48 35 33 65 65 65 65 65 48 35 36 20 20 20 20 20 48 35 33 65 65 65 65 65 48 35 36 20 20 20 20 20 48 35 33 65 65 65 65 65 48 35 51 51 51 51 51 51 48 34 0 0 0 0 0 0 0])
noFolder "UIMaskEditor new openOnClass: self andSelector: #noFolder" <resource: #image> ^CachedImage on: (Image extent: 16@13 depth: 1 bitsPerPixel: 1 palette: MonoMappedPalette blackWhite usingBits: #[255 255 0 0 255 255 0 0 255 255 0 0 255 255 0 0 255 255 0 0 255 255 0 0 85 85 0 0 255 255 0 0 255 255 0 0 255 255 0 0 255 255 0 0 255 255 0 0 255 255 0 0])
openFolder "UIMaskEditor new openOnClass: self andSelector: #openFolder" <resource: #image> ^CachedImage on: (Image extent: 16@13 depth: 3 bitsPerPixel: 4 palette: (MappedPalette withColors: ((Array new: 5) at: 1 put: (ColorValue scaledRed: 6167 scaledGreen: 6167 scaledBlue: 6167); at: 2 put: ColorValue black; at: 3 put: (ColorValue scaledRed: 4112 scaledGreen: 4112 scaledBlue: 4112); at: 4 put: ColorValue white; at: 5 put: ColorValue yellow; yourself)) usingBits: #[51 50 34 34 51 51 51 51 51 36 68 68 35 51 51 51 50 68 64 64 66 34 34 35 50 68 4 4 4 68 68 33 50 64 64 64 64 64 68 33 34 34 34 34 34 34 36 33 36 68 68 68 68 66 16 33 36 4 4 4 4 4 18 33 34 64 64 64 64 64 33 33 50 68 4 4 4 4 1 33 51 36 64 64 64 64 66 17 51 34 34 34 34 34 34 17 51 49 17 17 17 17 17 17])
treeViewMenu "MenuEditor new openOnClass: self andSelector: #treeViewMenu" <resource: #menu> ^#(#{UI.Menu} #( #(#{UI.MenuItem} #rawLabel: 'expand' #value: #expand ) #(#{UI.MenuItem} #rawLabel: 'expand fully' #value: #expandFully ) #(#{UI.MenuItem} #rawLabel: 'contract' #value: #contractFully ) ) #(2 1 ) nil ) decodeAsLiteralArray
</methods> <methods> Examples.AdvancedTreeViewExample class <category>interface specs</category>
windowSpec "UIPainter new openOnClass: self andSelector: #windowSpec" <resource: #canvas> ^#(#{UI.FullSpec} #window: #(#{UI.WindowSpec} #label: 'Advanced Tree Demo' #bounds: #(#{Graphics.Rectangle} 700 498 900 703 ) #isEventDriven: true ) #component: #(#{UI.SpecCollection} #collection: #( #(#{UI.TreeViewSpec} #layout: #(#{Graphics.LayoutFrame} 5 0 5 0 -5 1 -5 1 ) #name: #treeView #model: #treeView #callbacksSpec: #(#{UI.UIEventCallbackSubSpec} #doubleClickSelector: #doubleClick: ) #menu: #treeViewMenu #useIcons: #none #autoSelect: true ) ) ) )
</methods> <methods> Examples.TreeTestNode class <category>resources</category>
img0 "UIMaskEditor new openOnClass: self andSelector: #img0" <resource: #image> ^CachedImage on: (Image extent: 16@16 depth: 1 bitsPerPixel: 1 palette: (MappedPalette withColors: ((Array new: 2) at: 1 put: ColorValue lightGray; at: 2 put: ColorValue red; yourself)) usingBits: #[0 0 0 0 7 224 0 0 7 240 0 0 12 48 0 0 12 48 0 0 12 48 0 0 12 48 0 0 12 48 0 0 12 48 0 0 12 48 0 0 12 48 0 0 12 48 0 0 12 48 0 0 15 240 0 0 3 224 0 0 0 0 0 0])
img1 "UIMaskEditor new openOnClass: self andSelector: #img1" <resource: #image> ^CachedImage on: (Image extent: 16@16 depth: 1 bitsPerPixel: 1 palette: (MappedPalette withColors: ((Array new: 2) at: 1 put: ColorValue lightGray; at: 2 put: ColorValue red; yourself)) usingBits: #[0 0 0 0 0 64 0 0 1 224 0 0 3 224 0 0 3 96 0 0 7 96 0 0 6 96 0 0 6 96 0 0 4 96 0 0 0 96 0 0 0 96 0 0 0 96 0 0 0 96 0 0 0 96 0 0 0 64 0 0 0 0 0 0])
img2 "UIMaskEditor new openOnClass: self andSelector: #img2" <resource: #image> ^CachedImage on: (Image extent: 16@16 depth: 1 bitsPerPixel: 1 palette: (MappedPalette withColors: ((Array new: 2) at: 1 put: ColorValue lightGray; at: 2 put: ColorValue red; yourself)) usingBits: #[0 0 0 0 3 128 0 0 15 192 0 0 12 96 0 0 12 48 0 0 0 48 0 0 0 48 0 0 0 96 0 0 0 192 0 0 1 128 0 0 3 0 0 0 6 0 0 0 12 0 0 0 15 224 0 0 15 224 0 0 0 0 0 0])
img3 "UIMaskEditor new openOnClass: self andSelector: #img3" <resource: #image> ^CachedImage on: (Image extent: 16@16 depth: 1 bitsPerPixel: 1 palette: (MappedPalette withColors: ((Array new: 2) at: 1 put: ColorValue lightGray; at: 2 put: ColorValue red; yourself)) usingBits: #[0 0 0 0 3 128 0 0 15 192 0 0 12 96 0 0 12 48 0 0 0 48 0 0 0 112 0 0 3 224 0 0 3 224 0 0 0 112 0 0 0 48 0 0 12 48 0 0 12 96 0 0 15 192 0 0 3 128 0 0 0 0 0 0])
img4 "UIMaskEditor new openOnClass: self andSelector: #img4" <resource: #image> ^CachedImage on: (Image extent: 16@16 depth: 1 bitsPerPixel: 1 palette: (MappedPalette withColors: ((Array new: 2) at: 1 put: ColorValue lightGray; at: 2 put: ColorValue red; yourself)) usingBits: #[0 0 0 0 0 0 0 0 12 0 0 0 12 0 0 0 12 0 0 0 13 128 0 0 13 128 0 0 13 128 0 0 15 240 0 0 15 240 0 0 1 128 0 0 1 128 0 0 1 128 0 0 1 128 0 0 1 128 0 0 0 0 0 0])
</methods> <methods> Examples.TreeViewExample class <category>interface specs</category>
editingTestNodesSpec "UIPainter new openOnClass: self andSelector: #editingTestNodesSpec" <resource: #canvas> ^#(#{UI.FullSpec} #window: #(#{UI.WindowSpec} #label: 'TreeView Example:Edit Nodes' #bounds: #(#{Graphics.Rectangle} 700 498 900 703 ) ) #component: #(#{UI.SpecCollection} #collection: #( #(#{UI.InputFieldSpec} #layout: #(#{Graphics.LayoutFrame} 0 0 0 0 0 0 0 0 ) #isOpaque: true ) #(#{UI.InputFieldSpec} #layout: #(#{Graphics.LayoutFrame} 0 0 0 0 0 0 0 0 ) #isOpaque: true ) #(#{UI.InputFieldSpec} #layout: #(#{Graphics.LayoutFrame} 0 0 0 0 0 0 0 0 ) #isOpaque: true ) #(#{UI.InputFieldSpec} #layout: #(#{Graphics.LayoutFrame} 0 0 0 0 0 0 0 0 ) #isOpaque: true ) #(#{UI.ActionButtonSpec} #layout: #(#{Graphics.LayoutFrame} -95 1 -30 1 -5 1 -5 1 ) #model: #closeRequest #label: 'Exit' #defaultable: true ) #(#{UI.TreeViewSpec} #layout: #(#{Graphics.LayoutFrame} 5 0 5 0 -5 1 -35 1 ) #model: #treeView #displayStringSelector: #mayEditedDisplayString #useIcons: #folder #autoSelect: true #inPlaceEditedSelector: #inPlaceEdited: ) #(#{UI.InputFieldSpec} #layout: #(#{Graphics.LayoutFrame} 0 0 0 0 0 0 0 0 ) #isOpaque: true ) ) ) )
testNodesAsTextSpec "UIPainter new openOnClass: self andSelector: #testNodesAsTextSpec" <resource: #canvas> ^#(#{UI.FullSpec} #window: #(#{UI.WindowSpec} #label: 'TreeView Example:Nodes As Text' #bounds: #(#{Graphics.Rectangle} 700 498 900 703 ) ) #component: #(#{UI.SpecCollection} #collection: #( #(#{UI.TreeViewSpec} #layout: #(#{Graphics.LayoutFrame} 5 0 5 0 -5 1 -5 1 ) #name: #treeView #model: #treeView #menu: #treeViewMenu #displayStringSelector: #printStringInTestApp #useIcons: #none #autoSelect: true ) ) ) )
testNodesWithIconsSpec "UIPainter new openOnClass: self andSelector: #testNodesWithIconsSpec" <resource: #canvas> ^#(#{UI.FullSpec} #window: #(#{UI.WindowSpec} #label: 'TreeView Example:Nodes With Icons' #bounds: #(#{Graphics.Rectangle} 700 498 900 703 ) ) #component: #(#{UI.SpecCollection} #collection: #( #(#{UI.TreeViewSpec} #layout: #(#{Graphics.LayoutFrame} 5 0 5 0 -5 1 -5 1 ) #name: #treeView #model: #treeView #useIcons: #other #iconSelectors: #(#zeroImage #childrenImage ) #autoSelect: false ) ) ) )
windowSpec "UIPainter new openOnClass: self andSelector: #windowSpec" <resource: #canvas> ^#(#{UI.FullSpec} #window: #(#{UI.WindowSpec} #label: 'TreeView Example' #bounds: #(#{Graphics.Rectangle} 700 498 900 703 ) ) #component: #(#{UI.SpecCollection} #collection: #( #(#{UI.TreeViewSpec} #layout: #(#{Graphics.LayoutFrame} 5 0 5 0 -5 1 -5 1 ) #name: #treeView #model: #treeView #menu: #treeViewMenu #useIcons: #folder #autoSelect: true ) ) ) )
</methods> <methods> Examples.TreeViewExample class <category>resources</category>
treeViewMenu "MenuEditor new openOnClass: self andSelector: #treeViewMenu" <resource: #menu> ^#(#{UI.Menu} #( #(#{UI.MenuItem} #rawLabel: 'expand' #value: #expand ) #(#{UI.MenuItem} #rawLabel: 'expand fully' #value: #expandFully ) #(#{UI.MenuItem} #rawLabel: 'contract' #value: #contractFully ) #(#{UI.MenuItem} #rawLabel: 'inspect' #value: #inspectItem ) ) #(2 1 1 ) nil ) decodeAsLiteralArray
</methods> "Imported Classes:" self error: 'Attempting to file-in parcel imports. Choose terminate or close' <class> <name>Object</name> <environment>Core</environment> <super></super> <private>false</private> none <imports></imports> <category>Kernel-Objects</category> <attributes> <package>Kernel-Objects</package> </attributes> </class> <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>