r2726 - in isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input: . population
Author: chatellier Date: 2009-11-02 15:57:12 +0000 (Mon, 02 Nov 2009) New Revision: 2726 Added: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/population/ZoneListModel.java Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/PopulationZonesEditorUI.jaxx Log: Utilisation des list model pour les zones Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/PopulationZonesEditorUI.jaxx =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/PopulationZonesEditorUI.jaxx 2009-11-02 15:51:03 UTC (rev 2725) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/PopulationZonesEditorUI.jaxx 2009-11-02 15:57:12 UTC (rev 2726) @@ -23,14 +23,8 @@ <fr.ifremer.isisfish.entities.PopulationImpl id='bean' javaBean='null'/> <script><![CDATA[ - -import jaxx.runtime.swing.JAXXList; import fr.ifremer.isisfish.entities.Zone; -import fr.ifremer.isisfish.ui.widget.editor.GenericCell; -import fr.ifremer.isisfish.entities.Population; -import fr.ifremer.isisfish.entities.PopulationImpl; -import org.nuiton.topia.persistence.TopiaEntity; -import fr.ifremer.isisfish.ui.WelcomePanelUI; +import fr.ifremer.isisfish.ui.input.population.ZoneListModel; import org.nuiton.math.matrix.gui.MatrixPanelEvent; import org.nuiton.math.matrix.gui.MatrixPanelListener; @@ -44,8 +38,8 @@ @Override public void refresh(){ setPopulationZonesPresenceModel(); - setFieldPopulationZonesReproductionModel(getSelectedValue(populationZonesPresence)); - setFieldPopulationZonesRecruitmentModel(getSelectedValue(populationZonesPresence)); + setFieldPopulationZonesReproductionModel(getSelectedValues(populationZonesPresence)); + setFieldPopulationZonesRecruitmentModel(getSelectedValues(populationZonesPresence)); fieldPopulationMappingZoneReproZoneRecru.removeMatrixPanelListener(listener); setFieldPopulationMappingZoneReproZoneRecru(); fieldPopulationMappingZoneReproZoneRecru.addMatrixListener(listener); @@ -82,59 +76,42 @@ setModel(zones, getBean().getRecruitmentZone(), fieldPopulationZonesRecruitment); } } -protected void setModel(java.util.List<Zone> zones, java.util.List<Zone> selected, JAXXList componant){ - DefaultListModel model = new DefaultListModel(); - java.util.List<GenericCell> selectedZones = new ArrayList<GenericCell>(); - if (zones != null){ - for (Zone z : zones){ - GenericCell cell = new GenericCell(z.getName(), z, Zone.class); - model.addElement(cell); - if (selected != null){ - if (selected.contains(z)){ - selectedZones.add(cell); - } - } - } + +/** + * Change model of {@code associatedList} with all available zones, but keep + * selection with {@code selectedZones}. + */ +protected void setModel(java.util.List<Zone> availableZones, java.util.List<Zone> selectedZones, JList associatedList){ + ZoneListModel zoneModel = new ZoneListModel(availableZones); + associatedList.setModel(zoneModel); + for (Zone selectedZone : selectedZones) { + int index = availableZones.indexOf(selectedZone); + associatedList.addSelectionInterval(index, index); } - componant.setModel(model); - if (selectedZones.size() > 0){ - java.util.List <Integer> indicesList = new ArrayList<Integer>(); - for (GenericCell c : selectedZones){ - indicesList.add(model.indexOf(c)); - } - int[] indices = new int[indicesList.size()]; - int cnt = 0; - for (Integer i : indicesList){ - indices[cnt]=i; - cnt ++; - } - componant.setSelectedIndices(indices); - } } protected void presenceChanged(){ - getBean().setPopulationZone(getSelectedValue(populationZonesPresence)); - setFieldPopulationZonesReproductionModel(getSelectedValue(populationZonesPresence)); - setFieldPopulationZonesRecruitmentModel(getSelectedValue(populationZonesPresence)); + getBean().setPopulationZone(getSelectedValues(populationZonesPresence)); + setFieldPopulationZonesReproductionModel(getSelectedValues(populationZonesPresence)); + setFieldPopulationZonesRecruitmentModel(getSelectedValues(populationZonesPresence)); setFieldPopulationMappingZoneReproZoneRecru(); } protected void reproductionChanged(){ - getBean().setReproductionZone(getSelectedValue(fieldPopulationZonesReproduction)); + getBean().setReproductionZone(getSelectedValues(fieldPopulationZonesReproduction)); setFieldPopulationMappingZoneReproZoneRecru(); } protected void recruitementChanged(){ - getBean().setRecruitmentZone(getSelectedValue(fieldPopulationZonesRecruitment)); + getBean().setRecruitmentZone(getSelectedValues(fieldPopulationZonesRecruitment)); setFieldPopulationMappingZoneReproZoneRecru(); } -protected java.util.List<Zone> getSelectedValue(JAXXList componant){ - Object[] selected = componant.getSelectedValues(); + +/** + * Get selected values for components as list. + */ +protected java.util.List<Zone> getSelectedValues(JList component){ + Object[] selectedValues = component.getSelectedValues(); java.util.List<Zone> selectedZone = new ArrayList<Zone>(); - if (selected != null){ - for (Object i : selected){ - GenericCell cell = (GenericCell)i; - if (cell.getValue() != null){ - selectedZone.add((Zone)cell.getValue()); - } - } + for (Object value : selectedValues) { + selectedZone.add((Zone)value); } return selectedZone; } Added: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/population/ZoneListModel.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/population/ZoneListModel.java (rev 0) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/population/ZoneListModel.java 2009-11-02 15:57:12 UTC (rev 2726) @@ -0,0 +1,77 @@ +/* *##% + * Copyright (C) 2009 Code Lutin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *##%*/ + +package fr.ifremer.isisfish.ui.input.population; + +import java.util.List; + +import javax.swing.DefaultListModel; + +import fr.ifremer.isisfish.entities.MetierSeasonInfo; +import fr.ifremer.isisfish.entities.Zone; + +/** + * Model pour la liste des {@link MetierSeasonInfo}. + * + * Pas de selection par defaut. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author: chatellier $ + */ +public class ZoneListModel extends DefaultListModel { + + /** serialVersionUID. */ + private static final long serialVersionUID = 6171850179969290032L; + + /** Zones list */ + protected List<Zone> zones; + + /** + * Constructor with species list. + * + * @param zones zones list + */ + public ZoneListModel(List<Zone> zones) { + super(); + this.zones = zones; + } + + /* + * @see javax.swing.ListModel#getElementAt(int) + */ + @Override + public Object getElementAt(int index) { + return zones.get(index); + } + + /* + * @see javax.swing.ListModel#getSize() + */ + @Override + public int getSize() { + int size = 0; + + if (zones != null) { + size = zones.size(); + } + return size; + } +} Property changes on: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/population/ZoneListModel.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL"
participants (1)
-
chatellierï¼ users.labs.libre-entreprise.org