RegisterSearchFAQ UsergroupsLog in
Problem setting table state with Grouped columns

 
Reply to topic    Citra Technologies Forum Index » Technical Support - Evaluation View previous topic
View next topic

Problem setting table state with Grouped columns
Author Message
navTeam2



Joined: 14 Jan 2011
Posts: 97

Post Problem setting table state with Grouped columns Reply with quote
Hi,

We're currently using tablelib version : 3.8.26

We are experiencing troubles when trying to use AdvancedJTable.setTableState with grouped columns :

The setTableState("0:10,2:10") doesn't seem to do anything

Hereafter is a simple test code with a frame embedding an AdvancedJTable and a button which triggers the setTableState action :

Code:


package com.OurTable;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.table.TableColumnModel;

import com.sciapp.filter.CustomPopupFilterHeaderModel;
import com.sciapp.table.AdvancedJScrollPane;
import com.sciapp.table.AdvancedJTable;
import com.sciapp.table.DefaultListTableModel;
import com.sciapp.table.FilterTableModel;
import com.sciapp.table.GroupTableColumn;
import com.sciapp.table.GroupTableHeader;
import com.sciapp.table.ListTableModel;
import com.sciapp.table.SortTableModel;
import com.sciapp.version.TableLibVersion;

public class ColumnGroupingTest {
   
   protected static final int FIRST_NAME = 0;
   protected static final int LAST_NAME = 1;
   protected static final int AGE = 2;
   
   private static AdvancedJTable table;
   
   public static class Customer {
      public String firstName;
      public String lastName;
      public String age;
      
      public Customer(String firstName, String lastName, String age) {
         this.firstName = firstName;
         this.lastName = lastName;
         this.age = age;
      }
      
      
   }

   public static void main(String[] args) {
      
      System.out.println(TableLibVersion.getVersion());
      
      // raw model
      final ArrayList<Customer> customerList = new ArrayList<Customer>();
      
      for(int i = 0 ; i < 10 ; i++) {
         customerList.add( new Customer( "firstName " + i, "lastName " + i, "age " + i ) );
      }
      
      ListTableModel rawModel = new DefaultListTableModel() {

         @Override
         public Object getValueAt(int row, int column) {
            Customer customer = customerList.get( row );
            return getCellValue(customer, column);
         }

         @Override
         public int getRowCount() {
            return 10;
         }

         @Override
         public int getColumnCount() {
            return 3;
         }

         @Override
         public String getColumnName(int column) {
            switch( column ) {
            case FIRST_NAME: return "First";
            case LAST_NAME: return "Last";
            case AGE: return "Age";
            default: throw new IllegalStateException("Unexpected column : " + column);
            }
         }

         @Override
         public Class<?> getColumnClass(int columnIndex) {
            return String.class;
         }
         
         @Override
         public Object getCellValue(Object o, int column) {
            Customer customer = (Customer) o;
            switch( column ) {
            case FIRST_NAME: return customer.firstName;
            case LAST_NAME: return customer.lastName;
            case AGE: return customer.age;
            default: throw new IllegalStateException("Unexpected column : " + column);
            }
         }
         
         @Override
         public List getRows() {
            return customerList;
         }
         
      };
      
      // Wrapping rawModel with filter then sort
      FilterTableModel filterModel = new FilterTableModel( rawModel );
      SortTableModel sortModel = new SortTableModel( filterModel  );
      table = new AdvancedJTable( sortModel );
      
      sortModel.setHeader(table.getTableHeader());
      CustomPopupFilterHeaderModel customPopupFilterHeaderModel = new CustomPopupFilterHeaderModel();
      customPopupFilterHeaderModel.attachToTable(table, filterModel);
      
      
      GroupTableHeader groupTableheader = (GroupTableHeader) table.getTableHeader();
      GroupTableColumn groupTableColumn = new GroupTableColumn("Name");
      TableColumnModel cm = table.getColumnModel();
      groupTableColumn.addColumn( cm.getColumn( FIRST_NAME ) );
      groupTableColumn.addColumn( cm.getColumn( LAST_NAME ) );
      groupTableheader.addGroupColumn( groupTableColumn );
      
      JButton buttonRestoreState = new JButton("Restore state");
      ActionListener restoreAction = new ActionListener() {
         public void actionPerformed(ActionEvent e) {
            table.setTableState("0:10,2:10");
         }
      };
      buttonRestoreState.addActionListener(restoreAction);
      
      JFrame frame = new JFrame();
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.add(buttonRestoreState, BorderLayout.SOUTH);
      frame.add( new AdvancedJScrollPane(table), BorderLayout.CENTER  );
      frame.pack();
      frame.setVisible(true);

   }

}



Do you have any clue what we're doing wrong ?

table.getTableAssistant().select( ... ) seems to work fine but is quite heavy burden...

Thanks in advance
Fri Jan 14, 2011 11:04 am View user's profile Send private message
support



Joined: 21 Feb 2006
Posts: 1463

Post Reply with quote
Hi,

This was fixed in the next version, 3.8.27. You need to download the latest version.
Thanks
Fri Jan 14, 2011 11:26 am View user's profile Send private message
Display posts from previous:    

Reply to topic    Citra Technologies Forum Index » Technical Support - Evaluation All times are GMT - 5 Hours
Page 1 of 1

 
Jump to: 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group