Author: chatellier Date: 2009-11-02 14:39:50 +0000 (Mon, 02 Nov 2009) New Revision: 2724 Removed: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/metier/MetierSeasonInfoTargetSpeciesModel.java Log: Use species combo model. Deleted: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/metier/MetierSeasonInfoTargetSpeciesModel.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/metier/MetierSeasonInfoTargetSpeciesModel.java 2009-11-02 14:06:07 UTC (rev 2723) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/metier/MetierSeasonInfoTargetSpeciesModel.java 2009-11-02 14:39:50 UTC (rev 2724) @@ -1,239 +0,0 @@ -/* *##% - * Copyright (C) 2009 Ifremer, Code Lutin - * - * 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.ifremer.isisfish.ui.input.metier; - -import static org.nuiton.i18n.I18n._; - -import java.awt.Component; -import java.util.List; - -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JLabel; -import javax.swing.JTable; -import javax.swing.table.AbstractTableModel; -import javax.swing.table.TableCellRenderer; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import fr.ifremer.isisfish.entities.Equation; -import fr.ifremer.isisfish.entities.MetierSeasonInfo; -import fr.ifremer.isisfish.entities.TargetSpecies; - -/** - * Table model for {@link MetierSeasonInfo}#{@link TargetSpecies}. - * - * Columns : - * <li>target species name</li> - * <li>target species equation</li> - * <li>target species primaryCatch</li> - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -public class MetierSeasonInfoTargetSpeciesModel extends AbstractTableModel implements TableCellRenderer { - - /** Log. */ - private static Log log = LogFactory.getLog(MetierSeasonInfoTargetSpeciesModel.class); - - /** serialVersionUID. */ - private static final long serialVersionUID = 3169786638868209920L; - - /** Columns names. */ - public final static String[] COLUMN_NAMES = { - _("isisfish.metierSeasonInfoSpecies.species"), - _("isisfish.metierSeasonInfoSpecies.targetFactor"), - _("isisfish.metierSeasonInfoSpecies.mainSpecies") }; - - protected List<TargetSpecies> targetSpeciesList; - - /** - * Empty constructor. - */ - public MetierSeasonInfoTargetSpeciesModel() { - this(null); - } - - /** - * Constructor with data. - * - * @param targetSpeciesList initial target species - */ - public MetierSeasonInfoTargetSpeciesModel( - List<TargetSpecies> targetSpeciesList) { - super(); - this.targetSpeciesList = targetSpeciesList; - } - - /** - * Set target species list. - * - * @param targetSpeciesList the targetSpecies to set - */ - public void setTargetSpecies(List<TargetSpecies> targetSpeciesList) { - this.targetSpeciesList = targetSpeciesList; - } - - /* - * @see javax.swing.table.TableModel#getColumnCount() - */ - @Override - public int getColumnCount() { - return COLUMN_NAMES.length; - } - - /* - * @see javax.swing.table.TableModel#getRowCount() - */ - @Override - public int getRowCount() { - int rows = 0; - if (targetSpeciesList != null) { - rows = targetSpeciesList.size(); - } - return rows; - } - - /* - * @see javax.swing.table.TableModel#getValueAt(int, int) - */ - @Override - public Object getValueAt(int rowIndex, int columnIndex) { - - Object result = null; - - TargetSpecies targetSpecies = targetSpeciesList.get(rowIndex); - switch (columnIndex) { - case 0: - result = targetSpecies.getSpecies().getName(); - break; - case 1: - result = targetSpecies.getTargetFactorEquation(); - break; - case 2: - result = targetSpecies.getPrimaryCatch(); - break; - default: - throw new IndexOutOfBoundsException("No such column " + columnIndex); - } - - return result; - } - - /* - * @see javax.swing.table.TableModel#getColumnClass(int) - */ - @Override - public Class<?> getColumnClass(int columnIndex) { - - Class<?> result = null; - - switch (columnIndex) { - case 0: - result = String.class; - break; - case 1: - result = Equation.class; - break; - case 2: - result = Boolean.class; - break; - default: - throw new IndexOutOfBoundsException("No such column " + columnIndex); - } - - return result; - } - - /* - * @see javax.swing.table.TableModel#getColumnName(int) - */ - @Override - public String getColumnName(int columnIndex) { - return COLUMN_NAMES[columnIndex]; - } - - /* - * @see javax.swing.table.TableModel#isCellEditable(int, int) - */ - @Override - public boolean isCellEditable(int rowIndex, int columnIndex) { - return columnIndex > 0; - } - - /* - * @see javax.swing.table.TableModel#setValueAt(java.lang.Object, int, int) - */ - @Override - public void setValueAt(Object value, int rowIndex, int columnIndex) { - - if (log.isDebugEnabled()) { - log.debug("Cell edition (column " + columnIndex + ") = " + value); - } - - TargetSpecies targetSpecies = targetSpeciesList.get(rowIndex); - switch (columnIndex) { - case 1: - Equation eq = (Equation)value; - // two events for event to be fired - targetSpecies.setTargetFactorEquation(null); - targetSpecies.setTargetFactorEquation(eq); - break; - case 2: - Boolean bValue = (Boolean)value; - targetSpecies.setPrimaryCatch(bValue); - break; - default: - throw new IndexOutOfBoundsException("Can't edit column " + columnIndex); - } - - } - - /* - * @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable, java.lang.Object, boolean, boolean, int, int) - */ - @Override - public Component getTableCellRendererComponent(JTable table, Object value, - boolean isSelected, boolean hasFocus, int row, int column) { - - Component c = null; - switch (column) { - case 0: - c = new JLabel(value.toString()); - break; - case 1: - Equation equation = (Equation)value; - c = new JButton(equation.getName() + "(" + equation.getCategory() + ")"); - break; - case 2: - Boolean bValue = (Boolean)value; - c = new JCheckBox(); - ((JCheckBox)c).setSelected(bValue); - break; - default: - throw new IndexOutOfBoundsException("No such column " + column); - } - return c; - } - -}