Author: sletellier Date: 2009-02-04 14:18:26 +0000 (Wed, 04 Feb 2009) New Revision: 1199 Modified: jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/JAXXList.java Log: Add fillList methods Modified: jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/JAXXList.java =================================================================== --- jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/JAXXList.java 2009-02-03 20:45:28 UTC (rev 1198) +++ jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/JAXXList.java 2009-02-04 14:18:26 UTC (rev 1199) @@ -193,17 +193,19 @@ */ public void fillList(Collection<?> data, Object select, String methodName) { // prepare method to use - Method m; - try { - m = select.getClass().getMethod(methodName); - m.setAccessible(true); - } catch (NoSuchMethodException e) { - throw new IllegalArgumentException("could not find method " + methodName + " on " + select.getClass()); - } + Method m = null; List<Item> items = new ArrayList<Item>(); for (Object o : data) { boolean selected = o.equals(select); + if (m == null){ + try { + m = o.getClass().getMethod(methodName); + m.setAccessible(true); + } catch (NoSuchMethodException e) { + throw new IllegalArgumentException("could not find method " + methodName + " on " + select.getClass()); + } + } try { items.add(new Item(o.toString(), (String) m.invoke(o), o, selected)); } catch (SecurityException e) { @@ -222,4 +224,45 @@ } setItems(items); } + + /** + * Fill a list model with some datas, and select after all the given object + * + * @param data data ot inject in combo + * @param selects the objects to select in list after reflling his model + * @param methodName method to invoke to display data's name + */ + public void fillList(Collection<?> data, Collection<?> selects, String methodName) { + // prepare method to use + Method m = null; + + List<Item> items = new ArrayList<Item>(); + for (Object o : data) { + boolean selected = selects.contains(o); + if (m == null){ + try { + m = o.getClass().getMethod(methodName); + m.setAccessible(true); + } catch (NoSuchMethodException e) { + throw new IllegalArgumentException("could not find method " + methodName + " on " + select.getClass()); + } + } + try { + items.add(new Item(o.toString(), (String) m.invoke(o), o, selected)); + } catch (SecurityException e) { + // shoudl never happen ? + throw new RuntimeException(e); + } catch (IllegalAccessException e) { + // shoudl never happen ? + throw new RuntimeException(e); + } catch (IllegalArgumentException e) { + // shoudl never happen ? + throw new RuntimeException(e); + } catch (InvocationTargetException e) { + // shoudl never happen ? + throw new RuntimeException(e); + } + } + setItems(items); + } } \ No newline at end of file