home *** CD-ROM | disk | FTP | other *** search
/ PC World 1997 November / PCWorld_1997-11_cd.bin / software / programy / komix / DATA.Z / lockmanvie.tcl < prev    next >
Encoding:
Text File  |  1997-06-03  |  8.6 KB  |  355 lines

  1. #---------------------------------------------------------------------------
  2. #
  3. #      (c)     Cayenne Software Inc.    1996
  4. #
  5. #      File:           @(#)lockmanvie.tcl    /main/hindenburg/27
  6. #      Author:         <generated>
  7. #      Description:
  8. #---------------------------------------------------------------------------
  9. # SccsId = @(#)lockmanvie.tcl    /main/hindenburg/27   3 Jun 1997 Copyright 1996 Cayenne Software Inc.
  10.  
  11. # Start user added include file section
  12. require "browstable.tcl"
  13. require "lockbrobje.tcl"
  14. require "lockbrtabl.tcl"
  15. require "lockfilter.tcl"
  16. require "lockfiltdi.tcl"
  17. require "setlockdia.tcl"
  18. # End user added include file section
  19.  
  20. require "reptoolvie.tcl"
  21.  
  22. Class LockManView : {RepToolView} {
  23.     method destructor
  24.     constructor
  25.     method initialize
  26.     method selectedObjSet
  27.     method selectionChanged
  28.     method update
  29.     method reload
  30.     method getLockLabel
  31.     method getLockDetails
  32.     method removeLocks
  33.     method lockServerNotOperable
  34.     method lockServerRunning
  35.     method setFont
  36.     method getFont
  37.     method fileNew
  38.     method fileDelete
  39.     method fileMakeOperable
  40.     method fileShutdown
  41.     method editSelectAll
  42.     method editDeselectAll
  43.     method editInvertSelection
  44.     method optionsLockFilter
  45.     method helpOnContext
  46.     attribute locksLoaded
  47.     attribute setLockPoppedUp
  48.     attribute lockList
  49.     attribute filterDialog
  50.     attribute setLockDialog
  51.     attribute shutdownDialog
  52.     attribute filter
  53. }
  54.  
  55. method LockManView::destructor {this} {
  56.     # Start destructor user section
  57.     # End destructor user section
  58.     $this RepToolView::destructor
  59. }
  60.  
  61. constructor LockManView {class this name} {
  62.     set this [RepToolView::constructor $class $this $name replock]
  63.  
  64.         $this setTitle "Lock Management" rep_lock_64
  65.         $this firstExposed "$this initialize"
  66.         $this filter [LockFilter new]
  67.         [$this filter] load
  68.     $this setLockPoppedUp 0
  69.  
  70.         [$this rep] quickTimeOut 5000
  71.  
  72.         # Create main interface part.
  73.         #
  74.         interface DlgColumn $this.gui.locks {
  75.         spaceType NONE
  76.         LockBrTable locks {
  77.         columnCount 72
  78.         rowCount 15
  79.             }
  80.         }
  81.         $this lockList $this.gui.locks.locks
  82.         [$this lockList] view $this
  83.         [$this lockList] font [m4_var get M4_font -context replock]
  84.         [$this lockList] selectionChanged "$this selectionChanged"
  85.         [$this lockList] setHeaderLabels \
  86.             {Object Type  User  Host  Pid   Date  Reason}
  87.  
  88.     return $this
  89. }
  90.  
  91. proc LockManView::repToolClass {} {
  92.     return "LockManView"
  93. }
  94.  
  95. method LockManView::initialize {this} {
  96.     busy {
  97.         $this viewRefresh
  98.     }
  99. }
  100.  
  101. method LockManView::selectedObjSet {this} {
  102.     return [[$this lockList] selectedSet]
  103. }
  104.  
  105. method LockManView::selectionChanged {this} {
  106.     $this RepToolView::selectionChanged
  107.     
  108.     set ls [[$this rep] getLockServer 0]
  109.     if ![$ls isNil] {
  110.     catch {$ls disconnect}
  111.     }
  112. }
  113.  
  114. method LockManView::update {this} {
  115.     busy {
  116.         $this reload
  117.  
  118.         # To update the "Make Lockserver Operable" menu entry:
  119.     $this selectionChanged
  120.     }
  121. }
  122.  
  123. method LockManView::reload {this} {
  124.     set lockList [$this lockList]
  125.  
  126.     $lockList removeAllObjects
  127.     $lockList format
  128.  
  129.     set filter [$this filter]
  130.     set locks [[$this rep] getLocks [$filter description] \
  131.                     [$filter lockHanging]]
  132.     if {$locks == "NO_LOCKSERVER"} {
  133.     return
  134.     }
  135.  
  136.     set i 0
  137.     foreach lock [osort type -asc objectId -asc date -int $locks] {
  138.     LockBrObject new $lockList.lock$i $lock \
  139.         -label [$this getLockLabel $lock] \
  140.         -details [$this getLockDetails $lock]
  141.     incr i
  142.     }
  143.     $lockList format
  144.  
  145.     set count [llength $locks]
  146.     if {$count != 1} {
  147.         set s "s"
  148.     } else {
  149.         set s ""
  150.     }
  151.     $this message "Selected $count lock$s."
  152. }
  153.  
  154. method LockManView::getLockLabel {this lock} {
  155.     return [[$this rep] describeLock $lock]
  156. }
  157.  
  158. method LockManView::getLockDetails {this lock} {
  159.     return [list \
  160.         [$lock type] \
  161.         [$lock user] \
  162.         [$lock host] \
  163.         [$lock pid] \
  164.         [fmtclock [$lock date]] \
  165.         [$lock reason] ]
  166. }
  167.  
  168. method LockManView::removeLocks {this locks} {
  169.     global errorCode
  170.     set errorCode 0
  171.  
  172.     set count 0
  173.     foreach lock $locks {
  174.         set n [[$this rep] removeLock $lock]
  175.         if {$n > 0} {
  176.         incr count $n
  177.         }
  178.     }
  179.  
  180.     if {$count > 0} {
  181.         $this message "Removed $count lock[expr {$count == 1 ? "" : "s"}]."
  182.     } else {
  183.         $this message "No locks were removed."
  184.     }
  185.  
  186.     busy { $this viewRefresh }
  187. }
  188.  
  189. method LockManView::lockServerNotOperable {this} {
  190.     set ls [[$this rep] getLockServer 0]
  191.     if [$ls isNil] {
  192.     return 0
  193.     }
  194.  
  195.     if [catch {set operable [$ls isOperable]}] {
  196.         return 1
  197.     }
  198.  
  199.     if $operable {
  200.         return 0
  201.     }
  202.     return 1
  203. }
  204.  
  205. method LockManView::lockServerRunning {this} {
  206.     set ls [[$this rep] getLockServer 0]
  207.     if [$ls isNil] {
  208.         return 0
  209.     }
  210.     return 1
  211. }
  212.  
  213. method LockManView::setFont {this font} {
  214.     [$this lockList] font $font
  215.  
  216.     $this RepToolView::setFont $font
  217. }
  218.  
  219. method LockManView::getFont {this} {
  220.     return [[$this lockList] font]
  221. }
  222.  
  223. method LockManView::fileNew {this {objectId ""} {clientCtx ""}} {
  224.     if {[$this setLockDialog] == ""} {
  225.     $this setLockDialog [SetLockDialog new $this.setlockdlg $this]
  226.     }
  227.  
  228.     # These are set when called by LockBrTable on which an object was
  229.     # dropped.
  230.     #
  231.     if {$objectId != ""} {
  232.         [$this setLockDialog] setObject $objectId
  233.     }
  234.     if {$clientCtx != ""} {
  235.         [$this setLockDialog] setClient $clientCtx
  236.     }
  237.  
  238.     if ![$this setLockPoppedUp] {
  239.     [$this setLockDialog] popUp
  240.         $this setLockPoppedUp 1
  241.     }
  242. }
  243.  
  244. method LockManView::fileDelete {this} {
  245.     foreach obj [[$this lockList] selectedSet] {
  246.         lappend locks [$obj lock]
  247.     }
  248.  
  249.     set cnt [llength $locks]
  250.     if {$cnt == 1} {
  251.         set lock [lindex $locks 0]
  252.     if ![[$this rep] checkLock $lock] {
  253.         busy { $this viewRefresh }
  254.         return
  255.     }
  256.  
  257.         set lock [lindex $locks 0]
  258.         set obj  [$lock objectId]
  259.         set type [LockFilter::lock2descType [$lock type]]
  260.         set user [$lock user]
  261.         set host [$lock host]
  262.         set what "the $type lock on\n'[[$this rep] describeLock $lock]'\
  263.                   set by '$user' on host '$host'"
  264.     } else {
  265.         set what "these $cnt locks"
  266.     }
  267.  
  268.     set dlg [YesNoWarningDialog new $this.removelockdlg \
  269.         -title "Remove Locks" \
  270.         -message "Do you really want to remove $what?" \
  271.         -yesPressed "busy { $this removeLocks [list $locks] }" \
  272.         -helpPressed "$this helpOnName deleteLock"]
  273.  
  274.     $dlg delCancelButton
  275.     $dlg popUp
  276. }
  277.  
  278. method LockManView::fileMakeOperable {this} {
  279.     set ls [[$this rep] getLockServer]
  280.     if [$ls isNil] {
  281.         $this warning "Lockserver is not running."
  282.         return
  283.     }
  284.  
  285.     if [catch {$ls makeOperable} error] {
  286.         $this error $error
  287.     }
  288.     $this selectionChanged
  289. }
  290.  
  291. method LockManView::fileShutdown {this {confirm 1}} {
  292.     if $confirm {
  293.     if {[$this shutdownDialog] == ""} {
  294.         $this shutdownDialog [WarningDialog new \
  295.         $this.shutdowndlg-lockserver \
  296.         -title "Shutdown Lockserver" \
  297.         -message "Are you sure you want to shutdown the lockserver?" \
  298.         -okPressed "busy { $this fileShutdown 0 }" \
  299.                 -helpPressed "$this helpOnName shutdownLockServer"]
  300.     }
  301.     [$this shutdownDialog] popUp
  302.         return
  303.     }
  304.  
  305.     set ls [[$this rep] getLockServer 0]
  306.     if [$ls isNil] {
  307.         return
  308.     }
  309.     if [catch {$ls shutdown} error] {
  310.         $this error $error
  311.     }
  312.     $this selectionChanged
  313. }
  314.  
  315. method LockManView::editSelectAll {this} {
  316.     [$this lockList] selectedSet [[$this lockList] objectSet]
  317.     $this selectionChanged
  318. }
  319.  
  320. method LockManView::editDeselectAll {this} {
  321.     [$this lockList] selectedSet {}
  322.     $this selectionChanged
  323. }
  324.  
  325. method LockManView::editInvertSelection {this} {
  326.     set selected [[$this lockList] selectedSet]
  327.     set inverse {}
  328.     foreach obj [[$this lockList] objectSet] {
  329.         if {[lsearch $selected $obj] == -1} {
  330.             lappend inverse $obj
  331.         }
  332.     }
  333.     [$this lockList] selectedSet $inverse
  334.     $this selectionChanged
  335. }
  336.  
  337. method LockManView::optionsLockFilter {this} {
  338.     if {[$this filterDialog] == ""} {
  339.         $this filterDialog [LockFiltDialog new $this.lockfiltdlg $this]
  340.     }
  341.     [$this filterDialog] popUp
  342. }
  343.  
  344. method LockManView::helpOnContext {this} {
  345.     set selected [[$this lockList] selectedSet]
  346.     if ![lempty $selected] {
  347.         $this helpOnName selectedLock
  348.     } else {
  349.         $this helpOnName repToolLockManView
  350.     }
  351. }
  352.  
  353. # Do not delete this line -- regeneration end marker
  354.  
  355.