Author: tchemit Date: 2008-01-20 12:20:14 +0000 (Sun, 20 Jan 2008) New Revision: 245 Added: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/JApplicationTableModel.java Log: ajout d'un composant pour la table des applications (le mod?\195?\168le) Added: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/JApplicationTableModel.java =================================================================== --- trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/JApplicationTableModel.java (rev 0) +++ trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/JApplicationTableModel.java 2008-01-20 12:20:14 UTC (rev 245) @@ -0,0 +1,114 @@ +/* +* \#\#% 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; + +import fr.cemagref.simexplorer.is.entities.metadata.MetaDataEntity; +import static org.codelutin.i18n.I18n._; + +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.util.ArrayList; +import java.util.List; + +/** @author tony */ +public class JApplicationTableModel extends AbstractTableModel { + + MetaDataEntity[] data; + + PropertyDescriptor[] descriptors; + private static final long serialVersionUID = -105647814466295077L; + + public JApplicationTableModel() { + } + + public JApplicationTableModel(MetaDataEntity[] data) { + this.data = data; + } + + public MetaDataEntity[] getData() { + return data; + } + + public void setData(MetaDataEntity[] data) { + this.data = data; + } + + private final String[] columnNames = { + _("simexplorer.common.uuid"), + _("simexplorer.common.name"), + _("simexplorer.common.type"), + _("simexplorer.common.description"), + _("simexplorer.common.version"), + _("simexplorer.common.create.date") + }; + + 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; + MetaDataEntity current = data[rowIndex]; + if (data != null) { + try { + result = getDescriptors()[columnIndex].getReadMethod().invoke(current); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } catch (InvocationTargetException e) { + throw new RuntimeException(e); + } + } + return result; + } + + protected PropertyDescriptor[] getDescriptors() { + if (descriptors == null) { + descriptors = new PropertyDescriptor[columnNames.length]; + BeanInfo beanInfo; + try { + beanInfo = Introspector.getBeanInfo(MetaDataEntity.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; + } +}
participants (1)
-
tchemit@users.labs.libre-entreprise.org