SmallSense__AbstractSearchProcessor.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Sat, 13 Dec 2014 00:11:58 +0000
changeset 366 e2083bc62428
child 370 b02030d796d8
permissions -rw-r--r--
Decoupling search logic from dialogs (part 1) Search logic has been moved to separate class hierarchy under `AbstractSearchProcessor`. This will allow for reusing search logic in multiple dialogs and/or use multiple searches in one dialog.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
366
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     1
"
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     2
stx:goodies/smallsense - A productivity plugin for Smalltalk/X IDE
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     3
Copyright (C) 2013-2014 Jan Vrany
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     4
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     5
This library is free software; you can redistribute it and/or
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     6
modify it under the terms of the GNU Lesser General Public
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     7
License as published by the Free Software Foundation; either
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     8
version 2.1 of the License.
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     9
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    10
This library is distributed in the hope that it will be useful,
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    11
but WITHOUT ANY WARRANTY; without even the implied warranty of
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    13
Lesser General Public License for more details.
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    14
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    15
You should have received a copy of the GNU Lesser General Public
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    16
License along with this library; if not, write to the Free Software
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    17
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    18
"
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    19
"{ Package: 'stx:goodies/smallsense' }"
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    20
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    21
"{ NameSpace: SmallSense }"
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    22
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    23
Object subclass:#AbstractSearchProcessor
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    24
	instanceVariableNames:''
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    25
	classVariableNames:''
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    26
	poolDictionaries:''
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    27
	category:'SmallSense-Core-Interface-Search'
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    28
!
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    29
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    30
!AbstractSearchProcessor class methodsFor:'documentation'!
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    31
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    32
copyright
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    33
"
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    34
stx:goodies/smallsense - A productivity plugin for Smalltalk/X IDE
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    35
Copyright (C) 2013-2014 Jan Vrany
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    36
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    37
This library is free software; you can redistribute it and/or
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    38
modify it under the terms of the GNU Lesser General Public
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    39
License as published by the Free Software Foundation; either
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    40
version 2.1 of the License.
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    41
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    42
This library is distributed in the hope that it will be useful,
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    43
but WITHOUT ANY WARRANTY; without even the implied warranty of
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    44
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    45
Lesser General Public License for more details.
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    46
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    47
You should have received a copy of the GNU Lesser General Public
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    48
License along with this library; if not, write to the Free Software
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    49
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    50
"
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    51
! !
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    52
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    53
!AbstractSearchProcessor class methodsFor:'queries'!
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    54
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    55
isAbstract
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    56
    "Return if this class is an abstract class.
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    57
     True is returned here for myself only; false for subclasses.
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    58
     Abstract subclasses must redefine again."
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    59
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    60
    ^ self == SmallSense::AbstractSearchProcessor.
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    61
! !
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    62
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    63
!AbstractSearchProcessor methodsFor:'searching'!
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    64
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    65
matchingObjectPOsFor: objects
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    66
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    67
    self subclassResponsibility.
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    68
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    69
    "Created: / 30-04-2014 / 09:46:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    70
!
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    71
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    72
matchingObjectPOsForPattern:pattern filter: filter inEnvironment:environment
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    73
    ^ self matchingObjectPOsFor: 
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    74
        (self matchingObjectsForPattern: pattern filter: filter inEnvironment: environment).
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    75
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    76
    "Created: / 12-12-2014 / 23:31:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    77
!
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    78
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    79
matchingObjectsForPattern:pattern filter: filter inEnvironment:environment
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    80
    | objects |
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    81
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    82
    objects := self matchingObjectsForPattern:pattern filter: filter inEnvironment:environment relax: 1.
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    83
    objects notEmptyOrNil ifTrue:[ ^ objects ].
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    84
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    85
    objects := self matchingObjectsForPattern:pattern filter: filter inEnvironment:environment relax: 2.
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    86
    objects notEmptyOrNil ifTrue:[ ^ objects ].
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    87
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    88
    objects := self matchingObjectsForPattern:pattern filter: filter inEnvironment:environment relax: 3.
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    89
    ^ objects
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    90
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    91
    "Created: / 12-12-2014 / 21:23:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    92
!
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    93
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    94
matchingObjectsForPattern:pattern filter: filter inEnvironment:environment relax: level
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    95
    self subclassResponsibility
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    96
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    97
    "Created: / 12-12-2014 / 21:22:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    98
! !
e2083bc62428 Decoupling search logic from dialogs (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    99