Automatic collapse of row in HierarchicalTable

This forum is used by users to request and discuss new product features. Please do not use this forum for technical support including bug reports.

Moderator: JIDE Support

Forum rules
Product suggestions only. Please do not use this forum for technical support including bug reports.

Automatic collapse of row in HierarchicalTable

Postby nicola.gioia » Mon Apr 03, 2006 6:53 am

If i have a HierarchicalTable with a HierarchicalTableModel and a row that is expanded will receive an event, recognized at TableModel level, that update the table model and make the hasChild(Object) to return false. after this event the icon to expand/collapse the row disappear, but the row is not collapsed.
An example of code to reproduce the bug is:
(before we must expand the row and after uncheck the checkBox)
Code: Select all
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
import com.jidesoft.grid.*;

public class HierarchicalTest {
   static String[]colNames = {"col1","col2"};
   static String[][]tabledata = {{"elem11","elem12"}};
   static String[][]tableData1 = {{"subTable11","subTable12"}};
   
   MyTableModel model;
   HierarchicalTable mainTable;
   
   public HierarchicalTest() {
      model = new MyTableModel(tabledata,colNames);
      mainTable = new HierarchicalTable(model);
      mainTable.setComponentFactory(new HierCompFactory());
      JPanel contP = new JPanel(new BorderLayout());
      contP.add(new JScrollPane(mainTable),BorderLayout.CENTER);
      
      JCheckBox cb = new JCheckBox("isHierarchical");
      cb.setSelected(true);
      cb.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e) {
            model.haschild = ((JCheckBox)e.getSource()).isSelected();
            model.fireTableDataChanged();
         }});
      
      contP.add(cb,BorderLayout.SOUTH);
      
      JFrame d = new JFrame();
      d.setContentPane(contP);
      d.pack();
      d.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      d.setVisible(true);
   }
   
   class MyTableModel extends DefaultTableModel implements HierarchicalTableModel{
      boolean haschild = true;
      
      MyTableModel childModel;
      
      public MyTableModel(Object[][] data, Object[] columnNames) {
         super(data, columnNames);
      }
      
      public boolean hasChild(int arg0) {
         return haschild;
      }

      public boolean isHierarchical(int arg0) {
         return true;
      }

      public Object getChildValueAt(int arg0) {
         if(childModel == null) {
            childModel = new MyTableModel(tableData1,colNames);
            childModel.haschild = false;
         }
         return childModel;
      }

      public boolean isExpandable(int arg0) {
         return true;
      }
   }

   class HierCompFactory implements HierarchicalTableComponentFactory{
      public Component createChildComponent(HierarchicalTable arg0, Object arg1, int arg2) {
         JPanel p = new JPanel(new BorderLayout());
         p.add(new JTable((TableModel) arg1),BorderLayout.CENTER);
         return new HierarchicalPanel(p);
      }

      public void destroyChildComponent(HierarchicalTable arg0, Component arg1, int arg2) {}
   }

   public static void main(String[] args) {
      new HierarchicalTest();
   }

}


There is a way to fix this problem and automatically collapse the expanded row?
nicola.gioia
 
Posts: 60
Joined: Tue Sep 20, 2005 6:57 am

Postby JIDE Support » Mon Apr 03, 2006 10:31 am

I'll fix it.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Postby nicola.gioia » Tue Apr 04, 2006 12:42 am

Sorry, but there is a workaround to solve temporarily the problem, before the fixing?
nicola.gioia
 
Posts: 60
Joined: Tue Sep 20, 2005 6:57 am

Postby JIDE Support » Tue Apr 04, 2006 8:38 am

Please use a development patch at http://www.jidesoft.com/downloads/jide.1.9.0.02.zip while waiting for formal release. We will have it released this week.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Postby JIDE Support » Mon Apr 10, 2006 12:03 pm

Just so you know, the fix is included in 1.9.1 formal release.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Postby nicola.gioia » Thu Jun 01, 2006 3:43 am

I found another little problem.
I have a table with only first row expandable, and when the first row is expanded, and someone add a row on the top of the table, the row expanded will remain expanded and positioned on the bottom of the old first row and is not possible to collapse it.
The step to reproduce the bug are:
    1 - expand the row expandable
    2 - click on button addRow.

The code needed is:
Code: Select all
import javax.swing.*;
import javax.swing.table.*;
import com.jidesoft.grid.*;

public class HierarchicalTest {
   static String[]colNames = {"col1","col2"};
   static String[][]tabledata = {{"elem11","elem12"}};
   static String[][]tableData1 = {{"subTable11","subTable12"}};
   
   MyTableModel model;
   HierarchicalTable mainTable;
   
   public HierarchicalTest() {
      model = new MyTableModel(tabledata,colNames);
      mainTable = new HierarchicalTable(model);
      mainTable.setComponentFactory(new HierCompFactory());
      JPanel contP = new JPanel(new BorderLayout());
      contP.add(new JScrollPane(mainTable),BorderLayout.CENTER);
      
      JButton b = new JButton("addRow");
      b.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e) {
            model.insertRow(0,new String[]{"elem01","elem02"});
         }});
      contP.add(b,BorderLayout.NORTH);
      
      JFrame d = new JFrame();
      d.setContentPane(contP);
      d.pack();
      d.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      d.setVisible(true);
   }
   
   class MyTableModel extends DefaultTableModel implements HierarchicalTableModel{
      private static final long serialVersionUID = 1L;

      
      MyTableModel childModel;
      
      public MyTableModel(Object[][] data, Object[] columnNames) {
         super(data, columnNames);
         
      }
      
      public boolean hasChild(int arg0) {
         return arg0 == 0;
      }

      public boolean isHierarchical(int arg0) {
         return true;
      }

      public Object getChildValueAt(int arg0) {
         if(childModel == null) {
            childModel = new MyTableModel(tableData1,colNames);
         }
         return childModel;
      }

      public boolean isExpandable(int arg0) {
         return true;
      }
      
   }

   class HierCompFactory implements HierarchicalTableComponentFactory{
      public Component createChildComponent(HierarchicalTable arg0, Object arg1, int arg2) {
         return new HierarchicalPanel(new JLabel("SUBTABLE!!!"));
      }

      public void destroyChildComponent(HierarchicalTable arg0, Component arg1, int arg2) {
         
      }
   }

   public static void main(String[] args) {
       new HierarchicalTest();
   }
}
    [list=][/list][list=][/list][list=][/list]
    nicola.gioia
     
    Posts: 60
    Joined: Tue Sep 20, 2005 6:57 am

    Postby JIDE Support » Thu Jun 01, 2006 8:51 am

    This is not really a bug. You have code

    Code: Select all
            public boolean hasChild(int arg0) {
                return arg0 == 0;
            }


    Basically you specified only the first row has child. That's why the +/- button is not displayed after you added a row.

    Thanks,
    JIDE Software Technical Support Team
    JIDE Support
    Site Admin
     
    Posts: 37219
    Joined: Sun Sep 14, 2003 10:49 am

    Postby nicola.gioia » Fri Jul 21, 2006 2:48 am

    I have a problem that I cannot reproduce in few row code.
    When in the hierarchical table with at least a row expanded I insert a row on top of the table the elements of the table will be update correctly, and also the selected row is correctly shifted by one but the component of the subtable is shifted by two position.
    Have you a suggestion of how find which is the listener that move downward the child element twice instead of one?
    Thanks
    nicola.gioia
     
    Posts: 60
    Joined: Tue Sep 20, 2005 6:57 am


    Return to Product Suggestions

    Who is online

    Users browsing this forum: No registered users and 70 guests