Author: chatellier Date: 2009-06-08 15:36:09 +0000 (Mon, 08 Jun 2009) New Revision: 2340 Added: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/metier/ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/metier/MetierSeasonInfoTargetSpeciesModel.java 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/MetierSeasonInfoSpeciesUI.jaxx isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/MetierSeasonInfoZoneUI.jaxx Log: Metrier (zone and season) refactoring. Replace generic cell editor by specific tale 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-06-08 15:35:11 UTC (rev 2339) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/MetierSeasonInfoSpeciesEditorUI.jaxx 2009-06-08 15:36:09 UTC (rev 2340) @@ -22,15 +22,12 @@ <!-- bean property --> <fr.ifremer.isisfish.entities.MetierImpl id='bean' javaBean='null'/> + <fr.ifremer.isisfish.entities.MetierSeasonInfoImpl id='metierSeasonInfo' javaBean='null'/> - <fr.ifremer.isisfish.entities.MetierSeasonInfoImpl id='metierInfo' javaBean='null'/> - <Boolean id='metierSeasonSelected' javaBean='false'/> - <Boolean id='targetSpeciesSelected' javaBean='false'/> <script><![CDATA[ -import com.l2fprod.common.swing.renderer.BooleanCellRenderer; import fr.ifremer.isisfish.entities.Equation; import fr.ifremer.isisfish.entities.Formule; import fr.ifremer.isisfish.entities.Metier; @@ -38,14 +35,11 @@ import fr.ifremer.isisfish.entities.MetierSeasonInfo; import fr.ifremer.isisfish.entities.MetierSeasonInfoImpl; 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.widget.editor.EquationTableEditor; -import fr.ifremer.isisfish.ui.WelcomePanelUI; -import org.codelutin.topia.persistence.TopiaEntity; import javax.swing.table.DefaultTableModel; import fr.ifremer.isisfish.entities.Species; -import org.codelutin.topia.TopiaContext; -import javax.swing.table.TableCellEditor; tableTargetSpecies.addMouseListener(new MouseAdapter() { @Override @@ -56,21 +50,20 @@ @Override public void refresh() { - - if (log.isDebugEnabled()) { - log.debug("Refresh called in ui : " + this); - } - getVerifier().addCurrentPanel(targetFactor); - if (getBean() != null){ + if (getBean() != null) { setTableTargetSpeciesModel(); } - else{ + else { setTargetSpeciesModel(); } setTargetSpeciesModel(); remove.setEnabled(false); setAddButton(); + + // is actif is not working for targetFactor + // maybe set to true by addCurrentPanel + targetFactor.setActif(targetSpeciesSelected); } @Override @@ -78,7 +71,7 @@ } -protected void setTargetSpeciesModel(){ +protected void setTargetSpeciesModel() { DefaultComboBoxModel fieldTargetSpeciesModel = new DefaultComboBoxModel(); java.util.List<Species> species = getRegion().getSpecies(); if (species != null){ @@ -89,47 +82,28 @@ } fieldTargetSpecies.setModel(fieldTargetSpeciesModel); } -protected void setTableTargetSpeciesModel(){ - DefaultTableModel model = new DefaultTableModel(){ - @Override - public boolean isCellEditable(int row, int column) { - boolean result = false; - if (column > 0){ - result =true; - } - return result; - } - }; - if (getMetierInfo() != null) { - Collection<TargetSpecies> targetSpecies = ((MetierSeasonInfo)getMetierInfo()).getSpeciesTargetSpecies(); - if (targetSpecies != null) { - java.util.List<GenericCell> species = new ArrayList <GenericCell>(); - java.util.List<Equation> equations = new ArrayList <Equation>(); - java.util.List<Boolean> primaryCatch = new ArrayList <Boolean>(); - for (TargetSpecies t : targetSpecies) { - Species s = t.getSpecies(); - Equation e = t.getTargetFactorEquation(); - Boolean b = t.getPrimaryCatch(); - species.add(new GenericCell(s.getName(), s, Species.class)); - equations.add(e); - primaryCatch.add(b); - } - model.addColumn(_("isisfish.metierSeasonInfoSpecies.species"), species.toArray()); - model.addColumn(_("isisfish.metierSeasonInfoSpecies.targetFactor"), equations.toArray()); - model.addColumn(_("isisfish.metierSeasonInfoSpecies.mainSpecies"), primaryCatch.toArray()); + +protected void setTableTargetSpeciesModel() { + if (getMetierSeasonInfo() != null) { + java.util.List<TargetSpecies> targetSpecies = new ArrayList<TargetSpecies>(); + for (TargetSpecies oneTargetSpecies : getMetierSeasonInfo().getSpeciesTargetSpecies()) { + getVerifier().addCurrentEntity(oneTargetSpecies); + targetSpecies.add(oneTargetSpecies); } + MetierSeasonInfoTargetSpeciesModel model = new MetierSeasonInfoTargetSpeciesModel(targetSpecies); tableTargetSpecies.setModel(model); - EquationTableEditor cellEditor = new EquationTableEditor(); - tableTargetSpecies.getColumnModel().getColumn(1).setCellEditor(cellEditor); + tableTargetSpecies.setDefaultRenderer(Equation.class, model); + tableTargetSpecies.setDefaultEditor(Equation.class, new EquationTableEditor()); } } + protected void add() { Object species = ((GenericCell)fieldTargetSpecies.getSelectedItem()).getValue(); - if (getMetierInfo() != null && species != null) { + if (getMetierSeasonInfo() != null && species != null) { Formule selectedFormule = (Formule)targetFactor.getFormuleComboBox().getSelectedItem(); getContextValue(InputAction.class).addTargetSpecies( getBean(), - (MetierSeasonInfo)getMetierInfo(), + getMetierSeasonInfo(), (Species)species, selectedFormule.getName(), targetFactor.getEditor().getText(), @@ -137,25 +111,28 @@ setTableTargetSpeciesModel(); } } + protected void remove() { if (isMetierSeasonSelected()) { - Object[] targetSpecies = getMetierInfo().getSpeciesTargetSpecies().toArray(); + Object[] targetSpecies = getMetierSeasonInfo().getSpeciesTargetSpecies().toArray(); Object o = targetSpecies[tableTargetSpecies.getSelectedRow()]; if (o != null) { TargetSpecies ts = (TargetSpecies)o; - getAction().removeTargetSpecies(getMetierInfo(), ts); + getAction().removeTargetSpecies(getMetierSeasonInfo(), ts); setTableTargetSpeciesModel(); } } } + protected void targetSpeciesChanged() { setTargetSpeciesSelected(fieldTargetSpecies.getSelectedItem() != null); setTableTargetSpeciesModel(); setAddButton(); } + protected void setAddButton() { - add.setEnabled(getMetierSeasonSelected() && getTargetSpeciesSelected()); + add.setEnabled(isMetierSeasonSelected() && isTargetSpeciesSelected()); } ]]></script> <Table id='body'> @@ -164,16 +141,16 @@ <Table> <row> <cell fill='horizontal' anchor='east'> - <JLabel text="isisfish.metierSeasonInfoSpecies.selectSpecies" enabled='{isActif()}'/> + <JLabel text="isisfish.metierSeasonInfoSpecies.selectSpecies" enabled='{isMetierSeasonSelected()}'/> </cell> <cell fill='horizontal' weightx='1.0'> - <JComboBox id="fieldTargetSpecies" onActionPerformed='targetSpeciesChanged()' enabled='{isActif()}'/> + <JComboBox id="fieldTargetSpecies" onActionPerformed='targetSpeciesChanged()' enabled='{isMetierSeasonSelected()}'/> </cell> </row> <row> <cell columns='2' fill='both' weightx='1.0' weighty='1.0'> <InputOneEquationUI id='targetFactor' constructorParams='this' - actif='{isActif()}' + actif='{isTargetSpeciesSelected()}' lblText='{_("isisfish.metierSeasonInfoSpecies.targetFactor")}' bean='{getBean()}' nameEquation='TargetFactor' clazz='{fr.ifremer.isisfish.equation.TargetSpeciesTargetFactorEquation.class}' @@ -185,7 +162,7 @@ <JPanel/> </cell> <cell fill='horizontal' weightx='1.0'> - <JCheckBox id="fieldPrimaryCatch" text="isisfish.metierSeasonInfoSpecies.mainSpecies" enabled='{isActif()}'/> + <JCheckBox id="fieldPrimaryCatch" text="isisfish.metierSeasonInfoSpecies.mainSpecies" enabled='{isTargetSpeciesSelected()}'/> </cell> </row> </Table> @@ -196,19 +173,19 @@ <Table> <row> <cell columns='2' fill='horizontal' weightx='1.0'> - <JButton id="add" text="isisfish.common.add" onActionPerformed='add()' enabled='{isActif()}'/> + <JButton id="add" text="isisfish.common.add" onActionPerformed='add()' enabled='{isMetierSeasonSelected()}'/> </cell> </row> <row> <cell columns='2' fill='both' weightx='1.0' weighty='1.0'> <JScrollPane minimumSize='{new Dimension(0,0)}' preferredSize='{new Dimension(0,0)}'> - <JTable id="tableTargetSpecies" rowHeight='24' enabled='{isActif()}'/> + <JTable id="tableTargetSpecies" rowHeight='24' enabled='{isMetierSeasonSelected()}'/> </JScrollPane> </cell> </row> <row> <cell columns='2' fill='horizontal' weightx='1.0'> - <JButton id="remove" text="isisfish.common.remove" onActionPerformed='remove()' enabled='{isActif()}'/> + <JButton id="remove" text="isisfish.common.remove" onActionPerformed='remove()' enabled='false'/> </cell> </row> </Table> Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/MetierSeasonInfoSpeciesUI.jaxx =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/MetierSeasonInfoSpeciesUI.jaxx 2009-06-08 15:35:11 UTC (rev 2339) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/MetierSeasonInfoSpeciesUI.jaxx 2009-06-08 15:36:09 UTC (rev 2340) @@ -23,9 +23,9 @@ <!-- bean property --> <fr.ifremer.isisfish.entities.MetierImpl id='bean' javaBean='null'/> - <fr.ifremer.isisfish.entities.MetierSeasonInfoImpl id='metierInfo' javaBean='null'/> + <fr.ifremer.isisfish.entities.MetierSeasonInfoImpl id='metierSeasonInfo' javaBean='null'/> - <Boolean id='metierSeasonSelected' javaBean='false'/> + <Boolean id='metierSeasonInfoSelected' javaBean='false'/> <script><![CDATA[ import fr.ifremer.isisfish.entities.Metier; @@ -62,23 +62,26 @@ protected void setSeasonModel(){ DefaultComboBoxModel seasonModel = new DefaultComboBoxModel(); java.util.List<MetierSeasonInfo> metierSeasonInfo = getBean().getMetierSeasonInfo(); - if (metierSeasonInfo != null){ + if (metierSeasonInfo != null) { seasonModel.addElement(new GenericCell(" ", null, null)); for (MetierSeasonInfo m : metierSeasonInfo){ seasonModel.addElement(new GenericCell(m.getFirstMonth().toString() + "-" + m.getLastMonth().toString(), m, MetierSeasonInfo.class)); } } fieldMetierSeasonInfo.setModel(seasonModel); + + // fix refresh() problem false, because first is null + setMetierSeasonInfoSelected(false); } -protected void metierSeasonChanged(){ - setMetierSeasonSelected(fieldMetierSeasonInfo.getSelectedItem() != null); - if (isMetierSeasonSelected()){ +protected void metierSeasonInfoChanged() { + setMetierSeasonInfoSelected(((GenericCell)fieldMetierSeasonInfo.getSelectedItem()).getValue() != null); + if (isMetierSeasonInfoSelected()) { MetierSeasonInfoImpl msii = (MetierSeasonInfoImpl)((GenericCell)fieldMetierSeasonInfo.getSelectedItem()).getValue(); if (log.isDebugEnabled()) { log.debug("Metier season changed : " + msii); } - setMetierInfo(msii); - getVerifier().addCurrentEntity(getMetierInfo()); + setMetierSeasonInfo(msii); + getVerifier().addCurrentEntity(getMetierSeasonInfo()); } metierSeasonInfoSpeciesEditor.refresh(); } @@ -92,13 +95,13 @@ <JLabel text="isisfish.metierSeasonInfoSpecies.selectSeason" enabled='{isActif()}'/> </cell> <cell fill='horizontal' weightx='1.0'> - <JComboBox id="fieldMetierSeasonInfo" onActionPerformed='metierSeasonChanged()' enabled='{isActif()}'/> + <JComboBox id="fieldMetierSeasonInfo" onActionPerformed='metierSeasonInfoChanged()' enabled='{isActif()}'/> </cell> </row> <row> <cell columns='2' fill='both' weightx='1.0' weighty='1.0'> <MetierSeasonInfoSpeciesEditorUI id='metierSeasonInfoSpeciesEditor' constructorParams='this' - bean='{getBean()}' metierInfo='{getMetierInfo()}' metierSeasonSelected='{getMetierSeasonSelected()}' + bean='{getBean()}' metierSeasonInfo='{getMetierSeasonInfo()}' metierSeasonSelected='{isMetierSeasonInfoSelected()}' actif='{isActif()}' decorator='boxed' _bean='{MetierSeasonInfoImpl.class}' _method='"SpeciesTargetSpecies"'/> </cell> Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/MetierSeasonInfoZoneUI.jaxx =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/MetierSeasonInfoZoneUI.jaxx 2009-06-08 15:35:11 UTC (rev 2339) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/MetierSeasonInfoZoneUI.jaxx 2009-06-08 15:36:09 UTC (rev 2340) @@ -22,7 +22,6 @@ <!-- bean property --> <fr.ifremer.isisfish.entities.MetierImpl id='bean' javaBean='null'/> - <fr.ifremer.isisfish.entities.MetierSeasonInfoImpl id='metierSeasonInfo' javaBean='null'/> <Boolean id='metierSeasonInfoNotNull' javaBean='false'/> @@ -96,9 +95,9 @@ log.debug("Refresh called in ui : " + this); } - if (!isActif()) { - setMetierSeasonInfoNotNull(false); - } + //if (!isActif()) { + setMetierSeasonInfoNotNull(false); + //} Metier metier = getVerifier().getEntity(Metier.class); // don't add setBean(null) here : useless @@ -239,7 +238,8 @@ </cell> <cell fill='both' weightx='1.0' weighty='0.3'> <JScrollPane minimumSize='{new Dimension(0,0)}' preferredSize='{new Dimension(0,0)}'> - <JTextArea id="fieldMetierSeasonZoneComment" text='{getMetierSeasonInfo().getSeasonZoneComment()}' onKeyReleased='getMetierSeasonInfo().setSeasonZoneComment(fieldMetierSeasonZoneComment.getText())' enabled='{isMetierSeasonInfoNotNull()}' decorator='boxed'/> + <!-- jaxx.runtime.SwingUtil.getStringValue for null values --> + <JTextArea id="fieldMetierSeasonZoneComment" text='{jaxx.runtime.SwingUtil.getStringValue(getMetierSeasonInfo().getSeasonZoneComment())}' onKeyReleased='getMetierSeasonInfo().setSeasonZoneComment(fieldMetierSeasonZoneComment.getText())' enabled='{isMetierSeasonInfoNotNull()}' decorator='boxed'/> </JScrollPane> </cell> </row> Added: 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 (rev 0) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/metier/MetierSeasonInfoTargetSpeciesModel.java 2009-06-08 15:36:09 UTC (rev 2340) @@ -0,0 +1,243 @@ +/* *##% + * 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 static org.codelutin.i18n.I18n._; + +import java.awt.Checkbox; +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.event.TableModelListener; +import javax.swing.table.AbstractTableModel; +import javax.swing.table.TableCellRenderer; +import javax.swing.table.TableModel; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import fr.ifremer.isisfish.IsisFishRuntimeException; +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: 1.0 $ + * + * Last update : $Date: 8 juin 2009 $ + * By : $Author: chatellier $ + */ +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(); + ((Checkbox)c).setState(bValue); + break; + default: + throw new IndexOutOfBoundsException("No such column " + column); + } + return c; + } + +}
participants (1)
-
chatellierï¼ users.labs.libre-entreprise.org