Mailingliste - Einträge 2005

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [qftestJUI] How to identify a row of a table by the values of more than one column ?

  • Subject: RE: [qftestJUI] How to identify a row of a table by the values of more than one column ?
  • From: "Philippe Gaudin" <Philippe.Gaudin@?.com>
  • Date: Fri, 14 Oct 2005 14:57:20 +0200

Title: Message


Thanks for your help.

I'm trying to implement what you proposed... but I'm facing some problems :-(
First of all, I created a properties file containing for each "table" the list of the columns which are a "primary key" for that table.
Form there, I can in an itemNameResolver return the values of these pk columns.
Here is my code :

public class BsbItemNameResolver implements ItemNameResolver {
  protected static BsbItemNameResolver instance = new BsbItemNameResolver();
  private static HashMap dwKeys;
  private static Properties props;
  private static final String fileSep = System.getProperty("file.separator");
  private static final String propertiesFileName = System.getProperty("qftestJUI.home") + fileSep + "plugin" + fileSep + "sut" + fileSep + "";
  protected BsbItemNameResolver() {
   * Register the BsbItemNameResolver instance as global ItemNameResolver.
  public static void install() {
    ResolverRegistry.instance().registerItemNameResolver("javax.swing.JTable", instance);
    props = new Properties();
    try {
      props.load(new FileInputStream(propertiesFileName));
    catch (IOException e) {
      throw new RuntimeException(e);
  public static void uninstall() {
    ResolverRegistry.instance().unregisterItemNameResolver("javax.swing.JTable", instance);
  public String getItemName(Object object, Object object1, Object object2) {
      if ((object instanceof GridDwcTable) && (object2 != null) ) {
        GridDwcTable dw = (GridDwcTable) object;
        String dwName = dw.getDwName();
        int row = ((Integer)object2).intValue();
        int col = ((Integer)object1).intValue();
        System.out.println("getItemName() on \"" + dwName + "\" COLS : " + toString(dw.getDwColNames()));
        System.out.println("ROW : " + row + " - COL : " + col);
        int[] pkColNbrs = getPkCols(dwName,dw.getDwColNames());
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < pkColNbrs.length; i++) {
          int pkColNbr = pkColNbrs[i];
          if (i < pkColNbrs.length-1) sb.append('|');
        String result = sb.toString();
        System.out.println("Result = " + result);
        return result;
      else {
        return null;
  private static int[] getPkCols(String dwName, String[] dwColNames) {
    String pkProperty = props.getProperty(dwName + ".pk");
    if (pkProperty != null) {
      String[] pkColNames = pkProperty.split(";");
      int[] pkColNbrs = new int[pkColNames.length];
      for (int i = 0; i < pkColNames.length; i++) {
        boolean found = false;
        String col = pkColNames[i];
        for (int j = 0; j < dwColNames.length; j++) {
          String dwColName = dwColNames[j];
          if (col.equals(dwColName)) {
            pkColNbrs[i] = j;
            found = true;
        if (!found) return new int[0];
      return pkColNbrs;
    else {
      return new int[0];

It seems to work fine : each time I do a check text on a cell, it returns me the values of the primary key columns.
But after that I'm a little bit lost...
  • I tryed to create a "Fetch Index" node... but I don't know which Component Id to provide.
  • If I can get the number of the row identified by the values of the pk columns, I don't know how it will be possible to check the value of a cell of the table because the check text always returns me the pk, not the contents of the cell.
  • I'm afraid I need a new kind of resolver : a TableRowResolver to help me find the number of a row
Any ideas/hints to help me to go further ??
Thanks in advance,

-----Original Message-----
From: Gregor Schmid [
Sent: Thursday, 13 October, 2005 11:00
To: qftestJUI-list@?.de
Cc: Philippe Gaudin
Subject: Re: [qftestJUI] How to identify a row of a table by the values of more than one column ?

Hi Philippe,

"Philippe Gaudin" <Philippe.Gaudin@?.com> writes:

>    Hi !
>    I have an application using a lot of tables... and I would like to be
>    able to check the values of cells on these tables.
>    My problem is to identify the row of the table in a way which is
>    independent of the order of the rows.
>    What I need is to be able to identify a row by the values of some
>    primary key columns.

If you have a primary key column the standard way is to first use a "Fetch index" node to retrieve the index of the row based on the key column, then work with that row index in the other rows.

>    Can I write a "table row" resolver returning the text or feature for
>    that row as the concat of the PK row values ?

Yes, and that's actually a very good idea because it will make your life a lot easier. This is how qftest's TreeTable support works. All row indices are mapped to the index of the tree node in the first column.

>    Is it possbile ? How ?

Register an ItemNameResolver on JTable (or better yet your specific table). Implement the getItemName(object, primary, secondary) method to check for the correct type of table. Completely ignore the primary parameter - you don't care which column qftestJUI is currently working on. Instead, simply return the key identifier for the row identified by the secondary parameter.

Should work like a charm :-)

Please post your results, this should be a tremendously useful near-generic paradigm. I think it would be possible to provide a class that implements ItemNameResolver based on this paradigm and that could be instantiated by simply passing the key column(s) to its constructor.

Best regards,

>    Thanks in advance for your help !
>    Philippe

Gregor Schmid                                Gregor.Schmid@?.de
Quality First Software GmbH           
Tulpenstr. 41                                Tel: +49 8171 919870
DE-82538 Geretsried                          Fax: +49 8171 919876