eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'TreeItem':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: TreeItem


Inheritance:

   Object
   |
   +--TreeItem
      |
      +--FileSelectionItem
      |
      +--TreeItemWithImage

Package:
stx:libwidg2
Category:
Interface-Support
Version:
rev: 1.73 date: 2023/09/07 21:39:17
user: stefan
file: TreeItem.st directory: libwidg2
module: stx stc-classLibrary: libwidg2

Description:


THIS CLASS HAS BEEN OBSOLETED by HierarchicalItem with its corresponding
view class HierarchicalListView. Please use these new ones.

Class to build up tree-like structures to represent file-trees, class tress etc.
Especially suited for use with (also now obsolete) SelectionInTree and SelectionInTreeView.

copyright

COPYRIGHT (c) 1997 by eXept Software AG / Claus Gittinger All Rights Reserved This software is furnished under a license and may be used only in accordance with the terms of that license and with the inclusion of the above copyright notice. This software may not be provided or otherwise made available to, or used by, any other person. No title to or ownership of the software is hereby transferred.

Class protocol:

class initialization
o  initialize
self initialize

default icons
o  keysAndIcons
returns an IdentityDictionary containing a list of images and keys used
by any file entry; could be redefined by subclass

example-instance creation
o  newAsTreeFromNestedList: aListOfElementsOrSublists named: name
create a tree of nodes with fix elements from aListOfElementsOrSublists.
The tree will contain leafs for any non-collection elements in aListOfElementsOrSublists,
and sub-trees for 2-element array-elements.
Useful to be shown in long selection lists, if some grouping is possible

Usage example(s):

      |top model sel root|

      root  := TreeItem 
                newAsTreeFromNestedList:
                    #(
                        'one-1'
                        'two-1'
                        ('three...' 
                            ('three-1'
                             'three-2'
                             'three-3'))
                        'four-1'
                        ('five...' 
                            ('five-1'
                             'five-2'
                             'five-3'
                             'five-4'
                             'five-5'))
                        ('six...' 
                            ('six-1' 
                             'six-2' 
                             ('six-3...' 
                                ('six-3-1' 
                                 'six-3-2'
                                 'six-3-3'))
                             'six-4'
                             ('six-5...'
                                ('six-5-1' 
                                 'five-5-2'))
                             ) 
                        )    
                        'seven-1'
                    ).
      root expand.
      model := SelectionInTree new root:root.

      top := StandardSystemView new.
      top extent:300@300.

      sel := SelectionInTreeView new.
      sel showDirectoryIndicator:true.
      sel showRoot:false.
      sel imageOpened:nil.
      sel imageClosed:nil.
      sel imageItem:nil.
      sel model: model.
      sel action:[:nr | Transcript show:'selected:'; showCR:nr].
      top add:(ScrollableView forView:sel) in:((0.0 @ 0.0 ) corner:( 1.0 @ 1.0)).
      top open.

o  newAsTreeFromSmalltalkClass: aClass
create a tree of nodes with aClass and all its
subclasses as contents. Set the initial level as given.

Usage example(s):

      |top model sel root|

      root  := TreeItem newAsTreeFromSmalltalkClass:ByteArray.
      root expand.
      model := SelectionInTree new root:root.
      top := StandardSystemView new.
      top extent:300@300.

      sel := SelectionInTreeView new.
      sel model: model.
      sel action:[:nr | Transcript show:'selected:'; showCR:nr].
      top add:(ScrollableView forView:sel) in:((0.0 @ 0.0 ) corner:( 1.0 @ 1.0)).
      top open.

instance creation
o  contents: aContents

o  name: aName

o  name: aName contents: aContents

o  name: aName value: aContents

o  new
(comment from inherited method)
return an instance of myself without indexed variables


Instance protocol:

accessing
o  contents
get the contents;
usually, the contents is computed lazily
i.e. #retrieveContents is invoked when the contents has not yet been set.

o  contents: something
set the contents

o  editor
returns an editor on the editable value or nil

o  hide
retrieve the hide flag

o  hide: aBoolean
set hide flag

o  icon
get the icon

o  label
for protocol compatibility with herarchical item

o  labelPath
for protocol compatibility with hierarchical item

o  level
get the nesting level

o  middleButtonMenu
returns the middleButtonMenu of the item or nil

o  name
get name

o  name: aString

o  parent
get parent

o  parent: something
set parent

o  string

o  value
get contents

o  value: something
allow TreeItem to be used as a model

accessing-children
o  basicLastChild
returns the last child without checking for valid sequence

o  children
get list of children

o  children: aCollection
set children

o  firstChild
returns first child in sequence

o  lastChild
returns the last child in sequence

o  readChildren: aBoolean
set MUSTread children flag

accessing-dimensions
o  childrenWidthOn: aDevice
returns the maximum name length of my children

accessing-hierarchy
o  allParents
return a collection of all parents (in parent, grandparent, ... order)

o  collapse
hide all my children

o  collapseAll
hide all my children and sub children

o  expand
show all my children

o  expandAll
show all my children and sub children

o  parentsDo: aBlock
evaluate a block for each parent

accessing-mvc
o  model
get my model (an instance of selection in tree) or nil

o  model: aSelectionInTree
set my model (an instance of selection in tree) or nil

o  tree
get my model (an instance of selection in tree) or nil

o  tree: aSelectionInTree
set my model (an instance of selection in tree) or nil

adding & removing
o  add: something
add a child or collection of children add end

o  add: something after: aChild
add a child or collection of children add end

o  add: something afterIndex: anIndex
add a child or collection after an index

o  add: something before: aChild
add a child or collection of children add end

o  add: something beforeIndex: anIndex
add a child or collection before an index

o  addFirst: something
add a child at the beginning

o  remove: something
remove a child or collection of children

o  removeAll
remove all children

o  removeChild: aChild
remove a aChild

o  removeIndex: anIndex
remove child at index

change & update
o  changed
node changed; raise notification to model

o  changed: what
node changed; raise notification to model

o  changedSelected
called if the node is selected

o  update: something with: aParameter from: anItem
raise change notification to my model

converting
o  fromLiteralArrayEncoding: aLiteralEncodedArray
read my contents from a aLiteralEncodedArray.

o  literalArrayEncoding
return myself encoded as a literal array

copying
o  copy
(comment from inherited method)
return a copy of the receiver - defaults to shallowcopy here.
Notice, that copy does not copy dependents.

enumerating
o  allChildrenDo: aOneArgBlock
recursively enumerate children
and evaluate a block on each child and subchildren

o  allWithParentAndChildrenDo: aTwoArgBlock

o  childrenDo: aOneArgBlock
evaluate a block on each child (excluding sub-children)

o  detectParent: aBlock
evaluate aBlock for my parent-chain;
return the parent for which it returns true

o  each: itemOrCollectionOfItems do: aOneArgBlock
evaluate a block for something or in case of a collection for each
element in the collection

initialization & release
o  initialize
setup defaults

printing & storing
o  asString
sometimes used by the SelectionInListView to get the name

o  displayOn: aGCOrStream
Compatibility
append a printed desription on some stream (Dolphin, Squeak)
OR:
display the receiver in a graphicsContext at 0@0 (ST80).
This method allows for any object to be displayed in some view
(although the fallBack is to display its printString ...)

o  printOn: aStream
sometimes used by the SelectionInListView to get the name

o  printString
sometimes used by the SelectionInListView to get the name

o  printableEditValue
returns the printable edit value or nil

queries
o  canCollapse
children existing and shown?

o  canEdit
returns true if field is editable

o  canExpand
is expandable: children exist and not already expanded

o  hasChildren
returns true if any child exists

o  hasChildrenWithSubChildren
returns true if any child exists and has children too

o  hasExpandedChildren
returns true if any of my children is expanded

o  hidden
returns true if node is not visible

o  isCollapsable
children existing and shown

** This is an obsolete interface - do not use it (it may vanish in future versions) **

o  isContainedByParent: aParent
returns true if contained in subtree of a parent

o  isExpandable
is expandable; children existing and hidden

** This is an obsolete interface - do not use it (it may vanish in future versions) **

o  isExpanded
return true if I am expanded

o  numberOfChildren
returns number of children

o  showIndicator
returns true if children exists

o  shown
returns true if node is visible

recomputation
o  addVisibleChildrenTo: aList
add all visible children and sub-children to the list

o  numberOfAllVisibleChildren
returns number of all visible children including all the children of children

retrieving
o  childrenAction
get children action block

o  contentsAction
get contents action block

o  iconAction
get icon action block

o  labelAction
get label action block

o  retrieveAll
retrieve all values from model

o  retrieveAndEvaluate: selectorToReturnABlockOrValueHolder
retrieve a specific value from the model;
if no model exists, nil is returned.

The model mist return a block or valueHolder,
which is evaluate with self as optopal argument.
So the model can compute icons, labels, etc. dynamically.

Typical selectors are:
#iconAction
#childrenAction
#contentsAction
#labelAction

o  retrieveChildren
retrieve children from model

o  retrieveContents
retrieve contents value from model;

o  retrieveLabel
retrieve label from model

searching
o  childAt: anIndex
get child at an index or nil

o  detectChild: aOneArgBlock
evaluate the block on each child;
returns the child's node or nil.
This searches my direct children only - not walking down sublevels.

o  detectChild: aTwoArgBlock arguments: args
detect a child the evaluation of the block returns true. The
first argument to the block is the item, the second argument
the value derived from the argument list at node-level ...
I.e. for each sublevel, a different block arg can be specified.
The number of arguments also defines the search level.
i.e. if you pass (1 to:10) as args, the block will get the sub-level
as second argument and stop the search after 10 levels.

o  detectFirstChild: anOneArgBlock
detect the first child which evaluation of anOneArgBlock returns true.
Recursively walks down the node-tree.

o  indexOfChild: aChild
get index of a child or 0

searching-private
o  detectChild: aTwoArgBlock arguments: args index: idxArgs
helper for limited search.
detect a child the evaluation of the block returns true. The
first argument to the block is the item, the second argument
the value derived from the argument list at an index.
This one recursively walks down the tree searching for a node.



ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Mon, 18 Nov 2024 06:30:14 GMT