LNS Home
FaceSpan 4.3
FaceSpan 4 Home
x Download
x Documentation & Examples
 
bullet Progress Dialog
bullet Dock Icon
bullet Browser View
bullet DTI Tutorials
x O'Reilly MacDevCenter.com
 
bullet Building Applications with AppleScript and FaceSpan
Join the FaceSpan Mailing List
x AppleScript/Scripting Links
Products
Affrus 1.0
x FaceSpan 4.3
Script Debugger 4.0
Site Contents
Home Page
bullet Mark’s Blog
Product Registration
Bug Reporting
x Freeware
Contacting Us

Browser View Example

Download Example Project (48K)

This example shows how to display a hierarchical data structure in a Browser View.

briwserview

How Browser Views Work

Unlike Table Views and Outline Views, Browser Views don't use data sources. Instead, you must define two handlers in the script attached to your Browser View which provide the information the Browser View requires to display your data:

on number of browser rows theObject ¬
     in column inColumn

This handler must return the number of rows in a given column (inColumn) of your browser.

on will display browser cell theObject ¬
     row theRow ¬
     browser cell browserCell ¬
     in column inColumn

This handler must modify browserCell with the data to be displayed for a given row in a column within the browser. Minimally, you must set the cell's content and leaf properties. The cell content property contains the text that appears for the given row and column in the browser. The leaf property determines if there are sub-items. Setting the leaf property to true indicates that the cell does not have any sub-items.

The Code

The code that presents the browser outline shown in the screen shot above looks like this:

--  The data structure I want to display in the browser
property pData : {¬
    {name:"XXXX 1", data:missing value}, ¬
    {name:"XXXX 2", data:missing value}, ¬
    {name:"XXXX 3", data:missing value}, ¬
    {name:"XXXX 4", data:{¬
        {name:"YYYY 1", data:missing value}, ¬
        {name:"YYYY 2", data:{¬
            {name:"ZZZZ 1", data:missing value}, ¬
            {name:"ZZZZ 2", data:missing value}, ¬
            {name:"ZZZZ 3", data:missing value}, ¬
            {name:"ZZZZ 4", data:missing value}, ¬
            {name:"ZZZZ 5", data:missing value}, ¬
            {name:"ZZZZ 6", data:missing value} ¬
                }}, ¬
        {name:"YYYY 3", data:missing value} ¬
            }}, ¬
    {name:"XXXX 5", data:missing value} ¬
        }

on splitPath(thePath)
    --    Split a path string into a list of column values
    if thePath is "" then return {}
    if character 1 of thePath is "/" then ¬
        set thePath to text 2 thru -1 of thePath

    set saveDelims to AppleScript's text item delimiters
    set AppleScript's text item delimiters to "/"
    set theItems to text items of thePath
    set AppleScript's text item delimiters to saveDelims
    return theItems
end splitPath

on itemWithName(theList, theName)
    --    Find the item in a list whose name = theName
    --   
    --    AppleScript *should* do this for us (i.e. first item whose name is theName of theList),
    --    but alas it does not.
    repeat with anItem in theList
        if name of anItem = theName then
            return data of anItem
        end if
    end repeat
    return missing value -- theName not found
end itemWithName

on itemFromPath(thePath)
    --    Navigate through the pData structure to the node pointed to by thePath
    set thePath to splitPath(thePath)
    set theList to pData
   
    repeat with aSegment in thePath
        set theList to itemWithName(theList, contents of aSegment)
    end repeat
   
    return theList
end itemFromPath

on number of browser rows theObject in column inColumn
    if inColumn is 1 then
        set theList to pData
    else
        set thePath to path for theObject column ((selected column of theObject) + 1)
        set theList to itemFromPath(thePath)
    end if
   
    if class of theList is list then
        return length of theList
    else
        return 0
    end if
end number of browser rows

on will display browser cell theObject row theRow browser cell browserCell in column inColumn
    if inColumn is 1 then
        set theList to pData
    else
        set thePath to path for theObject column ((selected column of theObject) + 1)
        set theList to itemFromPath(thePath)
    end if
    set theItem to item theRow of theList
   
    set content of browserCell to name of theItem
    set leaf of browserCell to class of data of theItem is not list
end will display browser cell

 


Copyright © 1998-2007 Late Night Software Ltd. - All Rights Reserved.