Author: tchemit Date: 2012-12-04 18:59:54 +0100 (Tue, 04 Dec 2012) New Revision: 27 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/27 Log: introduce species package + save species catches batches Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/AbstractSelectTableAction.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/CatchTreeModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/CatchTreeNode.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/MoveToNextEditableCellAction.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/MoveToNextEditableRowAction.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/MoveToPreviousEditableCellAction.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/MoveToPreviousEditableRowAction.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesCatchEntryModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesTabUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesTabUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesTabUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesTabUIModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesTableModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiColorHighlighter.java Removed: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/SpeciesTabUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/SpeciesTabUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/SpeciesTabUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/SpeciesTabUIModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/SpeciesTableModel.java Modified: trunk/tutti-persistence-dev/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceDevImpl.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistence.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/TraitSpeciesCatchBean.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/TuttiBeans.java trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/AbstractTuttiUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/TuttiUIUtil.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/CatchesUI.jaxx trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistence.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistence.java 2012-12-04 17:59:17 UTC (rev 26) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistence.java 2012-12-04 17:59:54 UTC (rev 27) @@ -107,6 +107,8 @@ TraitBean getTrait(String traitId); + TraitSpeciesCatchBean getTraitSpeciesCatch(String id); + SurveyBean createSurvey(SurveyBean bean); SurveyBean saveSurvey(SurveyBean bean); @@ -119,4 +121,8 @@ TraitBean saveTrait(TraitBean bean); + TraitSpeciesCatchBean createTraitSpeciesCatch(TraitSpeciesCatchBean bean); + + TraitSpeciesCatchBean saveTraitSpeciesCatch(TraitSpeciesCatchBean bean); + } Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/TraitSpeciesCatchBean.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/TraitSpeciesCatchBean.java 2012-12-04 17:59:17 UTC (rev 26) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/TraitSpeciesCatchBean.java 2012-12-04 17:59:54 UTC (rev 27) @@ -34,7 +34,7 @@ * @author tchemit <chemit@codelutin.com> * @since 0.1 */ -public class TraitSpeciesCatchBean extends AbstractTuttiBean implements TraitCatchBeanAware{ +public class TraitSpeciesCatchBean extends AbstractTuttiBean implements TraitCatchBeanAware { private static final long serialVersionUID = 1L; @@ -115,6 +115,13 @@ */ protected Float elevationRatio; + /** + * Comment on this catches. + * + * @since 0.2 + */ + protected String comment; + public TraitBean getTrait() { return trait; } @@ -139,14 +146,6 @@ this.speciesToConfirm = speciesToConfirm; } - public boolean isSpeciesToConfirm() { - return speciesToConfirm; - } - - public void setSpeciesToConfirm(boolean speciesToConfirm) { - this.speciesToConfirm = speciesToConfirm; - } - public VracHorsVracEnum getVracHorsVrac() { return vracHorsVrac; } @@ -210,4 +209,12 @@ public void setElevationRatio(Float elevationRatio) { this.elevationRatio = elevationRatio; } + + public String getComment() { + return comment; + } + + public void setComment(String comment) { + this.comment = comment; + } } Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/TuttiBeans.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/TuttiBeans.java 2012-12-04 17:59:17 UTC (rev 26) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/TuttiBeans.java 2012-12-04 17:59:54 UTC (rev 27) @@ -37,6 +37,10 @@ */ public class TuttiBeans { + public static <B extends AbstractTuttiBean> boolean isNew(B bean) { + return bean.getId() == null; + } + public static <B extends AbstractTuttiBean> Predicate<B> newIdPredicate(String id) { return new IdPredicate<B>(id); } Modified: trunk/tutti-persistence-dev/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceDevImpl.java =================================================================== --- trunk/tutti-persistence-dev/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceDevImpl.java 2012-12-04 17:59:17 UTC (rev 26) +++ trunk/tutti-persistence-dev/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceDevImpl.java 2012-12-04 17:59:54 UTC (rev 27) @@ -277,6 +277,12 @@ } @Override + public TraitSpeciesCatchBean getTraitSpeciesCatch(String id) { + TraitSpeciesCatchBean result = TuttiBeans.findById(getData(TraitSpeciesCatchBean.class), id); + return result; + } + + @Override public SurveyBean createSurvey(SurveyBean bean) { SurveyBean result = new SurveyBean(); persist(SurveyBean.class, bean, result); @@ -318,6 +324,20 @@ return result; } + @Override + public TraitSpeciesCatchBean createTraitSpeciesCatch(TraitSpeciesCatchBean bean) { + TraitSpeciesCatchBean result = new TraitSpeciesCatchBean(); + persist(TraitSpeciesCatchBean.class, bean, result); + return result; + } + + @Override + public TraitSpeciesCatchBean saveTraitSpeciesCatch(TraitSpeciesCatchBean bean) { + TraitSpeciesCatchBean result = getTraitSpeciesCatch(bean.getId()); + persist(TraitSpeciesCatchBean.class, bean, result); + return result; + } + protected <B extends AbstractTuttiBean> void persist(Class<B> beanType, B source, B target) { Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java 2012-12-04 17:59:17 UTC (rev 26) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java 2012-12-04 17:59:54 UTC (rev 27) @@ -256,6 +256,12 @@ } @Override + public TraitSpeciesCatchBean getTraitSpeciesCatch(String id) { + checkDriverExists(); + return driver.getTraitSpeciesCatch(id); + } + + @Override public SurveyBean createSurvey(SurveyBean bean) { checkDriverExists(); return driver.createSurvey(bean); @@ -291,6 +297,18 @@ return driver.saveTrait(bean); } + @Override + public TraitSpeciesCatchBean createTraitSpeciesCatch(TraitSpeciesCatchBean bean) { + checkDriverExists(); + return driver.createTraitSpeciesCatch(bean); + } + + @Override + public TraitSpeciesCatchBean saveTraitSpeciesCatch(TraitSpeciesCatchBean bean) { + checkDriverExists(); + return driver.saveTraitSpeciesCatch(bean); + } + protected void checkDriverExists() { Preconditions.checkNotNull( driver, Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/AbstractTuttiUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/AbstractTuttiUIHandler.java 2012-12-04 17:59:17 UTC (rev 26) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/AbstractTuttiUIHandler.java 2012-12-04 17:59:54 UTC (rev 27) @@ -270,6 +270,17 @@ jlist.setSelectedIndices(result); } + protected <O> Decorator<O> getDecorator(Class<O> type, String name) { + DecoratorService decoratorService = + context.getService(DecoratorService.class); + + Preconditions.checkNotNull(type); + + Decorator<O> decorator = decoratorService.getDecoratorByType(type, name); + Preconditions.checkNotNull(decorator); + return decorator; + } + protected <O> ListCellRenderer newListCellRender(Class<O> type) { return newListCellRender(type, null); @@ -277,15 +288,15 @@ protected <O> ListCellRenderer newListCellRender(Class<O> type, String name) { - DecoratorService decoratorService = - context.getService(DecoratorService.class); + Decorator<O> decorator = getDecorator(type, name); + return newListCellRender(decorator); + } - Preconditions.checkNotNull(type); + protected <O> ListCellRenderer newListCellRender(Decorator<O> decorator) { - Decorator<O> decorator = decoratorService.getDecoratorByType(type, name); Preconditions.checkNotNull(decorator); - DecoratorListCellRenderer result = new DecoratorListCellRenderer(decorator); + ListCellRenderer result = new DecoratorListCellRenderer(decorator); return result; } @@ -296,12 +307,14 @@ protected <O> TableCellRenderer newTableCellRender(Class<O> type, String name) { - DecoratorService decoratorService = - context.getService(DecoratorService.class); + Decorator<O> decorator = getDecorator(type, name); - Preconditions.checkNotNull(type); + TableCellRenderer result = newTableCellRender(decorator); + return result; + } - Decorator<O> decorator = decoratorService.getDecoratorByType(type, name); + protected <O> TableCellRenderer newTableCellRender(Decorator<O> decorator) { + Preconditions.checkNotNull(decorator); DecoratorTableCellRenderer result = new DecoratorTableCellRenderer(decorator); Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/TuttiUIUtil.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/TuttiUIUtil.java 2012-12-04 17:59:17 UTC (rev 26) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/TuttiUIUtil.java 2012-12-04 17:59:54 UTC (rev 27) @@ -26,11 +26,14 @@ import com.google.common.base.Preconditions; import fr.ifremer.tutti.service.TuttiServiceTechnicalException; +import fr.ifremer.tutti.ui.swing.util.TuttiColorHighlighter; import jaxx.runtime.JAXXUtil; import jaxx.runtime.SwingUtil; import org.apache.commons.beanutils.PropertyUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jdesktop.swingx.decorator.HighlightPredicate; +import org.jdesktop.swingx.decorator.Highlighter; import org.nuiton.util.FileUtil; import javax.swing.Action; @@ -41,6 +44,7 @@ import javax.swing.JRootPane; import javax.swing.KeyStroke; import javax.swing.UIManager; +import java.awt.Color; import java.awt.Component; import java.awt.Cursor; import java.awt.Dimension; @@ -242,4 +246,12 @@ throw new TuttiServiceTechnicalException("Could not get property '" + property + "' on object of type '" + bean.getClass().getName() + "'", e); } } + + public static Highlighter newBackgroundColorHighlighter(HighlightPredicate predicate, Color color) { + return new TuttiColorHighlighter(predicate, color, false); + } + + public static Highlighter newForegroundColorHighlighter(HighlightPredicate predicate, Color color) { + return new TuttiColorHighlighter(predicate, color, true); + } } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/CatchesUI.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/CatchesUI.jaxx 2012-12-04 17:59:17 UTC (rev 26) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/CatchesUI.jaxx 2012-12-04 17:59:54 UTC (rev 27) @@ -26,7 +26,9 @@ <import> fr.ifremer.tutti.persistence.entities.TraitBean + fr.ifremer.tutti.ui.swing.TuttiUIContext + fr.ifremer.tutti.ui.swing.content.catches.species.SpeciesTabUI jaxx.runtime.swing.editor.bean.BeanComboBox Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/SpeciesTabUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/SpeciesTabUI.css 2012-12-04 17:59:17 UTC (rev 26) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/SpeciesTabUI.css 2012-12-04 17:59:54 UTC (rev 27) @@ -1,83 +0,0 @@ -/* - * #%L - * Tutti :: UI - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 Ifremer - * %% - * 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 3 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, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -NumberEditor { - autoPopup:{handler.getConfig().isAutoPopupNumberEditor()}; - showPopupButton:{handler.getConfig().isShowNumberEditorButton()}; - bean:{model}; - showReset:true; -} - -#totalWeightLabel { - text:"tutti.label.fishes.totalWeight"; - labelFor:{totalWeightField}; -} - -#totalWeightField { - property:"totalWeight"; - model:{model.getTotalWeight()}; - useFloat:false; - numberPattern:{INT_6_DIGITS_PATTERN}; -} - -#totalVracWeightLabel { - text:"tutti.label.fishes.totalVracWeight"; - labelFor:{totalVracWeightField}; -} - -#totalVracWeightField { - property:"totalVracWeight"; - model:{model.getTotalVracWeight()}; - useFloat:false; - numberPattern:{INT_6_DIGITS_PATTERN}; -} - -#sampleVracWeightLabel { - text:"tutti.label.fishes.sampleVracWeight"; - labelFor:{sampleVracWeightField}; -} - -#sampleVracWeightField { - property:"sampleVracWeight"; - model:{model.getSampleVracWeight()}; - useFloat:false; - numberPattern:{INT_6_DIGITS_PATTERN}; -} - -#totalHorsVracWeightLabel { - text:"tutti.label.fishes.totalHorsVracWeight"; - labelFor:{totalHorsVracWeightField}; -} - -#totalHorsVracWeightField { - property:"totalHorsVracWeight"; - model:{model.getTotalHorsVracWeight()}; - useFloat:false; - numberPattern:{INT_6_DIGITS_PATTERN}; -} - -#table { - model:{getContextValue(TableModel.class)}; - columnModel:{getContextValue(TableColumnModel.class)}; -} Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/SpeciesTabUI.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/SpeciesTabUI.jaxx 2012-12-04 17:59:17 UTC (rev 26) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/SpeciesTabUI.jaxx 2012-12-04 17:59:54 UTC (rev 27) @@ -1,114 +0,0 @@ -<!-- - #%L - Tutti :: UI - $Id$ - $HeadURL$ - %% - Copyright (C) 2012 Ifremer - %% - 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 3 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, see - <http://www.gnu.org/licenses/gpl-3.0.html>. - #L% - --> -<JPanel id='homePanel' layout='{new BorderLayout()}' - implements='fr.ifremer.tutti.ui.swing.TuttiUI<SpeciesTabUIModel, SpeciesTabUIHandler>'> - - <import> - fr.ifremer.tutti.persistence.entities.referential.BeaufortScaleBean - fr.ifremer.tutti.persistence.entities.referential.SeaStateBean - fr.ifremer.tutti.persistence.entities.StrataBean - fr.ifremer.tutti.persistence.entities.TraitBean - fr.ifremer.tutti.persistence.entities.referential.UserBean - fr.ifremer.tutti.ui.swing.TuttiUIContext - - jaxx.runtime.swing.editor.NumberEditor - - jaxx.runtime.validator.swing.SwingValidatorUtil - jaxx.runtime.validator.swing.SwingValidatorMessageTableModel - - javax.swing.table.TableModel - javax.swing.table.TableColumnModel - - static org.nuiton.i18n.I18n._ - </import> - - <script><![CDATA[ - -public SpeciesTabUI(CatchesUI parentUI) { - SpeciesTabUIHandler handler = new SpeciesTabUIHandler(parentUI, this); - setContextValue(handler); - handler.beforeInitUI(); -} - -public void selectTrait(TraitBean trait) { handler.selectTrait(trait); } - -protected void $afterCompleteSetup() { handler.afterInitUI(); } - ]]></script> - - <SpeciesTabUIHandler id='handler' - initializer='getContextValue(SpeciesTabUIHandler.class)'/> - - <SpeciesTabUIModel id='model' - initializer='getContextValue(SpeciesTabUIModel.class)'/> - - <SwingValidatorMessageTableModel id='errorTableModel'/> - - <BeanValidator id='validator' bean='model' errorTableModel='errorTableModel' - uiClass='jaxx.runtime.validator.swing.ui.ImageValidationUI'> - <field name='totalWeight' component='totalWeightField'/> - <field name='totalVracWeight' component='totalVracWeightField'/> - <field name='sampleVracWeight' component='sampleVracWeightField'/> - <field name='totalHorsVracWeight' component='totalHorsVracWeightField'/> - </BeanValidator> - - <Table id='form' fill='both' constraints='BorderLayout.NORTH'> - - <!-- Poids total / Poids total vrac --> - <row> - <cell anchor='west'> - <JLabel id='totalWeightLabel'/> - </cell> - <cell weightx='1.0'> - <NumberEditor id='totalWeightField' constructorParams='this'/> - </cell> - <cell anchor='west'> - <JLabel id='totalVracWeightLabel'/> - </cell> - <cell weightx='1.0'> - <NumberEditor id='totalVracWeightField' constructorParams='this'/> - </cell> - </row> - - <!-- Poids échantillonné vrac / Poids total hors vrac --> - <row> - <cell> - <JLabel id='sampleVracWeightLabel'/> - </cell> - <cell> - <NumberEditor id='sampleVracWeightField' constructorParams='this'/> - </cell> - <cell> - <JLabel id='totalHorsVracWeightLabel'/> - </cell> - <cell> - <NumberEditor id='totalHorsVracWeightField' constructorParams='this'/> - </cell> - </row> - </Table> - - <JScrollPane id='tableScrollPane' constraints='BorderLayout.CENTER'> - <JTable id='table'/> - </JScrollPane> - -</JPanel> Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/SpeciesTabUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/SpeciesTabUIHandler.java 2012-12-04 17:59:17 UTC (rev 26) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/SpeciesTabUIHandler.java 2012-12-04 17:59:54 UTC (rev 27) @@ -1,290 +0,0 @@ -package fr.ifremer.tutti.ui.swing.content.catches; - -/* - * #%L - * Tutti :: UI - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 Ifremer - * %% - * 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 3 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, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import fr.ifremer.tutti.persistence.entities.TraitBean; -import fr.ifremer.tutti.persistence.entities.TraitSpeciesCatchBean; -import fr.ifremer.tutti.persistence.entities.VracHorsVracEnum; -import fr.ifremer.tutti.persistence.entities.referential.SexBean; -import fr.ifremer.tutti.persistence.entities.referential.SpeciesBean; -import fr.ifremer.tutti.persistence.entities.referential.WeightCategoryBean; -import fr.ifremer.tutti.service.DecoratorService; -import fr.ifremer.tutti.service.PersistenceService; -import fr.ifremer.tutti.ui.swing.AbstractTuttiUIHandler; -import jaxx.runtime.SwingUtil; -import jaxx.runtime.swing.editor.EnumEditor; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.jdesktop.swingx.autocomplete.ComboBoxCellEditor; - -import javax.swing.JComboBox; -import javax.swing.JTable; -import javax.swing.table.DefaultTableColumnModel; -import javax.swing.table.TableCellEditor; -import javax.swing.table.TableCellRenderer; -import javax.swing.table.TableColumn; -import javax.swing.table.TableColumnModel; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.util.List; - -import static org.nuiton.i18n.I18n._; - -/** - * @author tchemit <chemit@codelutin.com> - * @since 0.1 - */ -public class SpeciesTabUIHandler extends AbstractTuttiUIHandler<SpeciesTabUIModel> { - - /** Logger. */ - private static final Log log = LogFactory.getLog(SpeciesTabUIHandler.class); - - private final SpeciesTabUI ui; - - private final CatchesUI parentUi; - - private final PersistenceService persistenceService; - - public SpeciesTabUIHandler(CatchesUI parentUi, SpeciesTabUI ui) { - super(parentUi.getHandler().getContext()); - this.ui = ui; - this.parentUi = parentUi; - this.persistenceService = context.getService(PersistenceService.class); - } - - @Override - public void beforeInitUI() { - - SpeciesTabUIModel model = new SpeciesTabUIModel(); - ui.setContextValue(model); - - JTable tb = new JTable(); - - TableCellEditor defaultEditor = tb.getDefaultEditor(String.class); - TableCellRenderer defaultRenderer = tb.getDefaultRenderer(Object.class); - - // prepare the table column model - TableColumnModel columnModel = new DefaultTableColumnModel(); - - TableColumn col; - - // Espèce à confirmer - col = new TableColumn(0); - col.setCellEditor(SwingUtil.newBooleanTableCellEditor(defaultRenderer)); - col.setCellRenderer(SwingUtil.newBooleanTableCellRenderer(defaultRenderer)); - col.setHeaderValue(_("tutti.table.species.header.toConfirm")); - col.setIdentifier(SpeciesTableModel.ColumnIdentifier.speciesToConfirm); - columnModel.addColumn(col); - - // species (by code) column - col = new TableColumn(1); - - List<SpeciesBean> allSpecies = persistenceService.getAllSpecies(); - JComboBox speciesEditor = new JComboBox(); - speciesEditor.setRenderer(newListCellRender(SpeciesBean.class, DecoratorService.SPECIES_BY_CODE)); - SwingUtil.fillComboBox(speciesEditor, allSpecies, null); - col.setCellEditor(new ComboBoxCellEditor(speciesEditor)); - col.setCellRenderer(newTableCellRender(SpeciesBean.class, DecoratorService.SPECIES_BY_CODE)); - col.setHeaderValue(_("tutti.table.species.header.speciesByCode")); - col.setIdentifier(SpeciesTableModel.ColumnIdentifier.speciesByCode); - columnModel.addColumn(col); - - // species (by genusCode) column - col = new TableColumn(2); - - JComboBox speciesEditor2 = new JComboBox(); - speciesEditor2.setRenderer(newListCellRender(SpeciesBean.class, DecoratorService.SPECIES_BY_GENUS)); - SwingUtil.fillComboBox(speciesEditor2, allSpecies, null); - col.setCellEditor(new ComboBoxCellEditor(speciesEditor2)); - col.setCellRenderer(newTableCellRender(SpeciesBean.class, DecoratorService.SPECIES_BY_GENUS)); - col.setHeaderValue(_("tutti.table.species.header.speciesByGenusCode")); - col.setIdentifier(SpeciesTableModel.ColumnIdentifier.speciesByGenusCode); - columnModel.addColumn(col); - - // Vrac / Hors vrac - col = new TableColumn(3); - - EnumEditor<VracHorsVracEnum> vracEditor = EnumEditor.newEditor(VracHorsVracEnum.values()); - - col.setCellEditor(new ComboBoxCellEditor(vracEditor)); -// col.setCellRenderer(SwingUtil.newEnumTableCellRenderer(defaultRenderer, VracHorsVracEnum.class)); - col.setCellRenderer(defaultRenderer); - col.setHeaderValue(_("tutti.table.species.header.vracHorsVrac")); -// col.setHeaderRenderer(SwingUtil.newStringTableCellRenderer(dRender,50, true)); - col.setIdentifier(SpeciesTableModel.ColumnIdentifier.vracHorsVrac); - columnModel.addColumn(col); - - // Catégorie de poids - col = new TableColumn(4); - - JComboBox weightCategoryCombo = new JComboBox(); - weightCategoryCombo.setRenderer(newListCellRender(WeightCategoryBean.class, DecoratorService.BY_NAME)); - SwingUtil.fillComboBox(weightCategoryCombo, persistenceService.getAllWeightCategories(), null); - col.setCellEditor(new ComboBoxCellEditor(weightCategoryCombo)); - col.setCellRenderer(newTableCellRender(WeightCategoryBean.class, DecoratorService.BY_NAME)); - col.setHeaderValue(_("tutti.table.species.header.weightCategory")); -// col.setHeaderRenderer(SwingUtil.newStringTableCellRenderer(dRender,50, true)); - col.setIdentifier(SpeciesTableModel.ColumnIdentifier.weightCategory); - columnModel.addColumn(col); - - // Sex - col = new TableColumn(5); - - JComboBox sexCombo = new JComboBox(); - sexCombo.setRenderer(newListCellRender(SexBean.class, DecoratorService.BY_NAME)); - SwingUtil.fillComboBox(sexCombo, persistenceService.getAllSex(), null); - col.setCellEditor(new ComboBoxCellEditor(sexCombo)); - col.setCellRenderer(newTableCellRender(SexBean.class, DecoratorService.BY_NAME)); - - col.setHeaderValue(_("tutti.table.species.header.sex")); -// col.setHeaderRenderer(SwingUtil.newStringTableCellRenderer(dRender,50, true)); - col.setIdentifier(SpeciesTableModel.ColumnIdentifier.sex); - columnModel.addColumn(col); - - // Maturity - col = new TableColumn(6); - col.setCellEditor(defaultEditor); - col.setCellRenderer(defaultRenderer); - col.setHeaderValue(_("tutti.table.species.header.maturity")); -// col.setHeaderRenderer(SwingUtil.newStringTableCellRenderer(dRender,50, true)); - col.setIdentifier(SpeciesTableModel.ColumnIdentifier.maturity); - columnModel.addColumn(col); - - // Age - col = new TableColumn(7); - col.setCellEditor(defaultEditor); - col.setCellRenderer(defaultRenderer); - col.setHeaderValue(_("tutti.table.species.header.age")); -// col.setHeaderRenderer(SwingUtil.newStringTableCellRenderer(dRender,50, true)); - col.setIdentifier(SpeciesTableModel.ColumnIdentifier.age); - columnModel.addColumn(col); - - // Poids observé - col = new TableColumn(8); - col.setCellEditor(defaultEditor); - col.setCellRenderer(defaultRenderer); - col.setHeaderValue(_("tutti.table.species.header.weight")); -// col.setHeaderRenderer(SwingUtil.newStringTableCellRenderer(dRender,50, true)); - col.setIdentifier(SpeciesTableModel.ColumnIdentifier.weight); - columnModel.addColumn(col); - - // Poids calculé - col = new TableColumn(9); - col.setCellEditor(defaultEditor); - col.setCellRenderer(defaultRenderer); - col.setHeaderValue(_("tutti.table.species.header.computedWeight")); -// col.setHeaderRenderer(SwingUtil.newStringTableCellRenderer(dRender,50, true)); - col.setIdentifier(SpeciesTableModel.ColumnIdentifier.computedWeight); - columnModel.addColumn(col); - - // Nombre calculé - col = new TableColumn(10); - col.setCellEditor(defaultEditor); - col.setCellRenderer(defaultRenderer); - col.setHeaderValue(_("tutti.table.species.header.computedNumber")); -// col.setHeaderRenderer(SwingUtil.newStringTableCellRenderer(dRender,50, true)); - col.setIdentifier(SpeciesTableModel.ColumnIdentifier.computedNumber); - columnModel.addColumn(col); - - // Poids d'échantillon - col = new TableColumn(11); - col.setCellEditor(defaultEditor); - col.setCellRenderer(defaultRenderer); - col.setHeaderValue(_("tutti.table.species.header.sampleWeight")); -// col.setHeaderRenderer(SwingUtil.newStringTableCellRenderer(dRender,50, true)); - col.setIdentifier(SpeciesTableModel.ColumnIdentifier.sampleWeight); - columnModel.addColumn(col); - - // Fraction d'élévation - col = new TableColumn(12); - col.setCellEditor(defaultEditor); - col.setCellRenderer(defaultRenderer); - col.setHeaderValue(_("tutti.table.species.header.elevationRate")); -// col.setHeaderRenderer(SwingUtil.newStringTableCellRenderer(dRender,50, true)); - col.setIdentifier(SpeciesTableModel.ColumnIdentifier.elevationRatio); - columnModel.addColumn(col); - - ui.setContextValue(columnModel); - - final SpeciesTableModel tableModel = new SpeciesTableModel(columnModel); - ui.setContextValue(tableModel); - - model.addPropertyChangeListener(SpeciesTabUIModel.PROPERTY_CATCHES, new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - tableModel.setData((List<TraitSpeciesCatchBean>) evt.getNewValue()); - } - }); - } - - @Override - public void afterInitUI() { - SpeciesTabUIModel model = ui.getModel(); - - initUI(ui); - } - - @Override - public void onCloseUI() { - } - - @Override - protected SpeciesTabUIModel getModel() { - return ui.getModel(); - } - - public void selectTrait(TraitBean bean) { - - boolean empty = bean == null; - - SpeciesTabUIModel model = ui.getModel(); - - List<TraitSpeciesCatchBean> catches; - - if (empty) { - catches = null; - bean = new TraitBean(); - } else { - catches = persistenceService.getAllTraitSpeciesCatch(bean.getId()); - } - - model.fromBean(bean); - model.setCatches(catches); - - } - - public void cancel() { - - if (log.isInfoEnabled()) { - log.info("Cancel edition"); - } - } - - public void save() { - if (log.isInfoEnabled()) { - log.info("Will save"); - } - } -} Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/SpeciesTabUIModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/SpeciesTabUIModel.java 2012-12-04 17:59:17 UTC (rev 26) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/SpeciesTabUIModel.java 2012-12-04 17:59:54 UTC (rev 27) @@ -1,123 +0,0 @@ -package fr.ifremer.tutti.ui.swing.content.catches; - -/* - * #%L - * Tutti :: UI - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 Ifremer - * %% - * 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 3 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, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import fr.ifremer.tutti.persistence.entities.TraitBean; -import fr.ifremer.tutti.persistence.entities.TraitSpeciesCatchBean; -import org.jdesktop.beans.AbstractSerializableBean; -import org.nuiton.util.beans.BinderFactory; - -import java.util.List; - -/** - * @author tchemit <chemit@codelutin.com> - * @since 0.1 - */ -public class SpeciesTabUIModel extends AbstractSerializableBean { - - private static final long serialVersionUID = 1L; - - public static final String PROPERTY_TOTAL_WEIGHT = "totalWeight"; - - public static final String PROPERTY_TOTAL_VRAC_WEIGHT = "totalVracWeight"; - - public static final String PROPERTY_SAMPLE_VRAC_WEIGHT = "sampleVracWeight"; - - public static final String PROPERTY_TOTAL_HORS_VRAC_WEIGHT = "totalHorsVracWeight"; - - public static final String PROPERTY_CATCHES = "catches"; - - protected Float totalWeight; - - protected Float totalVracWeight; - - protected Float sampleVracWeight; - - protected Float totalHorsVracWeight; - - protected List<TraitSpeciesCatchBean> catches; - - public Float getTotalWeight() { - return totalWeight; - } - - public void setTotalWeight(Float totalWeight) { - Object oldValue = getTotalWeight(); - this.totalWeight = totalWeight; - firePropertyChange(PROPERTY_TOTAL_WEIGHT, oldValue, totalWeight); - } - - public Float getTotalVracWeight() { - return totalVracWeight; - } - - public void setTotalVracWeight(Float totalVracWeight) { - Object oldValue = getTotalVracWeight(); - this.totalVracWeight = totalVracWeight; - firePropertyChange(PROPERTY_TOTAL_VRAC_WEIGHT, oldValue, totalVracWeight); - } - - public Float getSampleVracWeight() { - return sampleVracWeight; - } - - public void setSampleVracWeight(Float sampleVracWeight) { - Object oldValue = getSampleVracWeight(); - this.sampleVracWeight = sampleVracWeight; - firePropertyChange(PROPERTY_SAMPLE_VRAC_WEIGHT, oldValue, sampleVracWeight); - } - - public Float getTotalHorsVracWeight() { - return totalHorsVracWeight; - } - - public void setTotalHorsVracWeight(Float totalHorsVracWeight) { - Object oldValue = getTotalHorsVracWeight(); - this.totalHorsVracWeight = totalHorsVracWeight; - firePropertyChange(PROPERTY_TOTAL_HORS_VRAC_WEIGHT, oldValue, totalHorsVracWeight); - } - - public List<TraitSpeciesCatchBean> getCatches() { - return catches; - } - - public void setCatches(List<TraitSpeciesCatchBean> catches) { - Object oldValue = getCatches(); - this.catches = catches; - firePropertyChange(PROPERTY_CATCHES, oldValue, catches); - } - - public void fromBean(TraitBean bean) { - BinderFactory.newBinder(TraitBean.class, - SpeciesTabUIModel.class).copy(bean, this); - } - - public TraitBean toBean() { - TraitBean result = new TraitBean(); - BinderFactory.newBinder(SpeciesTabUIModel.class, - TraitBean.class).copy(this, result); - return result; - } -} Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/SpeciesTableModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/SpeciesTableModel.java 2012-12-04 17:59:17 UTC (rev 26) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/SpeciesTableModel.java 2012-12-04 17:59:54 UTC (rev 27) @@ -1,180 +0,0 @@ -package fr.ifremer.tutti.ui.swing.content.catches; - -/* - * #%L - * Tutti :: UI - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 Ifremer - * %% - * 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 3 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, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import com.google.common.collect.Lists; -import fr.ifremer.tutti.persistence.entities.TraitSpeciesCatchBean; -import fr.ifremer.tutti.ui.swing.TuttiUIUtil; -import jaxx.runtime.SwingUtil; - -import javax.swing.table.AbstractTableModel; -import javax.swing.table.TableColumn; -import javax.swing.table.TableColumnModel; -import java.util.List; - -/** - * @author tchemit <chemit@codelutin.com> - * @since 0.1 - */ -public class SpeciesTableModel extends AbstractTableModel { - - public static enum ColumnIdentifier { - speciesToConfirm, - speciesByCode("species"), - speciesByGenusCode("species"), - vracHorsVrac, - weightCategory, - sex, - maturity, - age, - weight, - computedWeight(null), - computedNumber(null), - sampleWeight, - elevationRatio; - - final String propertyName; - - ColumnIdentifier() { - this(""); - } - - ColumnIdentifier(String propertyName) { - this.propertyName = "".equals(propertyName) ? name() : propertyName; - } - - public void setValue(TraitSpeciesCatchBean entry, Object value) { - if (propertyName != null) - TuttiUIUtil.setProperty(entry, propertyName, value); - } - - public Object getValue(TraitSpeciesCatchBean entry) { - Object result = null; - if (propertyName != null) { - result = TuttiUIUtil.getProperty(entry, propertyName); - } - return result; - } - } - - private static final long serialVersionUID = 1L; - - protected List<TraitSpeciesCatchBean> data; - - protected final List<ColumnIdentifier> columnIdentifiers; - - protected final TableColumn[] columns; - - protected final TraitSpeciesCatchBean newRow = new TraitSpeciesCatchBean(); - - public SpeciesTableModel(TableColumnModel columnModel) { - - int nbcols = columnModel.getColumnCount(); - columns = new TableColumn[nbcols]; - columnIdentifiers = Lists.newArrayList(); - for (int i = 0; i < nbcols; i++) { - TableColumn column = columnModel.getColumn(i); - columns[i] = column; - columnIdentifiers.add((ColumnIdentifier) column.getIdentifier()); - } - } - - public void setData(List<TraitSpeciesCatchBean> data) { - if (data == null) { - data = Lists.newArrayList(); - data.add(new TraitSpeciesCatchBean()); - } - this.data = data; - fireTableDataChanged(); - } - - @Override - public int getRowCount() { - return (data == null ? 0 : data.size()) + 1; - } - - @Override - public int getColumnCount() { - return columns.length; - } - - @Override - public Object getValueAt(int rowIndex, int columnIndex) { - TraitSpeciesCatchBean entry = getEntry(rowIndex); - ColumnIdentifier propertyName = getPropertyName(columnIndex); - Object result = propertyName.getValue(entry); - return result; - } - - @Override - public void setValueAt(Object aValue, int rowIndex, int columnIndex) { - TraitSpeciesCatchBean entry = getEntry(rowIndex); - ColumnIdentifier propertyName = getPropertyName(columnIndex); - propertyName.setValue(entry, aValue); - - if (propertyName == ColumnIdentifier.speciesByCode) { - - // update also speciesByGenusCode column - int otherColumnIndex = getColumnIndex(ColumnIdentifier.speciesByGenusCode); - fireTableCellUpdated(rowIndex, otherColumnIndex); - } else if (propertyName == ColumnIdentifier.speciesByGenusCode) { - - // update also speciesByCode column - int otherColumnIndex = getColumnIndex(ColumnIdentifier.speciesByCode); - fireTableCellUpdated(rowIndex, otherColumnIndex); - } - } - - @Override - public boolean isCellEditable(int rowIndex, int columnIndex) { - return true; - } - - protected TraitSpeciesCatchBean getEntry(int rowIndex) { - SwingUtil.ensureRowIndex(this, rowIndex); - TraitSpeciesCatchBean result; - if (data == null || rowIndex >= data.size()) { - result = newRow; - } else { - result = data.get(rowIndex); - } - return result; - } - - protected TableColumn getColumn(int columnIndex) { - SwingUtil.ensureColumnIndex(this, columnIndex); - return columns[columnIndex]; - } - - protected ColumnIdentifier getPropertyName(int columnIndex) { - TableColumn column = getColumn(columnIndex); - return (ColumnIdentifier) column.getIdentifier(); - } - - protected int getColumnIndex(ColumnIdentifier property) { - int result = columnIdentifiers.indexOf(property); - return result; - } -} Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/AbstractSelectTableAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/AbstractSelectTableAction.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/AbstractSelectTableAction.java 2012-12-04 17:59:54 UTC (rev 27) @@ -0,0 +1,99 @@ +package fr.ifremer.tutti.ui.swing.content.catches.species; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 Ifremer + * %% + * 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 3 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, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.swing.AbstractAction; +import javax.swing.JTable; + +/** + * Abstract action to select something in a table. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.2 + */ +public abstract class AbstractSelectTableAction extends AbstractAction { + + private static final long serialVersionUID = 1L; + + /** Logger. */ + private static final Log log = + LogFactory.getLog(AbstractSelectTableAction.class); + + private final JTable table; + + private final SpeciesTabUIModel model; + + public AbstractSelectTableAction(SpeciesTabUIModel model, + JTable table) { + this.model = model; + this.table = table; + } + + protected void doSelectCell(int rowIndex, int columnIndex) { + + if (log.isDebugEnabled()) { + log.debug("Will select cell at " + + getCellCoordinate(rowIndex, columnIndex)); + } + + table.editCellAt(rowIndex, columnIndex); + table.setColumnSelectionInterval(columnIndex, columnIndex); + table.setRowSelectionInterval(rowIndex, rowIndex); + } + + + protected int getSelectedRow() { + int result = table.getSelectedRow(); + return result; + } + + protected int getSelectedColumn() { + int result = table.getSelectedColumn(); + return result; + } + + protected int getRowCount() { + return table.getRowCount(); + } + + protected int getColumnCount() { + return table.getColumnCount(); + } + + protected boolean isCellEditable(int rowIndex, int columnIndex) { + return table.isCellEditable(rowIndex, columnIndex); + } + + protected String getCellCoordinate(int rowIndex, int columnIndex) { + return " [" + rowIndex + ", " + columnIndex + "]"; + } + + protected SpeciesTabUIModel getModel() { + return model; + } +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/AbstractSelectTableAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/CatchTreeModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/CatchTreeModel.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/CatchTreeModel.java 2012-12-04 17:59:54 UTC (rev 27) @@ -0,0 +1,104 @@ +package fr.ifremer.tutti.ui.swing.content.catches.species; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 Ifremer + * %% + * 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 3 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, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import com.google.common.collect.Lists; +import fr.ifremer.tutti.persistence.entities.TraitSpeciesCatchBean; +import fr.ifremer.tutti.ui.swing.TuttiUIUtil; + +import java.io.Serializable; +import java.util.List; + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 0.2 + */ +public class CatchTreeModel implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * Root node (with no sampling on it. + * + * @since 0.2 + */ + protected final CatchTreeNode root; + + /** + * Property which are used to sub sampling. + * + * @since 0.2 + */ + protected final String[] samplingOrder; + + /** + * Samplings view as a linear list (to display in the table). + * + * @since 0.2 + */ + protected final List<CatchTreeNode> lines; + + public CatchTreeModel(String... samplingOrder) { + this.samplingOrder = samplingOrder; + root = new CatchTreeNode(); + lines = Lists.newArrayList(); + } + + public CatchTreeNode getNode(int rowIndex) { + return lines.get(rowIndex); + } + + public int getSize() { + return lines.size(); + } + + public void populate(List<TraitSpeciesCatchBean> data) { + + // clear tree representation + root.removeAllChildren(); + + // clear linear representation + lines.clear(); + } + + public Object[] getSamplingKey(TraitSpeciesCatchBean bean) { + List<Object> result = Lists.newArrayList(); + for (String s : samplingOrder) { + Object property = TuttiUIUtil.getProperty(bean, s); + if (property == null) { + // stop findind sample key + break; + } + result.add(property); + } + return result.toArray(); + } + + public String[] getSamplingDefinition(TraitSpeciesCatchBean bean) { + return null; + } +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/CatchTreeModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/CatchTreeNode.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/CatchTreeNode.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/CatchTreeNode.java 2012-12-04 17:59:54 UTC (rev 27) @@ -0,0 +1,152 @@ +package fr.ifremer.tutti.ui.swing.content.catches.species; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 Ifremer + * %% + * 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 3 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, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ifremer.tutti.persistence.entities.TraitSpeciesCatchBean; + +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.TreeNode; +import java.io.Serializable; + +/** + * Defines a node of a species catches. + * <p/> + * UserObject is the {@link TraitSpeciesCatchBean}. It can be null on two cases: + * <ul> + * <li>On root node</li> + * <li>For node on a path of sampling but with no filled data </li> + * </ul> + * + * @author tchemit <chemit@codelutin.com> + * @since 0.2 + */ +public class CatchTreeNode extends DefaultMutableTreeNode { + + private static final long serialVersionUID = 1L; + + /** + * Property name defining the sampling. + * <p/> + * <strong>Note:</strong> can be null (only for root node). + * + * @since 0.2 + */ + protected final String samplingPropertyKey; + + /** + * Property value defining the sampling. + * <p/> + * <strong>Note:</strong> can be null (only for root node). + * + * @since 0.2 + */ + protected final Serializable samplingPropertyValue; + + public CatchTreeNode() { + this(null, null, null); + } + + public CatchTreeNode(TraitSpeciesCatchBean userObject, + String samplingPropertyKey, + Serializable samplingPropertyValue) { + this.samplingPropertyKey = samplingPropertyKey; + this.samplingPropertyValue = samplingPropertyValue; + setUserObject(userObject); + } + + public String getSamplingPropertyKey() { + return samplingPropertyKey; + } + + public Serializable getSamplingPropertyValue() { + return samplingPropertyValue; + } + + @Override + public TraitSpeciesCatchBean getUserObject() { + return (TraitSpeciesCatchBean) super.getUserObject(); + } + + @Override + public CatchTreeNode getParent() { + return (CatchTreeNode) super.getParent(); + } + + @Override + public CatchTreeNode getRoot() { + return (CatchTreeNode) super.getRoot(); + } + + @Override + public CatchTreeNode getFirstChild() { + return (CatchTreeNode) super.getFirstChild(); + } + + @Override + public CatchTreeNode getLastChild() { + return (CatchTreeNode) super.getLastChild(); + } + + @Override + public CatchTreeNode getChildAfter(TreeNode aChild) { + return (CatchTreeNode) super.getChildAfter(aChild); + } + + @Override + public CatchTreeNode getChildBefore(TreeNode aChild) { + return (CatchTreeNode) super.getChildBefore(aChild); + } + + @Override + public CatchTreeNode getNextSibling() { + return (CatchTreeNode) super.getNextSibling(); + } + + @Override + public CatchTreeNode getPreviousSibling() { + return (CatchTreeNode) super.getPreviousSibling(); + } + + @Override + public CatchTreeNode getFirstLeaf() { + return (CatchTreeNode) super.getFirstLeaf(); + } + + @Override + public CatchTreeNode getLastLeaf() { + return (CatchTreeNode) super.getLastLeaf(); + } + + @Override + public CatchTreeNode getNextLeaf() { + return (CatchTreeNode) super.getNextLeaf(); + } + + @Override + public CatchTreeNode getPreviousLeaf() { + return (CatchTreeNode) super.getPreviousLeaf(); + } + +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/CatchTreeNode.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/MoveToNextEditableCellAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/MoveToNextEditableCellAction.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/MoveToNextEditableCellAction.java 2012-12-04 17:59:54 UTC (rev 27) @@ -0,0 +1,98 @@ +package fr.ifremer.tutti.ui.swing.content.catches.species; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 Ifremer + * %% + * 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 3 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, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.swing.JTable; +import java.awt.event.ActionEvent; + +/** + * Action to select next editable cell in a table. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.2 + */ +public class MoveToNextEditableCellAction extends AbstractSelectTableAction { + + private static final long serialVersionUID = 1L; + + /** Logger. */ + private static final Log log = + LogFactory.getLog(MoveToNextEditableCellAction.class); + + public MoveToNextEditableCellAction(SpeciesTabUIModel model, + JTable table) { + super(model, table); + } + + @Override + public void actionPerformed(ActionEvent e) { + + int currentRow = getSelectedRow(); + int currentColumn = getSelectedColumn(); + + if (log.isDebugEnabled()) { + log.debug("Move to previous editable cell " + + getCellCoordinate(currentRow, currentColumn)); + } + + int columnCount = getColumnCount(); + + int rowCount = getRowCount(); + + while (currentRow <= rowCount || currentColumn <= columnCount) { + + // go to next cell + currentColumn++; + + // select next cell + if (currentColumn >= columnCount) { + + // no more cell, so will move to next editable column on next row + currentColumn = 0; + currentRow++; + + if (currentRow == rowCount) { + // create a new row in model + getModel().addNewCatch(); + } + } + + if (isCellEditable(currentRow, currentColumn)) { + + doSelectCell(currentRow, currentColumn); + + break; + } else { + if (log.isDebugEnabled()) { + log.debug("Cell not editable at " + + getCellCoordinate(currentRow, currentColumn)); + } + } + } + } +} \ No newline at end of file Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/MoveToNextEditableCellAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/MoveToNextEditableRowAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/MoveToNextEditableRowAction.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/MoveToNextEditableRowAction.java 2012-12-04 17:59:54 UTC (rev 27) @@ -0,0 +1,82 @@ +package fr.ifremer.tutti.ui.swing.content.catches.species; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 Ifremer + * %% + * 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 3 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, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.swing.JTable; +import java.awt.event.ActionEvent; + +/** + * Action to select next editable row in a table. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.2 + */ +public class MoveToNextEditableRowAction extends AbstractSelectTableAction { + + private static final long serialVersionUID = 1L; + + /** Logger. */ + private static final Log log = + LogFactory.getLog(MoveToNextEditableRowAction.class); + + public MoveToNextEditableRowAction(SpeciesTabUIModel model, + JTable table) { + super(model, table); + } + + @Override + public void actionPerformed(ActionEvent e) { + int currentRow = getSelectedRow(); + int currentColumn = getSelectedColumn(); + + if (isCellEditable(currentRow, currentColumn)) { + if (log.isDebugEnabled()) { + log.debug("Move to next row editable cell " + + getCellCoordinate(currentRow, currentColumn)); + } + currentRow++; + + if (currentRow >= getRowCount()) { + if (log.isDebugEnabled()) { + log.debug("No next row"); + } + + // create a new row in model + getModel().addNewCatch(); + } + + doSelectCell(currentRow, currentColumn); + + } else { + if (log.isDebugEnabled()) { + log.debug("Cell not editable at " + + getCellCoordinate(currentRow, currentColumn)); + } + } + } +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/MoveToNextEditableRowAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/MoveToPreviousEditableCellAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/MoveToPreviousEditableCellAction.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/MoveToPreviousEditableCellAction.java 2012-12-04 17:59:54 UTC (rev 27) @@ -0,0 +1,87 @@ +package fr.ifremer.tutti.ui.swing.content.catches.species; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 Ifremer + * %% + * 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 3 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, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.swing.JTable; +import java.awt.event.ActionEvent; + +/** + * Action to select previous editable cell in a table. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.2 + */ +public class MoveToPreviousEditableCellAction extends AbstractSelectTableAction { + + private static final long serialVersionUID = 1L; + + /** Logger. */ + private static final Log log = + LogFactory.getLog(MoveToPreviousEditableCellAction.class); + + public MoveToPreviousEditableCellAction(SpeciesTabUIModel model, + JTable table) { + super(model,table); + } + + @Override + public void actionPerformed(ActionEvent e) { + int currentRow = getSelectedRow(); + int currentColumn = getSelectedColumn(); + + if (log.isDebugEnabled()) { + log.debug("Move to previous editable cell, " + + getCellCoordinate(currentRow, currentColumn)); + } + + int columnCount = getColumnCount(); + + while (currentRow > 0 || currentColumn > 0) { + + // go to next cell + currentColumn--; + + // select next cell + if (currentColumn < 0) { + + currentColumn = columnCount - 1; + currentRow--; + } + + if (isCellEditable(currentRow, currentColumn)) { + doSelectCell(currentRow, currentColumn); + break; + } else { + if (log.isDebugEnabled()) { + log.debug("Cell not editable at " + + getCellCoordinate(currentRow, currentColumn)); + } + } + } + } +} \ No newline at end of file Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/MoveToPreviousEditableCellAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/MoveToPreviousEditableRowAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/MoveToPreviousEditableRowAction.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/MoveToPreviousEditableRowAction.java 2012-12-04 17:59:54 UTC (rev 27) @@ -0,0 +1,79 @@ +package fr.ifremer.tutti.ui.swing.content.catches.species; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 Ifremer + * %% + * 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 3 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, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.swing.JTable; +import java.awt.event.ActionEvent; + +/** + * Action to select previous editable row in a table. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.2 + */ +public class MoveToPreviousEditableRowAction extends AbstractSelectTableAction { + + private static final long serialVersionUID = 1L; + + /** Logger. */ + private static final Log log = + LogFactory.getLog(MoveToPreviousEditableRowAction.class); + + public MoveToPreviousEditableRowAction(SpeciesTabUIModel model, + JTable table) { + super(model,table); + } + + @Override + public void actionPerformed(ActionEvent e) { + + int currentRow = getSelectedRow(); + int currentColumn = getSelectedColumn(); + + if (isCellEditable(currentRow, currentColumn)) { + if (log.isDebugEnabled()) { + log.debug("Move to previous row editable cell " + + getCellCoordinate(currentRow, currentColumn)); + } + currentRow--; + + if (currentRow < 0) { + if (log.isDebugEnabled()) { + log.debug("No previous row"); + } + } else { + doSelectCell(currentRow, currentColumn); + } + } else { + if (log.isDebugEnabled()) { + log.debug("Cell not editable at " + + getCellCoordinate(currentRow, currentColumn)); + } + } + } +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/MoveToPreviousEditableRowAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesCatchEntryModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesCatchEntryModel.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesCatchEntryModel.java 2012-12-04 17:59:54 UTC (rev 27) @@ -0,0 +1,281 @@ +package fr.ifremer.tutti.ui.swing.content.catches.species; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 Ifremer + * %% + * 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 3 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, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ifremer.tutti.persistence.entities.TraitBean; +import fr.ifremer.tutti.persistence.entities.TraitSpeciesCatchBean; +import fr.ifremer.tutti.persistence.entities.VracHorsVracEnum; +import fr.ifremer.tutti.persistence.entities.referential.SexBean; +import fr.ifremer.tutti.persistence.entities.referential.SpeciesBean; +import fr.ifremer.tutti.persistence.entities.referential.WeightCategoryBean; +import fr.ifremer.tutti.ui.swing.AbstractTuttiBeanUIModel; +import org.nuiton.util.beans.BinderFactory; + +/** + * represents a row in the table + * + * @author tchemit <chemit@codelutin.com> + * @since 0.2 + */ +public class SpeciesCatchEntryModel extends AbstractTuttiBeanUIModel { + + private static final long serialVersionUID = 1L; + + public static final String PROPERTY_SPECIES = "species"; + + public static final String PROPERTY_SPECIES_TO_CONFIRM = "speciesToConfirm"; + + public static final String PROPERTY_VRAC_HORS_VRAC = "vracHorsVrac"; + + public static final String PROPERTY_WEIGHT_CATEGORY = "weightCategory"; + + public static final String PROPERTY_SEX = "sex"; + + public static final String PROPERTY_MATURITY = "maturity"; + + public static final String PROPERTY_AGE = "age"; + + public static final String PROPERTY_WEIGHT = "weight"; + + public static final String PROPERTY_SAMPLE_WEIGHT = "sampleWeight"; + + public static final String PROPERTY_ELEVATION_RATIO = "elevationRatio"; + + public static final String PROPERTY_COMMENT = "comment"; + + /** + * When catch was observed. + * + * @since 0.2 + */ + protected TraitBean trait; + + /** + * Species observed. + * + * @since 0.2 + */ + protected SpeciesBean species; + + /** + * Is the species need to be confirmed?. + * + * @since 0.2 + */ + protected boolean speciesToConfirm; + + /** + * Is catch is vrac or horsVrac?. + * + * @since 0.2 + */ + protected VracHorsVracEnum vracHorsVrac; + + /** + * Weight category (can be null). + * + * @since 0.2 + */ + protected WeightCategoryBean weightCategory; + + /** + * Sex (can be null). + * + * @since 0.2 + */ + protected SexBean sex; + + /** + * Maturity (can be null). + * + * @since 0.2 + */ + protected Float maturity; + + /** + * Age (can be null). + * + * @since 0.2 + */ + protected Float age; + + /** + * Observed weight. + * + * @since 0.2 + */ + protected Float weight; + + /** + * Sample weight. + * + * @since 0.2 + */ + protected Float sampleWeight; + + /** + * Elevation ratio. + * + * @since 0.2 + */ + protected Float elevationRatio; + + /** + * Comment on this catches. + * + * @since 0.2 + */ + protected String comment; + + public TraitBean getTrait() { + return trait; + } + + public void setTrait(TraitBean trait) { + this.trait = trait; + } + + public SpeciesBean getSpecies() { + return species; + } + + public void setSpecies(SpeciesBean species) { + Object oldValue = getSpecies(); + this.species = species; + firePropertyChange(PROPERTY_SPECIES, oldValue, species); + } + + public Boolean getSpeciesToConfirm() { + return speciesToConfirm; + } + + public void setSpeciesToConfirm(Boolean speciesToConfirm) { + Object oldValue = getSpeciesToConfirm(); + this.speciesToConfirm = speciesToConfirm; + firePropertyChange(PROPERTY_SPECIES_TO_CONFIRM, oldValue, speciesToConfirm); + } + + public VracHorsVracEnum getVracHorsVrac() { + return vracHorsVrac; + } + + public void setVracHorsVrac(VracHorsVracEnum vracHorsVrac) { + Object oldValue = getVracHorsVrac(); + this.vracHorsVrac = vracHorsVrac; + firePropertyChange(PROPERTY_VRAC_HORS_VRAC, oldValue, vracHorsVrac); + } + + public WeightCategoryBean getWeightCategory() { + return weightCategory; + } + + public void setWeightCategory(WeightCategoryBean weightCategory) { + Object oldValue = getWeightCategory(); + this.weightCategory = weightCategory; + firePropertyChange(PROPERTY_WEIGHT_CATEGORY, oldValue, weightCategory); + } + + public SexBean getSex() { + return sex; + } + + public void setSex(SexBean sex) { + Object oldValue = getSex(); + this.sex = sex; + firePropertyChange(PROPERTY_SEX, oldValue, sex); + } + + public Float getMaturity() { + return maturity; + } + + public void setMaturity(Float maturity) { + Object oldValue = getMaturity(); + this.maturity = maturity; + firePropertyChange(PROPERTY_MATURITY, oldValue, maturity); + } + + public Float getAge() { + return age; + } + + public void setAge(Float age) { + Object oldValue = getAge(); + this.age = age; + firePropertyChange(PROPERTY_AGE, oldValue, age); + } + + public Float getWeight() { + return weight; + } + + public void setWeight(Float weight) { + Object oldValue = getWeight(); + this.weight = weight; + firePropertyChange(PROPERTY_WEIGHT, oldValue, weight); + } + + public Float getSampleWeight() { + return sampleWeight; + } + + public void setSampleWeight(Float sampleWeight) { + Object oldValue = getSampleWeight(); + this.sampleWeight = sampleWeight; + firePropertyChange(PROPERTY_SAMPLE_WEIGHT, oldValue, sampleWeight); + } + + public Float getElevationRatio() { + return elevationRatio; + } + + public void setElevationRatio(Float elevationRatio) { + Object oldValue = getElevationRatio(); + this.elevationRatio = elevationRatio; + firePropertyChange(PROPERTY_ELEVATION_RATIO, oldValue, elevationRatio); + } + + public String getComment() { + return comment; + } + + public void setComment(String comment) { + Object oldValue = getComment(); + this.comment = comment; + firePropertyChange(PROPERTY_COMMENT, oldValue, comment); + } + + public void fromBean(TraitSpeciesCatchBean bean) { + BinderFactory.newBinder(TraitSpeciesCatchBean.class, + SpeciesCatchEntryModel.class).copy(bean, this); + } + + public TraitSpeciesCatchBean toBean() { + TraitSpeciesCatchBean result = new TraitSpeciesCatchBean(); + BinderFactory.newBinder(SpeciesCatchEntryModel.class, + TraitSpeciesCatchBean.class).copy(this, result); + return result; + } +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesCatchEntryModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesTabUI.css (from rev 25, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/SpeciesTabUI.css) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesTabUI.css (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesTabUI.css 2012-12-04 17:59:54 UTC (rev 27) @@ -0,0 +1,84 @@ +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 Ifremer + * %% + * 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 3 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, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +NumberEditor { + autoPopup:{handler.getConfig().isAutoPopupNumberEditor()}; + showPopupButton:{handler.getConfig().isShowNumberEditorButton()}; + bean:{model}; + showReset:true; +} + +#totalWeightLabel { + text:"tutti.label.fishes.totalWeight"; + labelFor:{totalWeightField}; +} + +#totalWeightField { + property:"totalWeight"; + model:{model.getTotalWeight()}; + useFloat:false; + numberPattern:{INT_6_DIGITS_PATTERN}; +} + +#totalVracWeightLabel { + text:"tutti.label.fishes.totalVracWeight"; + labelFor:{totalVracWeightField}; +} + +#totalVracWeightField { + property:"totalVracWeight"; + model:{model.getTotalVracWeight()}; + useFloat:false; + numberPattern:{INT_6_DIGITS_PATTERN}; +} + +#sampleVracWeightLabel { + text:"tutti.label.fishes.sampleVracWeight"; + labelFor:{sampleVracWeightField}; +} + +#sampleVracWeightField { + property:"sampleVracWeight"; + model:{model.getSampleVracWeight()}; + useFloat:false; + numberPattern:{INT_6_DIGITS_PATTERN}; +} + +#totalHorsVracWeightLabel { + text:"tutti.label.fishes.totalHorsVracWeight"; + labelFor:{totalHorsVracWeightField}; +} + +#totalHorsVracWeightField { + property:"totalHorsVracWeight"; + model:{model.getTotalHorsVracWeight()}; + useFloat:false; + numberPattern:{INT_6_DIGITS_PATTERN}; +} + +#table { + selectionMode:{ListSelectionModel.SINGLE_SELECTION}; + selectionBackground:{null}; + selectionForeground:{Color.BLACK}; +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesTabUI.css ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesTabUI.jaxx (from rev 25, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/SpeciesTabUI.jaxx) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesTabUI.jaxx (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesTabUI.jaxx 2012-12-04 17:59:54 UTC (rev 27) @@ -0,0 +1,120 @@ +<!-- + #%L + Tutti :: UI + $Id$ + $HeadURL$ + %% + Copyright (C) 2012 Ifremer + %% + 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 3 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, see + <http://www.gnu.org/licenses/gpl-3.0.html>. + #L% + --> +<JPanel id='homePanel' layout='{new BorderLayout()}' + implements='fr.ifremer.tutti.ui.swing.TuttiUI<SpeciesTabUIModel, SpeciesTabUIHandler>'> + + <import> + fr.ifremer.tutti.persistence.entities.referential.BeaufortScaleBean + fr.ifremer.tutti.persistence.entities.referential.SeaStateBean + fr.ifremer.tutti.persistence.entities.StrataBean + fr.ifremer.tutti.persistence.entities.TraitBean + fr.ifremer.tutti.persistence.entities.referential.UserBean + fr.ifremer.tutti.ui.swing.TuttiUIContext + fr.ifremer.tutti.ui.swing.content.catches.CatchesUI + + org.jdesktop.swingx.JXTable + + jaxx.runtime.swing.editor.NumberEditor + + jaxx.runtime.validator.swing.SwingValidatorUtil + jaxx.runtime.validator.swing.SwingValidatorMessageTableModel + + javax.swing.ListSelectionModel + javax.swing.table.TableModel + javax.swing.table.TableColumnModel + + java.awt.Color + + static org.nuiton.i18n.I18n._ + </import> + + <script><![CDATA[ + +public SpeciesTabUI(CatchesUI parentUI) { + SpeciesTabUIHandler handler = new SpeciesTabUIHandler(parentUI, this); + setContextValue(handler); + handler.beforeInitUI(); +} + +public void selectTrait(TraitBean trait) { handler.selectTrait(trait); } + +protected void $afterCompleteSetup() { handler.afterInitUI(); } + ]]></script> + + <SpeciesTabUIHandler id='handler' + initializer='getContextValue(SpeciesTabUIHandler.class)'/> + + <SpeciesTabUIModel id='model' + initializer='getContextValue(SpeciesTabUIModel.class)'/> + + <SwingValidatorMessageTableModel id='errorTableModel'/> + + <BeanValidator id='validator' bean='model' errorTableModel='errorTableModel' + uiClass='jaxx.runtime.validator.swing.ui.ImageValidationUI'> + <field name='totalWeight' component='totalWeightField'/> + <field name='totalVracWeight' component='totalVracWeightField'/> + <field name='sampleVracWeight' component='sampleVracWeightField'/> + <field name='totalHorsVracWeight' component='totalHorsVracWeightField'/> + </BeanValidator> + + <Table id='form' fill='both' constraints='BorderLayout.NORTH'> + + <!-- Poids total / Poids total vrac --> + <row> + <cell anchor='west'> + <JLabel id='totalWeightLabel'/> + </cell> + <cell weightx='1.0'> + <NumberEditor id='totalWeightField' constructorParams='this'/> + </cell> + <cell anchor='west'> + <JLabel id='totalVracWeightLabel'/> + </cell> + <cell weightx='1.0'> + <NumberEditor id='totalVracWeightField' constructorParams='this'/> + </cell> + </row> + + <!-- Poids échantillonné vrac / Poids total hors vrac --> + <row> + <cell> + <JLabel id='sampleVracWeightLabel'/> + </cell> + <cell> + <NumberEditor id='sampleVracWeightField' constructorParams='this'/> + </cell> + <cell> + <JLabel id='totalHorsVracWeightLabel'/> + </cell> + <cell> + <NumberEditor id='totalHorsVracWeightField' constructorParams='this'/> + </cell> + </row> + </Table> + + <JScrollPane id='tableScrollPane' constraints='BorderLayout.CENTER'> + <JXTable id='table' onFocusLost='handler.saveSelectedRowIfRequired(event);'/> + </JScrollPane> + +</JPanel> Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesTabUI.jaxx ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesTabUIHandler.java (from rev 25, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/SpeciesTabUIHandler.java) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesTabUIHandler.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesTabUIHandler.java 2012-12-04 17:59:54 UTC (rev 27) @@ -0,0 +1,568 @@ +package fr.ifremer.tutti.ui.swing.content.catches.species; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 Ifremer + * %% + * 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 3 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, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import com.google.common.collect.Lists; +import fr.ifremer.tutti.persistence.entities.TraitBean; +import fr.ifremer.tutti.persistence.entities.TraitSpeciesCatchBean; +import fr.ifremer.tutti.persistence.entities.TuttiBeans; +import fr.ifremer.tutti.persistence.entities.VracHorsVracEnum; +import fr.ifremer.tutti.persistence.entities.referential.SexBean; +import fr.ifremer.tutti.persistence.entities.referential.SpeciesBean; +import fr.ifremer.tutti.persistence.entities.referential.WeightCategoryBean; +import fr.ifremer.tutti.service.DecoratorService; +import fr.ifremer.tutti.service.PersistenceService; +import fr.ifremer.tutti.ui.swing.AbstractTuttiUIHandler; +import fr.ifremer.tutti.ui.swing.TuttiUIUtil; +import fr.ifremer.tutti.ui.swing.content.catches.CatchesUI; +import jaxx.runtime.SwingUtil; +import jaxx.runtime.swing.JAXXWidgetUtil; +import jaxx.runtime.swing.editor.EnumEditor; +import jaxx.runtime.swing.editor.bean.BeanUIUtil; +import jaxx.runtime.swing.editor.cell.NumberCellEditor; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.jdesktop.swingx.JXTable; +import org.jdesktop.swingx.autocomplete.ComboBoxCellEditor; +import org.jdesktop.swingx.autocomplete.ObjectToStringConverter; +import org.jdesktop.swingx.decorator.HighlightPredicate; +import org.jdesktop.swingx.table.DefaultTableColumnModelExt; +import org.jdesktop.swingx.table.TableColumnExt; +import org.nuiton.util.beans.BeanMonitor; +import org.nuiton.util.decorator.Decorator; + +import javax.swing.JComboBox; +import javax.swing.ListSelectionModel; +import javax.swing.border.LineBorder; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import javax.swing.table.TableCellEditor; +import javax.swing.table.TableCellRenderer; +import javax.swing.table.TableColumn; +import javax.swing.table.TableColumnModel; +import java.awt.Color; +import java.awt.Component; +import java.awt.event.FocusEvent; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.List; + +import static fr.ifremer.tutti.ui.swing.content.catches.species.SpeciesTableModel.ColumnIdentifier; +import static org.nuiton.i18n.I18n._; + +/** + * @author tchemit <chemit@codelutin.com> + * @since 0.1 + */ +public class SpeciesTabUIHandler extends AbstractTuttiUIHandler<SpeciesTabUIModel> { + + /** Logger. */ + private static final Log log = LogFactory.getLog(SpeciesTabUIHandler.class); + + private final SpeciesTabUI ui; + + private final CatchesUI parentUi; + + private final PersistenceService persistenceService; + + private final BeanMonitor monitor; + + public SpeciesTabUIHandler(CatchesUI parentUi, SpeciesTabUI ui) { + super(parentUi.getHandler().getContext()); + this.ui = ui; + this.parentUi = parentUi; + this.persistenceService = context.getService(PersistenceService.class); + monitor = new BeanMonitor( + SpeciesCatchEntryModel.PROPERTY_SPECIES, + SpeciesCatchEntryModel.PROPERTY_SPECIES_TO_CONFIRM, + SpeciesCatchEntryModel.PROPERTY_VRAC_HORS_VRAC, + SpeciesCatchEntryModel.PROPERTY_WEIGHT_CATEGORY, + SpeciesCatchEntryModel.PROPERTY_SEX, + SpeciesCatchEntryModel.PROPERTY_MATURITY, + SpeciesCatchEntryModel.PROPERTY_AGE, + SpeciesCatchEntryModel.PROPERTY_WEIGHT, + SpeciesCatchEntryModel.PROPERTY_SAMPLE_WEIGHT, + SpeciesCatchEntryModel.PROPERTY_ELEVATION_RATIO, + SpeciesCatchEntryModel.PROPERTY_COMMENT); + } + + @Override + public void beforeInitUI() { + + SpeciesTabUIModel model = new SpeciesTabUIModel(); + ui.setContextValue(model); + } + + @Override + public void afterInitUI() { + + initUI(ui); + + JXTable table = ui.getTable(); + + // create table column model + TableColumnModel columnModel = createTableColumnModel(table); + + SpeciesTabUIModel model = ui.getModel(); + + // create table model + final SpeciesTableModel tableModel = new SpeciesTableModel(columnModel, model); + + // when model datas change let's propagate it + + model.addPropertyChangeListener(SpeciesTabUIModel.PROPERTY_ROWS, new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + tableModel.refreshData((List<SpeciesCatchEntryModel>) evt.getNewValue()); + } + }); + model.addPropertyChangeListener(SpeciesTabUIModel.PROPERTY_NEW_ROW, new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + tableModel.addNewRow((SpeciesCatchEntryModel) evt.getNewValue()); + } + }); + + + table.setModel(tableModel); + table.setColumnModel(columnModel); + table.getTableHeader().setReorderingAllowed(false); + + table.addHighlighter(TuttiUIUtil.newBackgroundColorHighlighter(HighlightPredicate.READ_ONLY, Color.LIGHT_GRAY)); + + table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { + + @Override + public void valueChanged(ListSelectionEvent e) { + if (!e.getValueIsAdjusting()) { + ListSelectionModel source = (ListSelectionModel) e.getSource(); + int selectedRow = source.getLeadSelectionIndex(); + + // save selected entry if required + saveSelectedRowIfRequired(); + + if (log.isInfoEnabled()) { + log.info("New selected row: " + selectedRow); + } + + SpeciesCatchEntryModel entry = + tableModel.getEntry(selectedRow); + + if (log.isInfoEnabled()) { + log.info("Will monitor entry: " + entry); + } + monitor.setBean(entry); + } + } + }); + } + + public void saveSelectedRowIfRequired(FocusEvent event) { + Component oppositeComponent = event.getOppositeComponent(); + + JXTable parentContainer = SwingUtil.getParentContainer( + oppositeComponent, JXTable.class); + + if (parentContainer == null) { + + // out of the table can save + saveSelectedRowIfRequired(); + } + } + + public void saveSelectedRowIfRequired() { + + SpeciesCatchEntryModel bean = (SpeciesCatchEntryModel) monitor.getBean(); + if (bean != null) { + + // there is a bean attached to the monitor + + if (monitor.wasModified()) { + + // monitored bean was modified, save it + if (log.isInfoEnabled()) { + log.info("Row " + bean + " was modified, will save it"); + } + + TraitSpeciesCatchBean catchBean = bean.toBean(); + + TraitBean trait = parentUi.getModel().getSelectedTrait(); + catchBean.setTrait(trait); + + if (TuttiBeans.isNew(catchBean)) { + + catchBean = persistenceService.createTraitSpeciesCatch(catchBean); + bean.setId(catchBean.getId()); + } else { + persistenceService.saveTraitSpeciesCatch(catchBean); + } + + // clear modified flag on the monitor + monitor.clearModified(); + } + } + } + + @Override + public void onCloseUI() { + } + + public void selectTrait(TraitBean bean) { + + // make sure selection is empty (will remove bean from monitor) + ui.getTable().clearSelection(); + + boolean empty = bean == null; + + SpeciesTabUIModel model = ui.getModel(); + + List<SpeciesCatchEntryModel> rows; + + if (empty) { + rows = null; + bean = new TraitBean(); + } else { + List<TraitSpeciesCatchBean> catches = + persistenceService.getAllTraitSpeciesCatch(bean.getId()); + rows = Lists.newArrayList(); + for (TraitSpeciesCatchBean aCatch : catches) { + SpeciesCatchEntryModel entry = new SpeciesCatchEntryModel(); + entry.setTrait(bean); + entry.fromBean(aCatch); + rows.add(entry); + } + } + + model.fromBean(bean); + model.setCatches(rows); + + //monitor.setBean(null); + + rows = model.getRows(); + monitor.setBean(rows.get(0)); + + } + + public void cancel() { + + if (log.isInfoEnabled()) { + log.info("Cancel edition"); + } + } + + @Override + protected SpeciesTabUIModel getModel() { + return ui.getModel(); + } + + public void save() { + if (log.isInfoEnabled()) { + log.info("Will save"); + } + } + + protected TableColumnModel createTableColumnModel(JXTable table) { + + KeyListener keyAdapter = createTableKeyListener(getModel(), table); + + { + NumberCellEditor<Float> editor = + JAXXWidgetUtil.newNumberTableCellEditor(Float.class, false); + editor.getNumberEditor().setSelectAllTextOnError(true); + editor.getNumberEditor().getTextField().addKeyListener(keyAdapter); + editor.getNumberEditor().getTextField().setBorder(new LineBorder(Color.GRAY, 2)); + table.setDefaultEditor(float.class, editor); + table.setDefaultEditor(Float.class, editor); + } + + // Boolean + { + TableCellRenderer renderer = table.getDefaultRenderer(Boolean.class); + table.setDefaultRenderer(boolean.class, renderer); + + TableCellEditor editor = table.getDefaultEditor(Boolean.class); + table.setDefaultEditor(boolean.class, editor); + } + + table.addKeyListener(keyAdapter); + + // prepare the table column model + DefaultTableColumnModelExt columnModel = new DefaultTableColumnModelExt(); + + { // Species to confirm + + addColumnToModel(columnModel, + table.getDefaultEditor(Boolean.class), + table.getDefaultRenderer(Boolean.class), + _("tutti.table.species.header.toConfirm"), + ColumnIdentifier.speciesToConfirm); + + } + + List<SpeciesBean> allSpecies = persistenceService.getAllSpecies(); + + { // Species (by code) + + Decorator<SpeciesBean> decorator = getDecorator(SpeciesBean.class, DecoratorService.SPECIES_BY_CODE); + + JComboBox comboBox = new JComboBox(); + comboBox.setRenderer(newListCellRender(decorator)); + SwingUtil.fillComboBox(comboBox, allSpecies, null); + + ObjectToStringConverter converter = BeanUIUtil.newDecoratedObjectToStringConverter(decorator); + BeanUIUtil.decorate(comboBox, converter); + TableCellEditor editor = new ComboBoxCellEditor(comboBox); + TableCellRenderer renderer = + newTableCellRender(SpeciesBean.class, DecoratorService.SPECIES_BY_CODE); + + addColumnToModel(columnModel, + editor, + renderer, + _("tutti.table.species.header.speciesByCode"), + ColumnIdentifier.speciesByCode); + } + + { // Species (by genusCode) + + Decorator<SpeciesBean> decorator = + getDecorator(SpeciesBean.class, DecoratorService.SPECIES_BY_CODE); + + JComboBox comboBox = new JComboBox(); + + comboBox.setRenderer(newListCellRender(decorator)); + SwingUtil.fillComboBox(comboBox, allSpecies, null); + + ObjectToStringConverter converter = BeanUIUtil.newDecoratedObjectToStringConverter(decorator); + BeanUIUtil.decorate(comboBox, converter); + + TableCellEditor editor = new ComboBoxCellEditor(comboBox); + TableCellRenderer renderer = newTableCellRender(SpeciesBean.class, DecoratorService.SPECIES_BY_GENUS); + + addColumnToModel(columnModel, + editor, + renderer, + _("tutti.table.species.header.speciesByGenusCode"), + ColumnIdentifier.speciesByGenusCode); + + } + + { // Vrac / Hors vrac + + EnumEditor<VracHorsVracEnum> comboBox = + EnumEditor.newEditor(VracHorsVracEnum.values()); + BeanUIUtil.decorate(comboBox, ObjectToStringConverter.DEFAULT_IMPLEMENTATION); + TableCellEditor editor = new ComboBoxCellEditor(comboBox); + + addColumnToModel(columnModel, + editor, + table.getDefaultRenderer(Object.class), + _("tutti.table.species.header.vracHorsVrac"), + ColumnIdentifier.vracHorsVrac); + } + + { // Catégorie de poids + + Decorator<WeightCategoryBean> decorator = + getDecorator(WeightCategoryBean.class, DecoratorService.BY_NAME); + + JComboBox comboBox = new JComboBox(); + + comboBox.setRenderer(newListCellRender(decorator)); + SwingUtil.fillComboBox(comboBox, persistenceService.getAllWeightCategories(), null); + + ObjectToStringConverter converter = BeanUIUtil.newDecoratedObjectToStringConverter(decorator); + BeanUIUtil.decorate(comboBox, converter); + + TableCellEditor editor = new ComboBoxCellEditor(comboBox); + TableCellRenderer renderer = + newTableCellRender(WeightCategoryBean.class, DecoratorService.BY_NAME); + + addColumnToModel(columnModel, + editor, + renderer, + _("tutti.table.species.header.weightCategory"), + ColumnIdentifier.weightCategory); + } + + { // Sex + + Decorator<SexBean> decorator = + getDecorator(SexBean.class, DecoratorService.BY_NAME); + + JComboBox comboBox = new JComboBox(); + comboBox.setRenderer(newListCellRender(decorator)); + SwingUtil.fillComboBox(comboBox, persistenceService.getAllSex(), null); + + ObjectToStringConverter converter = + BeanUIUtil.newDecoratedObjectToStringConverter(decorator); + BeanUIUtil.decorate(comboBox, converter); + + TableCellEditor editor = new ComboBoxCellEditor(comboBox); + TableCellRenderer renderer = + newTableCellRender(SexBean.class, DecoratorService.BY_NAME); + + addColumnToModel(columnModel, + editor, + renderer, + _("tutti.table.species.header.sex"), + ColumnIdentifier.sex); + } + + { // Maturity + + addColumnToModel(columnModel, + table.getDefaultEditor(Float.class), + table.getDefaultRenderer(Object.class), + _("tutti.table.species.header.maturity"), + ColumnIdentifier.maturity); + } + + { // Age + + addColumnToModel(columnModel, + table.getDefaultEditor(Float.class), + table.getDefaultRenderer(Object.class), + _("tutti.table.species.header.age"), + ColumnIdentifier.age); + } + + { // Poids observé + + addColumnToModel(columnModel, + table.getDefaultEditor(Float.class), + table.getDefaultRenderer(Object.class), + _("tutti.table.species.header.weight"), + ColumnIdentifier.weight); + } + + { // Poids calculé + + addColumnToModel(columnModel, + null, + table.getDefaultRenderer(Object.class), + _("tutti.table.species.header.computedWeight"), + ColumnIdentifier.computedWeight); + } + + { // Nombre calculé + + addColumnToModel(columnModel, + null, + table.getDefaultRenderer(Object.class), + _("tutti.table.species.header.computedNumber"), + ColumnIdentifier.computedNumber); + } + + { // Poids d'échantillon + + addColumnToModel(columnModel, + null, + table.getDefaultRenderer(Object.class), + _("tutti.table.species.header.sampleWeight"), + ColumnIdentifier.sampleWeight); + } + + { // Fraction d'élévation + + addColumnToModel(columnModel, + null, + table.getDefaultRenderer(Object.class), + _("tutti.table.species.header.elevationRate"), + ColumnIdentifier.elevationRatio); + } + + { // Commentaire + + addColumnToModel(columnModel, + null, + table.getDefaultRenderer(Object.class), + _("tutti.table.species.header.comment"), + ColumnIdentifier.comment); + } + + { // Pièces-jointes + + addColumnToModel(columnModel, + null, + table.getDefaultRenderer(Object.class), + _("tutti.table.species.header.file"), + ColumnIdentifier.file); + } + return columnModel; + } + + private KeyListener createTableKeyListener(SpeciesTabUIModel model, JXTable table) { + final MoveToNextEditableCellAction nextCellAction = new MoveToNextEditableCellAction(model, table); + final MoveToPreviousEditableCellAction previousCellAction = new MoveToPreviousEditableCellAction(model, table); + + final MoveToNextEditableRowAction nextRowAction = new MoveToNextEditableRowAction(model, table); + final MoveToPreviousEditableRowAction previousRowAction = new MoveToPreviousEditableRowAction(model, table); + + // Key adapter à ajouter sur les éditeurs où l'on souhaite gérer les + // touches "entrer", "gauche", "doite" de facon personnalisée. + return new KeyAdapter() { + + @Override + public void keyPressed(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_ENTER || + e.getKeyCode() == KeyEvent.VK_RIGHT || + e.getKeyCode() == KeyEvent.VK_TAB) { + e.consume(); + nextCellAction.actionPerformed(null); + } else if (e.getKeyCode() == KeyEvent.VK_LEFT) { + e.consume(); + previousCellAction.actionPerformed(null); + } else if (e.getKeyCode() == KeyEvent.VK_UP) { + e.consume(); + previousRowAction.actionPerformed(null); + } else if (e.getKeyCode() == KeyEvent.VK_DOWN) { + e.consume(); + nextRowAction.actionPerformed(null); + } else if (e.getKeyCode() == KeyEvent.VK_DOWN && e.isControlDown()) { + e.consume(); + + // create a new line with same sample + } + } + }; + } + + protected void addColumnToModel(TableColumnModel model, + TableCellEditor editor, + TableCellRenderer renderer, + String header, + Object identifier) { + + TableColumn col = new TableColumnExt(model.getColumnCount()); + col.setCellEditor(editor); + col.setCellRenderer(renderer); + col.setHeaderValue(header); + col.setIdentifier(identifier); + model.addColumn(col); + } +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesTabUIHandler.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesTabUIModel.java (from rev 25, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/SpeciesTabUIModel.java) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesTabUIModel.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesTabUIModel.java 2012-12-04 17:59:54 UTC (rev 27) @@ -0,0 +1,156 @@ +package fr.ifremer.tutti.ui.swing.content.catches.species; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 Ifremer + * %% + * 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 3 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, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import com.google.common.base.Preconditions; +import com.google.common.collect.Lists; +import fr.ifremer.tutti.persistence.entities.TraitBean; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.jdesktop.beans.AbstractSerializableBean; +import org.nuiton.util.beans.BinderFactory; + +import java.util.List; + +/** + * @author tchemit <chemit@codelutin.com> + * @since 0.1 + */ +public class SpeciesTabUIModel extends AbstractSerializableBean { + + private static final long serialVersionUID = 1L; + + /** Logger. */ + private static final Log log = LogFactory.getLog(SpeciesTabUIModel.class); + + public static final String PROPERTY_TOTAL_WEIGHT = "totalWeight"; + + public static final String PROPERTY_TOTAL_VRAC_WEIGHT = "totalVracWeight"; + + public static final String PROPERTY_SAMPLE_VRAC_WEIGHT = "sampleVracWeight"; + + public static final String PROPERTY_TOTAL_HORS_VRAC_WEIGHT = "totalHorsVracWeight"; + + public static final String PROPERTY_ROWS = "rows"; + + public static final String PROPERTY_NEW_ROW = "newRow"; + + protected Float totalWeight; + + protected Float totalVracWeight; + + protected Float sampleVracWeight; + + protected Float totalHorsVracWeight; + + /** + * List of catches (linear representation). + * + * @since 0.2 + */ + protected List<SpeciesCatchEntryModel> rows; + + public Float getTotalWeight() { + return totalWeight; + } + + public int getRowCount() { + return rows == null ? 0 : rows.size(); + } + + public void setTotalWeight(Float totalWeight) { + Object oldValue = getTotalWeight(); + this.totalWeight = totalWeight; + firePropertyChange(PROPERTY_TOTAL_WEIGHT, oldValue, totalWeight); + } + + public Float getTotalVracWeight() { + return totalVracWeight; + } + + public void setTotalVracWeight(Float totalVracWeight) { + Object oldValue = getTotalVracWeight(); + this.totalVracWeight = totalVracWeight; + firePropertyChange(PROPERTY_TOTAL_VRAC_WEIGHT, oldValue, totalVracWeight); + } + + public Float getSampleVracWeight() { + return sampleVracWeight; + } + + public void setSampleVracWeight(Float sampleVracWeight) { + Object oldValue = getSampleVracWeight(); + this.sampleVracWeight = sampleVracWeight; + firePropertyChange(PROPERTY_SAMPLE_VRAC_WEIGHT, oldValue, sampleVracWeight); + } + + public Float getTotalHorsVracWeight() { + return totalHorsVracWeight; + } + + public void setTotalHorsVracWeight(Float totalHorsVracWeight) { + Object oldValue = getTotalHorsVracWeight(); + this.totalHorsVracWeight = totalHorsVracWeight; + firePropertyChange(PROPERTY_TOTAL_HORS_VRAC_WEIGHT, oldValue, totalHorsVracWeight); + } + + public List<SpeciesCatchEntryModel> getRows() { + return rows; + } + + public void setCatches(List<SpeciesCatchEntryModel> rows) { + Object oldValue = getRowCount(); + if (rows == null) { + rows = Lists.newArrayList(); + } + this.rows = rows; + firePropertyChange(PROPERTY_ROWS, oldValue, rows); + } + + public void addNewCatch() { + Preconditions.checkState( + rows != null, + "Cant add a row, rows list is null"); + SpeciesCatchEntryModel newRow = new SpeciesCatchEntryModel(); + if (log.isInfoEnabled()) { + log.info("Add a new catch "); + } + rows.add(newRow); + firePropertyChange(PROPERTY_NEW_ROW, null, newRow); + } + + public void fromBean(TraitBean bean) { + BinderFactory.newBinder(TraitBean.class, + SpeciesTabUIModel.class).copy(bean, this); + } + + public TraitBean toBean() { + TraitBean result = new TraitBean(); + BinderFactory.newBinder(SpeciesTabUIModel.class, + TraitBean.class).copy(this, result); + return result; + } + +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesTabUIModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesTableModel.java (from rev 25, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/SpeciesTableModel.java) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesTableModel.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesTableModel.java 2012-12-04 17:59:54 UTC (rev 27) @@ -0,0 +1,209 @@ +package fr.ifremer.tutti.ui.swing.content.catches.species; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 Ifremer + * %% + * 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 3 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, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import com.google.common.base.Preconditions; +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; +import fr.ifremer.tutti.ui.swing.TuttiUIUtil; +import jaxx.runtime.SwingUtil; + +import javax.swing.table.AbstractTableModel; +import javax.swing.table.TableColumn; +import javax.swing.table.TableColumnModel; +import java.util.List; +import java.util.Set; + +/** + * @author tchemit <chemit@codelutin.com> + * @since 0.1 + */ +public class SpeciesTableModel extends AbstractTableModel { + + public static enum ColumnIdentifier { + speciesToConfirm, + speciesByCode("species"), + speciesByGenusCode("species"), + vracHorsVrac, + weightCategory, + sex, + maturity, + age, + weight, + computedWeight(null), + computedNumber(null), + sampleWeight, + elevationRatio, + comment, + file(null); + + final String propertyName; + + ColumnIdentifier() { + this(""); + } + + ColumnIdentifier(String propertyName) { + this.propertyName = "".equals(propertyName) ? name() : propertyName; + } + + public void setValue(SpeciesCatchEntryModel entry, Object value) { + if (propertyName != null) + TuttiUIUtil.setProperty(entry, propertyName, value); + } + + public Object getValue(SpeciesCatchEntryModel entry) { + Object result = null; + if (propertyName != null && entry != null) { + result = TuttiUIUtil.getProperty(entry, propertyName); + } + return result; + } + } + + private static final long serialVersionUID = 1L; + + // TODO This will be dynamic by the protocol... + final Set<ColumnIdentifier> noneEditableCols = Sets.newHashSet( + ColumnIdentifier.age, + ColumnIdentifier.maturity, + ColumnIdentifier.computedWeight, + ColumnIdentifier.computedNumber, + ColumnIdentifier.sampleWeight, + ColumnIdentifier.elevationRatio, + ColumnIdentifier.file + ); + + protected final List<ColumnIdentifier> columnIdentifiers; + + protected final TableColumn[] columns; + + protected final SpeciesTabUIModel model; + + public SpeciesTableModel(TableColumnModel columnModel, + SpeciesTabUIModel model) { + this.model = model; + int nbcols = columnModel.getColumnCount(); + columns = new TableColumn[nbcols]; + columnIdentifiers = Lists.newArrayList(); + for (int i = 0; i < nbcols; i++) { + TableColumn column = columnModel.getColumn(i); + columns[i] = column; + columnIdentifiers.add((ColumnIdentifier) column.getIdentifier()); + } + } + + public void refreshData(List<SpeciesCatchEntryModel> data) { + + // can't accept a empty data list + Preconditions.checkNotNull(data, "Data list can not be null."); + + if (data.isEmpty()) { + + // add a first edit line + data.add(new SpeciesCatchEntryModel()); + } + fireTableDataChanged(); + } + + public void addNewRow(SpeciesCatchEntryModel newValue) { + + List<SpeciesCatchEntryModel> data = getData(); + Preconditions.checkNotNull(data, "Data list can not be null."); + + int rowIndex = data.indexOf(newValue); + fireTableRowsInserted(rowIndex, rowIndex); + } + + @Override + public int getRowCount() { + return model.getRowCount(); + } + + @Override + public int getColumnCount() { + return columns.length; + } + + @Override + public Object getValueAt(int rowIndex, int columnIndex) { + SpeciesCatchEntryModel entry = getEntry(rowIndex); + ColumnIdentifier propertyName = getPropertyName(columnIndex); + Object result = propertyName.getValue(entry); + return result; + } + + @Override + public void setValueAt(Object aValue, int rowIndex, int columnIndex) { + SpeciesCatchEntryModel entry = getEntry(rowIndex); + ColumnIdentifier propertyName = getPropertyName(columnIndex); + propertyName.setValue(entry, aValue); + + if (propertyName == ColumnIdentifier.speciesByCode) { + + // update also speciesByGenusCode column + int otherColumnIndex = getColumnIndex(ColumnIdentifier.speciesByGenusCode); + fireTableCellUpdated(rowIndex, otherColumnIndex); + } else if (propertyName == ColumnIdentifier.speciesByGenusCode) { + + // update also speciesByCode column + int otherColumnIndex = getColumnIndex(ColumnIdentifier.speciesByCode); + fireTableCellUpdated(rowIndex, otherColumnIndex); + } + } + + @Override + public boolean isCellEditable(int rowIndex, int columnIndex) { + ColumnIdentifier identifier = getPropertyName(columnIndex); + boolean result = !noneEditableCols.contains(identifier); + return result; + } + + public SpeciesCatchEntryModel getEntry(int rowIndex) { + SwingUtil.ensureRowIndex(this, rowIndex); + List<SpeciesCatchEntryModel> data = getData(); + SpeciesCatchEntryModel result = data == null ? null : data.get(rowIndex); + return result; + } + + protected TableColumn getColumn(int columnIndex) { + SwingUtil.ensureColumnIndex(this, columnIndex); + return columns[columnIndex]; + } + + protected ColumnIdentifier getPropertyName(int columnIndex) { + TableColumn column = getColumn(columnIndex); + return (ColumnIdentifier) column.getIdentifier(); + } + + protected int getColumnIndex(ColumnIdentifier property) { + int result = columnIdentifiers.indexOf(property); + return result; + } + + protected List<SpeciesCatchEntryModel> getData() { + return model.getRows(); + } +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/catches/species/SpeciesTableModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiColorHighlighter.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiColorHighlighter.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiColorHighlighter.java 2012-12-04 17:59:54 UTC (rev 27) @@ -0,0 +1,70 @@ +package fr.ifremer.tutti.ui.swing.util; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 Ifremer + * %% + * 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 3 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, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import org.jdesktop.swingx.decorator.AbstractHighlighter; +import org.jdesktop.swingx.decorator.ComponentAdapter; +import org.jdesktop.swingx.decorator.HighlightPredicate; +import org.jdesktop.swingx.util.PaintUtils; + +import javax.swing.JButton; +import java.awt.Color; +import java.awt.Component; + +/** + * @author tchemit <chemit@codelutin.com> + * @since 0.2 + */ +public class TuttiColorHighlighter extends AbstractHighlighter { + + protected Color color; + + protected boolean foreground; + + public TuttiColorHighlighter(HighlightPredicate predicate, Color color, boolean foreground) { + super(predicate); + this.color = color; + this.foreground = foreground; + } + + @Override + protected Component doHighlight(Component component, ComponentAdapter adapter) { + if (component instanceof JButton) { + // do nothing + + } else { + if (foreground) { + component.setForeground(color); + + } else { + component.setBackground(color); + if (adapter.isSelected()) { + component.setForeground(PaintUtils.computeForeground(color)); + } + } + } + return component; + } +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiColorHighlighter.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties =================================================================== --- trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties 2012-12-04 17:59:17 UTC (rev 26) +++ trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties 2012-12-04 17:59:54 UTC (rev 27) @@ -133,9 +133,11 @@ tutti.table.plancton.header.speciesByCode=Espèce tutti.table.plancton.header.weight=Poids observé tutti.table.species.header.age=Age +tutti.table.species.header.comment=Commentaire tutti.table.species.header.computedNumber=Nombre calculé tutti.table.species.header.computedWeight=Poids calculé tutti.table.species.header.elevationRate=Fraction d'él +tutti.table.species.header.file=Pièces jointes tutti.table.species.header.maturity=Maturité tutti.table.species.header.sampleWeight=Poids échan tutti.table.species.header.sex=Sexe