craftleft.gif (3002 bytes)QuickTable
Home | API | Tutorial | Download | Support | Contact topblack.gif (108 bytes)


QuickTable User Cp  |  Register  |  Members  |  Search  |  Help
    |- QuickTable Discussion Forums > Column Post New Topic   Post A Reply
cellValueChanged.col not returning the original columns , bu... printer friendly version
next newest post | next oldest post
Author Messages
tilh
Private First Class

Gender: Male
Location: Singapore
Registered: Jul 2005
Status: Offline
Posts: 19

Click here to see the profile for tilh Send email to tilh Send private message to tilh Find more posts by tilh Edit or delete this message Reply w/Quote
Posted Saturday, August 20, 2005 @ 21:52:40  

DBTableCellListener.cellValueChanged.col does not return the original columns
(as per documentation), but the current columns, if columns are shuffled.

Please verify the correct functionality.

See the example below. The results were obtained by selecting
the columns from left to right, and changing its values

This shuffling can be simualted by

dBTable1.moveColumn(2,0);
dBTable1.moveColumn(1,2);

QuickTable 2.0.5.20 (Free Version)
oldValue = col=1 origCol=2
oldValue = R0C2 col=2 origCol=1
oldValue = R0C1 col=3 origCol=0

with the moveColumn() lines removed

QuickTable 2.0.5.20 (Free Version).
oldValue = R0C1 col=1 origCol=0
oldValue = R0C2 col=2 origCol=1
oldValue = col=3 origCol=2

---- program follows ----
import java.awt.BorderLayout;
import java.io.*;
import java.util.Properties;
import javax.swing.JFrame;
import quick.dbtable.*;
/*
* dBTableTest.java
*
* Created on August 21, 2005, 3:43 AM
*/

public class dBTableTest extends JFrame {
DBTable dBTable1;
/** Creates a new instance of dBTableTest */
public dBTableTest(PipedOutputStream pOut) {
Properties prop = new Properties();
prop.put("delimiter","\t");
prop.put("firstRowHasColumnNames","true");

setSize(500,200);
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
// InputStream in = new InputStream();
dBTable1 = new DBTable();

try {
PipedInputStream pIn = new PipedInputStream(pOut);

getContentPane().add(dBTable1, BorderLayout.CENTER);
dBTable1.refresh(pIn,prop);
dBTable1.addTableCellListener(new MyCellListerner());

int num = dBTable1.getColumnCount()+1;
Column c = new Column(num);
c.setHeaderValue("Column " + num);
dBTable1.addColumn(c);
// uncomment these 2 statments and it comes out right
//dBTable1.moveColumn(2,1);
dBTable1.moveColumn(1,2);

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

class MyCellListerner implements quick.dbtable.DBTableCellListener {
public java.lang.Object cellValueChanged(int row,
int col,
java.lang.Object oldValue,
java.lang.Object newValue) {
// note the row starts with 0, col start with 1 :-(
// 2.0.5.20 : col can change after shuffling, not guaranteed, contrary to doc
int editingCol = dBTable1.getEditingColumn();
int origCol = dBTable1.getOriginalColumnIndex(editingCol) ;

System.out.println("oldValue = " + oldValue + " col=" + col + " origCol=" + origCol);
col = origCol;

return null;
}
}


public static void writer(PipedOutputStream pOut) {
StringBuffer buf = new StringBuffer();
buf.append("Column 1\tColumn 2\n");
buf.append("R0C1\tR0C2\n");

String s = new String(buf);
byte[] byteArray = s.getBytes();
try {
pOut.write(byteArray);
pOut.flush();
pOut.close();
} catch (Exception e) {
e.printStackTrace();
}

}
public static void main(String args[]) {
final PipedOutputStream pOut = new PipedOutputStream();
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
dBTableTest comp = new dBTableTest(pOut);
comp.setVisible(true);
comp.toFront();
}
});
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
writer(pOut);
}
});

}
}

Admin
Board Owner

Gender: Unspecified
Location:
Registered: Jul 2003
Status: Offline
Posts: 9

Click here to see the profile for Admin Send email to Admin Send private message to Admin Find more posts by Admin Edit or delete this message Reply w/Quote
Posted Sunday, August 21, 2005 @ 06:08:27  

If user drags and moves the column, then it should give you the original column.

when you use moveColumn() method the column indexes are rearranged, in this case you will get the current column index.

Post New Topic   Post A Reply Jump to:
Contact Us | QuickTable - A Java DBGrid | Privacy Policy All times are GMT -5 Hours.
Welcome to QuickTable Forums, Guest!  
Login
Username :
Password :
In order to fully utilize the abilities of this board, you are required to register as a member. Registration is free, and allows you to do lots of things including turning on or off certain features of this board. Register now!
Powered by CuteCast v2.0 BETA 2
Copyright © 2001-2003 ArtsCore Studios