3
 public class TabularMibTreeModel extends DefaultTreeModel {
     public TabularMibTreeModel() {
         super(new DefaultMutableTreeNode("Tablular MIBs"));
         loadParentMibs();
     }

     @Override
     public void reload() {
         super.reload();
     }

     private void loadParentMibs() {
           try {
                 ResultSet rs=Application.getDBHandler().executeQuery(SQLQueries.SELECT_TABULARMIBS_PARENT);

               while(rs.next()){            
                    String entryOID = rs.getString("mt_oid");       
                    DefaultMutableTreeNode node=new DefaultMutableTreeNode(new MibNode(entryOID, "Parent"));
                    node.add(new DefaultMutableTreeNode(Boolean.TRUE));

                    ((DefaultMutableTreeNode) getRoot()).insert(node,((DefaultMutableTreeNode)getRoot()).getChildCount())

                     node=null;

                 }

          } catch (SQLException e) {
           e.printStackTrace();
         }
     }

 }

JTreeについて勉強し始めたところです。親として entryOID を持つ jtree を作成しました。実際には、バックエンドでは entryOID に親があります。この親を取得できますか? entryOID を回避して表示するにはどうすればよいですか? 助けてください?

4

1 に答える 1

1
 private void loadParentMibs throws SQLException () {

   ResultSet resultSet = Application.getDBHandler()
     .executeQuery(SQLQueries.SELECT_TABULARMIBS_PARENT);

   DefaultMutableTreeNode root = (DefaultMutableTreeNode)getRoot();

   Map<String, DefaultMutableTreeNode> parentsMap
     = new HashMap<String, DefaultMutableTreeNode>();

   while( resultSet.next() ) {  
     String parentId = resultSet.getString("mt_oid");

     DefaultMutableTreeNode parent = parentsMap.get(parentId);
     if ( parent == null ) {
       parent = new DefaultMutableTreeNode( parentId );
       parentsMap.add( parentId, parent );
       root.add( parent );
     }

       // Are you sure, you want Boolean.TRUE leafs 
       //   in number of parent coincindence?
       // May be you want leafs to contains some 
       //   additional info from resultSet entity?
     DefaultMutableTreeNode leaf = new DefaultMutableTreeNode(Boolean.TRUE);
     parent.add(leaf);
   }

 }
于 2012-11-16T16:11:52.770 に答える