Forum - Info Center - Eltima Software

Eltima Help Center => The rest of our products & other questions => Topic started by: raccoonwao on March 18, 2008, 07:58:56 AM

Title: Swing library - Table column group over columne group
Post by: raccoonwao on March 18, 2008, 07:58:56 AM
Is it possible to group two col groups?

e.g.

Col0 - Group A  - Big Group 01
Col1 - Group A  - Big Group 01

Col2 - Group B  - Big Group 01
Col3 - Group B  - Big Group 01

I tried this in SampleELTable.java

    groupCol3 = new ELColumnGroup("Group of Group");
    groupEnt3.add(groupCol);
    groupEnt3.add(groupCol2);

Only groupCol and groupCol2 are displayed.  Here are the result of

    header.getTopColumnGroup(groupCol);    [result:= the BigColGroup]
    header.getTopColumnGroup(groupCol2);   [result:= the BigColGroup]

    header.getTopColumnGroup(cm.getColumn(2)));   [result:= the groupCol]
    header.getTopColumnGroup(cm.getColumn(5)));   [result:= the groupCol2]

What's wrong?

Thanks


Title: Re: Swing library - Table column group over columne group
Post by: Maria on March 18, 2008, 03:14:12 PM
We were unable to reproduce the problem you have reported us about.

If the issue still persists, please, send us the compiled sample illustrating the problem you have encountered. Send it to support@eltima.com
Title: Re: Swing library - Table column group over columne group
Post by: raccoonwao on March 20, 2008, 04:11:20 AM
I have already sent.  Looking forward to your advice
Title: Re: Swing library - Table column group over columne group
Post by: raccoonwao on March 28, 2008, 03:10:30 AM
Got the email?
Title: Re: Swing library - Table column group over columne group
Post by: Maria on April 07, 2008, 11:00:23 AM
No email was received from the email address you usually use. Please, resend the email.
Title: Re: Swing library - Table column group over columne group
Post by: raccoonwao on April 09, 2008, 04:12:03 AM
Just resent.  For safety, I post it here as well.

As you see, only 1-level col group is displayed.  No "group of col groups" can be ceated  ??? ??? ???

Code: [Select]

package swing;


import java.awt.Color;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;
import java.util.Random;
import java.util.Vector;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumnModel;

import com.eltima.components.ui.ELButton;
import com.eltima.components.ui.ELTable;
import com.eltima.components.ui.table.ELColumnGroup;
import com.eltima.components.ui.table.ELColumnTotal;
import com.eltima.components.ui.table.ELGroupAttribute;
import com.eltima.components.ui.table.ELGroupModel;
import com.eltima.components.ui.table.ELTableColumn;
import com.eltima.components.ui.table.ELTableHeader;


public class SampleELTable extends JFrame {
  GridBagLayout gridBagLayout1 = new GridBagLayout();
  JScrollPane jScrollPane1 = new JScrollPane();
//  ELTable eLTable1;
  ELTable eLTable1;
  ELColumnGroup groupEnt;
  ELColumnGroup groupEnt2;
  ELColumnGroup groupEnt3;
  ELTableHeader header;
 
 
  Vector vdata = new Vector();
  Vector vcol = new Vector();
 
 
 
  void initData(int row, int col) {
  for(int i=0;i<row;i++) {
  Vector vdatrow = new Vector();
  for(int j=0;j<col;j++) {
  if(j % 5 == 0) {
  vdatrow.add(true);
  }
  else if(j % 5 == 1) {
//   vdatrow.add(new Double(0.123));
  vdatrow.add(j);
  }
  else if(j % 5 == 2) {
  vdatrow.add(new Date());
  }
  else {
  vdatrow.add("dat-["+i+","+j+"]");
  }

  }
  vdata.add(vdatrow);
  }
 
  for(int j=0;j<col;j++) {
  vcol.add("col "+j);
  }
  }
 
  /** SampleELTable constructor.
   * It initializes all GUI components.
   */
  public SampleELTable() {
    try {
    initData(10,5);
      initComponents();
      setBounds( 100, 100, 600, 500 );
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }


  /** This method is called from within the constructor to
   * initialize the form.
   */
  private void initComponents() throws Exception {

    addWindowListener(new java.awt.event.WindowAdapter() {
    public void windowClosing(java.awt.event.WindowEvent evt) {
        System.exit(0);
      }
    });


//    ELGroupModel model = new ELGroupModel(vdata, vcol);
    ELGroupModel model = new ELGroupModel(
            new Object[][]{
            {"Chicago" ,"Jonson",  "Piter",   new Integer(8), new Integer(1), new Integer(14)},
            {"Chicago" ,"Jonson",  "Pamella", new Integer(7), new Integer(0), new Integer(23)},
            {"Chicago" ,"Jonson",  "Cate",    new Integer(6), new Integer(2), new Integer(20)},
            {"Chicago" ,"Smith" ,  "Cate",    new Integer(7), new Integer(1), new Integer(30)},
            {"Chicago" ,"Smith" ,  "Piter",   new Integer(8), new Integer(0), new Integer(17)},

            {"Boston" ,"Jonson" ,  "Garry",   new Integer(8), new Integer(1), new Integer(32)},
            {"Boston" ,"Jonson" ,  "Pamella", new Integer(6), new Integer(0), new Integer(23)},
            {"Boston" ,"Brown"  ,  "Galina",  new Integer(7), new Integer(1), new Integer(20)},
            {"Boston" ,"Brown"  ,  "Garry",   new Integer(8), new Integer(0), new Integer(14)},
            {"Boston" ,"Brown"  ,  "Nataly",  new Integer(9), new Integer(1), new Integer(15)},

            {"London" ,"Jonson" ,  "Garry",   new Integer(6), new Integer(1), new Integer(23)},
            {"London" ,"Jonson" ,  "Pamella", new Integer(9), new Integer(2), new Integer(14)},
            {"London" ,"Smith"  ,  "Pamella", new Integer(7), new Integer(3), new Integer(51)},
            {"London" ,"Smith"  ,  "Galina",  new Integer(7), new Integer(1), new Integer(15)},
            {"London" ,"Smith"  ,  "Nataly",  new Integer(6), new Integer(2), new Integer(17)},
            {"London" ,"Scott"  ,  "Cate",    new Integer(9), new Integer(0), new Integer(32)},
            {"London" ,"Scott"  ,  "Nataly",  new Integer(8), new Integer(1), new Integer(30)},
            {"London" ,"Smith"  ,  "Cate",    new Integer(8), new Integer(0), new Integer(20)}
          },
              new Object[] {"City", "Family", "Name", "Age", "Pets", "Toys"}
    );

   
//    model.setGroupColumns(new int[]{0, 1, 2 ,3});
    model.getGroupColumns();

    model.setTotals(
         new ELColumnTotal[] {
                  new ELColumnTotal(ELColumnTotal.TOTAL_TYPE_SUM, 3),
                  new ELColumnTotal(ELColumnTotal.TOTAL_TYPE_MAX, 4),
                  new ELColumnTotal(ELColumnTotal.TOTAL_TYPE_MIN, 5)
         });

    model.setGroupAttribute(1, new ELGroupAttribute(ELGroupAttribute.SCHEME_YELLOW, 1));
    model.setGroupAttribute(2, new ELGroupAttribute(ELGroupAttribute.SCHEME_CYAN, 2));
    model.setGroupAttribute(3, new ELGroupAttribute(ELGroupAttribute.SCHEME_MAGENTA, 3));

    eLTable1 = new ELTable();
   
    for(int i=0;i< model.getColumnCount();i++) {
    ELTableColumn col = new ELTableColumn(i);
    col.setHeaderValue(model.getColumnName(i));
    col.setWidth(i);
    eLTable1.addColumn(col);
    }
   
    eLTable1.setModel(model);
    eLTable1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
//
    final TableColumnModel cm = eLTable1.getColumnModel();

    ((ELTableColumn)cm.getColumn(0)).setVisible(false);

    groupEnt = new ELColumnGroup("Entertainments");
    groupEnt.getHeaderAttribute().getBackgroundAttribute().setGradientDirection(1);
    groupEnt.getHeaderAttribute().getBackgroundAttribute().setNumberOfCycles(2);
    groupEnt.add(cm.getColumn(4));
    groupEnt.add(cm.getColumn(5));
   
    groupEnt2 = new ELColumnGroup("Top");
    groupEnt2.getHeaderAttribute().getBackgroundAttribute().setGradientDirection(1);
    groupEnt2.getHeaderAttribute().getBackgroundAttribute().setNumberOfCycles(2);
    groupEnt2.add(cm.getColumn(2));
    groupEnt2.add(cm.getColumn(3));
   
    groupEnt3 = new ELColumnGroup("Group of Group");
    groupEnt3.getHeaderAttribute().getBackgroundAttribute().setGradientDirection(1);
    groupEnt3.getHeaderAttribute().getBackgroundAttribute().setNumberOfCycles(2);
    groupEnt3.add(cm.getColumn(2));
    groupEnt3.add(cm.getColumn(3));
    groupEnt3.add(cm.getColumn(4));
    groupEnt3.add(cm.getColumn(5));
    groupEnt3.add(groupEnt);
    groupEnt3.add(groupEnt2);

    header = (ELTableHeader)eLTable1.getTableHeader();
    header.addColumnGroup(groupEnt);
    header.addColumnGroup(groupEnt2);
    header.addColumnGroup(groupEnt3);
   
    ((ELTableColumn)cm.getColumn(3)).getHeaderAttribute().getBackgroundAttribute().
          setGradientColor1(new Color(255,200,200));
    ((ELTableColumn)cm.getColumn(3)).getHeaderAttribute().getBackgroundAttribute().
          setNumberOfCycles(2);
    ((ELTableColumn)cm.getColumn(3)).getHeaderAttribute().setFont(
          new Font("Dialoge", Font.ITALIC, 15));


    this.getContentPane().setLayout(gridBagLayout1);
    this.getContentPane().add(jScrollPane1,  new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0
            ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0));
    jScrollPane1.getViewport().add(eLTable1, null);
   
    ELButton btn = new ELButton();
    btn.setText("Refresh");
    btn.addActionListener(new ActionListener() {

    final Random rnd = new Random();
   
public void actionPerformed(ActionEvent e) {
((DefaultTableModel)eLTable1.getModel()).insertRow(0, new Object[]
                                                          {"NewChicago" ,"NewJonson",  "NewPiter",   new Integer(rnd.nextInt()), new Integer(rnd.nextInt()), new Integer(14)}
                                                           );

((ELGroupModel)eLTable1.getModel()).sortGroup(eLTable1.getColumn("Age"), false);

eLTable1.setRowSelectionInterval(0, 0);

Rectangle rect = eLTable1.getCellRect(0, 0, true);
eLTable1.scrollRectToVisible(rect);

}
   
    });
   
    this.getContentPane().add(btn,  new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0
            ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0));

  }

  void printGroup() {
  final TableColumnModel cm = eLTable1.getColumnModel();
 
    System.out.println(header.getTopColumnGroup(groupEnt));
    System.out.println(header.getTopColumnGroup(groupEnt2));
    System.out.println(header.getTopColumnGroup(cm.getColumn(2)));
    System.out.println(header.getTopColumnGroup(cm.getColumn(5)));

  }
  /** Starts the application.
   * @param args Application arguments.
   */
  public static void main(String[] args) {
    SampleELTable sampleFrame = new SampleELTable();
    sampleFrame.setTitle("ELTable Sample");
    sampleFrame.setVisible(true);
 
 
  }

}

Title: Re: Swing library - Table column group over columne group
Post by: Maria on April 09, 2008, 02:08:05 PM
Have received your email and replied to it.