2017-02-22 2 views
0

JTree 구성 요소 및 XML에 익숙하지 않습니다.Java JTree/Prestashop 범주

<?xml version="1.0" encoding="UTF-8"?> 
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink"> 
<categories> 
    <category> 
     <id><![CDATA[1]]></id> 
     <id_parent><![CDATA[0]]></id_parent> 
     <level_depth><![CDATA[0]]></level_depth> 
     <nb_products_recursive notFilterable="true"><![CDATA[83]]></nb_products_recursive> 
     <active><![CDATA[1]]></active> 
     <id_shop_default><![CDATA[1]]></id_shop_default> 
     <is_root_category><![CDATA[0]]></is_root_category> 
     <position><![CDATA[1]]></position> 
     <date_add><![CDATA[2015-09-08 09:40:14]]></date_add> 
     <date_upd><![CDATA[2015-09-08 09:40:14]]></date_upd> 
     <name> 
     <language id="1" xlink:href="https://mywebsite/api/languages/1"><![CDATA[Racine]]></language> 
     <language id="3" xlink:href="https://mywebsite/api/languages/3"><![CDATA[Racine]]></language> 
     <language id="4" xlink:href="https://mywebsite/api/languages/4"><![CDATA[Racine]]></language> 
     </name> 
     <associations> 
      <categories nodeType="category" api="categories"> 
       <category xlink:href="https://mywebsite/api/categories/2"> 
        <id><![CDATA[2]]></id> 
       </category> 
      </categories> 
      <products nodeType="product" api="products"/> 
     </associations> 
    </category> 
    <category> 
     <id><![CDATA[2]]></id> 
     <id_parent xlink:href="https://mywebsite/api/categories/1"><![CDATA[1]]></id_parent> 
     <level_depth><![CDATA[1]]></level_depth> 
     <nb_products_recursive notFilterable="true"><![CDATA[83]]></nb_products_recursive> 
     <active><![CDATA[1]]></active> 
     <id_shop_default><![CDATA[1]]></id_shop_default> 
     <is_root_category><![CDATA[1]]></is_root_category> 
     <position><![CDATA[1]]></position> 
     <date_add><![CDATA[2015-09-08 09:40:14]]></date_add> 
     <date_upd><![CDATA[2015-09-08 09:40:14]]></date_upd> 
     <name> 
     <language id="1" xlink:href="https://mywebsite/api/languages/1"><![CDATA[Accueil]]></language> 
     <language id="3" xlink:href="https://mywebsite/api/languages/3"><![CDATA[Accueil]]></language> 
     <language id="4" xlink:href="https://mywebsite/api/languages/4"><![CDATA[Accueil]]></language> 
     </name> 
     <associations> 
      <categories nodeType="category" api="categories"> 
       <category xlink:href="https://mywebsite/api/categories/15"> 
        <id><![CDATA[15]]></id> 
       </category> 
       <category xlink:href="https://mywebsite/api/categories/21"> 
        <id><![CDATA[21]]></id> 
       </category> 
       <category xlink:href="https://mywebsite/api/categories/14"> 
        <id><![CDATA[14]]></id> 
       </category> 
       <category xlink:href="https://mywebsite/api/categories/33"> 
        <id><![CDATA[33]]></id> 
       </category> 
      </categories> 
      <products nodeType="product" api="products"/> 
     </associations> 
    </category> 
    <category> 
     <id><![CDATA[14]]></id> 
     <id_parent xlink:href="https://mywebsite/api/categories/2"><![CDATA[2]]></id_parent> 
     <level_depth><![CDATA[2]]></level_depth> 
     <nb_products_recursive notFilterable="true"><![CDATA[14]]></nb_products_recursive> 
     <active><![CDATA[1]]></active> 
     <id_shop_default><![CDATA[1]]></id_shop_default> 
     <is_root_category><![CDATA[0]]></is_root_category> 
     <position><![CDATA[3]]></position> 
     <date_add><![CDATA[2016-01-12 09:41:45]]></date_add> 
     <date_upd><![CDATA[2016-02-12 10:20:54]]></date_upd> 
     <name> 
     <language id="1" xlink:href="https://mywebsite/api/languages/1"><![CDATA[Télécommande]]></language> 
     <language id="3" xlink:href="https://mywebsite/api/languages/3"><![CDATA[Télécommande]]></language> 
     <language id="4" xlink:href="https://mywebsite/api/languages/4"><![CDATA[Télécommande]]></language> 
     </name> 
     <associations> 
      <categories nodeType="category" api="categories"/> 
      <products nodeType="product" api="products"/> 
     </associations> 
    </category> 
    <category> 
     <id><![CDATA[15]]></id> 
     <id_parent xlink:href="https://mywebsite/api/categories/2"><![CDATA[2]]></id_parent> 
     <level_depth><![CDATA[2]]></level_depth> 
     <nb_products_recursive notFilterable="true"><![CDATA[41]]></nb_products_recursive> 
     <active><![CDATA[1]]></active> 
     <id_shop_default><![CDATA[1]]></id_shop_default> 
     <is_root_category><![CDATA[0]]></is_root_category> 
     <position><![CDATA[1]]></position> 
     <date_add><![CDATA[2016-01-13 15:34:14]]></date_add> 
     <date_upd><![CDATA[2016-02-29 15:11:49]]></date_upd> 
     <name> 
      <language id="1" xlink:href="https://mywebsite/api/languages/1"><![CDATA[Audio-Vidéo]]></language> 
      <language id="3" xlink:href="https://mywebsite/api/languages/3"><![CDATA[Audio-Video]]></language> 
      <language id="4" xlink:href="https://mywebsite/api/languages/4"><![CDATA[Audio-Vidéo]]></language> 
     </name> 
     <associations> 
      <categories nodeType="category" api="categories"> 
       <category xlink:href="https://mywebsite/api/categories/16"> 
        <id><![CDATA[16]]></id> 
       </category> 
       <category xlink:href="https://mywebsite/api/categories/17"> 
        <id><![CDATA[17]]></id> 
       </category> 
       <category xlink:href="https://mywebsite/api/categories/18"> 
        <id><![CDATA[18]]></id> 
       </category> 
       <category xlink:href="https://mywebsite/api/categories/19"> 
        <id><![CDATA[19]]></id> 
       </category> 
       <category xlink:href="https://mywebsite/api/categories/20"> 
        <id><![CDATA[20]]></id> 
       </category> 
      </categories> 
      <products nodeType="product" api="products"/> 
     </associations> 
    </category> 
    <category> 
     <id><![CDATA[19]]></id> 
     <id_parent xlink:href="https://mywebsite/api/categories/15"><![CDATA[15]]></id_parent> 
     <level_depth><![CDATA[3]]></level_depth> 
     <nb_products_recursive notFilterable="true"><![CDATA[-1]]></nb_products_recursive> 
     <active><![CDATA[1]]></active> 
     <id_shop_default><![CDATA[1]]></id_shop_default> 
     <is_root_category><![CDATA[0]]></is_root_category> 
     <position><![CDATA[4]]></position> 
     <date_add><![CDATA[2016-01-13 15:43:23]]></date_add> 
     <date_upd><![CDATA[2016-02-29 15:13:45]]></date_upd> 
     <name> 
     <language id="1" xlink:href="https://mywebsite/api/languages/1"><![CDATA[Casque Yurbuds]]></language> 
     <language id="3" xlink:href="https://mywebsite/api/languages/3"><![CDATA[Casque Yurbuds]]></language> 
     <language id="4" xlink:href="https://mywebsite/api/languages/4"><![CDATA[Casque Yurbuds]]></language> 
     </name> 
     <associations> 
      <categories nodeType="category" api="categories"> 
       <category xlink:href="https://mywebsite/api/categories/24"> 
        <id><![CDATA[24]]></id> 
       </category> 
      </categories> 
      <products nodeType="product" api="products"/> 
     </associations> 
    </category> 
    <category> 
     <id><![CDATA[21]]></id> 
     <id_parent xlink:href="https://mywebsite/api/categories/2"><![CDATA[2]]></id_parent> 
     <level_depth><![CDATA[2]]></level_depth> 
     <nb_products_recursive notFilterable="true"><![CDATA[35]]></nb_products_recursive> 
     <active><![CDATA[1]]></active> 
     <id_shop_default><![CDATA[1]]></id_shop_default> 
     <is_root_category><![CDATA[0]]></is_root_category> 
     <position><![CDATA[2]]></position> 
     <date_add><![CDATA[2016-01-13 15:46:00]]></date_add> 
     <date_upd><![CDATA[2016-02-12 10:19:24]]></date_upd> 
     <name> 
     <language id="1" xlink:href="https://mywebsite/api/languages/1"><![CDATA[Multimédia]]></language> 
     <language id="3" xlink:href="https://mywebsite/api/languages/3"><![CDATA[Multimedia]]></language> 
     <language id="4" xlink:href="https://mywebsite/api/languages/4"><![CDATA[Multimédia]]></language> 
     </name> 
     <associations> 
      <categories nodeType="category" api="categories"> 
       <category xlink:href="https://mywebsite/api/categories/26"> 
        <id><![CDATA[26]]></id> 
       </category> 
       <category xlink:href="https://mywebsite/api/categories/28"> 
        <id><![CDATA[28]]></id> 
       </category> 
      </categories> 
      <products nodeType="product" api="products" /> 
     </associations> 
    </category> 
</categories> 
</prestashop> 

이 PrestaShop 버전 웹 서비스에 의해 생성 있기 때문에 내가 XML 파일 형식을 변경할 수 : 나는 PrestaShop 버전의 전자 상거래 플랫폼에서 카테고리를 나타내는 XML 파일이 있습니다. 내가하고 싶은 것은 계층 적으로 XML 내부의 모든 카테고리로 JTree를 채우는 것입니다.

예를 들어, 여기에 "Racine"이라고 쓰여 있습니다. Racine 밑에는 "Accueil"이 있습니다. 결과는 다음과 같아야합니다.

Racine 
    Accueil 
     Télécommande 
     Audio-Vidéo 
      Casque Yurbuds 
     Multimédia 

어떻게하면됩니까? 감사합니다.

답변

0

해결책을 찾았습니다.

TreeModel을 구현하는 클래스 "MyTreeModel"을 만듭니다. 이 클래스 안에는 내 범주를 나타내는 Object를 추가하십시오. 카테고리의 모든 하위 항목 가져 오기 및

을 사용하여 HashMap에 추가

매개 변수로 MyTreeModel을 사용하여 JTree를 구성합니다. Voilà