!!! Listings aus dem Artikel "Forstwesen"
!!! von Karsten Düsterloh, iX 8/2005, S. 148

!!! Listing 1: Tree.xul

<?xml version="1.0"?>
<window
  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  title="Tree">
  <tree flex="1">
    <treecols>
      <treecol id="col1" label="Spalte 1" flex="1" primary="true"/>
      <treecol id="col2" label="Spalte 2" flex="1"/>
    </treecols>
    <treechildren>
      <treeitem container="true">
        <treerow>
          <treecell label="Text A1"/>
          <treecell label="Text A2"/>
        </treerow>
        <treechildren>
          <treeitem container="true" open="true">
            <treerow>
              <treecell label="Text B1"/>
              <treecell label="Text B2"/>
            </treerow>
            <treechildren>
              <treeitem>
                <treerow>
                  <treecell label="Text C1"/>
                  <treecell label="Text C2"/>
                </treerow>
              </treeitem>
              <treeseparator label="(Trennzeile)"/>
              <treeitem>
                <treerow>
                  <treecell label="Text C3"/>
                  <treecell label="Text C4"/>
                </treerow>
              </treeitem>
            </treechildren>
          </treeitem>
        </treechildren>
      </treeitem>
    </treechildren>
  </tree>
</window>

!!! Listing 2: TreeView.xul

<?xml version="1.0"?>
<window 
  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  title="TreeView" onload="InitView()">

  <script type="application/x-javascript">
    <![CDATA[
      function InitView()
      {
        const koTreeView = 
        {
          // 100 Zeilen im Baum
          rowCount: 100,
          getCellText: function(aiRow, aoColumn)
          {
            if (aoColumn.id == "RowCol")
              // Zeilennummer
              return "Zeile " + aiRow;
            else 
              // aktuelles Datum und Uhrzeit
              return (new Date).toLocaleString();
          },
          setTree: function(aoTreeBox)
          { // die zugehörige XUL-Box merken
            this.treebox = aoTreeBox; 
          },
          isContainer: function(aiRow)
          { // jedes 5. Zeile sei ein Blatt
            return !!(aiRow % 5); 
          },
          isSeparator: function(aiRow)
          { // jedes Blatt sei ein Trenner
            return !(aiRow % 5); 
          },
          getLevel: function(aiRow)
          { // Blätter auf tiefster Ebene
            return (aiRow - 1) % 5; 
          },
          getParentIndex: function(aiRow)
          { // unter vorhergehende hängen
            return aiRow - 1;
          },
          hasNextSibling: function(aiRow, afterIndex)
          { // nur auf Ebene 0
            return !((aiRow - 1) % 5); 
          },
          // nicht selbst genutzte Funktionen
          // der nsITreeView-Schnittstelle
          // müssen dennoch vorhanden sein
          getRowProperties: function(index, properties){},
          getCellProperties: function(row, col, properties){},
          getColumnProperties: function(col, properties) {},
          isContainerOpen: function(index){return true},
          isContainerEmpty: function(index){return false},
          isSorted: function(){return false},
          canDrop: function(index, orientation){return false},
          drop: function(row, orientation){}, 
          getImageSrc: function(row, col){return null},
          getProgressMode: function(row, col){return 3},
          getCellValue: function(row, col){return null},
          toggleOpenState: function(index){},
          cycleHeader: function(col){},
          selectionChanged: function(){},
          cycleCell: function(row, col){},
          isEditable: function(row, col){return false},
          setCellValue: function(row, col, value){},
          setCellText: function(row, col, value){},
          performAction: function(action){},
          performActionOnRow: function(action, row){},
          performActionOnCell: function(action, row, col){}
        };
        // eigene Baumansicht setzen
        document.getElementById('treeview').view = koTreeView;
      }
    ]]>
  </script>

  <tree id="treeview" flex="1">
    <treecols>
      <treecol id="RowCol"  label="Zeile"   flex="1" primary="true"/>
      <treecol id="DateCol" label="Uhrzeit" flex="1"/>
    </treecols>
    <treechildren/>
  </tree>

</window>

!!! Listing 3: TreeStyle.xul

<?xml version="1.0"?>
<?xml-stylesheet type="text/css" 
                 href="data:text/css, 
  treechildren::-moz-tree-column(primary)
  { background-color: blue; }
  treechildren::-moz-tree-row(rot, gelb)
  { background-color: red; }
  treechildren::-moz-tree-cell
  { background-color: yellow; }
  treechildren::-moz-tree-cell-text(gelb)
  { color: green; font-size: 120%; }
"?>

<window 
  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  title="TreeStyle">
  <tree flex="1">
    <treecols>
      <treecol id="col1" label="Spalte 1" flex="1" primary="true"/>
      <treecol id="col2" label="Spalte 2" flex="1"/>
    </treecols>
    <treechildren alternatingbackground="true">
      <treeitem container="true" open="true">
        <treerow>
          <treecell label="Text A1" properties="gelb"/>
          <treecell label="Text A2"/>
        </treerow>
        <treechildren>
          <treeitem container="true" open="true">
            <treerow properties="gelb rot">
              <treecell label="Text B1"/>
              <treecell label="Text B2" properties="gelb"/>
            </treerow>
          </treeitem>
        </treechildren>
      </treeitem>
    </treechildren>
  </tree>
</window>

!!! Listing 4: TreeRDF.rdf

<?xml version="1.0"?>
<RDF:RDF xmlns:c="http://www.mozilla.org/rdf/chrome#"
         xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
  <RDF:Seq RDF:about="urn:mozilla:package:root">
    <RDF:li>
      <RDF:Description RDF:about="urn:mozilla:package:global"
           c:baseURL="jar:resource:/chrome/toolkit.jar!/content/global/"
           c:locType="install"
           c:displayName="Toolkit"
           c:author="mozilla.org"
           c:name="global"
           c:localeVersion="1.7"
           c:skinVersion="1.5" />
    </RDF:li>
    <RDF:li>
      <RDF:Description RDF:about="urn:mozilla:package:inspector"
           c:hasOverlays="true"
           c:baseURL="jar:resource:/chrome/inspector.jar!/content/inspector/"
           c:locType="install"
           c:displayName="Document Inspector"
           c:author="Joe Hewitt"
           c:name="inspector"
           c:localeVersion="1.7"
           c:skinVersion="1.5" />
    </RDF:li>
    <RDF:li>
      <RDF:Description RDF:about="urn:mozilla:package:mozapps"
           c:baseURL="jar:resource:/chrome/toolkit.jar!/content/mozapps/"
           c:locType="install"
           c:displayName="Mozilla Application Support"
           c:author="mozilla.org"
           c:name="mozapps"
           c:skinVersion="1.5"
           c:localeVersion="1.7" />
    </RDF:li>
  </RDF:Seq>
</RDF:RDF>

!!! Listing 5: TreeRDF.xul

<?xml version="1.0"?>
<window 
  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  title="TreeRDF">
  <tree id="treerdf" flex="1"
        datasources="TreeRDF.rdf" 
        ref="urn:mozilla:package:root">
    <treecols>
      <treecol id="Name" label="Name" primary="true" flex="1"/>
    </treecols>
    <template>
      <treechildren flex="1">
        <treeitem uri="rdf:*">
          <treerow>
            <treecell label="rdf:http://www.mozilla.org/rdf/chrome#name"/>
          </treerow>
        </treeitem>
      </treechildren>
    </template>
  </tree>
</window>

!!! Listing 6: TreeRDFext.xul

<?xml version="1.0"?>
<window 
  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  title="TreeRDFext"
  xmlns:c="http://www.mozilla.org/rdf/chrome#"
  xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
  <tree id="treerdfext" flex="1"
        datasources="TreeRDF.rdf" 
        ref="urn:mozilla:package:root">
    <treecols>
      <treecol id="Name" label="Name" primary="true" flex="1"/>
    </treecols>
    <template>
      <rule>
        <conditions>
          <content uri="?uri"/>
          <member container="?uri" child="?paket"/>
          <triple subject="?paket" 
             predicate="http://www.mozilla.org/rdf/chrome#name" 
             object="?name"/>
        </conditions>
        <action>
          <treechildren flex="1">
            <treeitem uri="?paket">
              <treerow>
                <treecell label="?name"/>
              </treerow>
            </treeitem>
          </treechildren>
        </action>
      </rule>
    </template>
  </tree>
</window>
