Author: tchemit Date: 2008-02-16 14:56:00 +0000 (Sat, 16 Feb 2008) New Revision: 1016 Added: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/ListTableModel.java Removed: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/JApplicationTableModel.java Modified: trunk/simexplorer-is/simexplorer-is-swing/src/uimodel/fr/cemagref/simexplorer/is/ui/swing/JListTab.jaxx Log: renommage model Deleted: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/JApplicationTableModel.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/JApplicationTableModel.java 2008-02-16 14:54:21 UTC (rev 1015) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/JApplicationTableModel.java 2008-02-16 14:56:00 UTC (rev 1016) @@ -1,127 +0,0 @@ -/* -* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Code Lutin, -* Tony Chemit -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version 2 -* of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -* ##% */ -package fr.cemagref.simexplorer.is.ui.swing.model; - -import fr.cemagref.simexplorer.is.entities.metadata.MetaData; -import static org.codelutin.i18n.I18n._; -import static org.codelutin.i18n.I18n.n_; - -import javax.swing.table.AbstractTableModel; -import java.beans.BeanInfo; -import java.beans.IntrospectionException; -import java.beans.Introspector; -import java.beans.PropertyDescriptor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.List; - -/** @author tony */ -public class JApplicationTableModel extends AbstractTableModel { - - MetaData[] data; - - PropertyDescriptor[] descriptors; - private static final long serialVersionUID = -105647814466295077L; - private SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss.SSS"); - - public JApplicationTableModel() { - } - - public JApplicationTableModel(MetaData[] data) { - this.data = data; - } - - public MetaData[] getData() { - return data; - } - - public void setData(MetaData[] data) { - this.data = data; - } - - private final String[] columnNames = { - n_("simexplorer.common.name"), - n_("simexplorer.common.type"), - n_("simexplorer.common.description"), - n_("simexplorer.common.version"), - n_("simexplorer.common.creationDate") - }; - - public int getRowCount() { - return data == null ? 0 : data.length; - } - - public int getColumnCount() { - return columnNames.length; - } - - public Object getValueAt(int rowIndex, int columnIndex) { - Object result = null; - MetaData current = data[rowIndex]; - if (current != null) { - try { - PropertyDescriptor propertyDescriptor = getDescriptors()[columnIndex]; - Method readMethod = propertyDescriptor.getReadMethod(); - result = readMethod.invoke(current); - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } catch (InvocationTargetException e) { - throw new RuntimeException(e); - } - } - if (columnIndex == columnNames.length - 1) { - result = DATE_FORMAT.format(result); - } - return result; - } - - @Override - public String getColumnName(int column) { - return _(columnNames[column]); - } - - protected PropertyDescriptor[] getDescriptors() { - if (descriptors == null) { - descriptors = new PropertyDescriptor[columnNames.length]; - BeanInfo beanInfo; - try { - beanInfo = Introspector.getBeanInfo(MetaData.class); - List<String> props = new ArrayList<String>(columnNames.length); - int index = "simexplorer.common.".length(); - for (String columnName : columnNames) { - props.add(columnName.substring(index)); - } - - descriptors = new PropertyDescriptor[props.size()]; - for (PropertyDescriptor descriptor : beanInfo.getPropertyDescriptors()) { - index = props.indexOf(descriptor.getName()); - if (index == -1) { - continue; - } - descriptors[index] = descriptor; - } - } catch (IntrospectionException e) { - throw new RuntimeException(e); - } - } - return descriptors; - } -} Copied: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/ListTableModel.java (from rev 1014, trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/JApplicationTableModel.java) =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/ListTableModel.java (rev 0) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/ListTableModel.java 2008-02-16 14:56:00 UTC (rev 1016) @@ -0,0 +1,133 @@ +/* +* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Code Lutin, +* Tony Chemit +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +* ##% */ +package fr.cemagref.simexplorer.is.ui.swing.model; + +import fr.cemagref.simexplorer.is.entities.metadata.MetaData; +import fr.cemagref.simexplorer.is.entities.EntityHelper; +import static org.codelutin.i18n.I18n._; +import static org.codelutin.i18n.I18n.n_; + +import javax.swing.table.AbstractTableModel; +import java.beans.BeanInfo; +import java.beans.IntrospectionException; +import java.beans.Introspector; +import java.beans.PropertyDescriptor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.List; + +/** @author tony */ +public class ListTableModel extends AbstractTableModel { + + MetaData[] data; + + PropertyDescriptor[] descriptors; + private static final long serialVersionUID = -105647814466295077L; + private SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss.SSS"); + + public ListTableModel() { + } + + public ListTableModel(MetaData[] data) { + this.data = data; + } + + public MetaData[] getData() { + return data; + } + + public void setData(MetaData[] data) { + this.data = data; + } + + private final String[] columnNames = { + n_("simexplorer.common.name"), + n_("simexplorer.common.type"), + n_("simexplorer.common.description"), + n_("simexplorer.common.version"), + n_("simexplorer.common.creationDate") + }; + + public int getRowCount() { + return data == null ? 0 : data.length; + } + + public int getColumnCount() { + return columnNames.length; + } + + public Object getValueAt(int rowIndex, int columnIndex) { + Object result = null; + MetaData current = data[rowIndex]; + if (current != null) { + try { + if (columnIndex==1) { + // use I18n + result = EntityHelper.Type.getLibelle(current); + } else { + PropertyDescriptor propertyDescriptor = getDescriptors()[columnIndex]; + Method readMethod = propertyDescriptor.getReadMethod(); + result = readMethod.invoke(current); + } + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } catch (InvocationTargetException e) { + throw new RuntimeException(e); + } + } + if (columnIndex == columnNames.length - 1) { + result = DATE_FORMAT.format(result); + } + return result; + } + + @Override + public String getColumnName(int column) { + return _(columnNames[column]); + } + + protected PropertyDescriptor[] getDescriptors() { + if (descriptors == null) { + descriptors = new PropertyDescriptor[columnNames.length]; + BeanInfo beanInfo; + try { + beanInfo = Introspector.getBeanInfo(MetaData.class); + List<String> props = new ArrayList<String>(columnNames.length); + int index = "simexplorer.common.".length(); + for (String columnName : columnNames) { + props.add(columnName.substring(index)); + } + + descriptors = new PropertyDescriptor[props.size()]; + for (PropertyDescriptor descriptor : beanInfo.getPropertyDescriptors()) { + index = props.indexOf(descriptor.getName()); + if (index == -1) { + continue; + } + descriptors[index] = descriptor; + } + } catch (IntrospectionException e) { + throw new RuntimeException(e); + } + } + return descriptors; + } +} Modified: trunk/simexplorer-is/simexplorer-is-swing/src/uimodel/fr/cemagref/simexplorer/is/ui/swing/JListTab.jaxx =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/uimodel/fr/cemagref/simexplorer/is/ui/swing/JListTab.jaxx 2008-02-16 14:54:21 UTC (rev 1015) +++ trunk/simexplorer-is/simexplorer-is-swing/src/uimodel/fr/cemagref/simexplorer/is/ui/swing/JListTab.jaxx 2008-02-16 14:56:00 UTC (rev 1016) @@ -30,7 +30,7 @@ <row fill='both' weightx='1' weighty='1'> <cell insets='0,0,0,0'> <JScrollPane> - <JTable id='table' model='{new fr.cemagref.simexplorer.is.ui.swing.model.JApplicationTableModel()}'/> + <JTable id='table' model='{new fr.cemagref.simexplorer.is.ui.swing.model.ListTableModel()}'/> </JScrollPane> </cell> </row>