package require java
set clientManager [java::call com.surpac.client.ClientManager getSharedInstance]
set progressFeedback [java::new com.surpac.gui.ProgressDialog [$clientManager getActiveFrame] ]
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 databaseType "unknown"
set databaseBlastSupport "false"
set dbMapperFileExt [lindex $argv 1]
set blastDbMapperName [lindex $argv 0]
proc databaseConnect { ddb_file directory promptPasswd username passwd} {
global databaseType
global databaseBlastSupport
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 EDIT DDB FILE"
$myApp setParam DDBFile  "$ddb_file"
$myApp setParam Directory "$directory"
$myApp setParam PromptPassword "$promptPasswd"
$myApp setParam Username "$username"
$myApp setParam Password "$passwd"
set status [$myApp invoke]
if {$status == -1} {
if {[$myApp getParam IncorrectDirectorySpecific]} {
set return_code "WRONG_DIRECTORY"
} elseif {[$myApp getParam ConnectionError]} {
set return_code "CONNECTION_ERROR"
} elseif {[$myApp getParam StylesNotUpdatedError]} {
set return_code "STYLES_NOT_UPDATED_ERROR"
}
} else {
set databaseBlastSupport [$myApp getParam DatabaseBlastSupport]
set return_code "CONNECTED"
set databaseType [$myApp getParam "DatabaseType"]
}
$myApp destroy
$progressFeedback {remove int} 99999
return $return_code
}
GuidoForm selectDDBFileForm {
-defaults_management false
-action initial {[endProgressFeedback]}
-help_id 778
-label "Edit the database definition"
GuidoPanel outerPanel {
-layout BoxLayout Y_AXIS
GuidoFiller filler1 {
-height 0.5
}
GuidoLabel title {
-font_style bold
-label "[GuidoMessage translate "Select the"] $dbMapperFileExt [GuidoMessage translate "file to edit"]"
}
GuidoPanel selectDDBFilePanel {
-border etched true
-layout BoxLayout Y_AXIS
GuidoFileChooser fileChooser {
-file_mask "*.$dbMapperFileExt"
-multiple_selection "false"
-browser_type "file"
}
}
GuidoFiller filler12 {
-height 1
}
GuidoPanel innerPanel {
-layout CentreLineLayout
GuidoCheckBox promptPassword {
-label "Password required to open database"
-default 0
-selected_value 1
-unselected_value 0
}
}
GuidoPanel buttonPanel {
-layout FlowLayout Left
GuidoButton helpButton {
-action valueChanged { [$selectDDBFileForm setStatus "help"] }
-icon "icons/16/help.png"
-caption " "
}
GuidoFiller filler12 {
-width 21
}
GuidoButton nextButton {
-action valueChanged { [$selectDDBFileForm setStatus "next"] }
-display_length 10
-icon "icons/RightArrow.gif"
-caption "Next"
}
GuidoButton cancelButton {
-action valueChanged { [$selectDDBFileForm setStatus "cancel"] }
-display_length 10
-icon "icons/cancel.png"
-caption "Cancel"
}
}
}
}
GuidoForm confirmDisconectDataBaseForm {
-default_buttons "Yes" "No"
-label "Close current database?"
-help_id 778
set translated_val [GuidoMessage translate DB_ALREADY_OPEN_CONFIRM]
GuidoTextArea confirmText {
-height 2
-width 40
-editable false
-linewrap true
-wrap_style_word true
-format none
-input false
-default DB_ALREADY_OPEN_CONFIRM
}
$confirmText setCurrentValue $translated_val
}
GuidoForm selectDataSourceDirectoryForm {
-defaults_management false
-label "Select the data source directory"
-tip DB_SELECT_DATA_SOURCE_DIRECTORY
GuidoPanel outerPanel {
-layout BoxLayout Y_AXIS
GuidoFiller filler12 {
-height 0.5
}
GuidoPanel selectDataSourceDirectoryPanel {
-layout CentreLineLayout
GuidoFileBrowserField dataSourceDirectoryFld {
-browser_type directory
-display_length 32
-format none
-label "Data source directory"
-max_length 256
-translate none
-tip DB_DATA_SOURCE_DIRECTORY
-absolutePath
}
}
GuidoFiller filler14 {
-height 1
}
GuidoPanel buttonPanel {
-layout FlowLayout Left
GuidoButton helpButton {
-action valueChanged { [$selectDataSourceDirectoryForm setStatus "help"] }
-icon "icons/16/help.png"
-caption " "
}
GuidoButton prevButton {
-action valueChanged { [$selectDataSourceDirectoryForm setStatus "prev"] }
-display_length 10
-icon "icons/LeftArrow.gif"
-caption "Prev"
}
GuidoButton nextButton {
-action valueChanged { [$selectDataSourceDirectoryForm setStatus "next"] }
-display_length 10
-icon "icons/RightArrow.gif"
-caption "Next"
}
GuidoButton cancelButton {
-action valueChanged { [$selectDataSourceDirectoryForm setStatus "cancel"] }
-display_length 10
-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 buffer [GuidoExecServer LegacyGetCurrentDatabaseHandle [subst {sessionType = "GeologyDatabase"}]]
set confForm $confirmDisconectDataBaseForm
set returnCode "apply"
if {[GuidoGetParamBufferValue $buffer status] == 0} {
set returnCode [$confForm interact]
}
if {"$returnCode" == "apply"} {
$progressFeedback setAbortEnabled false
$progressFeedback { add String int} "Form loading - Please Wait" 99999
GuidoApp app "DDB EDITOR"
set nextForm $selectDDBFileForm
while {1} {
set returnCode [$nextForm interact]
if {"$nextForm" == "$selectDDBFileForm"} {
if {"$returnCode" == "next"} {
set ddb_file "[$fileChooser getCurrentValue]"
if {"$ddb_file" != ""} {
if {[$promptPassword getCurrentValue]} {
set nextForm $passwordForm
} else {
set rcode "[databaseConnect "$ddb_file" "" false "" ""]"
if {"$databaseBlastSupport" == "true" && "$blastDbMapperName" != "blast_db_mapper.tcl"} {
puts "Error : Use BLAST DDB EDITOR function to edit a blast database definition."
GuidoExecServer "MapDatabaseCleanup" [subst {DatabaseType = "GeologyDatabase"}]
break
}
if {"$rcode" == "CONNECTED"} {
set scriptHdle [GuidoScript "scripts/mapDatabase.tcl" "$app [getDatabaseType $dbMapperFileExt] $databaseType false"]
set returnStatus "[$scriptHdle getReturnStatus]"
if {"$returnStatus" == "FINISH" || "$returnStatus" == "CANCEL"} {
break
}
} elseif {"$rcode" == "CONNECTON_ERROR"} {
} elseif {"$rcode" == "WRONG_DIRECTORY"} {
set nextForm $selectDataSourceDirectoryForm
}
}
}
} else {
break
}
} elseif {"$nextForm" == "$passwordForm"} {
if {"$returnCode" == "next"} {
set user "[$username getCurrentValue]"
set passwd "[$passwordFld getCurrentValue]"
set rcode "[databaseConnect "$ddb_file" "" true $user $passwd]"
if {"$rcode" == "CONNECTED"} {
set scriptHdle [GuidoScript "scripts/mapDatabase.tcl" "$app [getDatabaseType $dbMapperFileExt] $databaseType true"]
set returnStatus "[$scriptHdle getReturnStatus]"
if {"$returnStatus" == "FINISH" || "$returnStatus" == "CANCEL"} {
break
}
} elseif {"$rcode" == "CONNECTON_ERROR"} {
} elseif {"$rcode" == "WRONG_DIRECTORY"} {
set nextForm $selectDataSourceDirectoryForm
}
}  elseif {"$returnCode" == "prev"} {
set nextForm $selectDDBFileForm
} elseif {"$returnCode" == "cancel"} {
break
}
} elseif {"$nextForm" == "$selectDataSourceDirectoryForm"} {
if {"$returnCode" == "next"} {
set directory "[$dataSourceDirectoryFld getCurrentValue]"
set rcode "[databaseConnect "$ddb_file" "$directory" false "" ""]"
if {"$rcode" == "CONNECTED"} {
set scriptHdle [GuidoScript "scripts/mapDatabase.tcl" "$app [getDatabaseType $dbMapperFileExt] $databaseType false"]
set returnStatus "[$scriptHdle getReturnStatus]"
if {"$returnStatus" == "FINISH" || "$returnStatus" == "CANCEL"} {
break
}
} elseif {"$rcode" == "CONNECTION_ERROR" ||
"$rcode" == "STYLES_NOT_UPDATED_ERROR"} {
if {[$promptPassword getCurrentValue]} {
set nextForm $passwordForm
} else {
set nextForm $selectDDBFileForm
}
} elseif {"$rcode" == "WRONG_DIRECTORY"} {
GuidoMessage message DB_DATA_SOURCE_DIRECTORY_INCORRECT
set nextForm $selectDataSourceDirectoryForm
}
} elseif {"$returnCode" == "prev"} {
if {[$promptPassword getCurrentValue]} {
set nextForm $passwordForm
} else {
set nextForm $selectDDBFileForm
}
} elseif {"$returnCode" == "cancel"} {
break
}
}
}
}
$selectDDBFileForm destroy
$selectDataSourceDirectoryForm destroy
$confForm destroy
$passwordForm destroy
$app destroy
