Trees

  • 리비전 슬러그: XUL_Tutorial/Trees
  • 리비전 제목: Trees
  • 리비전 아이디: 88808
  • 제작일시:
  • 만든이: Channy
  • 현재 리비전인가요? 아니오
  • 댓글 New page: <breadcrumbs></breadcrumbs> {{PreviousNext|XUL Tutorial:XPCOM Examples|XUL Tutorial:More Tree Features}} XUL은 tree를 사용하여 표형태 또는 계층목록을 만드는 방법을 ...

리비전 내용

{{ PreviousNext("XUL Tutorial:XPCOM Examples", "XUL Tutorial:More Tree Features") }}

XUL은 tree를 사용하여 표형태 또는 계층목록을 만드는 방법을 제공합니다.

트리

tree에서 가장 복잡한 요소중 하나가 tree입니다. listbox처럼, tree는 항목을 만드는 데 사용할 수 있습니다. tree 요소는 계층적 목록 또는 표를 만들 수도 있습니다. 예를 들어 메일 프로그램에서 메시지 목록, 또는 모질라의 북마크 편집창을 tree를 사용하여 만들 수 있습니다.

어떤 측면에서 tree는 listbox와 유사합니다. 둘다 다중 행과 열을 가진 표를 만드는 데 사용할 수 있으며, 둘다 열 머릿말(header)을 담을 수 있습니다. tree는 안쪽(netsted) 행을 지원하지만, listbox는 그렇지 않습니다. 하지만, listbox는 어떤 형태의 내용도 담을 수 있습니다. 반면 tree는 글과 그림 내용만 담을 수 있습니다. listbox는 단순하게 처리할 경우, tree에 대한 대안으로 만들어졌기 때문에, 필요한 경우 대신 사용할 수 있습니다. (프로그레스 바나 체크 박스 같은 경우 트리에 추가할 수 있습니다.)

tree는 칼럼 세트와 tree body 두 가지 부분으로 나누어 집니다. A tree consists of two parts, the set of columns, and the tree body.

  • 칼럼 세트는 treecol 요소의 갯수로 표시합니다. 각 칼럼은 tree의 상위 헤더로 나타납니다.

elements, one for each column. Each column will appear as a header at the top of the tree.

  • tree body는 tree에 포함되거나 treechildren 태그로 만든 데이터를 말합니다.

The tree is unique in that the body of the tree consists only of a single widget which draws all of the data in the tree. This contrasts with the listbox, where individual listitem and listcell tags are used to specify the rows in the listbox. In a tree, all of the data to be displayed is supplied by a separate object, called a tree view. When it comes time to display a cell, the tree widget will call out to this tree view to determine what to display, which in turn will be drawn by the tree. The tree is smart enough to only ask for information from the view for those rows that need to be displayed. This allows the view to be optimized such that it only needs to load the data for displayed content. For instance, a tree might have thousands of rows, yet most of them will be scrolled off the border of the tree, hidden from view. This means that the tree is scalable to any number of rows without any performance problems. Of course, this is independant of the performance of the view object itself.

A tree view is an object which implements the nsITreeView interface. This interface contains thirty properties and functions which you may implement. These functions will be called by the tree as necessary to retrieve data and state about the tree. For instance, the getCellText() function will be called to get the label for a particular cell in the tree.

An advantage of using a tree view is that it allows the view to store the data in a manner which is more suitable for the data, or to load the data on demand as rows are displayed. This allows more flexibility when using trees.

Naturally, having to implement a tree view with thirty or so properties and methods for every tree can be very cumbersome, especially for simple trees. Fortunately, XUL provides a couple of built-in view implementations which do most of the hard work for you. For most trees, especially when you first start to use trees, you will use one of these built-in types. However, you can create a view entirely from scratch if necessary. If you do, you might store the data in an array or JavaScript data structure, or load the data from an XML file.

Since the entire body of the tree is a single widget, you can't change the style of individual rows or cells in the normal way. This is because there are no elements that display the individual cells, like there is with the listbox. Instead, all drawing is done by the tree body using data supplied by the view. This is an important point and many XUL developers have trouble understanding this aspect. To modify the appearance of a tree cell, the view must instead associate a set of keywords for a row and cell. A special CSS syntax is used which styles components of the tree body with those keywords. In a sense, it is somewhat like using CSS classes. Tree styling will be discussed in detail in a later section.

Tree 요소

Trees can be created with the {{ XULElem("tree") }} element, which is described in the following sections. There are also two elements used to define the columns to be displayed in the tree.

{{ XULElem("tree") }}
This is the outer element of a tree.
{{ XULElem("treecols") }}
This element is a placeholder for a set of {{ XULElem("treecol") }} elements.
{{ XULElem("treecol") }}
This is used to declare a column of the tree. By using this element, you can specify additional information about how the data in the columns are sorted and if the user can resize the columns. You should always place an id attribute on a column, as Mozilla uses the ids to identify the columns when rearranging and hiding them. This is no longer required in Mozilla 1.8 and later, but it is still a good idea to use ids on columns.
{{ XULElem("treechildren") }}
This contains the main body of the tree where the individual rows of data will be displayed.
두개 칼럼을 가진 트리

{{ Xultu-sv("ex_trees_1.xul") }}

<tree flex="1">

  <treecols>
    <treecol id="nameColumn" label="Name" flex="1"/>
    <treecol id="addressColumn" label="Address" flex="2"/>
  </treecols>

  <treechildren/>

</tree>

First, the entire table is surrounded with a {{ XULElem("tree") }} element. This declares an element that is used as a table or tree. As with HTML tables, the data in a tree is always organized into rows. The columns are specified using the {{ XULElem("treecols") }} tag.

You may place as many columns as you wish in a tree. As with listboxes, a header row will appear with column labels. A drop-down menu will appear in the upper-right corner of the tree, which the user may use to show and hide individual columns. Each column is created with a {{ XULElem("treecol") }} element. You can set the header label using the label attribute. You may also want to make the columns flexible if your tree is flexible, so that the columns stretch as the tree does. In this example, the second column will be approximately twice as wide as the first column. All of the columns should be placed directly inside a {{ XULElem("treecols") }} element.

In this case we haven't specified a view to supply the tree's data, so we'll only see column headers and an empty tree body. You may have to resize the window to see anything since there isn't any data to display. Since the tree has been marked as flexible, the body will stretch to fit the available space. Making a tree flexible is quite commonly done, as it is often the case that the data in the tree is the most significant information displayed, so it makes sense to make the tree grow to fit. However, you may specify a specific number of rows to appear in a tree by setting the {{ XULAttr("rows") }} attribute on the {{ XULElem("tree") }} element. This attribute specifies how many rows are displayed in the user interface, not how many rows of data there are. The total number of rows is supplied by the tree view. If there are more rows of data in the tree, a scrollbar will appear to allow the user to see the rest of them. If you don't specify the {{ XULAttr("rows") }} attribute, the default value is 0, which means that none of the rows will appear. In this case, you would make the tree flexible. If your tree is flexible, it doesn't need a {{ XULAttr("rows") }} attribute since it will grow to fit the available space.

The Content Tree View

Having said that the data to be displayed in a tree comes from a view and not from XUL tags, there happens to be a built-in tree view which gets its data from XUL tags. This may be a bit confusing, but essentially, one of the built-in tree views uses a set of tags which can be used to specify information about the data in the tree. The following tags are used:

{{ XULElem("treeitem") }}
This contains a single parent row and all its descendants. This element also serves as the item which can be selected by the user. The treeitem tag would go around the entire row so that it is selectable as a whole.
{{ XULElem("treerow") }}
A single row in the tree, which should be placed inside a {{ XULElem("treeitem") }} tag.
{{ XULElem("treecell") }}
A single cell in a tree. This element would go inside a treerow element.

Conveniently, these tags may be placed directly inside the {{ XULElem("treechildren") }} tag, nested in the order above. The tags define the data to be displayed in the tree body. In this case, the tree uses the built-in tree view, called a content tree view, which uses the labels and values specified on these elements as the data for the tree. When the tree needs to display a row, the tree asks the content tree view for a cell's label by calling the view's getCellText function, which in turn gets the data from the label of the appropriate {{ XULElem("treecell") }}.

However, the three elements listed above are not displayed directly. They are used only as the source for the data for the view. Thus, only a handful of attributes apply to the {{ XULElem("treeitem") }} and related elements. For instance, you cannot change the appearance of the tree rows using the {{ XULAttr("style") }} attribute or with other CSS properties and the box related features such as flexibility and orientation cannot be used.

In fact, apart from some tree specific attributes, the only attributes that will have any effect will be the {{ XULAttr("label") }} attribute to set a text label for a cell and the {{ XULAttr("src") }} attribute to set an image. However, there are special ways of styling the tree and setting other features which we will see in later sections.

Also, events do not get sent to {{ XULElem("treeitem") }} element and their children; instead they get sent to the {{ XULElem("treechildren") }} element.

That the treeitems are unlike other XUL elements is a common source of confusion for XUL developers. Essentially, the tree content view is a view where the data for the cells is supplied from tags placed inside the tree. Naturally, if you are using a different kind of view, the data will be supplied from another source, and there won't be any {{ XULElem("treeitem") }} elements at all.

Let's start by looking at how to create a simple tree with multiple columns using the tree content view. This could be used to create a list of mail messages. There might be multiple columns, such as the sender and the subject.

treechildren 예제

{{ Xultu-sv("ex_trees_2.xul") }}

Image:trees1.png
<tree flex="1">

  <treecols>
    <treecol id="sender" label="Sender" flex="1"/>
    <treecol id="subject" label="Subject" flex="2"/>
  </treecols>

  <treechildren>
    <treeitem>
      <treerow>
        <treecell label="joe@somewhere.com"/>
        <treecell label="Top secret plans"/>
      </treerow>
    </treeitem>
    <treeitem>
      <treerow>
        <treecell label="mel@whereever.com"/>
        <treecell label="Let's do lunch"/>
      </treerow>
    </treeitem>
  </treechildren>

</tree>

그림에서 보듯이, 두개의 자료 열을 가진 tree가 만들어졌습니다.

이 tree는 두개의 열을 가지고 있고, 이 중 두번째는 첫번째보다 더많은 공간을 차지하게 되어있습니다. 이 경우 해당 열에 flex 속성을 줄 것입니다. CSS의 {{ XULAttr("width") }} 속성으로 넓이값을 줄 수도 있습니다. tree에 있는 열의 숫자만큼 {{ XULElem("treecol") }} 요소를 포함시켜야 한다. 그렇지않으면 엉뚱한 일이 발생합니다.


머릿말 행(header row)은 자동으로 만들어집니다. 오른쪽 위에 있는 버튼은 해당 열을 숨기고 감출 수 있습니다. 이 버튼을 숨기고 싶다면 {{ XULAttr("hidecolumnpicker") }} 속성을 tree에 넣거나 true 값을 주면 됩니다. 각 열에 id 속성을 설정했는 지 또는 행의 숨김과 보기가 작동하는 지를 확인하도록 합니다.

Make sure that you set an {{ XULAttr("id") }} attribute on each column or the hiding and showing of columns will not work in all versions of Mozilla.

The treechildren element surrounds all of the rows. Inside the body are individual rows, which may in turn contain other rows. For a simpler tree, each row is created with the {{ XULElem("treeitem") }} and {{ XULElem("treerow") }} elements. The treerow element surrounds all of the cells in a single row, while a treeitem element would surround a row and all of its children. Trees with nested rows are described in the next section.

Inside the rows, you will put individual tree cells. These are created using the {{ XULElem("treecell") }} element. You can set the text for the cell using the label attribute. The first {{ XULElem("treecell") }} in a row determines the content that will appear in the first column, the second {{ XULElem("treecell") }} determines the content that will appear in the second column, and so on.


사용자는 마우스로 항목을 클릭하거나 키보드를 사용해서, treeitem을 선택할 수 있습니다. Shift 또는 Control 키를 누른 상태에서 다른 행을 클릭해서 다중 항목을 선택할 수 있습니다. 다중선택을 사용 못하게 하려면, tree에 {{ XULAttr("seltype") }} 속성을 넣고, 값을 single로 합니다. 이렇게하면, 한번에 한 행만 선택할 수 있습니다.

찾은 파일에서 tree 추가

검색결과가 표시되도록 파일찾기(find files) 창에 tree를 추가해보자. 다음 코드는 iframe에 추가해야 한다. tree는 treeview를 사용합니다. 아래 코드는 iframe에 추가할 수 있습니다.

<tree flex="1">
  <treecols>
    <treecol id="name" label="Filename" flex="1"/>
    <treecol id="location" label="Location" flex="2"/>
    <treecol id="size" label="Size" flex="1"/>
  </treecols>

  <treechildren>
   <treeitem>
     <treerow>
       <treecell label="mozilla"/>
       <treecell label="/usr/local"/>
       <treecell label="2520 bytes"/>
     </treerow>
   </treeitem>
  </treechildren>
</tree>

<splitter collapse="before" resizeafter="grow"/>

파일명(filename), 위치(location) 그리고 파일크기(file size)라는 3개의 행을 가진 tree를 추가한 것입니다. 두번째 열은 더 큰 flex(flex="2")값을 가지고 있기 때문에 넓이가 2배가 됩니다. 하나의 행이 추가되었는 데, 하나의 행을 가진 표가 어떤 모습인지 설명하기 위한 것입니다. 실제 마무리 단계에서는, 검색했을 경우 해당 열은 스크립트에 의해 추가될 것입니다.

지금까지 예제는 {{ Xultu-sv("/findfile/findfile-trees.xul") }}에서 보실 수 있습니다.


다음 장에서는 고급 tree 기능에 대해 알아 보겠습니다.

{{ PreviousNext("XUL Tutorial:XPCOM Examples", "XUL Tutorial:More Tree Features") }}

{{ languages( { "en": "en/XUL_Tutorial/Trees", "fr": "fr/Tutoriel_XUL/Arbres", "ja": "ja/XUL_Tutorial/Trees", "pl": "pl/Kurs_XUL/Drzewa", "es": "es/Tutorial_de_XUL/\u00c1rboles" } ) }}

리비전 소스

<p>
</p><p>{{ PreviousNext("XUL Tutorial:XPCOM Examples", "XUL Tutorial:More Tree Features") }}
</p><p>XUL은 tree를 사용하여 표형태 또는 계층목록을 만드는 방법을 제공합니다.
</p>
<h3 name=".ED.8A.B8.EB.A6.AC"> 트리 </h3>
<p><a href="ko/XUL/tree">tree</a>에서 가장 복잡한 요소중 하나가 tree입니다. listbox처럼, tree는 항목을 만드는 데 사용할 수 있습니다. tree 요소는 계층적 목록 또는 표를 만들 수도 있습니다. 예를 들어 메일 프로그램에서 메시지 목록, 또는 모질라의 북마크 편집창을 tree를 사용하여 만들 수 있습니다.
</p><p>어떤 측면에서 tree는 <code><a href="ko/XUL/listbox">listbox</a></code>와 유사합니다. 둘다 다중 행과 열을 가진 표를 만드는 데 사용할 수 있으며, 둘다 열 머릿말(header)을 담을 수 있습니다. tree는 안쪽(netsted) 행을 지원하지만, listbox는 그렇지 않습니다. 하지만, listbox는 어떤 형태의 내용도 담을 수 있습니다. 반면 tree는 글과 그림 내용만 담을 수 있습니다. listbox는 단순하게 처리할 경우, tree에 대한 대안으로 만들어졌기 때문에, 필요한 경우 대신 사용할 수 있습니다. (프로그레스 바나 체크 박스 같은 경우 트리에 추가할 수 있습니다.)
</p><p>tree는 칼럼 세트와 tree body 두 가지 부분으로 나누어 집니다.
A tree consists of two parts, the set of columns, and the tree body. </p>
<ul><li> 칼럼 세트는 <code><a href="ko/XUL/treecol">treecol</a></code> 요소의 갯수로 표시합니다. 각 칼럼은 tree의 상위 헤더로 나타납니다.
</li></ul>
<p>elements, one for each column. Each column will appear as a header at the top of the tree. </p>
<ul><li> tree body는 tree에 포함되거나 <code><a href="ko/XUL/treechildren">treechildren</a></code> 태그로 만든 데이터를 말합니다.
</li></ul>
<p>The tree is unique in that the body of the tree consists only of a single widget which draws all of the data in the tree. This contrasts with the listbox, where individual <code><a href="ko/XUL/listitem">listitem</a></code> and <code><a href="ko/XUL/listcell">listcell</a></code> tags are used to specify the rows in the listbox. In a tree, all of the data to be displayed is supplied by a separate object, called a tree view. When it comes time to display a cell, the tree widget will call out to this tree view to determine what to display, which in turn will be drawn by the tree. The tree is smart enough to only ask for information from the view for those rows that need to be displayed. This allows the view to be optimized such that it only needs to load the data for displayed content. For instance, a tree might have thousands of rows, yet most of them will be scrolled off the border of the tree, hidden from view. This means that the tree is scalable to any number of rows without any performance problems. Of course, this is independant of the performance of the view object itself.
</p><p>A tree view is an object which implements the <a href="ko/NsITreeView">nsITreeView</a> interface. This interface contains thirty properties and functions which you may implement. These functions will be called by the tree as necessary to retrieve data and state about the tree. For instance, the <code>getCellText()</code> function will be called to get the label for a particular cell in the tree.
</p><p>An advantage of using a tree view is that it allows the view to store the data in a manner which is more suitable for the data, or to load the data on demand as rows are displayed. This allows more flexibility when using trees.
</p><p>Naturally, having to implement a tree view with thirty or so properties and methods for every tree can be very cumbersome, especially for simple trees. Fortunately, XUL provides a couple of built-in view implementations which do most of the hard work for you. For most trees, especially when you first start to use trees, you will use one of these built-in types. However, you can create a view entirely from scratch if necessary. If you do, you might store the data in an <a href="ko/A_re-introduction_to_JavaScript#Arrays">array</a> or JavaScript data structure, or load the data from an XML file.
</p><p>Since the entire body of the tree is a single widget, you can't change the style of individual rows or cells in the normal way. This is because there are no elements that display the individual cells, like there is with the <a href="ko/XUL_Tutorial/List_Controls#Multi-Column_List_Boxes">listbox</a>. Instead, all drawing is done by the tree body using data supplied by the view. This is an important point and many XUL developers have trouble understanding this aspect. To modify the appearance of a tree cell, the view must instead associate a set of keywords for a row and cell. A special CSS syntax is used which styles components of the tree body with those keywords. In a sense, it is somewhat like using CSS classes. Tree styling will be discussed in detail in a <a href="ko/XUL_Tutorial/Styling_a_Tree">later section</a>.
</p>
<h3 name="Tree_.EC.9A.94.EC.86.8C"> Tree 요소 </h3>
<p>Trees can be created with the <code>{{ XULElem("tree") }}</code> element, which is described in the following sections. There are also two elements used to define the columns to be displayed in the tree.
</p>
<dl><dt> {{ XULElem("tree") }}
</dt><dd> This is the outer element of a tree.
</dd></dl>
<dl><dt> {{ XULElem("treecols") }}
</dt><dd> This element is a placeholder for a set of <code>{{ XULElem("treecol") }}</code> elements.
</dd></dl>
<dl><dt> {{ XULElem("treecol") }}
</dt><dd> This is used to declare a column of the tree. By using this element, you can specify additional information about how the data in the columns are sorted and if the user can resize the columns. You should always place an <code><a href="ko/XUL/Attribute/id">id</a></code> attribute on a column, as Mozilla uses the ids to identify the columns when rearranging and hiding them. This is no longer required in Mozilla 1.8 and later, but it is still a good idea to use ids on columns.
</dd></dl>
<dl><dt> {{ XULElem("treechildren") }}
</dt><dd> This contains the main body of the tree where the individual rows of data will be displayed.
</dd></dl>
<h5 name=".EB.91.90.EA.B0.9C_.EC.B9.BC.EB.9F.BC.EC.9D.84_.EA.B0.80.EC.A7.84_.ED.8A.B8.EB.A6.AC"> 두개 칼럼을 가진 트리 </h5>
<p>{{ Xultu-sv("ex_trees_1.xul") }}
</p>
<pre>&lt;tree flex="1"&gt;

  &lt;treecols&gt;
    &lt;treecol id="nameColumn" label="Name" flex="1"/&gt;
    &lt;treecol id="addressColumn" label="Address" flex="2"/&gt;
  &lt;/treecols&gt;

  &lt;treechildren/&gt;

&lt;/tree&gt;
</pre>
<p>First, the entire table is surrounded with a <code>{{ XULElem("tree") }}</code> element. This declares an element that is used as a table or tree. As with HTML tables, the data in a tree is always organized into rows. The columns are specified using the <code>{{ XULElem("treecols") }}</code> tag.
</p><p>You may place as many columns as you wish in a tree. As with <a href="ko/XUL_Tutorial/List_Controls">listboxes</a>, a header row will appear with column labels. A drop-down menu will appear in the upper-right corner of the tree, which the user may use to show and hide individual columns. Each column is created with a <code>{{ XULElem("treecol") }}</code> element. You can set the header label using the <code>label</code> attribute. You may also want to make the columns flexible if your tree is flexible, so that the columns stretch as the tree does. In this example, the second column will be approximately twice as wide as the first column. All of the columns should be placed directly inside a <code>{{ XULElem("treecols") }}</code> element.
</p><p>In this case we haven't specified a view to supply the tree's data, so we'll only see column headers and an empty tree body. You may have to resize the window to see anything since there isn't any data to display. Since the tree has been marked as flexible, the body will stretch to fit the available space. Making a tree flexible is quite commonly done, as it is often the case that the data in the tree is the most significant information displayed, so it makes sense to make the tree grow to fit. However, you may specify a specific number of rows to appear in a tree by setting the <code>{{ XULAttr("rows") }}</code> attribute on the <code>{{ XULElem("tree") }}</code> element. This attribute specifies how many rows are displayed in the user interface, not how many rows of data there are. The total number of rows is supplied by the tree view. If there are more rows of data in the tree, a scrollbar will appear to allow the user to see the rest of them. If you don't specify the <code>{{ XULAttr("rows") }}</code> attribute, the default value is 0, which means that none of the rows will appear. In this case, you would make the tree flexible. If your tree is flexible, it doesn't need a <code>{{ XULAttr("rows") }}</code> attribute since it will grow to fit the available space.
</p>
<h3 name="The_Content_Tree_View"> The Content Tree View </h3>
<p>Having said that the data to be displayed in a tree comes from a view and not from XUL tags, there happens to be a built-in tree view which gets its data from XUL tags. This may be a bit confusing, but essentially, one of the built-in tree views uses a set of tags which can be used to specify information about the data in the tree. The following tags are used:
</p>
<dl><dt> {{ XULElem("treeitem") }}
</dt><dd> This contains a single parent row and all its descendants. This element also serves as the item which can be selected by the user. The treeitem tag would go around the entire row so that it is selectable as a whole.
</dd></dl>
<dl><dt> {{ XULElem("treerow") }}
</dt><dd> A single row in the tree, which should be placed inside a <code>{{ XULElem("treeitem") }}</code> tag.
</dd></dl>
<dl><dt> {{ XULElem("treecell") }}
</dt><dd> A single cell in a tree. This element would go inside a treerow element.
</dd></dl>
<p>Conveniently, these tags may be placed directly inside the <code>{{ XULElem("treechildren") }}</code> tag, nested in the order above. The tags define the data to be displayed in the tree body. In this case, the tree uses the built-in tree view, called a content tree view, which uses the labels and values specified on these elements as the data for the tree. When the tree needs to display a row, the tree asks the content tree view for a cell's label by calling the view's getCellText function, which in turn gets the data from the label of the appropriate <code>{{ XULElem("treecell") }}</code>.
</p><p>However, the three elements listed above are not displayed directly. They are used only as the source for the data for the view. Thus, only a handful of attributes apply to the <code>{{ XULElem("treeitem") }}</code> and related elements. For instance, you cannot change the appearance of the tree rows using the <code>{{ XULAttr("style") }}</code> attribute or with other CSS properties and the box related features such as flexibility and orientation cannot be used.
</p><p>In fact, apart from some tree specific attributes, the only attributes that will have any effect will be the <code>{{ XULAttr("label") }}</code> attribute to set a text label for a cell and the <code>{{ XULAttr("src") }}</code> attribute to set an image. However, there are special ways of styling the tree and setting other features which we will see in later sections.
</p><p>Also, events do not get sent to <code>{{ XULElem("treeitem") }}</code> element and their children; instead they get sent to the <code>{{ XULElem("treechildren") }}</code> element.
</p><p>That the treeitems are unlike other XUL elements is a common source of confusion for XUL developers. Essentially, the tree content view is a view where the data for the cells is supplied from tags placed inside the tree. Naturally, if you are using a different kind of view, the data will be supplied from another source, and there won't be any <code>{{ XULElem("treeitem") }}</code> elements at all.
</p><p>Let's start by looking at how to create a simple tree with multiple columns using the tree content view. This could be used to create a list of mail messages. There might be multiple columns, such as the sender and the subject.
</p>
<h4 name="treechildren_.EC.98.88.EC.A0.9C"> <code>treechildren</code> 예제</h4>
<p>{{ Xultu-sv("ex_trees_2.xul") }}
</p>
<div class="float-right"><img alt="Image:trees1.png" fileid="0" src="File:ko/Media_Gallery/Trees1.png"></div>
<pre>&lt;tree flex="1"&gt;

  &lt;treecols&gt;
    &lt;treecol id="sender" label="Sender" flex="1"/&gt;
    &lt;treecol id="subject" label="Subject" flex="2"/&gt;
  &lt;/treecols&gt;

  &lt;treechildren&gt;
    &lt;treeitem&gt;
      &lt;treerow&gt;
        &lt;treecell label="joe@somewhere.com"/&gt;
        &lt;treecell label="Top secret plans"/&gt;
      &lt;/treerow&gt;
    &lt;/treeitem&gt;
    &lt;treeitem&gt;
      &lt;treerow&gt;
        &lt;treecell label="mel@whereever.com"/&gt;
        &lt;treecell label="Let's do lunch"/&gt;
      &lt;/treerow&gt;
    &lt;/treeitem&gt;
  &lt;/treechildren&gt;

&lt;/tree&gt;
</pre>
<p>그림에서 보듯이, 두개의 자료 열을 가진 tree가 만들어졌습니다.
</p><p>이 tree는 두개의 열을 가지고 있고, 이 중 두번째는 첫번째보다 더많은 공간을 차지하게 되어있습니다. 이 경우 해당 열에 flex 속성을 줄 것입니다. CSS의 <code>{{ XULAttr("width") }}</code> 속성으로 넓이값을 줄 수도 있습니다. tree에 있는 열의 숫자만큼 <code>{{ XULElem("treecol") }}</code> 요소를 포함시켜야 한다. 그렇지않으면 엉뚱한 일이 발생합니다.
</p><p><br>
머릿말 행(header row)은 자동으로 만들어집니다. 오른쪽 위에 있는 버튼은 해당 열을 숨기고 감출 수 있습니다. 이 버튼을 숨기고 싶다면 <code>{{ XULAttr("hidecolumnpicker") }}</code> 속성을 tree에 넣거나 true 값을 주면 됩니다. 각 열에 id 속성을 설정했는 지 또는 행의 숨김과 보기가 작동하는 지를 확인하도록 합니다.
</p><p>Make sure that you set an <code>{{ XULAttr("id") }}</code> attribute on each column or the hiding and showing of columns will not work in all versions of Mozilla.
</p><p>The <code>treechildren</code> element surrounds all of the rows. Inside the body are individual rows, which may in turn contain other rows. For a simpler tree, each row is created with the <code>{{ XULElem("treeitem") }}</code> and <code>{{ XULElem("treerow") }}</code> elements. The <code>treerow</code> element surrounds all of the cells in a single row, while a <code>treeitem</code> element would surround a row and all of its children. Trees with nested rows are described in the next section.
</p><p>Inside the rows, you will put individual tree cells. These are created using the <code>{{ XULElem("treecell") }}</code> element. You can set the text for the cell using the <code>label</code> attribute. The first <code>{{ XULElem("treecell") }}</code> in a row determines the content that will appear in the first column, the second <code>{{ XULElem("treecell") }}</code> determines the content that will appear in the second column, and so on.
</p><p><br>
사용자는 마우스로 항목을 클릭하거나 키보드를 사용해서, treeitem을 선택할 수 있습니다. Shift 또는 Control 키를 누른 상태에서 다른 행을 클릭해서 다중 항목을 선택할 수 있습니다. 다중선택을 사용 못하게 하려면, tree에 <code>{{ XULAttr("seltype") }}</code> 속성을 넣고, 값을 <code>single</code>로 합니다. 이렇게하면, 한번에 한 행만 선택할 수 있습니다.
</p>
<div class="highlight">
<h4 name=".EC.B0.BE.EC.9D.80_.ED.8C.8C.EC.9D.BC.EC.97.90.EC.84.9C_tree_.EC.B6.94.EA.B0.80"> 찾은 파일에서 tree 추가 </h4>
<p>검색결과가 표시되도록 파일찾기(find files) 창에 tree를 추가해보자. 다음 코드는 iframe에 추가해야 한다. tree는 treeview를 사용합니다. 아래 코드는 <a href="ko/XUL_Tutorial/Content_Panels#iframe_example">iframe</a>에 추가할 수 있습니다.
</p>
<pre class="eval"><span class="highlightred">&lt;tree flex="1"&gt;
  &lt;treecols&gt;
    &lt;treecol id="name" label="Filename" flex="1"/&gt;
    &lt;treecol id="location" label="Location" flex="2"/&gt;
    &lt;treecol id="size" label="Size" flex="1"/&gt;
  &lt;/treecols&gt;

  &lt;treechildren&gt;
   &lt;treeitem&gt;
     &lt;treerow&gt;
       &lt;treecell label="mozilla"/&gt;
       &lt;treecell label="/usr/local"/&gt;
       &lt;treecell label="2520 bytes"/&gt;
     &lt;/treerow&gt;
   &lt;/treeitem&gt;
  &lt;/treechildren&gt;
&lt;/tree&gt;</span>

&lt;splitter collapse="before" resizeafter="grow"/&gt;
</pre>
<p>파일명(filename), 위치(location) 그리고 파일크기(file size)라는 3개의 행을 가진 tree를 추가한 것입니다. 두번째 열은 더 큰 flex(flex="2")값을 가지고 있기 때문에 넓이가 2배가 됩니다. 하나의 행이 추가되었는 데, 하나의 행을 가진 표가 어떤 모습인지 설명하기 위한 것입니다. 실제 마무리 단계에서는, 검색했을 경우 해당 열은 스크립트에 의해 추가될 것입니다.
</p><p>지금까지 예제는 {{ Xultu-sv("/findfile/findfile-trees.xul") }}에서 보실 수 있습니다.
</p>
</div>
<p><br>
다음 장에서는 <a href="ko/XUL_Tutorial/More_Tree_Features">고급 tree 기능</a>에 대해 알아 보겠습니다.
</p><p>{{ PreviousNext("XUL Tutorial:XPCOM Examples", "XUL Tutorial:More Tree Features") }}
</p>{{ languages( { "en": "en/XUL_Tutorial/Trees", "fr": "fr/Tutoriel_XUL/Arbres", "ja": "ja/XUL_Tutorial/Trees", "pl": "pl/Kurs_XUL/Drzewa", "es": "es/Tutorial_de_XUL/\u00c1rboles" } ) }}
Revert to this revision