Board index » jbuilder » JdbTable displaying QueryDataSet with a SortDescriptor (Sort.CASEINSENSITIVE)

JdbTable displaying QueryDataSet with a SortDescriptor (Sort.CASEINSENSITIVE)


2004-09-16 10:52:19 PM
jbuilder3
Hi all
I've been puzzling this for a long time and i can't find a clue any where...
I have a JdbTable displayind data comming from a database thanks to a
queryDataSet. I set a Sort Descriptor on the queryDataset for sorting
Strings case INSENSITIVE.
When the data are displayed for the first time, the sort is case insensitive
and it is what I want. but then when I clik on the header of the JdbTable
for sorting the column again, the sort becomes case SENSITIVE. And it's the
bug.
here are the data when opening
type |Label
aaa |aaa
Abb | AAA
Ba |Ba
here is what I have after clicking the 'Label' header =>sort is now case
SENSITIVE
type |Label
Abb | AAA
Ba |Ba
aaa |aaa
I should have
type |Label
Abb | AAA
aaa |aaa
Ba |Ba
and when I click again the 'type' header =>sort is stile case SENSITIVE
type |Label
Abb | AAA
Ba |Ba
aaa |aaa
I should have
type |Label
aaa |aaa
Abb | AAA
Ba |Ba
Here is a sample I made :
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.borland.dbswing.*;
import com.borland.dx.sql.dataset.*;
import com.borland.dx.dataset.*;
public class FrameSortingDB
extends JFrame {
JPanel contentPane;
BorderLayout borderLayout1 = new BorderLayout();
TableScrollPane tableScrollPane1 = new TableScrollPane();
JdbTable jdbTable1 = new JdbTable();
Database database1 = new Database();
QueryDataSet queryDataSet1 = new QueryDataSet();
Column column2 = new Column();
Column column3 = new Column();
//Construct the frame
public FrameSortingDB() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel)this.getContentPane();
contentPane.setLayout(borderLayout1);
this.setSize(new Dimension(400, 300));
this.setTitle("Frame Title");
database1.setConnection(new
com.borland.dx.sql.dataset.ConnectionDescriptor(
"jdbc:oracle:thin:@bl03sa32:1521:zf4", "act", "act", false,
"oracle.jdbc.driver.OracleDriver"));
queryDataSet1.setSort(new com.borland.dx.dataset.SortDescriptor("",
new String[] {"TYPE", "LIBELLE"}
, new boolean[] {false, false, }
, null, Sort.CASEINSENSITIVE));
queryDataSet1.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(
database1, "select TYPE, LIBELLE from hst_systeme order by
HD_CREATION", null, true,
Load.ALL));
jdbTable1.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
jdbTable1.setDataSet(queryDataSet1);
column2.setCaption("Type");
column2.setColumnName("TYPE");
column2.setDataType(com.borland.dx.dataset.Variant.STRING);
column2.setPrecision(100);
column2.setTableName("HST_SYSTEME");
column2.setServerColumnName("TYPE");
column2.setSqlType(12);
column3.setCaption("Libelle");
column3.setColumnName("LIBELLE");
column3.setDataType(com.borland.dx.dataset.Variant.STRING);
column3.setPrecision(500);
column3.setTableName("HST_SYSTEME");
column3.setServerColumnName("LIBELLE");
column3.setSqlType(12);
queryDataSet1.setColumns(new Column[] {column2, column3});
contentPane.add(tableScrollPane1, BorderLayout.CENTER);
tableScrollPane1.getViewport().add(jdbTable1, null);
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
//Main method
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (Exception e) {
e.printStackTrace();
}
FrameSortingDB frame = new FrameSortingDB();
frame.pack();
//Center the window
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
if (frameSize.height>screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width>screenSize.width) {
frameSize.width = screenSize.width;
}
frame.setLocation( (screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
frame.setVisible(true);
}
}
Am I missing somethig ?
Do you have any clue ?
Thanks in advance
Tibo v
 
 

Re:JdbTable displaying QueryDataSet with a SortDescriptor (Sort.CASEINSENSITIVE)

Tibov wrote:
Quote
Hi all

I've been puzzling this for a long time and i can't find a clue any
where...

I have a JdbTable displayind data comming from a database thanks to a
queryDataSet. I set a Sort Descriptor on the queryDataset for sorting
Strings case INSENSITIVE.

When the data are displayed for the first time, the sort is case
insensitive and it is what I want. but then when I clik on the header of
the JdbTable for sorting the column again, the sort becomes case
SENSITIVE. And it's the bug.

The problem is that the JdbTable has its own listener class that auto-sorts
when a user clicks on the column header. You will need to override this
listener to accomplish your objective. Look at the TableModelColumnListener
interface for more info, or disable the setColumnSortEnabled() to false
 

Re:JdbTable displaying QueryDataSet with a SortDescriptor (Sort.CASEINSENSITIVE)

Thank you Paul for the answer.
So after some analyse here is what I did (sorry coments are in French...) :
import com.borland.dx.sql.dataset.QueryDataSet;
import com.borland.dx.dataset.*;
/**
* Permet de definir si le tri sur la colonne doit etre sensible ?la case
* <p>Title: IHM Toscane</p>
* <p>Description: IHM de supervision Toscane</p>
* <p>Copyright : Copyright (c) 2004</p>
* <p>Sociét?: AMEC SPIE SUD EST</p>
* @author TVE
* @version $Revision: $ par $Author: $ le $Date: $
*/
public class AriQueryDataSet extends QueryDataSet {
boolean _sortCaseInsensitive = true;
/**
* @param columnName String le nom de la colonne ?trier
*/
public synchronized void toggleViewOrder(String columnName) {
boolean flag = false;
String as[] = s();
if (as != null && as.length == 1 && as[0].equals(columnName) &&
!getSort().isDescending(0)) {
flag = true;
}
setSort(new SortDescriptor(new String[] {columnName},
_sortCaseInsensitive, flag));
}
/**
* @return String[]
*/
String[] s() {
if (getSort() == null)
return null;
else
return getSort().getKeys();
}
/**
* parametre pour changer la manière de trier la manière de fair un tri
* @param sortCaseInsensitive boolean si le tri doit etre NON sensible ?
la casse
*/
public void setSortCaseInsensitive(boolean sortCaseInsensitive) {
_sortCaseInsensitive = sortCaseInsensitive;
}
}
Now I am wondering why there is not a parameter that can allow to do that in
the DataSet class.
And I think this could be a great improvement
Hop this can help someone else
Tibov
"Paul Nichols (TeamB)" < XXXX@XXXXX.COM >a écrit dans le message de
Quote
Tibov wrote:

>Hi all
>
>I've been puzzling this for a long time and i can't find a clue any
>where...
>
>I have a JdbTable displayind data comming from a database thanks to a
>queryDataSet. I set a Sort Descriptor on the queryDataset for sorting
>Strings case INSENSITIVE.
>
>When the data are displayed for the first time, the sort is case
>insensitive and it is what I want. but then when I clik on the header of
>the JdbTable for sorting the column again, the sort becomes case
>SENSITIVE. And it's the bug.
>
The problem is that the JdbTable has its own listener class that
auto-sorts
when a user clicks on the column header. You will need to override this
listener to accomplish your objective. Look at the
TableModelColumnListener
interface for more info, or disable the setColumnSortEnabled() to false


 

{smallsort}