Author: chatellier Date: 2009-11-02 14:06:07 +0000 (Mon, 02 Nov 2009) New Revision: 2723 Added: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/metier/MetierSeasonInfoTargetSpeciesTableModel.java isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/metier/SpeciesComboModel.java Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/MetierSeasonInfoSpeciesEditorUI.jaxx Log: Use species combo model. Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/MetierSeasonInfoSpeciesEditorUI.jaxx =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/MetierSeasonInfoSpeciesEditorUI.jaxx 2009-11-02 10:11:36 UTC (rev 2722) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/MetierSeasonInfoSpeciesEditorUI.jaxx 2009-11-02 14:06:07 UTC (rev 2723) @@ -29,17 +29,12 @@ <script><![CDATA[ import fr.ifremer.isisfish.entities.Equation; -import fr.ifremer.isisfish.entities.Formule; -import fr.ifremer.isisfish.entities.Metier; import fr.ifremer.isisfish.entities.MetierImpl; -import fr.ifremer.isisfish.entities.MetierSeasonInfo; -import fr.ifremer.isisfish.entities.MetierSeasonInfoImpl; +import fr.ifremer.isisfish.entities.Species; import fr.ifremer.isisfish.entities.TargetSpecies; -import fr.ifremer.isisfish.ui.input.metier.MetierSeasonInfoTargetSpeciesModel; -import fr.ifremer.isisfish.ui.widget.editor.GenericCell; +import fr.ifremer.isisfish.ui.input.metier.MetierSeasonInfoTargetSpeciesTableModel; +import fr.ifremer.isisfish.ui.input.metier.SpeciesComboModel; import fr.ifremer.isisfish.ui.widget.editor.EquationTableEditor; -import javax.swing.table.DefaultTableModel; -import fr.ifremer.isisfish.entities.Species; tableTargetSpecies.addMouseListener(new MouseAdapter() { @Override @@ -72,14 +67,8 @@ } protected void setTargetSpeciesModel() { - DefaultComboBoxModel fieldTargetSpeciesModel = new DefaultComboBoxModel(); java.util.List<Species> species = getRegion().getSpecies(); - if (species != null){ - fieldTargetSpeciesModel.addElement(new GenericCell(" ", null, null)); - for (Species s : species){ - fieldTargetSpeciesModel.addElement(new GenericCell(s.getName(), s, Species.class)); - } - } + SpeciesComboModel fieldTargetSpeciesModel = new SpeciesComboModel(species); fieldTargetSpecies.setModel(fieldTargetSpeciesModel); } @@ -98,7 +87,7 @@ } // set table model - MetierSeasonInfoTargetSpeciesModel model = new MetierSeasonInfoTargetSpeciesModel(targetSpecies); + MetierSeasonInfoTargetSpeciesTableModel model = new MetierSeasonInfoTargetSpeciesTableModel(targetSpecies); tableTargetSpecies.setModel(model); tableTargetSpecies.setDefaultRenderer(Equation.class, model); tableTargetSpecies.setDefaultEditor(Equation.class, new EquationTableEditor()); @@ -106,15 +95,14 @@ } protected void add() { - Object species = ((GenericCell)fieldTargetSpecies.getSelectedItem()).getValue(); - if (getMetierSeasonInfo() != null && species != null) { + Species selectedSpecies = (Species)fieldTargetSpecies.getSelectedItem(); + if (getMetierSeasonInfo() != null && selectedSpecies != null) { // il n'y en a pas a la creaion de la base //Formule selectedFormule = (Formule)targetFactor.getFormuleComboBox().getSelectedItem(); getContextValue(InputAction.class).addTargetSpecies( getBean(), getMetierSeasonInfo(), - (Species)species, - /* selectedFormule.getName(), */ + selectedSpecies, targetFactor.getEditor().getText(), fieldPrimaryCatch.isSelected()); setTableTargetSpeciesModel(); Copied: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/metier/MetierSeasonInfoTargetSpeciesTableModel.java (from rev 2668, 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/MetierSeasonInfoTargetSpeciesTableModel.java (rev 0) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/metier/MetierSeasonInfoTargetSpeciesTableModel.java 2009-11-02 14:06:07 UTC (rev 2723) @@ -0,0 +1,239 @@ +/* *##% + * 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 MetierSeasonInfoTargetSpeciesTableModel extends AbstractTableModel implements TableCellRenderer { + + /** Log. */ + private static Log log = LogFactory.getLog(MetierSeasonInfoTargetSpeciesTableModel.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 MetierSeasonInfoTargetSpeciesTableModel() { + this(null); + } + + /** + * Constructor with data. + * + * @param targetSpeciesList initial target species + */ + public MetierSeasonInfoTargetSpeciesTableModel( + 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; + } + +} Added: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/metier/SpeciesComboModel.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/metier/SpeciesComboModel.java (rev 0) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/metier/SpeciesComboModel.java 2009-11-02 14:06:07 UTC (rev 2723) @@ -0,0 +1,104 @@ +/* *##% + * Copyright (C) 2009 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 java.util.List; + +import javax.swing.DefaultComboBoxModel; + +import fr.ifremer.isisfish.entities.Species; + +/** + * Model pour la liste des {@link Species}. + * + * Pas de selection par defaut. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author: chatellier $ + */ +public class SpeciesComboModel extends DefaultComboBoxModel { + + /** serialVersionUID. */ + private static final long serialVersionUID = 6171850179969290032L; + + /** PopulationSeasonInfo list */ + protected List<Species> speciesList; + + /** + * Empty constructor. + */ + public SpeciesComboModel() { + this(null); + } + + /** + * Constructor with species list. + * + * @param speciesList species list + */ + public SpeciesComboModel(List<Species> speciesList) { + super(); + setPopulationSeasonInfos(speciesList); + } + + /** + * Get species list. + * + * @return species list + */ + public List<Species> getPopulationSeasonInfos() { + return speciesList; + } + + /** + * Set species list. + * + * @param speciesList species list + */ + public void setPopulationSeasonInfos(List<Species> speciesList) { + this.speciesList = speciesList; + + // clear selection + setSelectedItem(null); + } + + /* + * @see javax.swing.ListModel#getElementAt(int) + */ + @Override + public Object getElementAt(int index) { + return speciesList.get(index); + } + + /* + * @see javax.swing.ListModel#getSize() + */ + @Override + public int getSize() { + int size = 0; + + if (speciesList != null) { + size = speciesList.size(); + } + return size; + } +} Property changes on: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/metier/SpeciesComboModel.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL"
participants (1)
-
chatellierï¼ users.labs.libre-entreprise.org