Author: tchemit Date: 2008-01-20 13:33:50 +0000 (Sun, 20 Jan 2008) New Revision: 257 Removed: 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/SimExplorerAbstractTabAction.java Log: structuration des actions Deleted: 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 2008-01-20 13:33:33 UTC (rev 256) +++ trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/JApplicationTableModel.java 2008-01-20 13:33:50 UTC (rev 257) @@ -1,114 +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; - -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; - } -} Deleted: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerAbstractTabAction.java =================================================================== --- trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerAbstractTabAction.java 2008-01-20 13:33:33 UTC (rev 256) +++ trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerAbstractTabAction.java 2008-01-20 13:33:50 UTC (rev 257) @@ -1,77 +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; - -import org.apache.commons.beanutils.Converter; -import org.codelutin.i18n.I18n; -import org.codelutin.util.ConverterUtil; - -import javax.swing.JTabbedPane; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** @author tony */ -public class SimExplorerAbstractTabAction extends SimExplorerAbstractAction { - - protected SimExplorerTabManager.Tab tab; - - protected String methodName; - - protected Method method; - - private static final long serialVersionUID = 5285229914266682509L; - - - protected SimExplorerAbstractTabAction(String name, String prefixPatternName) { - super(name); - methodName = prefixPatternName; - Pattern patternName = Pattern.compile(prefixPatternName + "_(\\w+)"); - Matcher matcher = patternName.matcher(name); - if (!matcher.matches()) { - throw new IllegalArgumentException(I18n._("{0} should have a name like this {1}, but was {2}", getClass().getName(), patternName, name)); - } - Converter convertorLanguage = ConverterUtil.getConverter(SimExplorerTabManager.Tab.class); - tab = (SimExplorerTabManager.Tab) convertorLanguage.convert(SimExplorerTabManager.Tab.class, matcher.group(1)); - } - - public void actionPerformed(java.awt.event.ActionEvent e) { - log.info(this + " tab " + tab); - try { - getMethod().invoke(null, getMainUI().getContent(), tab); - } catch (IllegalAccessException e1) { - throw new RuntimeException(e1); - } catch (InvocationTargetException e1) { - throw new RuntimeException(e1); - } - } - - protected Method getMethod() { - if (method == null) { - try { - method = SimExplorerTabManager.class.getMethod(methodName, JTabbedPane.class, SimExplorerTabManager.Tab.class); - } catch (NoSuchMethodException e) { - throw new RuntimeException("could not found method '" + methodName + "' on " + SimExplorerTabManager.class); - } - } - return method; - } - -}