Author: chatellier Date: 2010-11-23 11:19:55 +0000 (Tue, 23 Nov 2010) New Revision: 252 Log: Add maturity species filter for L4 Added: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/model/MaturitySpecyListModel.java Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/services/ProjectService.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionHandler.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionListsView.jaxx trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/model/SizeAllYearSpecyListModel.java Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/services/ProjectService.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/services/ProjectService.java 2010-11-23 11:19:18 UTC (rev 251) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/services/ProjectService.java 2010-11-23 11:19:55 UTC (rev 252) @@ -1402,7 +1402,34 @@ return completeSpecies; } + + /** + * Recherche les especes qui ont au moins une maturité sur l'ensemble des + * données. + * + * @param selection selection to search into + * @return year list + */ + public Collection<String> getSpeciesWithMaturity(Selection selection) { + Set<String> speciesWithMaturity = new HashSet<String>(); + + // get all species with years + Iterator<String[]> itLength = selection.getLength().iterator(); + itLength.next(); // skip header + while (itLength.hasNext()) { + String[] tupleLength = itLength.next(); + String species = tupleLength[Length.INDEX_SPECIES]; + String maturity = tupleLength[Length.INDEX_MATURITY]; + + if ("m".equalsIgnoreCase(maturity)) { + speciesWithMaturity.add(species); + } + } + + return speciesWithMaturity; + } + /** * Get species name in project. * Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionHandler.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionHandler.java 2010-11-23 11:19:18 UTC (rev 251) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionHandler.java 2010-11-23 11:19:55 UTC (rev 252) @@ -112,6 +112,7 @@ MatrixND occurrence = projectService.getOccurrence(project, selection); MatrixND density = projectService.getDensity(project, selection); Collection<String> speciesAllYear = projectService.getSpeciesWithSizeAllYears(selection); + Collection<String> speciesWithMaturity = projectService.getSpeciesWithMaturity(selection); //MatrixND samplingEffort = projectService.getSamplingEffort(project, selection); // set matrix on list model @@ -120,11 +121,12 @@ // fill all specy data (at final) selectionListsView.getSelectionAllSpeciesListModel().setSpecies(selectionSpecyList); - + // select all list (not to do for reload) // init allSize and maturity before (select all with updateOccurrenceDensityFilter) ((CoserListSelectionModel)selectionListsView.getSelectionAllSpeciesList().getSelectionModel()).fillSelection(); selectionListsView.getSelectionSizeAllYearListModel().setSizeAllYearSpecies(speciesAllYear); + selectionListsView.getSelectionMaturityListModel().setMaturitySpecies(speciesWithMaturity); updateOccurrenceDensityFilter(selectionListsView); } } @@ -432,7 +434,7 @@ List<String> filteredSpecies = new ArrayList<String>(); for (int speciesIndex = 0 ; speciesIndex < speciesCount ; speciesIndex++) { String specy = (String)model.getElementAt(speciesIndex); - if (model.getDensity(specy) > density && model.getOccurrence(specy) > occurrence) { + if (model.getDensity(specy) >= density && model.getOccurrence(specy) >= occurrence) { filteredSpecies.add(specy); } } Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionListsView.jaxx =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionListsView.jaxx 2010-11-23 11:19:18 UTC (rev 251) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionListsView.jaxx 2010-11-23 11:19:55 UTC (rev 252) @@ -115,7 +115,7 @@ </cell> <cell weightx="1" fill="both" columns="2"> <JScrollPane> - <SpecyListModel id="selectionMaturityListModel" /> + <MaturitySpecyListModel id="selectionMaturityListModel" /> <JList id="selectionMaturityList" model="{selectionMaturityListModel}" selectionModel="{new CoserListSelectionModel(selectionMaturityList.getSelectionModel(), selectionMaturityListModel)}"/> </JScrollPane> Added: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/model/MaturitySpecyListModel.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/model/MaturitySpecyListModel.java (rev 0) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/model/MaturitySpecyListModel.java 2010-11-23 11:19:55 UTC (rev 252) @@ -0,0 +1,119 @@ +/* + * #%L + * Coser :: UI + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2010 Ifremer, Codelutin, Chatellier Eric + * %% + * 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% + */ + +package fr.ifremer.coser.ui.selection.model; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import javax.swing.AbstractListModel; +import javax.swing.JList; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; + +import fr.ifremer.coser.ui.util.CoserListModel; + +/** + * Specy list model with size all year. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class MaturitySpecyListModel extends AbstractListModel implements ListSelectionListener, CoserListModel { + + /** serialVersionUID. */ + private static final long serialVersionUID = -4769109927915812519L; + + protected List<String> species = new ArrayList<String>(); + + protected Collection<String> maturitySpecies; + + public List<String> getSpecies() { + return species; + } + + public void setSpecies(List<String> species) { + this.species = new ArrayList<String>(species); + this.species.retainAll(maturitySpecies); + fireContentsChanged(this, 0, this.species.size()); + } + + public void setMaturitySpecies(Collection<String> maturitySpecies) { + this.maturitySpecies = maturitySpecies; + } + + /* + * @see javax.swing.ListModel#getSize() + */ + @Override + public int getSize() { + int result = 0; + if (species != null) { + result = species.size(); + } + return result; + } + + /* + * @see javax.swing.ListModel#getElementAt(int) + */ + @Override + public Object getElementAt(int index) { + return species.get(index); + } + + + /* + * @see fr.ifremer.coser.ui.util.CoserListModel#indexOf(java.lang.Object) + */ + @Override + public int indexOf(Object o) { + return species.indexOf(o); + } + + /* + * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent) + */ + @Override + public void valueChanged(ListSelectionEvent event) { + + if (!event.getValueIsAdjusting()) { + JList source = (JList)event.getSource(); + Object[] selectedValues = source.getSelectedValues(); + species.clear(); + for (Object selectedValue : selectedValues) { + String specy = (String)selectedValue; + if (maturitySpecies.contains(specy)) { + species.add(specy); + } + } + fireContentsChanged(this, 0, species.size() - 1); + } + } +} Property changes on: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/model/MaturitySpecyListModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/model/SizeAllYearSpecyListModel.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/model/SizeAllYearSpecyListModel.java 2010-11-23 11:19:18 UTC (rev 251) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/model/SizeAllYearSpecyListModel.java 2010-11-23 11:19:55 UTC (rev 252) @@ -34,8 +34,6 @@ import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; -import org.apache.commons.collections.CollectionUtils; - import fr.ifremer.coser.ui.util.CoserListModel; /**