SelectionInHierarchyView.st
author Claus Gittinger <cg@exept.de>
Fri, 11 Oct 1996 16:41:20 +0200
changeset 253 01498f4ffcca
parent 252 4db843d36c46
child 254 d6272997aba4
permissions -rw-r--r--
comment

SelectionInListView subclass:#SelectionInHierarchyView
	instanceVariableNames:'itemList showConnectingLines itemClass'
	classVariableNames:''
	poolDictionaries:''
	category:'Views-Text'
!

!SelectionInHierarchyView  class methodsFor:'documentation'!

ation'!

documentation
"
    somewhat like a SelectionInListView; but specialized for hierarchical (i.e. tree-like)
    lists and adds the functions to show/hide subtrees. 
    Requires SelectionInHierarchy as model and HierarchyNode (or compatible) list entries.
    See examples.

    [Author:]
        W. Olberding AEG Factory Automation

    [See also:]
        SelectionInHierarchy HierarchyNode
        SelectionInListView
"
!

examples
"
    shows the tree of smalltalk classes:
                                                                        [exBegin]
      |top hierarchy hierarchyV scroller|

      hierarchy := SelectionInHierarchy new.
      hierarchy root:(HierarchyNode newAsTreeFromSmalltalkClass:Object).
      hierarchy setHideToChildren:true startingAt:hierarchy root.

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

      hierarchyV := SelectionInHierarchyView new.
      hierarchyV model: hierarchy.
      hierarchyV action:[:nr | Transcript show:'selected:'; showCR:nr].

      top add:(ScrollableView forView:hierarchyV)
          in:((0.0 @ 0.0 ) corner:( 1.0 @ 1.0)).
      top open.
                                                                        [exEnd]

    same, with nice connecting links:
                                                                        [exBegin]
      |top hierarchy hierarchyV scroller|

      hierarchy := SelectionInHierarchy new.
      hierarchy root:(HierarchyNode newAsTreeFromSmalltalkClass:Object).
      hierarchy setHideToChildren:true startingAt:hierarchy root.

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

      hierarchyV := SelectionInHierarchyView new.
      hierarchyV showConnectingLines:true.
      hierarchyV model: hierarchy.
      hierarchyV action:[:nr | Transcript show:'selected:'; showCR:nr].

      top add:(ScrollableView forView:hierarchyV)
          in:((0.0 @ 0.0 ) corner:( 1.0 @ 1.0)).
      top open.
                                                                        [exEnd]
"
! !

!SelectionInHierarchyView methodsFor:'accessing'!

textLine nextPutAll: '[-]'.
		   ]ifFalse:[textLine nextPutAll:((Character value:18)printString).].
		].

		textLine nextPutAll:' ', aNode name.
		textLine contents.
	    ].
	].

       ^textList

	"Modified: 10.10.94 / 16:13:39 / W.Olberding"
! !

!SelectionInHierarchyView methodsFor:'event handling'!

buttonPress:button x:x y:y
    |oldSelection listLineNr|

    ((button == 1) or:[button == #select]) ifTrue:[
        enabled ifTrue:[
            oldSelection := selection.
            listLineNr := self visibleLineToListLine:(self visibleLineOfY:y).
            (selectConditionBlock isNil or:[selectConditionBlock value:listLineNr]) ifTrue:[
                listLineNr notNil ifTrue: [
                    self selectWithoutScroll:listLineNr
                ].
                ((ignoreReselect not and:[selection notNil])
                 or:[selection ~= oldSelection]) ifTrue:[
                    "actionBlock notNil ifTrue:[actionBlock value:selection]."
                    "the ST-80 way of doing things"
                    model notNil ifTrue:[
                        model perform:#selectionIndex: with:(selection)
                    ]
                ].
                clickLine := listLineNr
            ]
        ]
    ] ifFalse:[
        super buttonPress:button x:x y:y
    ]

        "Modified: 10.10.94 / 17:13:38 / W.Olberding"
        "Modified: 08.11.94 / 15:38:43 / R.Sailer"
!

ne:(self visibleLineOfY:y).
            (selectConditionBlock isNil or:[selectConditionBlock value:listLineNr]) ifTrue:[
                listLineNr notNil ifTrue: [
                    self selectWithoutScroll:listLineNr
                ].
                ((ignoreReselect not and:[selection notNil])
                 or:[selection ~= oldSelection]) ifTrue:[
                    "actionBlock notNil ifTrue:[actionBlock value:selection]."
                    "the ST-80 way of doing things"
                    model notNil ifTrue:[
                        model perform:#selectionIndex: with:(selection)
                    ]
                ].
                clickLine := listLineNr
            ]
        ]
    ] ifFalse:[
        super buttonPress:button x:x y:y
    ]

        "Modified: 10.10.94 / 17:13:38 / W.Olberding"
        "Modified: 08.11.94 / 15:38:43 / R.Sailer"
!

((button == 1) or:[button == #select]) ifTrue:[
        enabled ifTrue:[
            oldSelection := selection.
            listLineNr := self visibleLineToListLine:(self visibleLineOfY:y).
            (selectConditionBlock isNil or:[selectConditionBlock value:listLineNr]) ifTrue:[
                listLineNr notNil ifTrue: [
                    self selectWithoutScroll:listLineNr
                ].
                ((ignoreReselect not and:[selection notNil])
                 or:[selection ~= oldSelection]) ifTrue:[
                    "actionBlock notNil ifTrue:[actionBlock value:selection]."
                    "the ST-80 way of doing things"
                    model notNil ifTrue:[
                        model perform:#selectionIndex: with:(selection)
                    ]
                ].
                clickLine := listLineNr
            ]
        ]
    ] ifFalse:[
        super buttonPress:button x:x y:y
    ]

        "Modified: 10.10.94 / 17:13:38 / W.Olberding"
        "Modified: 08.11.94 / 15:38:43 / R.Sailer"
!

selectionIndex: anIndex
        "Pass the selection along to the model."

        super selection:  anIndex.
        model selection:  anIndex.

        "Modified: 10.10.94 / 16:13:38 / W.Olberding"
! !

!SelectionInHierarchyView methodsFor:'initialization'!

:aNode)ifTrue:[
			 textLine nextPutAll:((Character value:14)printString).
			 treeLevels remove:(aNode level).
		    ]ifFalse:[
			textLine nextPutAll:((Character value:21)printString).
		    ].
		    textLine nextPutAll:((Character value:18)printString).
		].
		aNode isExpandable ifTrue: [
		    textLine nextPutAll: '[+]'.
		]ifFalse:[
		    aNode isCollapsable ifTrue: [
		       textLine nextPutAll: '[-]'.
		   ]ifFalse:[textLine nextPutAll:((Character value:18)printString).].
		].

		textLine nextPutAll:' ', aNode name.
		textLine contents.
	    ].
	].

       ^textList

	"Modified: 10.10.94 / 16:13:39 / W.Olberding"
!

.
		aNode isExpandable ifTrue: [
		    textLine nextPutAll: '[+]'.
		]ifFalse:[
		    aNode isCollapsable ifTrue: [
		       textLine nextPutAll: '[-]'.
		   ]ifFalse:[textLine nextPutAll:((Character value:18)printString).].
		].

		textLine nextPutAll:' ', aNode name.
		textLine contents.
	    ].
	].

       ^textList

	"Modified: 10.10.94 / 16:13:39 / W.Olberding"
! !

!SelectionInHierarchyView methodsFor:'model access'!

.
		aNode isExpandable ifTrue: [
		    textLine nextPutAll: ' ...'.
		].
		textLine contents.
	    ].
	] ifTrue:[
	    isLastOnLevel:=Set new.
	    treeLevels:=Set new.
	    oldLevel:=0.

	    listOfNodes reverseDo: [ :aNode |
		(treeLevels includes:(aNode level)) ifFalse:[
		    isLastOnLevel add:aNode.
		    treeLevels add:(aNode level).
		].
		aNode level < oldLevel ifTrue:[
		    treeLevels remove:oldLevel.
		].
		oldLevel:=aNode level.
	    ].

	    treeLevels:=Set new.
	    oldLevel:=0.
	    textList := listOfNodes collect: [ :aNode |
		textLine := ReadWriteStream on: String new.

		1 to:((aNode level)-1) do: [ :l |
		    (treeLevels includes:l) ifTrue:[
			textLine space; nextPutAll:((Character value:25)printString); space.
		    ]ifFalse:[
			textLine space; space; space.
		    ]
		].
		treeLevels add:(aNode level).
		oldLevel:=aNode level.

		(aNode = (listOfNodes first)) ifFalse:[
		    textLine space.
		    (isLastOnLevel includes:aNode)ifTrue:[
			 textLine nextPutAll:((Character value:14)printString).
			 treeLevels remove:(aNode level).
		    ]ifFalse:[
			textLine nextPutAll:((Character value:21)printString).
		    ].
		    textLine nextPutAll:((Character value:18)printString).
		].
		aNode isExpandable ifTrue: [
		    textLine nextPutAll: '[+]'.
		]ifFalse:[
		    aNode isCollapsable ifTrue: [
		       textLine nextPutAll: '[-]'.
		   ]ifFalse:[textLine nextPutAll:((Character value:18)printString).].
		].

		textLine nextPutAll:' ', aNode name.
		textLine contents.
	    ].
	].

       ^textList

	"Modified: 10.10.94 / 16:13:39 / W.Olberding"
!

]
                ].
                clickLine := listLineNr
            ]
        ]
    ] ifFalse:[
        super buttonPress:button x:x y:y
    ]

        "Modified: 10.10.94 / 17:13:38 / W.Olberding"
        "Modified: 08.11.94 / 15:38:43 / R.Sailer"
!

getSelectionFromModel
      "Get the current list selection from model. "

    ^  model selectionIndex

        "Modified: 10.10.94 / 16:13:39 / W.Olberding"
!

rue:[actionBlock value:selection]."
                    "the ST-80 way of doing things"
                    model notNil ifTrue:[
                        model perform:#selectionIndex: with:(selection)
                    ]
                ].
                clickLine := listLineNr
            ]
        ]
    ] ifFalse:[
        super buttonPress:button x:x y:y
    ]

        "Modified: 10.10.94 / 17:13:38 / W.Olberding"
        "Modified: 08.11.94 / 15:38:43 / R.Sailer"
! !

!SelectionInHierarchyView methodsFor:'private'!

to:((aNode level)-1) do: [ :l |
		    (treeLevels includes:l) ifTrue:[
			textLine space; nextPutAll:((Character value:25)printString); space.
		    ]ifFalse:[
			textLine space; space; space.
		    ]
		].
		treeLevels add:(aNode level).
		oldLevel:=aNode level.

		(aNode = (listOfNodes first)) ifFalse:[
		    textLine space.
		    (isLastOnLevel includes:aNode)ifTrue:[
			 textLine nextPutAll:((Character value:14)printString).
			 treeLevels remove:(aNode level).
		    ]ifFalse:[
			textLine nextPutAll:((Character value:21)printString).
		    ].
		    textLine nextPutAll:((Character value:18)printString).
		].
		aNode isExpandable ifTrue: [
		    textLine nextPutAll: '[+]'.
		]ifFalse:[
		    aNode isCollapsable ifTrue: [
		       textLine nextPutAll: '[-]'.
		   ]ifFalse:[textLine nextPutAll:((Character value:18)printString).].
		].

		textLine nextPutAll:' ', aNode name.
		textLine contents.
	    ].
	].

       ^textList

	"Modified: 10.10.94 / 16:13:39 / W.Olberding"
! !

!SelectionInHierarchyView methodsFor:'updating'!

seDo: [ :aNode |
		(treeLevels includes:(aNode level)) ifFalse:[
		    isLastOnLevel add:aNode.
		    treeLevels add:(aNode level).
		].
		aNode level < oldLevel ifTrue:[
		    treeLevels remove:oldLevel.
		].
		oldLevel:=aNode level.
	    ].

	    treeLevels:=Set new.
	    oldLevel:=0.
	    textList := listOfNodes collect: [ :aNode |
		textLine := ReadWriteStream on: String new.

		1 to:((aNode level)-1) do: [ :l |
		    (treeLevels includes:l) ifTrue:[
			textLine space; nextPutAll:((Character value:25)printString); space.
		    ]ifFalse:[
			textLine space; space; space.
		    ]
		].
		treeLevels add:(aNode level).
		oldLevel:=aNode level.

		(aNode = (listOfNodes first)) ifFalse:[
		    textLine space.
		    (isLastOnLevel includes:aNode)ifTrue:[
			 textLine nextPutAll:((Character value:14)printString).
			 treeLevels remove:(aNode level).
		    ]ifFalse:[
			textLine nextPutAll:((Character value:21)printString).
		    ].
		    textLine nextPutAll:((Character value:18)printString).
		].
		aNode isExpandable ifTrue: [
		    textLine nextPutAll: '[+]'.
		]ifFalse:[
		    aNode isCollapsable ifTrue: [
		       textLine nextPutAll: '[-]'.
		   ]ifFalse:[textLine nextPutAll:((Character value:18)printString).].
		].

		textLine nextPutAll:' ', aNode name.
		textLine contents.
	    ].
	].

       ^textList

	"Modified: 10.10.94 / 16:13:39 / W.Olberding"
! !

!SelectionInHierarchyView  class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libwidg2/SelectionInHierarchyView.st,v 1.5 1996-10-11 14:41:20 cg Exp $'
! !