home *** CD-ROM | disk | FTP | other *** search
/ PC World 1997 November / PCWorld_1997-11_cd.bin / software / programy / komix / DATA.Z / repdbdialo.tcl < prev    next >
Text File  |  1996-11-28  |  9KB  |  314 lines

  1. #---------------------------------------------------------------------------
  2. #
  3. #      (c)     Cayenne Software Inc.    1996
  4. #
  5. #      File:           @(#)repdbdialo.tcl    /main/hindenburg/10
  6. #      Author:         <generated>
  7. #      Description:
  8. #---------------------------------------------------------------------------
  9. # SccsId = @(#)repdbdialo.tcl    /main/hindenburg/10   28 Nov 1996 Copyright 1996 Cayenne Software Inc.
  10.  
  11. # Start user added include file section
  12. require "repdbms.tcl"
  13. require "repository.tcl"
  14. require "reppasswor.tcl"
  15. # End user added include file section
  16.  
  17. require "reptooldia.tcl"
  18.  
  19. Class RepDbDialog : {RepToolDialog} {
  20.     constructor
  21.     method destructor
  22.     method createDbInterface
  23.     method setupForPassword
  24.     method popUp
  25.     method passwordOk
  26.     method getDbFields
  27.     method setDbFields
  28.     method changePassword
  29.     method passwordChanged
  30.     attribute dbname
  31.     attribute dbuser
  32.     attribute dbpassword
  33.     attribute dbdirectory
  34.     attribute dbserver
  35.     attribute dbhost
  36.     attribute plainPassword
  37.     attribute cryptedPassword
  38.     attribute passwordButton
  39. }
  40.  
  41. constructor RepDbDialog {class this name view} {
  42.     set this [RepToolDialog::constructor $class $this $name $view]
  43.     # Start constructor user section
  44.     # End constructor user section
  45.     return $this
  46. }
  47.  
  48. method RepDbDialog::destructor {this} {
  49.     # Start destructor user section
  50.     # End destructor user section
  51.     $this RepToolDialog::destructor
  52. }
  53.  
  54. method RepDbDialog::createDbInterface {this parent {fieldWidth 25}} {
  55.     interface DlgRow $parent.name {
  56.     Label l { text "Name" }
  57.     SingleLineText name { }
  58.     }
  59.     if {[RepositoryDBMS::shortName] == "ora"} {
  60.         $parent.name.l text "Connect String"
  61.     }
  62.     $this dbname $parent.name.name
  63.     [$this dbname] columnCount $fieldWidth
  64.  
  65.     if [RepositoryDBMS::hasDirectory] {
  66.     interface DlgRow $parent.dir {
  67.         Label l { text "Directory" }
  68.         SingleLineText dir { }
  69.     }
  70.     $this dbdirectory $parent.dir.dir
  71.         [$this dbdirectory] columnCount $fieldWidth
  72.     }
  73.  
  74.     if [RepositoryDBMS::hasUser] {
  75.     interface DlgRow $parent.user {
  76.         Label l { text "User" }
  77.         SingleLineText user { }
  78.     }
  79.     $this dbuser $parent.user.user
  80.         [$this dbuser] columnCount $fieldWidth
  81.     }
  82.  
  83.     if [RepositoryDBMS::hasPassword] {
  84.     interface DlgRow $parent.password {
  85.         Label l {
  86.                 text "Password"
  87.                 justification CENTER
  88.             }
  89.             DlgRow row {
  90.         spaceType NONE
  91.         horStretchFactor 0
  92.         PushButton b { label "Enter..." }
  93.         SingleLineText password {
  94.             editable 0
  95.             verStretchFactor 0
  96.         }
  97.             }
  98.     }
  99.  
  100.     $this dbpassword $parent.password.row.password
  101.         [$this dbpassword] columnCount $fieldWidth
  102.  
  103.         $this passwordButton $parent.password.row.b
  104.     [$this passwordButton] activated "$this changePassword"
  105.  
  106.     $this passwordChanged
  107.     }
  108.  
  109.     if [RepositoryDBMS::hasHost] {
  110.     interface DlgRow $parent.host {
  111.         Label l { text "Host" }
  112.         SingleLineText host { }
  113.     }
  114.     $this dbhost $parent.host.host
  115.         [$this dbhost] columnCount $fieldWidth
  116.     }
  117.  
  118.     if [RepositoryDBMS::hasServer] {
  119.     interface DlgRow $parent.server {
  120.         Label l { text "Server" }
  121.         SingleLineText server { }
  122.     }
  123.     $this dbserver $parent.server.server
  124.         [$this dbserver] columnCount $fieldWidth
  125.     }
  126. }
  127.  
  128. method RepDbDialog::setupForPassword {this} {
  129.     [$this dbname] editable 0
  130.  
  131.     if [RepositoryDBMS::hasDirectory] {
  132.     [$this dbdirectory] editable 0
  133.     }
  134.  
  135.     if [RepositoryDBMS::hasUser] {
  136.     [$this dbuser] editable 0
  137.     }
  138.  
  139.     if [RepositoryDBMS::hasHost] {
  140.     [$this dbhost] editable 0
  141.     }
  142.  
  143.     if [RepositoryDBMS::hasServer] {
  144.     [$this dbserver] editable 0
  145.     }
  146. }
  147.  
  148. method RepDbDialog::popUp {this} {
  149.     $this passwordChanged
  150.     $this RepToolDialog::popUp
  151. }
  152.  
  153. method RepDbDialog::passwordOk {this} {
  154.     if [RepositoryDBMS::hasPassword] {
  155.         if {[$this plainPassword] == ""} {
  156.             return 0
  157.         }
  158.     }
  159.     return 1
  160. }
  161.  
  162. method RepDbDialog::getDbFields {this cmdInfoRef {requirePassword 1}} {
  163.     upvar $cmdInfoRef cmdInfo
  164.  
  165.     set cmdInfo(dbname) [[$this dbname] text]
  166.     if {[string length $cmdInfo(dbname)] == 0} {
  167.         [$this view] error "No database name specified."
  168.         return 0
  169.     }
  170.  
  171.     if [RepositoryDBMS::hasUser] {
  172.         set cmdInfo(dbuser) [[$this dbuser] text]
  173.     }
  174.     if [RepositoryDBMS::hasPassword] {
  175.     set cmdInfo(dbpassword) ""
  176.         if {[$this plainPassword] != ""} {
  177.         set cmdInfo(dbpassword) [$this plainPassword]
  178.         }
  179.  
  180.     set cmdInfo(dbcryptedpassword) ""
  181.         if {[$this cryptedPassword] != ""} {
  182.         set cmdInfo(dbcryptedpassword) [$this cryptedPassword]
  183.         }
  184.  
  185.         if {$requirePassword && $cmdInfo(dbpassword) == ""} {
  186.             [$this view] error "No password specified."
  187.             return 0
  188.         }
  189.     }
  190.     if [RepositoryDBMS::hasDirectory] {
  191.     set cmdInfo(dbdir) [Repository::expandDirName \
  192.                                 [[$this dbdirectory] text]]
  193.     }
  194.     if [RepositoryDBMS::hasServer] {
  195.     set cmdInfo(dbserver) [[$this dbserver] text]
  196.     }
  197.     if [RepositoryDBMS::hasHost] {
  198.     set cmdInfo(dbhost) [[$this dbhost] text]
  199.     }
  200.  
  201.     # Allow empty values for fields other than name. Assume
  202.     # dbtool knows proper default.
  203.     #
  204.     return 1
  205. }
  206.  
  207. method RepDbDialog::setDbFields {this} {
  208.     set rep [[$this view] rep]
  209.     set name [$rep currentName]
  210.     set corp [$rep currentCorporate]
  211.  
  212.     if ![$corp isNil] {
  213.     [$this dbname] text [$corp databaseName]
  214.  
  215.     if [RepositoryDBMS::hasDirectory] {
  216.         [$this dbdirectory] text [$corp databaseDirectory]
  217.     }
  218.  
  219.     if [RepositoryDBMS::hasUser] {
  220.         [$this dbuser] text [$corp databaseUser]
  221.     }
  222.  
  223.     if [RepositoryDBMS::hasPassword] {
  224.             if {[$this plainPassword] == ""} {
  225.         $this cryptedPassword [$corp databasePassword]
  226.         regsub -all {.} [$this cryptedPassword] {*} hiddenPassword
  227.             } else {
  228.                 $this cryptedPassword [ORB::cryptPassword [$this plainPassword]]
  229.         regsub -all {.} [$this plainPassword] {*} hiddenPassword
  230.             }
  231.         [$this dbpassword] text $hiddenPassword
  232.     }
  233.  
  234.     if [RepositoryDBMS::hasHost] {
  235.         [$this dbhost] text [$corp databaseHost]
  236.     }
  237.  
  238.     if [RepositoryDBMS::hasServer] {
  239.         [$this dbserver] text [$corp databaseServer]
  240.     }
  241.     } elseif {$name != ""} {
  242.         if [$rep getServerByName $name serverDef] {
  243.             set cmdLine $serverDef(cmdline)
  244.         if [$rep getInfoFromCmdLine $serverDef(id) $cmdLine cmdInfo] {
  245.         [$this dbname] text $cmdInfo(dbname)
  246.  
  247.         if [RepositoryDBMS::hasDirectory] {
  248.             [$this dbdirectory] text $cmdInfo(dbdir)
  249.         }
  250.  
  251.         if [RepositoryDBMS::hasUser] {
  252.             [$this dbuser] text $cmdInfo(dbuser)
  253.         }
  254.  
  255.         if [RepositoryDBMS::hasPassword] {
  256.                     if {[$this plainPassword] == ""} {
  257.             if [string length $cmdInfo(dbpassword)] {
  258.                 $this plainPassword $cmdInfo(dbpassword)
  259.                 $this cryptedPassword [ORB::cryptPassword \
  260.                             [$this plainPassword]]
  261.                 regsub -all {.} [$this plainPassword] {*} \
  262.                                                                 hiddenPassword
  263.             } elseif [string length $cmdInfo(dbcryptedpassword)] {
  264.                 $this plainPassword ""
  265.                 $this cryptedPassword $cmdInfo(dbcryptedpassword)
  266.                 regsub -all {.} [$this cryptedPassword] {*} \
  267.                                                                 hiddenPassword
  268.             }
  269.                     } else {
  270.                         $this cryptedPassword [ORB::cryptPassword \
  271.                             [$this plainPassword]]
  272.             regsub -all {.} [$this plainPassword] {*} \
  273.                                                                 hiddenPassword
  274.                     }
  275.             [$this dbpassword] text $hiddenPassword
  276.         }
  277.  
  278.         if [RepositoryDBMS::hasHost] {
  279.             [$this dbhost] text $cmdInfo(dbhost)
  280.         }
  281.  
  282.         if [RepositoryDBMS::hasServer] {
  283.             [$this dbserver] text $cmdInfo(dbserver)
  284.         }
  285.         }
  286.         }
  287.     }
  288. }
  289.  
  290. method RepDbDialog::changePassword {this} {
  291.     [$this view] changePassword "$this passwordChanged"
  292. }
  293.  
  294. method RepDbDialog::passwordChanged {this} {
  295.     if ![RepositoryDBMS::hasPassword] {
  296.         return
  297.     }
  298.  
  299.     set dlg [[$this view] passwordDialog]
  300.     if {$dlg != ""} {
  301.     $this plainPassword [$dlg plainPassword]
  302.     $this cryptedPassword [$dlg cryptedPassword]
  303.  
  304.     regsub -all {.} [$this plainPassword] {*} hiddenPassword
  305.     [$this dbpassword] text $hiddenPassword
  306.     } else {
  307.     [$this dbpassword] text ""
  308.     }
  309.     $this checkOk
  310. }
  311.  
  312. # Do not delete this line -- regeneration end marker
  313.  
  314.