r198 - in trunk: coser-business/src/main/java/fr/ifremer/coser/bean coser-business/src/main/java/fr/ifremer/coser/services coser-ui/src/main/java/fr/ifremer/coser/ui coser-ui/src/main/java/fr/ifremer/coser/ui/project coser-ui/src/main/java/fr/ifremer/coser/ui/selection coser-ui/src/main/java/fr/ifremer/coser/ui/selection/model coser-ui/src/main/java/fr/ifremer/coser/ui/util
Author: chatellier Date: 2010-11-10 12:58:40 +0000 (Wed, 10 Nov 2010) New Revision: 198 Log: Rechargement complet des selections, refactoring Added: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SpecyTypesListModel.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/ZoneListModel.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/ZoneListRenderer.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/model/ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/model/SpecyListTestModel.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/util/CoserListModel.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/util/CoserListSelectionModel.java Removed: trunk/coser-business/src/main/java/fr/ifremer/coser/bean/Specy.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionZoneListModel.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionZoneListRenderer.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SpecyListSelectionModel.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SpecyListTestModel.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/TypeSpecyListModel.java Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/services/ProjectService.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/CoserFrameHandler.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/project/ProjectOpenView.jaxx trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionDetailsView.jaxx 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/SelectionView.jaxx Deleted: trunk/coser-business/src/main/java/fr/ifremer/coser/bean/Specy.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/bean/Specy.java 2010-11-10 12:36:59 UTC (rev 197) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/bean/Specy.java 2010-11-10 12:58:40 UTC (rev 198) @@ -1,93 +0,0 @@ -/* - * #%L - * Coser :: Business - * - * $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 Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -package fr.ifremer.coser.bean; - -/** - * Specy. - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -public class Specy extends AbstractEntity { - - /** serialVersionUID. */ - private static final long serialVersionUID = -9161753536468850648L; - - protected String name; - - protected int x; - - protected double y; - - public Specy() { - super(); - } - - /** - * @param name - * @param x - * @param y - */ - public Specy(String name, int x, int y) { - this(); - this.name = name; - this.x = x; - this.y = y; - } - - public String getName() { - return name; - } - - public void setName(String name) { - String old = this.name; - this.name = name; - getPropertyChangeSupport().firePropertyChange("name", old, this.name); - } - - public int getX() { - return x; - } - - public void setX(int x) { - int old = this.x; - this.x = x; - getPropertyChangeSupport().firePropertyChange("x", old, this.name); - } - - public double getY() { - return y; - } - - public void setY(double y) { - double old = this.y; - this.y = y; - getPropertyChangeSupport().firePropertyChange("y", old, this.name); - } -} 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-10 12:36:59 UTC (rev 197) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/services/ProjectService.java 2010-11-10 12:58:40 UTC (rev 198) @@ -1234,11 +1234,12 @@ * @param project project * @param selection selection * @param newSpecyName new specy name (after merge) + * @param comment comment * @param speciesNames species name to merge * @return project * @throws CoserBusinessException */ - public Project mergeSpecies(Project project, Selection selection, String newSpecyName, String... speciesNames) throws CoserBusinessException { + public Project mergeSpecies(Project project, Selection selection, String newSpecyName, String comment, String... speciesNames) throws CoserBusinessException { if (!isSpecyNameExist(project, newSpecyName)) { throw new CoserBusinessException(_("Specy %s doesn't exist in referential", newSpecyName)); @@ -1247,6 +1248,7 @@ MergeSpeciesCommand command = new MergeSpeciesCommand(); command.setNewSpecyName(newSpecyName); command.setSpeciesNames(speciesNames); + command.setComment(comment); commandService.doAction(command, project, selection); return project; Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/CoserFrameHandler.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/CoserFrameHandler.java 2010-11-10 12:36:59 UTC (rev 197) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/CoserFrameHandler.java 2010-11-10 12:58:40 UTC (rev 198) @@ -128,7 +128,10 @@ */ protected void setMainComponent(Component component) { view.getMainViewContent().removeAll(); - view.getMainViewContent().add(component, BorderLayout.CENTER); + if (component != null) { + view.getMainViewContent().add(component, BorderLayout.CENTER); + } + view.getMainViewContent().repaint(); view.getMainViewContent().validate(); } @@ -302,49 +305,21 @@ * @param projectView view */ public void loadProject(final ProjectOpenView projectView) { - - final String projectName = (String)projectView.getProjectsComboBox().getSelectedItem(); - SwingWorker<Project, Void> task = new SwingWorker<Project, Void>() { - long before = System.currentTimeMillis(); - - @Override - protected Project doInBackground() { - projectView.getLoadingProgressBar().setVisible(true); - ProjectService projectService = projectView.getContextValue(ProjectService.class); - Project project = null; - try { - Project p = projectService.openProject(projectName); - project = p; - } catch (CoserBusinessException ex) { - if (log.isErrorEnabled()) { - log.error("Can't open project", ex); - } - JOptionPane.showMessageDialog(projectView, ex.getMessage(), _("coser.ui.project.openError"), - JOptionPane.ERROR_MESSAGE); - projectView.getLoadingProgressBar().setVisible(false); - } - return project; + final String projectName = (String)projectView.getProjectsComboBox().getSelectedItem(); + ProjectService projectService = projectView.getContextValue(ProjectService.class); + try { + Project project = projectService.openProject(projectName); + projectLoaded(project); + //showControlView(); + setMainComponent(null); + } catch (CoserBusinessException ex) { + if (log.isErrorEnabled()) { + log.error("Can't open project", ex); } - - @Override - protected void done() { - if (log.isInfoEnabled()) { - long after = System.currentTimeMillis(); - log.info("Project reloaded in " + (after-before) + "ms"); - } - try { - Project project = get(); - if (project != null) { - projectLoaded(project); - showControlView(); - } - } catch (Exception ex) { - throw new CoserException("Can't create project", ex); - } - } - }; - task.execute(); + JOptionPane.showMessageDialog(projectView, ex.getMessage(), _("coser.ui.project.openError"), + JOptionPane.ERROR_MESSAGE); + } } /** @@ -448,10 +423,12 @@ // basé sur un hack, car ici, on ne sais pas ce que contient // le panel principal // attention, c'est du big hack ;) - Component comp = view.getMainViewContent().getComponent(0); - if (comp instanceof ControlView) { - ControlView controlView = (ControlView)comp; - result = controlView.getHandler().checkValidationModelErrors(controlView); + if (view.getMainViewContent().getComponentCount() > 0) { + Component comp = view.getMainViewContent().getComponent(0); + if (comp instanceof ControlView) { + ControlView controlView = (ControlView)comp; + result = controlView.getHandler().checkValidationModelErrors(controlView); + } } return result; @@ -468,16 +445,19 @@ Project project = view.getContextValue(Project.class); Selection selection = project.getSelections().get(selectionName); try { - projectService.loadSelectionData(project, selection); - + project = projectService.loadSelectionData(project, selection); view.setContextValue(selection); SelectionView selectionView = new SelectionView(view); selectionView.setSelection(selection); + // fix, binding not working ? selectionView.getSelectionDetailsTab().getValidatorSelection().setBean(selection); - selectionView.setHandler(new SelectionHandler()); + SelectionHandler handler = new SelectionHandler(); + selectionView.setHandler(handler); + handler.reloadSelection(selectionView); + File file = new File("/home/chatellier/tmp/coser/zones.png"); selectionView.getSelectionDetailsTab().getZonesMap().setImage(file); Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/project/ProjectOpenView.jaxx =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/project/ProjectOpenView.jaxx 2010-11-10 12:36:59 UTC (rev 197) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/project/ProjectOpenView.jaxx 2010-11-10 12:58:40 UTC (rev 198) @@ -43,11 +43,6 @@ onActionPerformed="getHandler().loadProject(this)" /> </cell> </row> - <row> - <cell weightx="1" fill="horizontal" columns="2"> - <JProgressBar id="loadingProgressBar" indeterminate="true" visible="false" /> - </cell> - </row> </Table> </cell> </row> Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionDetailsView.jaxx =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionDetailsView.jaxx 2010-11-10 12:36:59 UTC (rev 197) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionDetailsView.jaxx 2010-11-10 12:58:40 UTC (rev 198) @@ -24,6 +24,11 @@ --> <Table> + <script><![CDATA[ + import fr.ifremer.coser.ui.selection.model.SpecyListTestModel; + import fr.ifremer.coser.ui.util.CoserListSelectionModel; + ]]></script> + <SelectionHandler id="handler" javaBean="null" /> <Boolean id="creationState" javaBean="false" /> @@ -35,7 +40,7 @@ <BeanValidator id='validatorSelection' bean='selection' uiClass="jaxx.runtime.validator.swing.ui.ImageValidationUI" errorTableModel="errorsTableModel"> - <field name="name" component="selectionDetailsSelectionNameField" /> + <field name="name" component="detailsSelectionNameField" /> </BeanValidator> <row> @@ -46,11 +51,11 @@ <JLabel text="coser.ui.selection.details.name" /> </cell> <cell weightx="1" fill="horizontal" columns="3"> - <JTextField id="selectionDetailsSelectionNameField" text="{getSelection().getName()}" + <JTextField id="detailsSelectionNameField" text="{getSelection().getName()}" enabled="{isCreationState()}"/> - <javax.swing.text.Document javaBean="selectionDetailsSelectionNameField.getDocument()" - onInsertUpdate='getSelection().setName(selectionDetailsSelectionNameField.getText())' - onRemoveUpdate='getSelection().setName(selectionDetailsSelectionNameField.getText())' /> + <javax.swing.text.Document javaBean="detailsSelectionNameField.getDocument()" + onInsertUpdate='getSelection().setName(detailsSelectionNameField.getText())' + onRemoveUpdate='getSelection().setName(detailsSelectionNameField.getText())' /> </cell> </row> <row> @@ -59,11 +64,11 @@ </cell> <cell weightx="1" fill="horizontal" columns="3"> <JScrollPane> - <JTextArea id="selectionDetailsDescription" text="{getSelection().getDescription()}" rows="3" /> + <JTextArea id="detailsDescription" text="{getSelection().getDescription()}" rows="3" /> </JScrollPane> - <javax.swing.text.Document javaBean="selectionDetailsDescription.getDocument()" - onInsertUpdate='getSelection().setDescription(selectionDetailsDescription.getText())' - onRemoveUpdate='getSelection().setDescription(selectionDetailsDescription.getText())' /> + <javax.swing.text.Document javaBean="detailsDescription.getDocument()" + onInsertUpdate='getSelection().setDescription(detailsDescription.getText())' + onRemoveUpdate='getSelection().setDescription(detailsDescription.getText())' /> </cell> </row> <row> @@ -72,18 +77,18 @@ </cell> <cell weightx="1" fill="horizontal"> <YearComboBoxModel id="beginYearComboBoxModel" constructorParams="this" /> - <JComboBox id="selectionDetailsBeginYearField" + <JComboBox id="beginYearComboBox" model="{beginYearComboBoxModel}" - onActionPerformed="getHandler().updateSelectionDateData(this, event); getSelection().setBeginDate((Integer)selectionDetailsBeginYearField.getSelectedItem())" /> + onActionPerformed="getHandler().updateSelectionDateData(this, event); getSelection().setBeginDate((Integer)beginYearComboBox.getSelectedItem())" /> </cell> <cell anchor="west"> <JLabel text="coser.ui.selection.details.endDate" /> </cell> <cell weightx="1" fill="horizontal"> <YearComboBoxModel id="endYearComboBoxModel" constructorParams="this" /> - <JComboBox id="selectionDetailsEndYearField" + <JComboBox id="endYearComboBox" model="{endYearComboBoxModel}" - onActionPerformed="getHandler().updateSelectionDateData(this, event); getSelection().setEndDate((Integer)selectionDetailsEndYearField.getSelectedItem())" /> + onActionPerformed="getHandler().updateSelectionDateData(this, event); getSelection().setEndDate((Integer)endYearComboBox.getSelectedItem())" /> </cell> </row> <row> @@ -98,12 +103,12 @@ <row> <cell weighty="2" fill="both" columns="4"> <JScrollPane> - <SelectionZoneListModel id="selectionZoneModel" /> - <JList id="zoneList" model="{selectionZoneModel}" - cellRenderer="{new SelectionZoneListRenderer()}" - enabled="{selectionDetailsBeginYearField.getSelectedItem() != null && selectionDetailsEndYearField.getSelectedItem() != null}" - selectionModel="{new OneClicListSelectionModel(zoneList.getSelectionModel(), selectionZoneModel)}" - onValueChanged="getHandler().zoneListChanged(this);"/> + <ZoneListModel id="zoneListModel" /> + <JList id="zoneList" model="{zoneListModel}" + cellRenderer="{new ZoneListRenderer()}" + enabled="{beginYearComboBox.getSelectedItem() != null && endYearComboBox.getSelectedItem() != null}" + selectionModel="{new CoserListSelectionModel(zoneList.getSelectionModel(), zoneListModel)}" + onValueChanged="getHandler().zoneListChanged(this, event);"/> </JScrollPane> </cell> </row> @@ -122,22 +127,24 @@ <row> <cell fill="both" weightx="1" weighty="1" columns="2"> <JScrollPane> - <TypeSpecyListModel id="typeSpecyModel" constructorParams="this" /> + <SpecyTypesListModel id="typeSpecyModel" constructorParams="this" /> <JList id="typeSpecyList" model="{typeSpecyModel}" - selectionModel="{new OneClicListSelectionModel(typeSpecyList.getSelectionModel(), typeSpecyModel)}" - onValueChanged="getHandler().typeSpecyListChanged(this)"/> + enabled="{beginYearComboBox.getSelectedItem() != null && endYearComboBox.getSelectedItem() != null}" + selectionModel="{new CoserListSelectionModel(typeSpecyList.getSelectionModel(), typeSpecyModel)}" + onValueChanged="getHandler().typeSpecyListChanged(this, event)"/> </JScrollPane> </cell> </row> <row> <cell weighty="2" fill="both" columns="2"> <JScrollPane> - <SpecyListTestModel id="specyListModel" /> + <fr.ifremer.coser.ui.selection.model.SpecyListTestModel id="specyListModel" /> <JList id="specyList" model="{specyListModel}" cellRenderer="{new SpecyListRenderer()}" + enabled="{beginYearComboBox.getSelectedItem() != null && endYearComboBox.getSelectedItem() != null}" onMouseClicked="getHandler().showSpeciesContextMenu(this, event)" - selectionModel="{new OneClicListSelectionModel(specyList.getSelectionModel(), specyListModel)}" - onValueChanged="getHandler().specyListChanged(this)"/> + selectionModel="{new CoserListSelectionModel(specyList.getSelectionModel(), specyListModel)}" + onValueChanged="getHandler().specyListChanged(this, event)"/> <ListSelectionModel id="specyListSelectionModel" javaBean="specyList.getSelectionModel()" /> </JScrollPane> </cell> @@ -148,7 +155,10 @@ <row> <cell weighty="1" fill="both" columns="4"> <JScrollPane> - <JXTextArea constructorParams='_("coser.ui.selection.details.comment")' rows="3" /> + <JXTextArea id="detailsComment" constructorParams='_("coser.ui.selection.details.comment")' rows="3" /> + <javax.swing.text.Document javaBean="detailsComment.getDocument()" + onInsertUpdate='getSelection().setComment(detailsComment.getText())' + onRemoveUpdate='getSelection().setComment(detailsComment.getText())' /> </JScrollPane> </cell> </row> 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-10 12:36:59 UTC (rev 197) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionHandler.java 2010-11-10 12:58:40 UTC (rev 198) @@ -25,6 +25,7 @@ import static org.nuiton.i18n.I18n._; +import java.awt.Component; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseEvent; @@ -34,6 +35,8 @@ import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JPopupMenu; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ListSelectionEvent; import jaxx.runtime.JAXXUtil; @@ -45,8 +48,8 @@ import fr.ifremer.coser.CoserException; import fr.ifremer.coser.bean.Project; import fr.ifremer.coser.bean.Selection; -import fr.ifremer.coser.bean.Specy; import fr.ifremer.coser.services.ProjectService; +import fr.ifremer.coser.ui.util.CoserListSelectionModel; /** * Selection handler. @@ -62,6 +65,68 @@ private static final Log log = LogFactory.getLog(SelectionHandler.class); /** + * Appelé sur un changement d'onglet dans l'interface de sélection. + * + * @param view view + * @param event change event + */ + public void selectionTabChanged(SelectionView view, ChangeEvent event) { + + // selected tab is Lists + Component selectedComponent = view.getSelectedComponent(); + if (selectedComponent instanceof SelectionListsView) { + SelectionListsView selectionListsView = (SelectionListsView)selectedComponent; + + if (log.isDebugEnabled()) { + log.debug("List details tab selected"); + } + + Selection selection = view.getContextValue(Selection.class); + + // si la selection n'est pas la même que que celle de la sélection + // on met à jour la liste de "Toutes les especes" (L1) + + List<String> currentList = selectionListsView.getSelectionAllSpeciesListModel().getSpecies(); + List<String> selectionSpecyList = selection.getSpecies(); + + if (!selectionSpecyList.equals(currentList)) { + selectionListsView.getSelectionAllSpeciesListModel().setSpecies(selectionSpecyList); + ((CoserListSelectionModel)selectionListsView.getSelectionAllSpeciesList().getSelectionModel()).fillSelection(); + } + } + } + + /** + * Recharge la selection en valorisant les différentes listes. + * + * Fait ici, car sinon, les evenements ne se déclenchent pas au même + * moment. + * + * @param view view to fill + */ + public void reloadSelection(SelectionView view) { + + if (log.isDebugEnabled()) { + log.debug("Reloading selection..."); + } + + Selection selection = view.getSelection(); + + // fill details view + SelectionDetailsView detailView = view.getSelectionDetailsTab(); + detailView.getBeginYearComboBox().setSelectedItem(selection.getBeginDate()); + detailView.getEndYearComboBox().setSelectedItem(selection.getEndDate()); + // "typeSpecies" before other, more performant + ((CoserListSelectionModel)detailView.getTypeSpecyList().getSelectionModel()).setSelectedObjects(selection.getFilterSpecyTypes()); + ((CoserListSelectionModel)detailView.getZoneList().getSelectionModel()).setSelectedObjects(selection.getZones()); + ((CoserListSelectionModel)detailView.getSpecyList().getSelectionModel()).setSelectedObjects(selection.getSpecies()); + + if (log.isDebugEnabled()) { + log.debug("Selection reloaded."); + } + } + + /** * Rafraichit la liste des zones suite à la selection des dates. * * @param view view @@ -72,8 +137,8 @@ Selection selection = view.getContextValue(Selection.class); ProjectService projectService = view.getContextValue(ProjectService.class); - Integer beginYear = (Integer)view.getSelectionDetailsBeginYearField().getSelectedItem(); - Integer endYear = (Integer)view.getSelectionDetailsEndYearField().getSelectedItem(); + Integer beginYear = (Integer)view.getBeginYearComboBox().getSelectedItem(); + Integer endYear = (Integer)view.getEndYearComboBox().getSelectedItem(); // il est possible que l'evenement fasse suite a une seule des selections if (beginYear != null && endYear != null) { @@ -81,7 +146,7 @@ log.debug("Refreshing zones list"); } List<String> zones = projectService.getProjectZone(selection, beginYear, endYear); - view.getSelectionZoneModel().setZones(zones); + view.getZoneListModel().setZones(zones); } } @@ -89,58 +154,61 @@ * Appellé lorsque la selection de la liste des zones a changé. * * @param view view + * @param event event */ - public void zoneListChanged(SelectionDetailsView view) { - Selection selection = view.getContextValue(Selection.class); + public void zoneListChanged(SelectionDetailsView view, ListSelectionEvent event) { - // get selected zones as list - Object[] selectedZones = view.getZoneList().getSelectedValues(); - List<String> zones = new ArrayList<String>(selectedZones.length); - for (Object selectedZone : selectedZones) { - zones.add((String)selectedZone); + // reload is slow without it + if (!event.getValueIsAdjusting()) { + + if (log.isDebugEnabled()) { + log.debug("Zone list selection changed, updating species list"); + } + + Selection selection = view.getContextValue(Selection.class); + + // get selected zones as list + Object[] selectedZones = view.getZoneList().getSelectedValues(); + List<String> zones = new ArrayList<String>(selectedZones.length); + for (Object selectedZone : selectedZones) { + zones.add((String)selectedZone); + } + selection.setZones(zones); + + updateSelectionSpecies(view); } - selection.setZones(zones); - - updateSelectionSpecies(view); } /** * Appelé lorsque la selection de la liste des types. * * @param view view + * @param event event */ - public void typeSpecyListChanged(SelectionDetailsView view) { - Selection selection = view.getContextValue(Selection.class); + public void typeSpecyListChanged(SelectionDetailsView view, ListSelectionEvent event) { + + // reload is slow without it + if (!event.getValueIsAdjusting()) { + + if (log.isDebugEnabled()) { + log.debug("Specy type selection changed, updating species list"); + } - // get selected specy types - Object[] selectedSpecyTypes = view.getTypeSpecyList().getSelectedValues(); - List<String> specyTypes = new ArrayList<String>(); - for (Object selectedSpecyType : selectedSpecyTypes) { - specyTypes.add((String)selectedSpecyType); + Selection selection = view.getContextValue(Selection.class); + + // get selected specy types + Object[] selectedSpecyTypes = view.getTypeSpecyList().getSelectedValues(); + List<String> specyTypes = new ArrayList<String>(); + for (Object selectedSpecyType : selectedSpecyTypes) { + specyTypes.add((String)selectedSpecyType); + } + selection.setFilterSpecyTypes(specyTypes); + + updateSelectionSpecies(view); } - selection.setFilterSpecyTypes(specyTypes); - - updateSelectionSpecies(view); } /** - * Appelé lorsque la selection de la liste des especes change. - * - * @param view - */ - public void specyListChanged(SelectionDetailsView view) { - Selection selection = view.getContextValue(Selection.class); - - // get selected species - Object[] selectedSpecies = view.getSpecyList().getSelectedValues(); - List<String> species= new ArrayList<String>(); - for (Object selectedSpecy : selectedSpecies) { - species.add((String)selectedSpecy); - } - selection.setSpecies(species); - } - - /** * Rafraichit la liste des especes avec les dates sélectionnées * et les zones selectionnées ET filtrées par la liste * des type d'especes. @@ -150,6 +218,11 @@ * @param view view */ protected void updateSelectionSpecies(SelectionDetailsView view) { + + if (log.isDebugEnabled()) { + log.debug("Updating species list"); + } + Project project = view.getContextValue(Project.class); Selection selection = view.getContextValue(Selection.class); ProjectService projectService = view.getContextValue(ProjectService.class); @@ -164,17 +237,43 @@ specyTypes.add((String)selectedSpecyType); } - Integer beginYear = (Integer)view.getSelectionDetailsBeginYearField().getSelectedItem(); - Integer endYear = (Integer)view.getSelectionDetailsEndYearField().getSelectedItem(); + Integer beginYear = (Integer)view.getBeginYearComboBox().getSelectedItem(); + Integer endYear = (Integer)view.getEndYearComboBox().getSelectedItem(); // il est possible que l'evenement fasse suite a une seule des selections if (beginYear != null && endYear != null && zones != null) { List<String> species = projectService.getProjectSpecies(project, selection, zones, beginYear, endYear, specyTypes); - view.getSpecyListModel().setSpecy(species); + view.getSpecyListModel().setSpecies(species); } } /** + * Appelé lorsque la selection de la liste des especes change. + * + * @param view view + * @param event event + */ + public void specyListChanged(SelectionDetailsView view, ListSelectionEvent event) { + + if (!event.getValueIsAdjusting()) { + + if (log.isDebugEnabled()) { + log.debug("Species selection changed, updating registered species"); + } + + Selection selection = view.getContextValue(Selection.class); + + // get selected species + Object[] selectedSpecies = view.getSpecyList().getSelectedValues(); + List<String> species= new ArrayList<String>(); + for (Object selectedSpecy : selectedSpecies) { + species.add((String)selectedSpecy); + } + selection.setSpecies(species); + } + } + + /** * Affiche un menu contextuel lors du clic (droit) sur la liste des especes. * * @param view view @@ -291,7 +390,7 @@ Project project = view.getContextValue(Project.class); Selection seletion = view.getContextValue(Selection.class); ProjectService projectService = view.getContextValue(ProjectService.class); - + boolean newSpecyExist = projectService.isSpecyNameExist(project, newSpecyName); if (!newSpecyExist) { JOptionPane.showMessageDialog(view, _("coser.ui.selection.invalidFusionName"), @@ -303,10 +402,10 @@ Object[] selectedSpecies = parent.getSpecyList().getSelectedValues(); String[] specyNames = new String[selectedSpecies.length]; for (int i = 0 ; i < selectedSpecies.length ; ++i) { - Specy selectedSpecy = (Specy)selectedSpecies[i]; - specyNames[i] = selectedSpecy.getName(); + String selectedSpecy = (String)selectedSpecies[i]; + specyNames[i] = selectedSpecy; } - + try { projectService.mergeSpecies(project, seletion, newSpecyName, comment, specyNames); } 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-10 12:36:59 UTC (rev 197) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionListsView.jaxx 2010-11-10 12:58:40 UTC (rev 198) @@ -26,16 +26,19 @@ <SelectionHandler id="handler" javaBean="null" /> <script><![CDATA[ + import fr.ifremer.coser.ui.selection.model.SpecyListTestModel; + import fr.ifremer.coser.ui.util.CoserListSelectionModel; + void $afterCompleteSetup() { // modification (all species -> all species list) selectionAllSpeciesList.addListSelectionListener(selectionOccurenceDensityListModel); - selectionOccurenceDensityListModel.addListDataListener((SpecyListSelectionModel)selectionOccurenceDensityList.getSelectionModel()); + selectionOccurenceDensityListModel.addListDataListener((CoserListSelectionModel)selectionOccurenceDensityList.getSelectionModel()); selectionOccurenceDensityList.addListSelectionListener(selectionSizeAllYearListModel); - selectionSizeAllYearListModel.addListDataListener((SpecyListSelectionModel)selectionSizeAllYearList.getSelectionModel()); + selectionSizeAllYearListModel.addListDataListener((CoserListSelectionModel)selectionSizeAllYearList.getSelectionModel()); selectionSizeAllYearList.addListSelectionListener(selectionMaturityListModel); - selectionMaturityListModel.addListDataListener((SpecyListSelectionModel)selectionMaturityList.getSelectionModel()); + selectionMaturityListModel.addListDataListener((CoserListSelectionModel)selectionMaturityList.getSelectionModel()); } ]]></script> @@ -76,69 +79,70 @@ <row> <cell weighty="1" weightx="1" fill="both" columns="2"> <JScrollPane> - <SpecyListTestModel id="selectionAllSpeciesListModel" javaBean="new fr.ifremer.coser.ui.selection.SpecyListTestModel()" /> + <SpecyListTestModel id="selectionAllSpeciesListModel" /> <JList id="selectionAllSpeciesList" model="{selectionAllSpeciesListModel}" - cellRenderer="{new fr.ifremer.coser.ui.selection.SpecyListCheckBoxRenderer()}" - selectionModel="{new SpecyListSelectionModel(selectionAllSpeciesList.getSelectionModel(), selectionAllSpeciesListModel)}"/> + cellRenderer="{new SpecyListCheckBoxRenderer()}" + selectionModel="{new CoserListSelectionModel(selectionAllSpeciesList.getSelectionModel(), selectionAllSpeciesListModel)}" + enabled="false" /> </JScrollPane> </cell> <cell weightx="1" fill="both" columns="2"> <JScrollPane> - <SpecyListTestModel id="selectionOccurenceDensityListModel" javaBean="new fr.ifremer.coser.ui.selection.SpecyListTestModel()" /> + <SpecyListTestModel id="selectionOccurenceDensityListModel" /> <JList id="selectionOccurenceDensityList" model="{selectionOccurenceDensityListModel}" - cellRenderer="{new fr.ifremer.coser.ui.selection.SpecyListCheckBoxRenderer(true)}" - selectionModel="{new SpecyListSelectionModel(selectionOccurenceDensityList.getSelectionModel(), selectionOccurenceDensityListModel)}"/> + cellRenderer="{new SpecyListCheckBoxRenderer(true)}" + selectionModel="{new CoserListSelectionModel(selectionOccurenceDensityList.getSelectionModel(), selectionOccurenceDensityListModel)}"/> </JScrollPane> </cell> <cell weightx="1" fill="both" columns="2"> <JScrollPane> - <SpecyListTestModel id="selectionSizeAllYearListModel" javaBean="new fr.ifremer.coser.ui.selection.SpecyListTestModel()" /> + <SpecyListTestModel id="selectionSizeAllYearListModel" /> <JList id="selectionSizeAllYearList" model="{selectionSizeAllYearListModel}" - cellRenderer="{new fr.ifremer.coser.ui.selection.SpecyListCheckBoxRenderer()}" - selectionModel="{new SpecyListSelectionModel(selectionSizeAllYearList.getSelectionModel(), selectionSizeAllYearListModel)}"/> + cellRenderer="{new SpecyListCheckBoxRenderer()}" + selectionModel="{new CoserListSelectionModel(selectionSizeAllYearList.getSelectionModel(), selectionSizeAllYearListModel)}"/> </JScrollPane> </cell> <cell weightx="1" fill="both" columns="2"> <JScrollPane> - <SpecyListTestModel id="selectionMaturityListModel" javaBean="new fr.ifremer.coser.ui.selection.SpecyListTestModel()" /> + <SpecyListTestModel id="selectionMaturityListModel" /> <JList id="selectionMaturityList" model="{selectionMaturityListModel}" - cellRenderer="{new fr.ifremer.coser.ui.selection.SpecyListCheckBoxRenderer()}" - selectionModel="{new SpecyListSelectionModel(selectionMaturityList.getSelectionModel(), selectionMaturityListModel)}"/> + cellRenderer="{new SpecyListCheckBoxRenderer()}" + selectionModel="{new CoserListSelectionModel(selectionMaturityList.getSelectionModel(), selectionMaturityListModel)}"/> </JScrollPane> </cell> </row> <row> <cell fill="horizontal" weightx="1"> - <JButton text='coser.ui.common.selectAll.short' - onActionPerformed="((SpecyListSelectionModel)selectionAllSpeciesList.getSelectionModel()).fillSelection()"/> + <JButton text='coser.ui.common.selectAll.short' enabled="false" + onActionPerformed="((CoserListSelectionModel)selectionAllSpeciesList.getSelectionModel()).fillSelection()"/> </cell> <cell fill="horizontal" weightx="1"> - <JButton text='coser.ui.common.unselectAll.short' - onActionPerformed="((SpecyListSelectionModel)selectionAllSpeciesList.getSelectionModel()).clearSelection()"/> + <JButton text='coser.ui.common.unselectAll.short' enabled="false" + onActionPerformed="((CoserListSelectionModel)selectionAllSpeciesList.getSelectionModel()).clearSelection()"/> </cell> <cell fill="horizontal" weightx="1"> <JButton text='coser.ui.common.selectAll.short' - onActionPerformed="((SpecyListSelectionModel)selectionOccurenceDensityList.getSelectionModel()).fillSelection()"/> + onActionPerformed="((CoserListSelectionModel)selectionOccurenceDensityList.getSelectionModel()).fillSelection()"/> </cell> <cell fill="horizontal" weightx="1"> <JButton text='coser.ui.common.unselectAll.short' - onActionPerformed="((SpecyListSelectionModel)selectionOccurenceDensityList.getSelectionModel()).clearSelection()"/> + onActionPerformed="((CoserListSelectionModel)selectionOccurenceDensityList.getSelectionModel()).clearSelection()"/> </cell> <cell fill="horizontal" weightx="1"> <JButton text='coser.ui.common.selectAll.short' - onActionPerformed="((SpecyListSelectionModel)selectionSizeAllYearList.getSelectionModel()).fillSelection()"/> + onActionPerformed="((CoserListSelectionModel)selectionSizeAllYearList.getSelectionModel()).fillSelection()"/> </cell> <cell fill="horizontal" weightx="1"> <JButton text='coser.ui.common.unselectAll.short' - onActionPerformed="((SpecyListSelectionModel)selectionSizeAllYearList.getSelectionModel()).clearSelection()"/> + onActionPerformed="((CoserListSelectionModel)selectionSizeAllYearList.getSelectionModel()).clearSelection()"/> </cell> <cell fill="horizontal" weightx="1"> <JButton text='coser.ui.common.selectAll.short' - onActionPerformed="((SpecyListSelectionModel)selectionMaturityList.getSelectionModel()).fillSelection()"/> + onActionPerformed="((CoserListSelectionModel)selectionMaturityList.getSelectionModel()).fillSelection()"/> </cell> <cell fill="horizontal" weightx="1"> <JButton text='coser.ui.common.unselectAll.short' - onActionPerformed="((SpecyListSelectionModel)selectionMaturityList.getSelectionModel()).clearSelection()"/> + onActionPerformed="((CoserListSelectionModel)selectionMaturityList.getSelectionModel()).clearSelection()"/> </cell> </row> <row> Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionView.jaxx =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionView.jaxx 2010-11-10 12:36:59 UTC (rev 197) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionView.jaxx 2010-11-10 12:58:40 UTC (rev 198) @@ -30,12 +30,22 @@ <SelectionHandler id="handler" javaBean="null" /> <script><![CDATA[ void $afterCompleteSetup() { - // modification (species -> all species list) + /*// modification (species -> all species list) SpecyListTestModel model = getSelectionListsView().getSelectionAllSpeciesListModel(); getSelectionDetailsTab().getSpecyList().addListSelectionListener(model); + ((SpecyListSelectionModel)getSelectionDetailsTab().getSpecyList().getSelectionModel()).fillSelection(); // FIXME add common interface to species models //getSelectionDetailsTab().getSpecyList().getModel().addListDataListener((SpecyListSelectionModel)getSelectionDetailsTab().getSpecyList().getSelectionModel()); + */ + + addChangeListener(new ChangeListener() { + public void stateChanged(ChangeEvent event) { + if (getHandler() != null) { + getHandler().selectionTabChanged(SelectionView.this, event); + } + } + }); } ]]></script> <tab title="coser.ui.selection.tab.details"> Deleted: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionZoneListModel.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionZoneListModel.java 2010-11-10 12:36:59 UTC (rev 197) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionZoneListModel.java 2010-11-10 12:58:40 UTC (rev 198) @@ -1,74 +0,0 @@ -/* - * #%L - * $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; - -import java.util.List; - -import javax.swing.AbstractListModel; - -/** - * Model contenant la liste des noms de zone (utilsé dans le detail de selection). - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -public class SelectionZoneListModel extends AbstractListModel { - - /** serialVersionUID. */ - private static final long serialVersionUID = -8155676616312843132L; - - protected List<String> zones; - - public List<String> getZones() { - return zones; - } - - public void setZones(List<String> zones) { - this.zones = zones; - fireContentsChanged(this, 0, zones.size()); - } - - /* - * @see javax.swing.ListModel#getSize() - */ - @Override - public int getSize() { - int size = 0; - if (zones != null) { - size = zones.size(); - } - return size; - } - - /* - * @see javax.swing.ListModel#getElementAt(int) - */ - @Override - public Object getElementAt(int index) { - return zones.get(index); - } -} Deleted: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionZoneListRenderer.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionZoneListRenderer.java 2010-11-10 12:36:59 UTC (rev 197) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionZoneListRenderer.java 2010-11-10 12:58:40 UTC (rev 198) @@ -1,56 +0,0 @@ -/* - * #%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; - -import java.awt.Component; - -import javax.swing.DefaultListCellRenderer; -import javax.swing.JList; - -/** - * Renderer de la liste des nom de zone. - * (pas forcement utile avec des String). - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -public class SelectionZoneListRenderer extends DefaultListCellRenderer { - - /** serialVersionUID. */ - private static final long serialVersionUID = 4329272863520663978L; - - @Override - public Component getListCellRendererComponent(JList list, Object value, - int index, boolean isSelected, boolean cellHasFocus) { - - String zone = (String)value; - - return super.getListCellRendererComponent(list, zone, index, isSelected, cellHasFocus); - } -} Deleted: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SpecyListSelectionModel.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SpecyListSelectionModel.java 2010-11-10 12:36:59 UTC (rev 197) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SpecyListSelectionModel.java 2010-11-10 12:58:40 UTC (rev 198) @@ -1,141 +0,0 @@ -/* - * #%L - * $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; - -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -import javax.swing.ListSelectionModel; -import javax.swing.event.ListDataEvent; -import javax.swing.event.ListDataListener; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; - -import jaxx.runtime.swing.OneClicListSelectionModel; - -import org.apache.commons.lang.NotImplementedException; - -import fr.ifremer.coser.bean.Specy; - -/** - * Model de selection de la liste des especes. - * (ecoute un autre Model de list, et ecoute sa propre selection). - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -public class SpecyListSelectionModel extends OneClicListSelectionModel implements ListDataListener, ListSelectionListener { - - /** serialVersionUID. */ - private static final long serialVersionUID = -4379088046119691748L; - - protected Set<Object> selectedObjects; - protected SpecyListTestModel specyListModel; - - /** - * @param delegate - * @param model - */ - public SpecyListSelectionModel(ListSelectionModel delegate, SpecyListTestModel model) { - super(delegate, model); - specyListModel = model; - selectedObjects = new HashSet<Object>(); - addListSelectionListener(this); - } - - /* - * @see javax.swing.event.ListDataListener#intervalAdded(javax.swing.event.ListDataEvent) - */ - @Override - public void intervalAdded(ListDataEvent e) { - throw new NotImplementedException("Not yet implemented"); - } - - /* - * @see javax.swing.event.ListDataListener#intervalRemoved(javax.swing.event.ListDataEvent) - */ - @Override - public void intervalRemoved(ListDataEvent e) { - throw new NotImplementedException("Not yet implemented"); - } - - /* - * @see javax.swing.event.ListDataListener#contentsChanged(javax.swing.event.ListDataEvent) - */ - @Override - public void contentsChanged(ListDataEvent e) { - clearSelection(); - - Iterator<Object> itO = selectedObjects.iterator(); - while (itO.hasNext()) { - Object o = itO.next(); - int index = specyListModel.getIndexOf(o); - - if (index >= 0) { - addSelectionInterval(index, index); - } - - // a voir, mais si on le remove, avec les evenements multiples - // on pert toutes la selection - /*else { - itO.remove(); - }*/ - } - } - - /* - * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent) - */ - @Override - public void valueChanged(ListSelectionEvent e) { - - // ne fonctionne pas si c'est fait seulement quand - // IsAdjusting est a true. - - if (e.getValueIsAdjusting()) { - int first = e.getFirstIndex(); - int last = e.getLastIndex(); - - for (int i = first ; i <= last ; ++i) { - Object o = specyListModel.getElementAt(i); - if (isSelectedIndex(i)) { - selectedObjects.add(o); - System.out.println(((Specy)o).getName() + " as selected"); - } - else { - selectedObjects.remove(o); - System.out.println(((Specy)o).getName() + " as unselected"); - } - } - } - } - - public void fillSelection() { - addSelectionInterval(0, specyListModel.getSize() - 1); - } -} Deleted: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SpecyListTestModel.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SpecyListTestModel.java 2010-11-10 12:36:59 UTC (rev 197) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SpecyListTestModel.java 2010-11-10 12:58:40 UTC (rev 198) @@ -1,101 +0,0 @@ -/* - * #%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; - -import java.util.ArrayList; -import java.util.List; - -import javax.swing.AbstractListModel; -import javax.swing.JList; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; - -/** - * Test list model. - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -public class SpecyListTestModel extends AbstractListModel implements ListSelectionListener { - - /** serialVersionUID. */ - private static final long serialVersionUID = -4769109927915812519L; - - protected List<String> species = new ArrayList<String>(); - - public void setSpecy(List<String> species) { - this.species = species; - fireContentsChanged(this, 0, species.size()); - } - - /* - * @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); - } - - public int getIndexOf(Object o) { - return species.indexOf(o); - } - - /* - * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent) - */ - @Override - public void valueChanged(ListSelectionEvent event) { - - // il le fait surrement deux fois, mais - // sans ca, la mise à jour des 4 listes en meme tps ne fonctionne pas - - //if (event.getValueIsAdjusting()) { - JList source = (JList)event.getSource(); - Object[] selectedValues = source.getSelectedValues(); - species.clear(); - for (Object selectedValue : selectedValues) { - String specy = (String)selectedValue; - species.add(specy); - } - fireContentsChanged(this, 0, species.size() - 1); - //} - } -} Copied: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SpecyTypesListModel.java (from rev 168, trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/TypeSpecyListModel.java) =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SpecyTypesListModel.java (rev 0) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SpecyTypesListModel.java 2010-11-10 12:58:40 UTC (rev 198) @@ -0,0 +1,91 @@ +/* + * #%L + * + * + * $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 Lesser 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +package fr.ifremer.coser.ui.selection; + +import java.util.List; + +import javax.swing.AbstractListModel; + +import fr.ifremer.coser.bean.Project; +import fr.ifremer.coser.services.ProjectService; +import fr.ifremer.coser.ui.util.CoserListModel; + +/** + * Affiche la liste des types d'especes définie dans le projet. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class SpecyTypesListModel extends AbstractListModel implements CoserListModel { + + /** serialVersionUID. */ + private static final long serialVersionUID = 441910182067909029L; + + protected SelectionDetailsView view; + + protected List<String> types; + + public SpecyTypesListModel(SelectionDetailsView view) { + super(); + this.view = view; + } + + protected List<String> getTypes() { + if (types == null) { + Project project = view.getContextValue(Project.class); + ProjectService service = view.getContextValue(ProjectService.class); + types = service.getProjectSpeciesTypes(project); + } + return types; + } + + /* + * @see javax.swing.ListModel#getSize() + */ + @Override + public int getSize() { + return getTypes().size(); + } + + /* + * @see javax.swing.ListModel#getElementAt(int) + */ + @Override + public Object getElementAt(int index) { + return getTypes().get(index); + } + + /* + * @see fr.ifremer.coser.ui.util.CoserListModel#indexOf(java.lang.Object) + */ + @Override + public int indexOf(Object element) { + return getTypes().indexOf(element); + } +} Deleted: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/TypeSpecyListModel.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/TypeSpecyListModel.java 2010-11-10 12:36:59 UTC (rev 197) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/TypeSpecyListModel.java 2010-11-10 12:58:40 UTC (rev 198) @@ -1,82 +0,0 @@ -/* - * #%L - * - * - * $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 Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -package fr.ifremer.coser.ui.selection; - -import java.util.List; - -import javax.swing.AbstractListModel; - -import fr.ifremer.coser.bean.Project; -import fr.ifremer.coser.services.ProjectService; - -/** - * Affiche la liste des types d'especes définie dans le projet. - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -public class TypeSpecyListModel extends AbstractListModel { - - /** serialVersionUID. */ - private static final long serialVersionUID = 441910182067909029L; - - protected SelectionDetailsView view; - - protected List<String> types; - - public TypeSpecyListModel(SelectionDetailsView view) { - super(); - this.view = view; - } - - protected List<String> getTypes() { - if (types == null) { - Project project = view.getContextValue(Project.class); - ProjectService service = view.getContextValue(ProjectService.class); - types = service.getProjectSpeciesTypes(project); - } - return types; - } - - /* - * @see javax.swing.ListModel#getSize() - */ - @Override - public int getSize() { - return getTypes().size(); - } - - /* - * @see javax.swing.ListModel#getElementAt(int) - */ - @Override - public Object getElementAt(int index) { - return getTypes().get(index); - } -} Copied: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/ZoneListModel.java (from rev 86, trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionZoneListModel.java) =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/ZoneListModel.java (rev 0) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/ZoneListModel.java 2010-11-10 12:58:40 UTC (rev 198) @@ -0,0 +1,84 @@ +/* + * #%L + * $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; + +import java.util.List; + +import javax.swing.AbstractListModel; + +import fr.ifremer.coser.ui.util.CoserListModel; + +/** + * Model contenant la liste des noms de zone (utilisé dans le detail de selection). + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class ZoneListModel extends AbstractListModel implements CoserListModel { + + /** serialVersionUID. */ + private static final long serialVersionUID = -8155676616312843132L; + + protected List<String> zones; + + public List<String> getZones() { + return zones; + } + + public void setZones(List<String> zones) { + this.zones = zones; + fireContentsChanged(this, 0, zones.size()); + } + + /* + * @see javax.swing.ListModel#getSize() + */ + @Override + public int getSize() { + int size = 0; + if (zones != null) { + size = zones.size(); + } + return size; + } + + /* + * @see javax.swing.ListModel#getElementAt(int) + */ + @Override + public Object getElementAt(int index) { + return zones.get(index); + } + + /* + * @see fr.ifremer.coser.ui.util.CoserListModel#indexOf(java.lang.Object) + */ + @Override + public int indexOf(Object element) { + return zones.indexOf(element); + } +} Copied: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/ZoneListRenderer.java (from rev 86, trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionZoneListRenderer.java) =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/ZoneListRenderer.java (rev 0) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/ZoneListRenderer.java 2010-11-10 12:58:40 UTC (rev 198) @@ -0,0 +1,56 @@ +/* + * #%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; + +import java.awt.Component; + +import javax.swing.DefaultListCellRenderer; +import javax.swing.JList; + +/** + * Renderer de la liste des nom de zone. + * (pas forcement utile avec des String). + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class ZoneListRenderer extends DefaultListCellRenderer { + + /** serialVersionUID. */ + private static final long serialVersionUID = 4329272863520663978L; + + @Override + public Component getListCellRendererComponent(JList list, Object value, + int index, boolean isSelected, boolean cellHasFocus) { + + String zone = (String)value; + + return super.getListCellRendererComponent(list, zone, index, isSelected, cellHasFocus); + } +} Copied: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/model/SpecyListTestModel.java (from rev 174, trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SpecyListTestModel.java) =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/model/SpecyListTestModel.java (rev 0) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/model/SpecyListTestModel.java 2010-11-10 12:58:40 UTC (rev 198) @@ -0,0 +1,112 @@ +/* + * #%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.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; + +/** + * Test list model. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class SpecyListTestModel extends AbstractListModel implements ListSelectionListener, CoserListModel { + + /** serialVersionUID. */ + private static final long serialVersionUID = -4769109927915812519L; + + protected List<String> species = new ArrayList<String>(); + + public List<String> getSpecies() { + return species; + } + + public void setSpecies(List<String> species) { + this.species = species; + fireContentsChanged(this, 0, species.size()); + } + + /* + * @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) { + + // il le fait surrement deux fois, mais + // sans ca, la mise à jour des 4 listes en meme tps ne fonctionne pas + + //if (event.getValueIsAdjusting()) { + JList source = (JList)event.getSource(); + Object[] selectedValues = source.getSelectedValues(); + species.clear(); + for (Object selectedValue : selectedValues) { + String specy = (String)selectedValue; + species.add(specy); + } + fireContentsChanged(this, 0, species.size() - 1); + //} + } +} Added: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/util/CoserListModel.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/util/CoserListModel.java (rev 0) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/util/CoserListModel.java 2010-11-10 12:58:40 UTC (rev 198) @@ -0,0 +1,49 @@ +/* + * #%L + * + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2010 Codelutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +package fr.ifremer.coser.ui.util; + +import javax.swing.ListModel; + +/** + * Interface que doivent implementer les modeles de List de coser. + * (à ne pas confondre avec les modeles de selection des List). + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public interface CoserListModel extends ListModel { + + /** + * Return index of element. + * + * @param element element to get index + * @return index of element + */ + int indexOf(Object element); +} Property changes on: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/util/CoserListModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/util/CoserListSelectionModel.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/util/CoserListSelectionModel.java (rev 0) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/util/CoserListSelectionModel.java 2010-11-10 12:58:40 UTC (rev 198) @@ -0,0 +1,176 @@ +/* + * #%L + * $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.util; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +import javax.swing.ListSelectionModel; +import javax.swing.event.ListDataEvent; +import javax.swing.event.ListDataListener; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; + +import jaxx.runtime.swing.OneClicListSelectionModel; + +import org.apache.commons.lang.NotImplementedException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * Model de selection fonctionnant avec les intances des objects selectionnée + * et non par indices. + * Etend {@link OneClicListSelectionModel} pour sélectionner par simple clic. + * + * Implemente {@link ListSelectionListener} pour que la selection que la liste + * courante sauvegarde les instances des objets correspondants aux indices selectionnés. + * + * Implemente {@link ListDataListener} pour que la selection apres changement + * des données reste la même au niveau des objets (sinon, les indices + * ne correspondent pas au données précédent le changement. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class CoserListSelectionModel extends OneClicListSelectionModel implements ListDataListener, ListSelectionListener { + + private static final Log log = LogFactory.getLog(CoserListSelectionModel.class); + + /** Selection objects. */ + protected Set<Object> selectedObjects; + + /** List model. */ + protected CoserListModel coserListModel; + + /** + * Constuctor. + * + * @param delegate + * @param coserListModel + */ + public CoserListSelectionModel(ListSelectionModel delegate, CoserListModel coserListModel) { + super(delegate, coserListModel); + this.coserListModel = coserListModel; + selectedObjects = new HashSet<Object>(); + + // pour que la selection que la liste courante + // sauvegarde les instances des objets correspondants + // aux indices selectionnés. + addListSelectionListener(this); + } + + /** + * Replace selection. + * + * @param objects new selected objects + */ + public void setSelectedObjects(Collection<?> objects) { + selectedObjects.clear(); + if (objects != null) { + selectedObjects.addAll(objects); + } + contentsChanged(null); + } + + /* + * @see javax.swing.event.ListDataListener#intervalAdded(javax.swing.event.ListDataEvent) + */ + @Override + public void intervalAdded(ListDataEvent e) { + throw new NotImplementedException("Not yet implemented"); + } + + /* + * @see javax.swing.event.ListDataListener#intervalRemoved(javax.swing.event.ListDataEvent) + */ + @Override + public void intervalRemoved(ListDataEvent e) { + throw new NotImplementedException("Not yet implemented"); + } + + /* + * @see javax.swing.event.ListDataListener#contentsChanged(javax.swing.event.ListDataEvent) + */ + @Override + public void contentsChanged(ListDataEvent e) { + clearSelection(); + + setValueIsAdjusting(true); + + Iterator<Object> itO = selectedObjects.iterator(); + while (itO.hasNext()) { + Object o = itO.next(); + int index = coserListModel.indexOf(o); + + if (index >= 0) { + addSelectionInterval(index, index); + } + + // a voir, mais si on le remove, avec les evenements multiples + // on pert toutes la selection + /*else { + itO.remove(); + }*/ + } + + setValueIsAdjusting(false); + } + + /* + * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent) + */ + @Override + public void valueChanged(ListSelectionEvent e) { + + // ne fonctionne pas si c'est fait seulement quand + // IsAdjusting est a true. + + if (!e.getValueIsAdjusting()) { + int first = e.getFirstIndex(); + int last = e.getLastIndex(); + + for (int i = first ; i <= last ; ++i) { + Object o = coserListModel.getElementAt(i); + if (isSelectedIndex(i)) { + selectedObjects.add(o); + } + else { + selectedObjects.remove(o); + } + } + } + } + + /** + * Fill selection. + */ + public void fillSelection() { + addSelectionInterval(0, coserListModel.getSize() - 1); + } +} Property changes on: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/util/CoserListSelectionModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL
participants (1)
-
chatellier@users.labs.libre-entreprise.org