SelectionInHierarchy.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Wed, 30 May 2018 09:34:26 +0100
branchjv
changeset 5814 70d07365a2d4
parent 3874 9accac7cbf67
child 5459 9f38d94ea752
permissions -rw-r--r--
Copyright updates
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
84
4478ea2d40c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"
4478ea2d40c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
 COPYRIGHT (c) 1994 by AEG Industry Automation
4478ea2d40c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
 COPYRIGHT (c) 1994 by Claus Gittinger
4478ea2d40c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
	      All Rights Reserved
4478ea2d40c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
4478ea2d40c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
 This software is furnished under a license and may be used
4478ea2d40c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 only in accordance with the terms of that license and with the
4478ea2d40c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 inclusion of the above copyright notice.   This software may not
4478ea2d40c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 be provided or otherwise made available to, or used by, any
4478ea2d40c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 other person.  No title to or ownership of the software is
4478ea2d40c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
 hereby transferred.
4478ea2d40c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
"
1818
fe99c5c721e9 category changes
Claus Gittinger <cg@exept.de>
parents: 1191
diff changeset
    13
"{ Package: 'stx:libwidg2' }"
fe99c5c721e9 category changes
Claus Gittinger <cg@exept.de>
parents: 1191
diff changeset
    14
84
4478ea2d40c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
Model subclass:#SelectionInHierarchy
252
4db843d36c46 comment & #selectionIndex:
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    16
	instanceVariableNames:'root list selection'
4db843d36c46 comment & #selectionIndex:
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    17
	classVariableNames:''
4db843d36c46 comment & #selectionIndex:
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    18
	poolDictionaries:''
4db843d36c46 comment & #selectionIndex:
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    19
	category:'Interface-Support-Models'
84
4478ea2d40c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
!
4478ea2d40c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
360
bff72c1dac78 comments
Claus Gittinger <cg@exept.de>
parents: 254
diff changeset
    22
!SelectionInHierarchy class methodsFor:'documentation'!
84
4478ea2d40c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
254
Claus Gittinger <cg@exept.de>
parents: 253
diff changeset
    24
copyright 
84
4478ea2d40c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
"
4478ea2d40c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
 COPYRIGHT (c) 1994 by AEG Industry Automation
4478ea2d40c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
 COPYRIGHT (c) 1994 by Claus Gittinger
4478ea2d40c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
	      All Rights Reserved
4478ea2d40c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
4478ea2d40c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
 This software is furnished under a license and may be used
4478ea2d40c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
 only in accordance with the terms of that license and with the
4478ea2d40c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
 inclusion of the above copyright notice.   This software may not
4478ea2d40c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 be provided or otherwise made available to, or used by, any
4478ea2d40c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
 other person.  No title to or ownership of the software is
4478ea2d40c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
 hereby transferred.
4478ea2d40c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
"
4478ea2d40c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
!
4478ea2d40c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
4478ea2d40c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
documentation
4478ea2d40c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
"
4478ea2d40c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
    model for a selection in a hierarchical list.
4478ea2d40c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
    See examples in SelectionInHierarchyView.
252
4db843d36c46 comment & #selectionIndex:
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    43
1189
0c2cf8ee62e3 comment
Claus Gittinger <cg@exept.de>
parents: 451
diff changeset
    44
    Notice: this class was provided for free by a customer
0c2cf8ee62e3 comment
Claus Gittinger <cg@exept.de>
parents: 451
diff changeset
    45
            It is more or less obsoleted by SelectionInTree, which provides
0c2cf8ee62e3 comment
Claus Gittinger <cg@exept.de>
parents: 451
diff changeset
    46
            similar (but more sphisticated) functionality.
0c2cf8ee62e3 comment
Claus Gittinger <cg@exept.de>
parents: 451
diff changeset
    47
            SelectionInHierarchy remains in the system for backward compatibility.
0c2cf8ee62e3 comment
Claus Gittinger <cg@exept.de>
parents: 451
diff changeset
    48
252
4db843d36c46 comment & #selectionIndex:
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    49
    [Author:]
4db843d36c46 comment & #selectionIndex:
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    50
        W. Olberding AEG Factory Automation
4db843d36c46 comment & #selectionIndex:
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    51
4db843d36c46 comment & #selectionIndex:
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    52
    [See also:]
360
bff72c1dac78 comments
Claus Gittinger <cg@exept.de>
parents: 254
diff changeset
    53
        HierarchyNode
254
Claus Gittinger <cg@exept.de>
parents: 253
diff changeset
    54
        SelectionInHierarchyView
1191
8d371ffa3adf comment
Claus Gittinger <cg@exept.de>
parents: 1189
diff changeset
    55
        SelectionInTree SelectionInTreeView TreeItem
84
4478ea2d40c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
"
4478ea2d40c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
! !
4478ea2d40c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
4478ea2d40c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
!SelectionInHierarchy methodsFor:'accessing'!
4478ea2d40c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
254
Claus Gittinger <cg@exept.de>
parents: 253
diff changeset
    61
getHierarchyNodeForContents: something
360
bff72c1dac78 comments
Claus Gittinger <cg@exept.de>
parents: 254
diff changeset
    62
     "return the hierarchyNode whose contents is something"
254
Claus Gittinger <cg@exept.de>
parents: 253
diff changeset
    63
451
8ef75f2cb825 updates
ca
parents: 442
diff changeset
    64
     root notNil ifTrue:[
2928
3edcbf957953 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1818
diff changeset
    65
         ^ root allChildren detect:[:each| (each contents = something)] ifNone:nil.
254
Claus Gittinger <cg@exept.de>
parents: 253
diff changeset
    66
     ].
360
bff72c1dac78 comments
Claus Gittinger <cg@exept.de>
parents: 254
diff changeset
    67
     ^ nil
bff72c1dac78 comments
Claus Gittinger <cg@exept.de>
parents: 254
diff changeset
    68
!
254
Claus Gittinger <cg@exept.de>
parents: 253
diff changeset
    69
Claus Gittinger <cg@exept.de>
parents: 253
diff changeset
    70
list
360
bff72c1dac78 comments
Claus Gittinger <cg@exept.de>
parents: 254
diff changeset
    71
    "Answer a collection of nodes representing the
bff72c1dac78 comments
Claus Gittinger <cg@exept.de>
parents: 254
diff changeset
    72
    list of currently viewed objects."
252
4db843d36c46 comment & #selectionIndex:
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    73
360
bff72c1dac78 comments
Claus Gittinger <cg@exept.de>
parents: 254
diff changeset
    74
    ^list
254
Claus Gittinger <cg@exept.de>
parents: 253
diff changeset
    75
360
bff72c1dac78 comments
Claus Gittinger <cg@exept.de>
parents: 254
diff changeset
    76
    "Modified: 10.10.1994 / 16:13:36 / W.Olberding"
bff72c1dac78 comments
Claus Gittinger <cg@exept.de>
parents: 254
diff changeset
    77
    "Modified: 15.4.1997 / 16:29:26 / cg"
bff72c1dac78 comments
Claus Gittinger <cg@exept.de>
parents: 254
diff changeset
    78
!
254
Claus Gittinger <cg@exept.de>
parents: 253
diff changeset
    79
451
8ef75f2cb825 updates
ca
parents: 442
diff changeset
    80
root: aHierarchyNode
8ef75f2cb825 updates
ca
parents: 442
diff changeset
    81
        "Set the root object - this means initialization."
254
Claus Gittinger <cg@exept.de>
parents: 253
diff changeset
    82
451
8ef75f2cb825 updates
ca
parents: 442
diff changeset
    83
        root := aHierarchyNode.
8ef75f2cb825 updates
ca
parents: 442
diff changeset
    84
        selection := nil.
8ef75f2cb825 updates
ca
parents: 442
diff changeset
    85
        self setNewList.
8ef75f2cb825 updates
ca
parents: 442
diff changeset
    86
!
252
4db843d36c46 comment & #selectionIndex:
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    87
254
Claus Gittinger <cg@exept.de>
parents: 253
diff changeset
    88
selectedPath 
451
8ef75f2cb825 updates
ca
parents: 442
diff changeset
    89
    "Answer the pathName to the currently selected node."
8ef75f2cb825 updates
ca
parents: 442
diff changeset
    90
8ef75f2cb825 updates
ca
parents: 442
diff changeset
    91
    |node|
84
4478ea2d40c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
451
8ef75f2cb825 updates
ca
parents: 442
diff changeset
    93
    (node := self selectedNode) isNil ifFalse:[
8ef75f2cb825 updates
ca
parents: 442
diff changeset
    94
        ^ node pathName
8ef75f2cb825 updates
ca
parents: 442
diff changeset
    95
    ].
8ef75f2cb825 updates
ca
parents: 442
diff changeset
    96
    ^ ''
8ef75f2cb825 updates
ca
parents: 442
diff changeset
    97
!
254
Claus Gittinger <cg@exept.de>
parents: 253
diff changeset
    98
Claus Gittinger <cg@exept.de>
parents: 253
diff changeset
    99
setHideToChildren: aBoolean startingAt: aHierarchyNode
Claus Gittinger <cg@exept.de>
parents: 253
diff changeset
   100
Claus Gittinger <cg@exept.de>
parents: 253
diff changeset
   101
     "set the hide-Falg to aBoolean starting at aHierarchyNode down"
252
4db843d36c46 comment & #selectionIndex:
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   102
451
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   103
     root notNil ifTrue:[
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   104
         root allChildren do:[:each| each hide:aBoolean].
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   105
         self setNewList.
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   106
     ]
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   107
!
252
4db843d36c46 comment & #selectionIndex:
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   108
254
Claus Gittinger <cg@exept.de>
parents: 253
diff changeset
   109
showCompleteHierarchyStartingAtNode: aHierarchyNode
Claus Gittinger <cg@exept.de>
parents: 253
diff changeset
   110
	"Set the hide-Flag to false for the hierarchy starting at aHierarchyNode"
252
4db843d36c46 comment & #selectionIndex:
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   111
254
Claus Gittinger <cg@exept.de>
parents: 253
diff changeset
   112
	 | |
Claus Gittinger <cg@exept.de>
parents: 253
diff changeset
   113
	aHierarchyNode isNil ifTrue: [^self].
Claus Gittinger <cg@exept.de>
parents: 253
diff changeset
   114
	aHierarchyNode hideToFalseForPath.
Claus Gittinger <cg@exept.de>
parents: 253
diff changeset
   115
	self setNewList.
84
4478ea2d40c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
2928
3edcbf957953 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1818
diff changeset
   117
	"Modified: 10.10.94 / 16:13:36 / W.Olberding"
3edcbf957953 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1818
diff changeset
   118
! !
84
4478ea2d40c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   119
1818
fe99c5c721e9 category changes
Claus Gittinger <cg@exept.de>
parents: 1191
diff changeset
   120
!SelectionInHierarchy methodsFor:'accessing-sequencable'!
442
930fe1485dc2 add new features
ca
parents: 440
diff changeset
   121
930fe1485dc2 add new features
ca
parents: 440
diff changeset
   122
addChildAndSubChildren:aHierarchyNode below:existingHierarchyNode after:aChild
930fe1485dc2 add new features
ca
parents: 440
diff changeset
   123
    "Add a new HierarchyNode to the tree."
930fe1485dc2 add new features
ca
parents: 440
diff changeset
   124
930fe1485dc2 add new features
ca
parents: 440
diff changeset
   125
     existingHierarchyNode addChildAndSubChildren:aHierarchyNode after:aChild. 
930fe1485dc2 add new features
ca
parents: 440
diff changeset
   126
     self setNewList.
930fe1485dc2 add new features
ca
parents: 440
diff changeset
   127
!
930fe1485dc2 add new features
ca
parents: 440
diff changeset
   128
930fe1485dc2 add new features
ca
parents: 440
diff changeset
   129
addChildAndSubChildren:aHierarchyNode below:existingHierarchyNode at:anIndex
930fe1485dc2 add new features
ca
parents: 440
diff changeset
   130
930fe1485dc2 add new features
ca
parents: 440
diff changeset
   131
     existingHierarchyNode addChildAndSubChildren:aHierarchyNode at:anIndex.
930fe1485dc2 add new features
ca
parents: 440
diff changeset
   132
     self setNewList.
930fe1485dc2 add new features
ca
parents: 440
diff changeset
   133
! !
930fe1485dc2 add new features
ca
parents: 440
diff changeset
   134
451
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   135
!SelectionInHierarchy methodsFor:'adding & removing'!
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   136
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   137
add:aChild below:aParent
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   138
    "add a new HierarchyNode to the tree."
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   139
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   140
     aParent addChild:aChild. 
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   141
     self setNewList.
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   142
!
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   143
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   144
add: aChild  belowIndex:aParentIndex
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   145
    "Add a new HierarchyNode to the tree below the node
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   146
     which is found in the list at anIndex."
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   147
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   148
    |parent|
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   149
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   150
    parent := list at:aParentIndex ifAbsent:[ ^ nil ]. 
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   151
    self add:aChild below:parent
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   152
!
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   153
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   154
remove:aHierarchyNode
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   155
    "Remove aHierarchyNode and all its children. "
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   156
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   157
     aHierarchyNode removeYourself.   
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   158
     self setNewList.
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   159
    ^aHierarchyNode
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   160
!
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   161
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   162
removeBelow: existingHierarchyNode
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   163
    "Remove all children below an existingHierarchyNode ."
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   164
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   165
     existingHierarchyNode hasChildren ifTrue:[
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   166
        existingHierarchyNode removeAllChildren. 
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   167
        self setNewList
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   168
     ].
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   169
!
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   170
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   171
removeBelowIndex: anIndex
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   172
        "Remove all the children of aHierarchyNode 
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   173
        which is found in the list at anIndex."
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   174
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   175
       | existingHierarchyNode |
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   176
         existingHierarchyNode := list at: anIndex ifAbsent: [^nil]. 
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   177
        ^self removeBelow:existingHierarchyNode.
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   178
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   179
        "Modified: 10.10.94 / 16:13:37 / W.Olberding"
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   180
!
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   181
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   182
removeIndex: anIndex
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   183
	"Remove the HierarchyNode and all its children
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   184
	which is found in the list at anIndex."
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   185
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   186
       | existingHierarchyNode |
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   187
	 existingHierarchyNode := list at: anIndex ifAbsent: [^nil]. 
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   188
	^self remove: existingHierarchyNode.
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   189
2928
3edcbf957953 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1818
diff changeset
   190
	"Modified: 10.10.94 / 16:13:36 / W.Olberding"
3edcbf957953 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1818
diff changeset
   191
! !
451
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   192
84
4478ea2d40c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   193
!SelectionInHierarchy methodsFor:'hierarchy manipulation'!
4478ea2d40c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   194
254
Claus Gittinger <cg@exept.de>
parents: 253
diff changeset
   195
collapse 
451
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   196
    "If possible, collapse the tree  at the currently selected node.
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   197
     The tree structure can be restored again with #expand. "
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   198
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   199
    |node|
84
4478ea2d40c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   200
451
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   201
    (node := self selectedNode) notNil ifTrue:[
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   202
        node isCollapsable ifTrue:[
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   203
            node collapse.
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   204
            self setNewList
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   205
        ]
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   206
    ]
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   207
!
252
4db843d36c46 comment & #selectionIndex:
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   208
254
Claus Gittinger <cg@exept.de>
parents: 253
diff changeset
   209
collapseAll 
451
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   210
    "If possible, collapse the tree at the currently selected node.
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   211
     A latter #expand will show the next hierarchy level"
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   212
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   213
    |node|
254
Claus Gittinger <cg@exept.de>
parents: 253
diff changeset
   214
451
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   215
    (node := self selectedNode) notNil ifTrue:[
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   216
        node isCollapsable ifTrue:[
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   217
            node collapseAll.
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   218
            self setNewList
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   219
        ]
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   220
    ]
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   221
!
84
4478ea2d40c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   222
254
Claus Gittinger <cg@exept.de>
parents: 253
diff changeset
   223
expand 
451
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   224
    "If possible, expand  the tree 
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   225
     at the currently selected node."
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   226
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   227
    |node|
254
Claus Gittinger <cg@exept.de>
parents: 253
diff changeset
   228
451
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   229
    (node := self selectedNode) notNil ifTrue:[
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   230
        node isExpandable ifTrue:[
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   231
            node expand.
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   232
            self setNewList
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   233
        ]
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   234
    ]
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   235
!
254
Claus Gittinger <cg@exept.de>
parents: 253
diff changeset
   236
Claus Gittinger <cg@exept.de>
parents: 253
diff changeset
   237
expandAll 
451
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   238
    "If possible, expand  the tree compleately to all leaves
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   239
     at the currently selected node."
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   240
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   241
    |node|
84
4478ea2d40c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   242
451
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   243
    (node := self selectedNode) notNil ifTrue:[
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   244
        node expandAll.
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   245
        self setNewList
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   246
    ]
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   247
!
254
Claus Gittinger <cg@exept.de>
parents: 253
diff changeset
   248
Claus Gittinger <cg@exept.de>
parents: 253
diff changeset
   249
hideShow
451
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   250
   "If possible, expand or collaps the tree 
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   251
    at the currently selected node."
254
Claus Gittinger <cg@exept.de>
parents: 253
diff changeset
   252
451
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   253
    |node|
254
Claus Gittinger <cg@exept.de>
parents: 253
diff changeset
   254
451
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   255
    (node := self selectedNode) notNil ifTrue:[
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   256
        node isExpandable ifTrue:[
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   257
            node expand
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   258
        ] ifFalse:[
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   259
            node isCollapsable ifFalse:[ ^ self ].
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   260
            node collapse
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   261
        ].
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   262
        self setNewList
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   263
    ]
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   264
! !
84
4478ea2d40c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   265
252
4db843d36c46 comment & #selectionIndex:
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   266
!SelectionInHierarchy methodsFor:'private'!
84
4478ea2d40c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   267
254
Claus Gittinger <cg@exept.de>
parents: 253
diff changeset
   268
setNewList
451
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   269
    "Travers the tree and build a new list."
254
Claus Gittinger <cg@exept.de>
parents: 253
diff changeset
   270
451
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   271
    root notNil ifTrue:[
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   272
        list := root withAllShownChildren
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   273
    ] ifFalse:[
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   274
        list := #()
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   275
    ].
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   276
    self changed:#list.
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   277
! !
252
4db843d36c46 comment & #selectionIndex:
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   278
4db843d36c46 comment & #selectionIndex:
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   279
!SelectionInHierarchy methodsFor:'selection'!
4db843d36c46 comment & #selectionIndex:
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   280
4db843d36c46 comment & #selectionIndex:
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   281
doubleClickSelection: anIndex
451
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   282
    "Set the current selected object to be the element
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   283
    at anIndex of the selection list.
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   284
    Also expand or collapse the tree at that point."
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   285
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   286
    self selectionIndex:anIndex.  
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   287
    self hideShow.
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   288
!
252
4db843d36c46 comment & #selectionIndex:
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   289
451
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   290
selectedNode
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   291
    "returns current selected node or nil
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   292
    "
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   293
    (selection isNil or:[selection == 0]) ifFalse:[
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   294
        ^ list at:selection
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   295
    ].
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   296
    ^ nil
252
4db843d36c46 comment & #selectionIndex:
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   297
!
4db843d36c46 comment & #selectionIndex:
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   298
4db843d36c46 comment & #selectionIndex:
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   299
selection
451
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   300
    "get the selection or nil
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   301
    "
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   302
    ^ self selectionIndex
252
4db843d36c46 comment & #selectionIndex:
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   303
!
4db843d36c46 comment & #selectionIndex:
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   304
451
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   305
selection:anIndexOrNil
3874
9accac7cbf67 comment/format in: #selection:
Claus Gittinger <cg@exept.de>
parents: 2928
diff changeset
   306
    "set the selection"
9accac7cbf67 comment/format in: #selection:
Claus Gittinger <cg@exept.de>
parents: 2928
diff changeset
   307
451
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   308
    self selectionIndex:anIndexOrNil
252
4db843d36c46 comment & #selectionIndex:
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   309
!
4db843d36c46 comment & #selectionIndex:
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   310
4db843d36c46 comment & #selectionIndex:
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   311
selectionIndex
451
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   312
    "get the selection or nil
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   313
    "
252
4db843d36c46 comment & #selectionIndex:
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   314
    ^ selection
4db843d36c46 comment & #selectionIndex:
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   315
!
4db843d36c46 comment & #selectionIndex:
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   316
451
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   317
selectionIndex:anIndexOrNil
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   318
    "set the selection
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   319
    "
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   320
    anIndexOrNil == selection ifFalse:[
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   321
        anIndexOrNil == 0 ifTrue:[
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   322
            selection isNil ifTrue:[^ self ].
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   323
            selection := nil
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   324
        ] ifFalse:[
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   325
            selection := anIndexOrNil
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   326
        ].
252
4db843d36c46 comment & #selectionIndex:
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   327
        self changed: #selection.
451
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   328
     ]
252
4db843d36c46 comment & #selectionIndex:
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   329
! !
4db843d36c46 comment & #selectionIndex:
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   330
4db843d36c46 comment & #selectionIndex:
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   331
!SelectionInHierarchy methodsFor:'testing & debugging'!
4db843d36c46 comment & #selectionIndex:
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   332
254
Claus Gittinger <cg@exept.de>
parents: 253
diff changeset
   333
root
451
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   334
    "get the root node
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   335
    "
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   336
    ^ root
8ef75f2cb825 updates
ca
parents: 442
diff changeset
   337
! !
252
4db843d36c46 comment & #selectionIndex:
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   338
360
bff72c1dac78 comments
Claus Gittinger <cg@exept.de>
parents: 254
diff changeset
   339
!SelectionInHierarchy class methodsFor:'documentation'!
252
4db843d36c46 comment & #selectionIndex:
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   340
4db843d36c46 comment & #selectionIndex:
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   341
version
3874
9accac7cbf67 comment/format in: #selection:
Claus Gittinger <cg@exept.de>
parents: 2928
diff changeset
   342
    ^ '$Header: /cvs/stx/stx/libwidg2/SelectionInHierarchy.st,v 1.14 2010-02-01 12:20:22 cg Exp $'
9accac7cbf67 comment/format in: #selection:
Claus Gittinger <cg@exept.de>
parents: 2928
diff changeset
   343
!
9accac7cbf67 comment/format in: #selection:
Claus Gittinger <cg@exept.de>
parents: 2928
diff changeset
   344
9accac7cbf67 comment/format in: #selection:
Claus Gittinger <cg@exept.de>
parents: 2928
diff changeset
   345
version_CVS
9accac7cbf67 comment/format in: #selection:
Claus Gittinger <cg@exept.de>
parents: 2928
diff changeset
   346
    ^ '$Header: /cvs/stx/stx/libwidg2/SelectionInHierarchy.st,v 1.14 2010-02-01 12:20:22 cg Exp $'
252
4db843d36c46 comment & #selectionIndex:
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   347
! !