Tools__BrowserListWithFilter.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Sun, 12 Feb 2012 00:06:21 +0000
branchjv
changeset 12154 f27f8ee5ef3a
parent 12146 80af7eef372f
child 12155 5eafbfc85934
permissions -rw-r--r--
More improvements in InlineMessageDialog

"
 COPYRIGHT (c) 2006 by eXept Software AG
              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.
"
"{ Package: 'stx:libtool' }"

"{ NameSpace: Tools }"

BrowserList subclass:#BrowserListWithFilter
	instanceVariableNames:'listView filterView filterPatternHolder showFilterHolder'
	classVariableNames:''
	poolDictionaries:''
	category:'Interface-Browsers-New'
!

!BrowserListWithFilter class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 2006 by eXept Software AG
              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.
"
!

documentation
"
    Abstract superclass for a browser list with user filter.
    Currently used only ChangeList and ChangeSetDiffList, but
    user filter may be usefull for class/category lists as well.

    [author:]
        Jan Vrany <jan.vrany@fit.cvut.cz>

    [instance variables:]

    [class variables:]

    [see also:]

"
! !

!BrowserListWithFilter class methodsFor:'plugIn spec'!

aspectSelectors

    ^#(
        showFilterHolder
    )

    "Created: / 11-02-2012 / 22:44:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!BrowserListWithFilter methodsFor:'accessing'!

filterPattern

    | p |
    p := filterPatternHolder value.
    ^p isEmptyOrNil ifTrue:[
        nil
    ] ifFalse:[
        StringPattern fromString: p
    ]

    "Created: / 29-11-2011 / 15:23:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

showFilter

    ^self showFilterHolder value

    "Created: / 29-11-2011 / 15:27:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!BrowserListWithFilter methodsFor:'aspects'!

filterPatternHolder
    "return/create the 'filterPatternHolder' value holder (automatically generated)"

    filterPatternHolder isNil ifTrue:[
        filterPatternHolder := ValueHolder new.
        filterPatternHolder addDependent:self.
    ].
    ^ filterPatternHolder
!

menuHolderWithShowFilter

    ^[
        | menu |
        menu := self menuHolder value copy.
        menu isArray ifTrue:[menu := Menu decodeFromLiteralArray: menu].
        menu addSeparator.
        menu addItem:
            ((MenuItem label:(self resources at: 'Show filter'))
                indication: self showFilterHolder;
                yourself).
        menu
    ]

    "Created: / 29-11-2011 / 15:40:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

showFilterHolder
    "return/create the 'showFilterHolder' value holder (automatically generated)"

    showFilterHolder isNil ifTrue:[
        showFilterHolder := ValueHolder with: false.
        showFilterHolder addDependent:self.
    ].
    ^ showFilterHolder

    "Modified: / 29-11-2011 / 15:43:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

showFilterHolder:something
    "set the 'showFilterHolder' value holder (automatically generated)"

    |oldValue newValue|

    showFilterHolder notNil ifTrue:[
        oldValue := showFilterHolder value.
        showFilterHolder removeDependent:self.
    ].
    showFilterHolder := something.
    showFilterHolder notNil ifTrue:[
        showFilterHolder addDependent:self.
    ].
    newValue := showFilterHolder value.
    oldValue ~~ newValue ifTrue:[
        self update:#value with:newValue from:showFilterHolder.
    ].
! !

!BrowserListWithFilter methodsFor:'change & update'!

update:something with:aParameter from:changedObject
    "Invoked when an object that I depend upon sends a change notification."


    changedObject == showFilterHolder ifTrue:[
        self showFilter: showFilterHolder value.
        ^self.
    ].
    changedObject == filterPatternHolder ifTrue:[
        listValid := false.
        self enqueueDelayedUpdateList.
        ^self
    ].
    super update:something with:aParameter from:changedObject

    "Modified: / 29-11-2011 / 15:51:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!BrowserListWithFilter methodsFor:'event handling-delegation'!

handlesKeyPress:key inView:aView
    ^ aView == filterView and:[key == #CursorDown]

    "Created: / 06-02-2012 / 23:02:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

keyPress:key x:x y:y view:aView

    (aView == filterView and:[key == #CursorDown]) ifTrue:[
        listView scrolledView 
            takeFocus;
            keyPress: key x:x y:y.
    ].

    "Created: / 06-02-2012 / 23:06:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!BrowserListWithFilter methodsFor:'hooks'!

commonPostBuild

    listView isNil ifTrue:[listView := builder componentAt:#List].
    listView isNil ifTrue:[self breakPoint: #jv].
    filterView isNil ifTrue:[self breakPoint: #jv].

    filterView delegate: self

    "Created: / 29-11-2011 / 14:47:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

postBuildFilterView: aView

    filterView := aView

    "Created: / 29-11-2011 / 14:47:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

postBuildListView: aView

    listView := aView

    "Created: / 29-11-2011 / 14:47:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!BrowserListWithFilter methodsFor:'private'!

filterList: list
    | pattern filteredList |

    self showFilter ifFalse:[ ^ list ].
    pattern := self filterPattern.
    pattern isNil ifTrue:[ ^ list ].    
    filteredList := list value select:[:each|pattern matchObject: each relax: 1].
    filteredList isEmpty ifTrue:[
    filteredList := list value select:[:each|pattern matchObject: each relax: 2].
    filteredList isEmpty ifTrue:[
    filteredList := list value select:[:each|pattern matchObject: each relax: 3].
    ]].
    ^filteredList

    "Created: / 29-11-2011 / 15:31:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

showFilter: aBoolean
    | offset |

    aBoolean ifTrue:[
        offset := filterView height.
    ] ifFalse:[
        offset := 0
    ].
    listView layout: (listView layout copy topOffset: offset) .
    filterView isVisible: aBoolean

    "Created: / 29-11-2011 / 14:55:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!BrowserListWithFilter class methodsFor:'documentation'!

version
    ^ '$Id: Tools__BrowserListWithFilter.st 7882 2012-02-12 00:06:21Z vranyj1 $'
!

version_CVS
    ^ '§Header: /cvs/stx/stx/libtool/Tools__BrowserListWithFilter.st,v 1.3 2011/12/01 10:53:42 vrany Exp §'
!

version_SVN
    ^ '$Id: Tools__BrowserListWithFilter.st 7882 2012-02-12 00:06:21Z vranyj1 $'
! !