added possibility to define the column by a method with parameters. BLD200202040100
authormkleint@netbeans.org
Sun, 03 Feb 2002 19:53:06 +0000
changeset 20341d051bf0c971
parent 2033 12c67615b2f4
child 2035 5d1b428b25bd
added possibility to define the column by a method with parameters.
vcscore/src/org/netbeans/modules/vcscore/util/table/TableInfoModel.java
     1.1 --- a/vcscore/src/org/netbeans/modules/vcscore/util/table/TableInfoModel.java	Fri Feb 01 11:50:47 2002 +0000
     1.2 +++ b/vcscore/src/org/netbeans/modules/vcscore/util/table/TableInfoModel.java	Sun Feb 03 19:53:06 2002 +0000
     1.3 @@ -34,6 +34,7 @@
     1.4        
     1.5        protected HashMap columnLabels;
     1.6        protected HashMap columnValueSetters;
     1.7 +      protected HashMap columnValueParams;
     1.8        protected HashMap columnSorted;
     1.9        protected HashMap columnComparators;
    1.10        
    1.11 @@ -46,6 +47,7 @@
    1.12            columnLabels = new HashMap();
    1.13            columnSorted = new HashMap();
    1.14            columnValueSetters = new HashMap();
    1.15 +          columnValueParams = new HashMap();
    1.16            columnComparators = new HashMap();
    1.17            setDirection(true);
    1.18            setActiveColumn(0);
    1.19 @@ -65,10 +67,11 @@
    1.20            Integer columnInt = new Integer(column);
    1.21            Object info = list.get(row);
    1.22            Method getter = (Method)columnValueSetters.get(columnInt);
    1.23 +          Object[] params = (Object[])columnValueParams.get(columnInt);
    1.24            TableInfoComparator comparator = (TableInfoComparator)columnComparators.get(columnInt);
    1.25            if (getter == null) return "";
    1.26            try {
    1.27 -              Object value = getter.invoke(info, null);
    1.28 +              Object value = getter.invoke(info, params);
    1.29                if (comparator != null) {
    1.30                    return comparator.getDisplayValue(value, info);
    1.31                }
    1.32 @@ -120,6 +123,19 @@
    1.33              columnLabels.put(integ, label);
    1.34              columnSorted.put(integ, new Boolean(sorted));
    1.35              columnValueSetters.put(integ, reflectionGetter);
    1.36 +            columnValueParams.put(integ, null);
    1.37 +            columnComparators.put(integ, comp);
    1.38 +      }
    1.39 +
    1.40 +      
    1.41 +      public void setColumnDefinition(int columnNumber, String label,  
    1.42 +                                      Method reflectionGetter, Object[] params, boolean sorted, TableInfoComparator comp) 
    1.43 +      {
    1.44 +            Integer integ = new Integer(columnNumber);
    1.45 +            columnLabels.put(integ, label);
    1.46 +            columnSorted.put(integ, new Boolean(sorted));
    1.47 +            columnValueSetters.put(integ, reflectionGetter);
    1.48 +            columnValueParams.put(integ, params);
    1.49              columnComparators.put(integ, comp);
    1.50        }
    1.51        
    1.52 @@ -174,13 +190,14 @@
    1.53      public int compare(java.lang.Object obj1,java.lang.Object obj2) {
    1.54          Integer columnInt = new Integer(getActiveColumn());
    1.55          Method getter = (Method)columnValueSetters.get(columnInt);
    1.56 +        Object[] params = (Object[])columnValueParams.get(columnInt);
    1.57          TableInfoComparator comparator = (TableInfoComparator)columnComparators.get(columnInt);
    1.58          if (getter == null) return 0;
    1.59          Object value1 = null;
    1.60          Object value2 = null;
    1.61          try {
    1.62 -            value1 = getter.invoke(obj1, null);
    1.63 -            value2 = getter.invoke(obj2, null);
    1.64 +            value1 = getter.invoke(obj1, params);
    1.65 +            value2 = getter.invoke(obj2, params);
    1.66          } catch (IllegalAccessException exc) {
    1.67              return 0;
    1.68          } catch (IllegalArgumentException exc2) {