home *** CD-ROM | disk | FTP | other *** search
/ com!online 2001 December / COMCD1201.iso / openoffice / f_0020 / FormWizard.xba < prev    next >
Encoding:
Extensible Markup Language  |  2001-08-24  |  10.1 KB  |  284 lines

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
  3. <script:module xmlns:script="http://openoffice.org/2000/script" script:name="FormWizard" script:language="StarBasic">Option Explicit
  4.  
  5. ' Todo: Gruppieren der DBControls mit den Textfeldern einbinden
  6. ' Evtl k├╢nnte dies auch am Ende geschehen
  7. Public DocumentName as String
  8. Public FormPath$, FormDBName$, FormReturnValue$
  9. Public TemplatePath$
  10. Public WizardPath as String
  11. Public WebWizardPath as String
  12. Public WorkPath as String
  13. Public TexturePath as String
  14. Public sQueryName as String
  15. Public NumberofStyles as Integer
  16. Public oDBConnection as Object
  17.  
  18. Public bNeedFieldRefresh as Boolean
  19. Public oDBForm as Object
  20. Public oColumns() as Object
  21. Public sDatabaseList()
  22. Public TableNames() as String
  23. Public QueryNames() as String
  24. Public FieldNames() as String
  25. Public oDBContext as Object
  26. Public oUcb as Object
  27. Public oDocInfo as Object
  28. 'Public TemplateList(50,1) as String
  29. Public WidthList(15,4)
  30. Public ImgWidthList(3,4)
  31. Public sDBName as String
  32. Public Tablename as String
  33.  
  34. ' Todo: Mit FS abschnacken, dass als CommandType Nur Queries und Tables zugelassen sind. Dabei m├╝sste noch abgkl├ñrt werden
  35. ' wann ein Content ein 'Command' ist.
  36.  
  37.  
  38. ' The macro can be called in 4 possible scenarios:
  39. ' Scenario 1. No parameters at given
  40. ' Scenario 2: Only Datasourcename is given, but no connection and no Content
  41. ' Scenario 3: a data source and a connection are given
  42. ' Scenario 4: all parameters (data source name, connection, object type and object) are given
  43.  
  44. Sub Main()
  45. Dim oLocDBContext as Object
  46. Dim oLocConnection as Object
  47.  
  48. ' Scenario 1. No parameters at given
  49.     MainWithDefault()
  50.  
  51. ' Scenario 2: Only Datasourcename is given, but no connection and no Content
  52. '    MainWithDefault("Bibliography")
  53.  
  54. ' Scenario 3: a data source and a connection are given
  55. '    oLocDBContext = CreateUnoService("com.sun.star.sdb.DatabaseContext")
  56. '    oLocConnection = oLocDBContext.GetByName("Bibliography").GetConnection("","")
  57. '    MainWithDefault("Bibliography", oLocConnection)
  58.  
  59. ' Scenario 4: all parameters (data source name, connection, object type and object) are given
  60. '    oLocDBContext = CreateUnoService("com.sun.star.sdb.DatabaseContext")
  61. '    oLocConnection = oLocDBContext.GetByName("Bibliography").GetConnection("","")
  62. '    MainWithDefault("Bibliography", oLocConnection, com.sun.star.sdb.CommandType.TABLE, "biblio")
  63. End Sub
  64.  
  65.  
  66. Sub MainWithDefault(Optional DatasourceName as String, Optional oConnection as Object, Optional CommandType as Integer, Optional sContent as String)
  67. Dim i as Integer
  68. Dim SelCount as Integer
  69. 'On Local Error Goto GlobalError
  70.     BasicLibraries.LoadLibrary("Tools")
  71.     BasicLibraries.LoadLibrary("WebWizard")
  72. ' Todo: Variable is initialized due to Bug#88329
  73.     CurArrangement = 0
  74.     bControlsareCreated = False
  75.     MaxIndex = -1
  76.     If Not InitResources("Formwizard","dbw") Then
  77.         Exit Sub
  78.     End If
  79.     oDBContext = CreateUnoService("com.sun.star.sdb.DatabaseContext")
  80.     oUcb = createUnoService("com.sun.star.ucb.SimpleFileAccess")
  81.     FormPath = GetOfficeSubPath("Template","wizard/bitmap")
  82.     WebWizardPath = GetOfficeSubPath("Template","wizard/web")
  83.     WizardPath = GetOfficeSubPath("Template","wizard/")
  84.     TexturePath = GetOfficeSubPath("Gallery", "www-back/")
  85.     WorkPath = GetPathSettings("Work")
  86.     OpenFormDocument()
  87.     GetDatabaseNames()
  88.     InitializeWidthList()
  89.     LoadLanguage
  90.     bNeedFieldRefresh = True
  91.  
  92.     With oDialogModel
  93.         .optIgnoreBinaries.State = True
  94.         .cmdBack.Enabled = False
  95.         .cmdGoOn.Enabled = False
  96.         .lblTables.Enabled = False
  97.         .lstSelFields.Tag = False
  98.         .Step = 1
  99.         .lstDatabases.StringItemList()= sDatabaseList()' = AddItem(sDatabaseList(i)
  100.     End With
  101.     If Not IsMissing(DataSourceName) Then
  102.         DlgFormDB.GetControl("lstDatabases").SelectItem(DataSourceName, True)
  103.         If Not IsMissing(oConnection) Then
  104.             ' Scenario 3: a data source and a connection are given
  105.             Set oDBConnection = oConnection
  106.             oDialogModel.lstTables.Enabled = True
  107.             oDialogModel.lblTables.Enabled = True
  108.             If GetDBMetaData() Then
  109.                 oDialogModel.lstTables.StringItemList() = AddListToList(TableNames(), QueryNames())
  110.                 If Not IsMissing(sContent) Then
  111.                     ' Scenario 4: all parameters (data source name, connection, object type and object) are given
  112.                     iCommandTypes() = CreateCommandTypeList()
  113.                     SelCount = CountItemsInArray(oDialogModel.lstTables.StringItemList(), sContent)
  114.                     If SelCount = 1 Then
  115.                         DlgFormDB.GetControl("lstTables").SelectItem(sContent, True)
  116.                     Else         ' Note: Here is no Error Handling in case that no valid content is transferred
  117.                         If CommandType = com.sun.star.sdb.CommandType.QUERY Then
  118.                             SelIndex = IndexInArray(sContent, QueryNames()
  119.                             DlgFormDB.GetControl("lstTables").SelectItemPos(SelIndex, True)
  120.                         ElseIf CommandType = com.sun.star.sdb.CommandType.TABLE Then
  121.                             SelIndex = IndexInArray(sContent, TableNames()
  122.                             DlgFormDB.GetControl("lstTables").SelectItemPos(Ubound(QueryNames()+1 + SelIndex, True)                
  123.                         End If
  124.                     End If
  125.                     CurCommandType = CommandType
  126.                     FillUpFieldsListbox(False)
  127.                 End If
  128.             End If
  129.         Else
  130.             ' Scenario 2: Only Datasourcename is given, but no connection and no Content
  131.             GetSelectedDBMetaData()
  132.         End If
  133.     Else
  134.         ' Scenario 1: No parameters are given 
  135.         ToggleListboxControls(oDialogModel, False)
  136.     End If
  137.  
  138.     DlgFormDB.Title = WizardTitle(1)
  139.     NumberofStyles = FillupWebListbox(oUcb, "/stl", DlgFormDB, "lstStyles", Styles())
  140.     ImportStyles()
  141.     ToggleWindow(True)
  142.     oDialogModel.imgTheme.ImageURL = FormPath & "FormWizard_1.bmp"
  143.     oDialogModel.cmdBack.Enabled = False
  144.  
  145.     DlgFormDB.Execute()
  146.     DlgFormDB.Dispose
  147.     If Not IsNull(oDBConnection) Then
  148.         oDBConnection.Dispose()
  149.     End If
  150.     oDocument.Dispose
  151.     Exit Sub
  152. GlobalError:
  153.     MsgBox(sMsgErrMsg , 16, sMsgWizardName)
  154.     ToggleWindow(True)
  155.     DlgFormDB.EndExecute()
  156. End Sub
  157.  
  158.  
  159. Sub FormGetFields()
  160. Dim i as Integer
  161.     ToggleDatabasePage(False)
  162.     FillUpFieldsListbox(True)
  163.     ToggleDatabasePage(True)
  164. End Sub
  165.  
  166.  
  167. Sub FillUpFieldsListbox(bGetCommandType as Boolean)
  168. Dim n as Integer
  169. Dim SelIndex as Integer
  170. Dim QueryIndex as Integer
  171.     n = Ubound(oDialogModel.lstTables.SelectedItems())
  172.     If n > -1 Then
  173.         SelIndex = oDialogModel.lstTables.SelectedItems(0)
  174.         If bGetCommandType Then
  175.             CurCommandType = iCommandTypes(SelIndex)
  176.         End If
  177.         If CurCommandType = com.sun.star.sdb.CommandType.QUERY Then
  178.             QueryIndex = SelIndex - Ubound(Tablenames()) - 1
  179.             Tablename = QueryNames(QueryIndex)
  180.             oColumns = oDBConnection.Queries.GetByName(TableName).Columns
  181.         Else
  182.             Tablename = Tablenames(SelIndex)
  183.             oColumns = oDBConnection.Tables.GetByName(Tablename).Columns
  184.         End If
  185.         GetSpecificFieldNames()
  186.         ToggleListboxControls(oDialogModel, True)
  187.     End If
  188.     Exit Sub
  189. 'TODO: Diese Fehlermarke sinnvoll einbinden    
  190. NOFIELDS:
  191.     MsgBox sMsgErrCouldNotOpenObject, 16, sMsgWizardName
  192. End Sub
  193.  
  194.  
  195. Sub CancelFormWizard()
  196.     DlgFormDB.EndExecute()
  197. End Sub
  198.  
  199.  
  200. Sub PreviousStep()
  201.     With oDialogModel
  202.         .Step = 1
  203.         .cmdBack.Enabled = False
  204.         .cmdGoOn.Enabled = True
  205.         .lstSelFields.Tag = Not bControlsareCreated
  206.         .cmdGoOn.Label = sGoOn
  207.         .imgTheme.ImageUrl = FormPath & "FormWizard_1.bmp"    
  208.     End With
  209.     DlgFormDB.Title = WizardTitle(1)
  210. End Sub
  211.  
  212.  
  213. Sub NextStep()
  214. Dim bOldVisible
  215.     ' Note: Unfortunately it is not possible to query the visibility of the imagecontrol directly
  216.     bOldVisible = oDialogModel.Height > 40
  217.     Select Case oDialogModel.Step
  218.         Case 1
  219.             bControlsAreCreated = Not (CBool(oDialogModel.lstSelFields.Tag))
  220.             If Not bControlsAreCreated Then
  221.                 GetTableMetaData()
  222.                 CreateDBForm()
  223.                 RemoveShapes()
  224.                 InitializeLayoutSettings()
  225.                 oDBForm.Load
  226.             End If
  227.             oDialogModel.cmdGoOn.Label = sReady
  228.             oDialogModel.cmdBack.Enabled = True
  229.             oDialogModel.Step = 2
  230.         Case 2
  231.             StoreForm()
  232.     End Select
  233.     DlgFormDB.GetControl("imgTheme").Visible = bOldVisible
  234.     oDialogModel.imgTheme.ImageUrl = FormPath & "FormWizard_" & oDialogModel.Step & ".bmp"
  235.     DlgFormDB.Title = WizardTitle(oDialogModel.Step)
  236. End Sub
  237.  
  238.  
  239. Sub InitializeLayoutSettings()
  240.     If oPageStyle.BackGraphicLocation = com.sun.star.style.GraphicLocation.TILED Then
  241.         oDialogModel.optTiled.State = 1
  242.     Else
  243.         oDialogModel.optArea.State = 1
  244.     End If
  245.     SwitchArrangementButtons(cTabled)
  246.     SwitchAlignMode(SBALIGNLEFT)
  247.     SwitchBorderMode(SB3DBORDER)
  248.     ToggleBorderGroup(bControlsAreCreated)
  249.     ToggleAlignGroup(bControlsAreCreated)
  250.     ArrangeControls()
  251.     If OldAlignMode <> 0 Then
  252.         DlgFormDB.GetControl("optAlign2").Model.State = 0
  253.     End If
  254. End Sub
  255.  
  256.  
  257. Sub ToggleDatabasePage(bDoEnable as Boolean)
  258.     With oDialogModel
  259.         .hlnBinaries.Enabled = bDoEnable
  260.         .optIgnoreBinaries.Enabled = bDoEnable
  261.         .optBinariesasGraphics.Enabled = bDoEnable
  262.         .cmdHelp.Enabled = bDoEnable
  263.     End With
  264. End Sub
  265.  
  266.  
  267. Sub StoreForm()
  268. Dim bDocIsStored as Boolean
  269. Dim FilterNames(1,2) as String
  270. Dim oMasterKey as Object
  271. Dim oFilters() as Object
  272.     oMasterKey = GetRegistryKeyContent("org.openoffice.Office.TypeDetection/")
  273.     oFilters() = oMasterKey.Types
  274.     FilterNames(0,0) = oFilters.GetByName("writer_StarOffice_XML_Writer").UIName
  275.     FilterNames(0,1) = "*.sxw"
  276.     FilterNames(0,2) = ""
  277.     FilterNames(1,0) = oFilters.GetByName("writer_StarOffice_XML_Writer_Template").UIName
  278.     FilterNames(1,1) = "*.stw"
  279.     FilterNames(1,2) = "swriter: writer_StarOffice_XML_Writer_Template"
  280.     bDocIsStored = StoreDocument(oDocument, FilterNames(), "Form_" & sDBName & "." & TableName, WorkPath)
  281.     If bDocIsStored Then
  282.         DlgFormDB.EndExecute()
  283.     End If
  284. End Sub</script:module>