Hello Users and Roberto

Well - ..let's just jump in.

I wanted to use the Switchboard extension for a database; grabbed the latest release, 1.0.7, from the repository; installed it; loaded the Base file and fired it up.

OOOPS - small problem.

- I like to use folders as a way of organizing my forms and reports into functional areas.
- Also as a way to let the users of the database know where to start.

For instance, I could have all my forms at the top level and when the user opened the file they might see something like this:
form1
form2
form3
form4
switcboard

Now, just which form should they run first?

Rather, I would prefer they see something like this:
FormsFolder
SWITCHBOARD

Put another way the containers contents might be something like this:
FOLDER1
--Form1
--Form2
--FOLDER2
----Form1
----Form2
SWITCHBOARD

This is more clear, IMO, as to which form to open first; "SWITCHBOARD".

However the switchboard extension doesn't support folders.

OK - so let's change that.

Opening the basic library that is the extension and the spot to change is easily found.

In the module "dlgCreatorCB" is the procedure "popDBDoc", used to load a listbox with all the form or report names.
The procedure uses the following code to do so:

   For I=0 To UBound(Container.ElementNames)

LB.addItem(Container.ElementNames(I),LB.getItemCount()) Next I
[LB here is a ListBox control]

Now here is the problem."Container" is documentcontainer, either FormDocuments or ReportDocuments, and can hold both document OR other documentcontainers. The code doesn't check to see that a given elementname may be for another container instead of a form or report.

In this case then the code above would load the listbox with these items:
FOLDER1
SWITCHBOARD

What I want is for the listbox to have these items:
FOLDER1/FOLDER2/Form1
FOLDER1/FOLDER2/Form2
FOLDER1/Form1
FOLDER1/Form2
SWITCHBOARD

So here is the hack. The extension has a module "Utils" and I'll add a new procedure to it:

' DJ - 04/08/2009
' ' sub FillElements( aListBox as variant,_
                 aContainer as new "com.sun.star.comp.dba.ODocumentContainer",_
                 aIncludeContainerName as boolean,_
                 OPTIONAL aParentName as string)

 dim cntr as integer
 dim tmpString as string
 dim ParentName as string
if not isMissing( aParentName ) then ParentName = aParentName

 else
ParentName = "" end if for cntr = 0 to aContainer.Count -1 tmpString = ""
   if aIncludeContainerName then

     tmpString = ParentName & acontainer.Name & "/"
end if
   if aContainer.getByIndex( cntr ).ImplementationName = _
                      "com.sun.star.comp.dba.ODocumentContainer" then
fillListBox( aListBox, aContainer.getByIndex( cntr ), True, tmpString ) else tmpString = tmpString & aContainer.getByIndex( cntr ).Name
     aListBox.AddItem( tmpString, aListBox.ItemCount )
end if next

end sub

Then update the procedure popDBDoc to use it:

' DJ - 04/08/2009
' changed to use FillElements
' procedure in Utils module
'For I=0 To UBound(Container.ElementNames)
'       LB.addItem(Container.ElementNames(I),LB.getItemCount()) 
'Next I 
FillElements( LB, Container, False)


Great - run the extension and sure enough the list box now lists all the forms in the database along with the full folder names as we want.
Create a switchboard and run it...
BAM! it doesn't work...

The extension uses a couple of tables, which it creates, to store the switchboard setup and a quick look at the SWITCHBOARDITEMS table shows that it did store the folder/form name as expected.

Back to reviewing the basic code and in module 'Runtime', procedure "openDBDoc" are these lines:

If Docs.hasByName(FormName) Then
   Doc=Docs.loadComponentFromURL(FormName,"_blank",0,Args())
Else
   MsgBox (Language.getMessage(Globals.LanguageId,5),16,Globals.APP_TITLE)
   Exit Sub
End If

Turns out the problem is not the loadComponentFromURL that works just fine with a Folder/Form name string. The problem is the hasByName function. [NOTE - seems like a bug to me...but that is for another email to a different list I suppose]

Fine - back to the 'Utils' module and I add one more function:

' DJ - 04/08/2009
'
' function hasByCanonicalName( aContainer as new "com.sun.star.comp.dba.ODocumentContainer",_
                            aFormName as string) as boolean
   dim pos as integer
pos = InStr( aFormName, "/" )
   if pos > 0 then
       hasByCanonicalName = hasByCanonicalName( 
aContainer.getByname(left(aFormName, pos -1 )),_
                                                 right(aFormName, 
len(aFormName) - pos_
                                                )
   else
       hasByCanonicalName = aContainer.hasByName(aFormName)
   end if

end function


Then to wrap it up once more to the "openDBDoc" procedure and change it to:

' DJ - 04/08/2009
' 'If Docs.hasByName(FormName) Then
if hasByCanonicalName( Docs, FormName ) then



Well, I haven't tested every possibility but so far it seems to now support folders for both forms and reports...and I'm sure others can improve on my coding, not to mention that I still don't think I should of had to add that last function...but as I say, it seems to be working.

So if you have the extension and you want to use folders, there you go and Happy Hacking...

Drew

ps - Oh yeah...about licenses and all that nonsense....it's free as in *FREE*.....LOL

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to