package require java
set clientManager [java::call com.surpac.client.ClientManager getSharedInstance]
set progressFeedback [java::new com.surpac.gui.ProgressDialog [$clientManager getActiveFrame] ]
$progressFeedback setAbortEnabled false
$progressFeedback { add String int} "Form loading - Please Wait" 99999
proc endProgressFeedback { } {
global progressFeedback
$progressFeedback {remove int} 99999
}
proc getDatabaseType { defFileExt } {
if {"$defFileExt" == "ddb"} {
set databaseType "GeologyDatabase"
} elseif {"$defFileExt" == "sdb"} {
set databaseType "SurveyDatabase"
} else {
set databaseType "UnknownDatabase"
}
return $databaseType
}
set dbMapperFileExt [lindex $argv 1]
proc getSelectedDatabase { type accessFileChooser paradoxFileChooser odbcButtonGroup oracleDatabaseName} {
if {"$type" == "access"} {
return "[$accessFileChooser getCurrentValue]"
} elseif {"$type" == "paradox"} {
return "[$paradoxFileChooser getCurrentValue]"
} elseif {"$type" == "ODBC"} {
return "[$odbcButtonGroup getCurrentValue]"
} elseif {"$type" == "oracle"} {
return "[$oracleDatabaseName getCurrentValue]"
}
}
proc setDDBName { nameFld existsLabel dbType dbName } {
global dbMapperFileExt
set ddbParams [GuidoExecServer "GetDefaultDDBFile" [subst { DatabaseType = $dbType DatabasePath = "$dbName" FileExt = "$dbMapperFileExt"} ]]
$nameFld setCurrentValue "[GuidoGetParamBufferValue $ddbParams RelativeDDBPath]"
if {"[GuidoGetParamBufferValue $ddbParams DDBExists]" == "true"} {
$existsLabel setLabel "already EXISTS"
} else {
$existsLabel setLabel "will be CREATED"
}
}
proc databaseConnect { databaseType databaseName ddbFileName promptPassword username passwd } {
global dbMapperFileExt
set clientManager [java::call com.surpac.client.ClientManager getSharedInstance]
set progressFeedback [java::new com.surpac.gui.ProgressDialog [$clientManager getActiveFrame]]
$progressFeedback setAbortEnabled false
$progressFeedback {add String int} "Connecting to database - Please Wait" 99999
GuidoApp myApp "CONNECT TO MAP DATABASE FILE"
$myApp setParam DatabaseName "$databaseName"
$myApp setParam DatabaseType "$databaseType"
$myApp setParam DDBFileName "$ddbFileName"
$myApp setParam PromptPassword "$promptPassword"
$myApp setParam Username "$username"
$myApp setParam Password "$passwd"
$myApp setParam FileExt "$dbMapperFileExt"
set status [$myApp invoke]
$myApp destroy
$progressFeedback {remove int} 99999
return $status
}
proc getODBCDataSources { databaseType odbcButtonGroup } {
set odbcParams [GuidoExecServer "GetODBCDataSources" { }]
set numDataSources [GuidoGetParamBufferValue $odbcParams DataSourcesCount]
if {$numDataSources == 0} {
$databaseType removeItem "ODBC"
} else {
for {set idx 0} {$idx < $numDataSources} {incr idx} {
set dataSourceName "[GuidoGetParamBufferValue $odbcParams DataSourceName($idx)]"
set description "[GuidoGetParamBufferValue $odbcParams Description($idx)]"
GuidoRadioButton "dataSourceButton$idx" {
-caption "$dataSourceName: $description"
-selected_value "$dataSourceName"
-unselected_value "none"
}
upvar 0 dataSourceButton$idx buttonName
if {$idx == 0} {
$buttonName setSelected true
}
$odbcButtonGroup add [$buttonName getObject]
}
}
return 1
}
proc createODBCSources { odbcButtonGroup form } {
set odbcParams [GuidoExecServer "CreateODBCSources" { }]
set count [$odbcButtonGroup getButtonCount]
set lastAdded $count
incr lastAdded -1
set numDataSources [GuidoGetParamBufferValue $odbcParams DataSourcesCount]
for {set idx 0} {$idx < $count} {incr idx} {
set button [GuidoFunction getComponentByName dataSourceButton$idx $form]
$odbcButtonGroup remove [$button getObject]
}
for {set idx 0} {$idx < $numDataSources} {incr idx} {
set dataSourceName "[GuidoGetParamBufferValue $odbcParams DataSourceName($idx)]"
set description "[GuidoGetParamBufferValue $odbcParams Description($idx)]"
GuidoRadioButton "dataSourceButton$idx" {
-caption "$dataSourceName: $description"
-selected_value "$dataSourceName"
-unselected_value "none"
}
upvar 0 dataSourceButton$idx buttonName
if {$idx == $lastAdded} {
$buttonName setSelected true
}
$odbcButtonGroup add [$buttonName getObject]
}
global buttonGroupScroll
$buttonGroupScroll refresh
return 1
}
proc refreshODBCTreeView { tables views procedures systables synonyms umask tmask tree} {
set getTables "false"
set getViews "false"
set getProcedures "false"
set getSystables "false"
set getSynonyms "false"
if {[$tables isSelected]} {
set getTables "true"
}
if {[$views isSelected]} {
set getViews "true"
}
if {[$procedures isSelected]} {
set getProcedures "true"
}
if {[$systables isSelected]} {
set getSystables "true"
}
if {[$synonyms isSelected]} {
set getSynonyms "true"
}
set userMask "[$umask getCurrentValue]"
set tableMask "[$umask getCurrentValue]"
$tree setRefreshEnabled false
set rootNode [$tree getRootNode]
set count [$rootNode getChildCount]
for {set idx 0} {$idx < $count} {incr idx} {
set node [$rootNode getChildAt $idx]
$node setInputAllowed false
}
set tableParam [GuidoExecServer "RefreshODBCDatabaseView" [subst {DatabaseType = [getDatabaseType $dbMapperFileExt] Tables = $getTables Views = $getViews Procedures = $getProcedures Systables = $getSystables Synonyms = $getSynonyms UserMask = "$userMask" TableMask = "$tableMask"} ]]
set tableCount [GuidoGetParamBufferValue $tableParam TableCount]
for {set idx 0} {$idx < $tableCount} {incr idx} {
set tableName "[GuidoGetParamBufferValue $tableParam TableName($idx)]"
set node [getNodeHandle $rootNode $tableName "branch"]
$node setInputAllowed true
}
$tree setRefreshEnabled true
return 1
}
proc getOracleDatabaseName { databaseType oracleDatabaseName } {
set oracleParam [GuidoExecServer "GetOracleDatabaseName" { }]
set databaseName [GuidoGetParamBufferValue $oracleParam OracleDatabaseName]
if {$databaseName == "NO_ORACLE_DATABASE"} {
$databaseType removeItem "oracle"
} else {
$oracleDatabaseName setLabel "DatabaseName: $databaseName"
}
return 1
}
proc validateButtonClick { selectDatabaseForm databaseType } {
set ddb_file ""
if {"[$databaseType getCurrentValue]" == "access" } {
global accessFileChooser
set ddb_file "[$accessFileChooser getCurrentValue]"
set dbExtension [string tolower [string range $ddb_file [expr [string last . $ddb_file]+1] end]]
set fileMask [$accessFileChooser getFileMask]
if { "$ddb_file" != "" } {
if { [string first $dbExtension $fileMask] == -1 } {
GuidoMessage message DB_SELECT_PROPER_DEF_FILE "$fileMask"
return
}
if {"[$accessFileChooser isFileExists]" == "false"} {
GuidoMessage error APP_FILE_NOT_FD $ddb_file
return
}
$selectDatabaseForm setStatus "next"
} else {
GuidoMessage error DB_NO_DATABASE_SELECTED
}
} elseif { "[$databaseType getCurrentValue]" == "paradox" } {
global paradoxFileChooser
set ddb_file "[$paradoxFileChooser getCurrentValue]"
set dbExtension [string range $ddb_file [expr [string last . $ddb_file]+1] end]
set fileMask [$paradoxFileChooser getFileMask]
if { "$ddb_file" != "" } {
if { [string first $dbExtension $fileMask] == -1 } {
GuidoMessage message DB_SELECT_PROPER_DEF_FILE "$fileMask"
return
}
if {"[$paradoxFileChooser isFileExists]" == "false"} {
GuidoMessage error APP_FILE_NOT_FD $ddb_file
return
}
$selectDatabaseForm setStatus "next"
} else {
GuidoMessage error DB_NO_DATABASE_SELECTED
}
} elseif { "[$databaseType getCurrentValue]" == "oracle" } {
return
} elseif { "[$databaseType getCurrentValue]" == "ODBC" } {
$selectDatabaseForm setStatus "next"
} else {
GuidoMessage error DB_UNKNOWN_DB_TYPE
}
}
GuidoForm selectDatabaseForm {
-defaults_management false
-action initial {[endProgressFeedback]}
-help_id 778
-label "Select the database to map"
GuidoPanel outerPanel {
-layout BoxLayout Y_AXIS
GuidoFiller filler1 {
-height 0.5
}
GuidoPanel selectDatabasePanel {
-layout BoxLayout Y_AXIS
GuidoPanel databaseTypePanel {
-layout BoxLayout X_AXIS
GuidoFiller filler2 {
-width 0.9
}
GuidoLabel typeLabel {
-label "Database type:"
}
GuidoFiller filler3 {
-width 0.9
}
GuidoComboBox databaseType {
-display_length 19
-exclusive true
-value_in "access" "paradox" "ODBC" "oracle"
-tip DB_MAPPER_SELECT_DATABASE_TYPE
-null disallowed
}
}
GuidoFiller filler4 {
-height 0.2
}
GuidoPanel databaseSelectionPanel {
-layout OverlayLayout
GuidoPanel accessDatabasePanel {
-layout BoxLayout Y_AXIS
-dependency {"[$databaseType getCurrentValue]" == "access"}
GuidoFileChooser accessFileChooser {
-file_mask "*.mdb *.dsa *.accdb"
-multiple_selection "false"
-browser_type "file"
}
}
GuidoPanel paradoxDatabasePanel {
-layout BoxLayout Y_AXIS
-dependency {"[$databaseType getCurrentValue]" == "paradox"}
GuidoFileChooser paradoxFileChooser {
-browser_type "files_and_directories"
-file_mask "*.db *.pdx"
-multiple_selection true
}
}
GuidoPanel odbcDatabasePanel {
-layout BoxLayout Y_AXIS
-dependency {"[$databaseType getCurrentValue]" == "ODBC"}
GuidoFiller filler9a {
-height 0.5
}
GuidoPanel innerPanel {
-layout BoxLayout X_AXIS
GuidoLabel selectionLabel {
-font_style bold
-label "Select the ODBC data source"
}
GuidoFiller filler10 {
-width 3.2
}
GuidoButton odbcCreateButton {
-action valueChanged { [createODBCSources $odbcButtonGroup $selectDatabaseForm] }
-caption "Create new data source..."
}
}
GuidoFiller filler10a {
-height 0.5
}
GuidoScrollPane buttonGroupScroll {
-border etched true
-width 20
-height 10
GuidoButtonGroupPanel odbcButtonGroup {
-layout GridLayout 0 1
}
}
GuidoFiller filler50 {
-height 0.5
}
}
GuidoPanel oracleDatabasePanel {
-layout CentreLineLayout
-dependency {"[$databaseType getCurrentValue]" == "oracle"}
GuidoPanel databaseNamePanel {
GuidoLabel oracleLabel {
-label "Database name:"
}
GuidoFiller filler3 {
-width 0.1
}
GuidoField oracleDatabaseName {
-display_length 20.5
-input false
-translate none
}
}
}
}
}
GuidoPanel innerPanel1 {
-layout BoxLayout Y_AXIS
GuidoPanel innerPanel2 {
-layout BoxLayout X_AXIS
GuidoFiller filler1 {
-width 0.6
}
GuidoCheckBox promptPassword {
-dependency {"[$databaseType getCurrentValue]" == "ODBC" || "[$databaseType getCurrentValue]" == "access" }
-label "Password required to open database"
-default 0
-selected_value 1
-unselected_value 0
}
}
GuidoPanel innerPanel3 {
-layout BoxLayout X_AXIS
GuidoFiller filler1 {
-width 10
}
GuidoCheckBox auditField {
-label "Audit database"
-default 0
-selected_value 1
-unselected_value 0
}
}
}
GuidoFiller filler12 {
-height 0.5
}
GuidoPanel buttonPanel {
-layout FlowLayout Left
GuidoButton helpButton {
-action valueChanged { [$selectDatabaseForm setStatus "help"] }
-icon "icons/16/help.png"
-caption " "
}
GuidoFiller filler12 {
-width 20
}
GuidoButton nextButton {
-action valueChanged { [validateButtonClick $selectDatabaseForm $databaseType] }
-display_length 10
-icon "icons/RightArrow.gif"
-caption "Next"
}
GuidoButton cancelButton {
-action valueChanged { [$selectDatabaseForm setStatus "cancel"] }
-display_length 10
-icon "icons/cancel.png"
-caption "Cancel"
}
}
}
}
$odbcDatabasePanel setActionCallback initial {[getODBCDataSources $databaseType $odbcButtonGroup]}
$oracleDatabasePanel setActionCallback initial {[getOracleDatabaseName $databaseType $oracleDatabaseName]}
GuidoForm selectDDBFileForm {
-defaults_management false
-help_id 778
-label "[GuidoMessage translate "Select the name of the"] $dbMapperFileExt [GuidoMessage translate "file"]"
GuidoPanel outerPanel {
-layout BoxLayout Y_AXIS
GuidoFiller filler12 {
-height 0.5
}
GuidoPanel selectDDBFilePanel {
-layout CentreLineLayout
GuidoFileBrowserField ddbFileNameFld {
-display_length 20
-extension false
-format none
-label "$dbMapperFileExt [GuidoMessage translate "file name"]"
-max_length 256
-null false
-file_mask "*.$dbMapperFileExt"
}
GuidoLabel fillerLabel {
}
GuidoLabel fileExistsLabel {
}
}
GuidoFiller filler14 {
-height 1
}
GuidoPanel buttonPanel {
-layout FlowLayout Left
GuidoButton helpButton {
-action valueChanged { [$selectDDBFileForm setStatus "help"] }
-icon "icons/16/help.png"
-caption " "
}
GuidoButton prevButton {
-action valueChanged { [$selectDDBFileForm setStatus "prev"] }
-display_length 8
-icon "icons/LeftArrow.gif"
-caption "Prev"
}
GuidoButton nextButton {
-action valueChanged { [$selectDDBFileForm setStatus "next"] }
-display_length 8
-icon "icons/RightArrow.gif"
-caption "Next"
}
GuidoButton cancelButton {
-action valueChanged { [$selectDDBFileForm setStatus "cancel"] }
-display_length 9
-icon "icons/cancel.png"
-caption "Cancel"
}
}
}
}
GuidoForm passwordForm {
-defaults_management false
-label "User Login Name"
-layout BoxLayout Y_AXIS
-tip DB_PROMPT_USERNAME_PASSWORD
GuidoFiller passwd_filler {
-height 1
}
GuidoPanel passwd_panel {
-border etched true
-label "Enter the user name and password of your database account"
-layout CentreLineLayout
GuidoField username {
-display_length 20
-label Username
-max_length 32
-tip DB_ENTER_USERNAME
}
GuidoPasswordField passwordFld {
-display_length 20
-label Password
-max_length 32
-null true
-tip DB_ENTER_PASSWORD
}
}
GuidoPanel buttonPanel {
-layout FlowLayout Left
GuidoButton helpButton {
-action valueChanged { [$passwordForm setStatus "help"] }
-icon "icons/16/help.png"
-caption " "
}
GuidoButton prevButton {
-action valueChanged { [$passwordForm setStatus "prev"] }
-display_length 10
-icon "icons/LeftArrow.gif"
-caption "Prev"
}
GuidoButton nextButton {
-action valueChanged { [$passwordForm setStatus "next"] }
-display_length 10
-icon "icons/RightArrow.gif"
-caption "Next"
}
GuidoButton cancelButton {
-action valueChanged { [$passwordForm setStatus "cancel"] }
-display_length 10
-icon "icons/cancel.png"
-caption "Cancel"
}
}
}
set performAudit false
GuidoApp app "DB MAPPER"
set nextForm $selectDatabaseForm
set user ""
set passwd ""
while {1} {
set returnCode [$nextForm interact]
if {"$nextForm" == "$selectDatabaseForm"} {
if {"$returnCode" == "next"} {
set type "[$databaseType getCurrentValue]"
set dbName "[getSelectedDatabase $type $accessFileChooser $paradoxFileChooser $odbcButtonGroup $oracleDatabaseName]"
if {"$dbName" == ""} {
GuidoMessage message DB_NO_DATABASE_SELECTED
} elseif {"$type" == "ODBC" && [$promptPassword getCurrentValue]} {
set nextForm $passwordForm
} else {
setDDBName $ddbFileNameFld $fileExistsLabel $type "$dbName"
set nextForm $selectDDBFileForm
}
} elseif {"$returnCode" == "cancel"} {
break
}
} elseif {"$nextForm" == "$passwordForm"} {
if {"$returnCode" == "next"} {
set user "[$username getCurrentValue]"
set passwd "[$passwordFld getCurrentValue]"
setDDBName $ddbFileNameFld $fileExistsLabel $type "$dbName"
set nextForm $selectDDBFileForm
}  elseif {"$returnCode" == "prev"} {
set nextForm $selectDatabaseForm
} elseif {"$returnCode" == "cancel"} {
break
}
} elseif {"$nextForm" == "$selectDDBFileForm"} {
set prompt_passwd "false"
if { ("$type" == "ODBC" || "$type" == "access") && [$promptPassword getCurrentValue]} {
set prompt_passwd "true"
}
if {"$returnCode" == "next"} {
set ddbName "[$ddbFileNameFld getCurrentValue]"
if {"$ddbName" != ""} {
set rcode "[databaseConnect $type "$dbName" $ddbName $prompt_passwd $user $passwd]"
if {"$rcode" != -1} {
set scriptHdle [GuidoScript "scripts/mapDatabase.tcl" "$app [getDatabaseType $dbMapperFileExt] $type $prompt_passwd"]
set returnStatus "[$scriptHdle getReturnStatus]"
if {"$returnStatus" == "FINISH"} {
if {[$auditField getCurrentValue]} {
set performAudit true
}
break
} elseif {"$returnStatus" == "CANCEL"} {
break
} elseif {"$returnStatus" == "PREVIOUS"} {
set nextForm $selectDDBFileForm
}
} else {
set nextForm $selectDatabaseForm
}
} else {
}
} elseif {"$returnCode" == "prev"} {
if {"$prompt_passwd" == "true"} {
set nextForm $passwordForm
} else {
set nextForm $selectDatabaseForm
}
} elseif {"$returnCode" == "cancel"} {
break
}
}
}
$selectDatabaseForm destroy
$selectDDBFileForm destroy
$passwordForm destroy
$app destroy
if {$performAudit} {
GuidoApp app "DB AUDITDB"
set status [$app invoke]
}
