Author: echatellier Date: 2012-08-14 14:26:07 +0200 (Tue, 14 Aug 2012) New Revision: 1043 Url: http://forge.codelutin.com/repositories/revision/coser/1043 Log: fixes #1325: Pouvoir renommer une esp?\195?\168ce depuis l'interface de s?\195?\169lection Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/services/ProjectService.java trunk/coser-business/src/main/resources/i18n/coser-business_en_GB.properties trunk/coser-business/src/main/resources/i18n/coser-business_fr_FR.properties trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionHandler.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SpeciesFusionDialog.jaxx trunk/coser-ui/src/main/resources/i18n/coser-ui_en_GB.properties trunk/coser-ui/src/main/resources/i18n/coser-ui_fr_FR.properties 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 2012-08-14 09:26:57 UTC (rev 1042) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/services/ProjectService.java 2012-08-14 12:26:07 UTC (rev 1043) @@ -63,6 +63,7 @@ import org.apache.commons.collections.ListUtils; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -2154,7 +2155,18 @@ while (itTuple.hasNext() && !result) { String[] tuple = itTuple.next(); // "C_Perm","NumSys","NivSys","C_VALIDE","L_VALIDE","AA_VALIDE","C_TxP\u00E8re","Taxa" - String specyCode = tuple[3]; + String specyCode = null; + switch (project.getStorageSpeciesType()) { + case C_PERM: + specyCode = tuple[0]; + break; + case C_Valide: + specyCode = tuple[3]; + break; + case L_Valide: + specyCode = tuple[4]; + break; + } if (specyCode.equals(newSpeciesName)) { result = true; } @@ -2178,9 +2190,19 @@ public Project mergeSpecies(Project project, Selection selection, String newSpeciesName, String comment, String... speciesNames) throws CoserBusinessException { if (!isSpeciesNameExist(project, newSpeciesName)) { - throw new CoserBusinessException(_("Species %s doesn't exist in referential", newSpeciesName)); + throw new CoserBusinessException(_("Species %s doesn't exist in referential", + project.getDisplaySpeciesText(newSpeciesName))); } + // check if new species name is not present in current selection + // species list (collision) + List<String> selectionSpecies = getProjectSpecies(selection, project, null); + if (selectionSpecies.contains(newSpeciesName) && + !ArrayUtils.contains(speciesNames, newSpeciesName)) { + throw new CoserBusinessException(_("Species %s already exists in current selection", + project.getDisplaySpeciesText(newSpeciesName))); + } + MergeSpeciesCommand command = new MergeSpeciesCommand(); command.setNewSpecyName(newSpeciesName); command.setSpeciesNames(speciesNames); Modified: trunk/coser-business/src/main/resources/i18n/coser-business_en_GB.properties =================================================================== --- trunk/coser-business/src/main/resources/i18n/coser-business_en_GB.properties 2012-08-14 09:26:57 UTC (rev 1042) +++ trunk/coser-business/src/main/resources/i18n/coser-business_en_GB.properties 2012-08-14 12:26:07 UTC (rev 1043) @@ -16,6 +16,7 @@ Project\ %s\ doesn't\ exists\ \!= Selection\ %s\ already\ exists= Selection\ %s\ doesn't\ exists\ \!= +Species\ %s\ already\ exists\ in\ current\ selection=Species %s already exists in current selection.\nYou have to perform merge with this species. Species\ %s\ doesn't\ exist\ in\ referential= Wrong\ header\ detected\ in\ file\ %s.\ Found\ \:\ %s,\ expected\ %s=Wrong header detected in file %s.\n\nFound \:\n\t%s\nexpected\n\t%s Wrong\ header\ detected\ in\ file\ %s.\ Found\ \:\ %s,\ expected\ %s\ or\ %s=Wrong header detected in file %s.\n\nFound \:\n\t%s\nexpected\n\t%s\nor\n\t%s Modified: trunk/coser-business/src/main/resources/i18n/coser-business_fr_FR.properties =================================================================== --- trunk/coser-business/src/main/resources/i18n/coser-business_fr_FR.properties 2012-08-14 09:26:57 UTC (rev 1042) +++ trunk/coser-business/src/main/resources/i18n/coser-business_fr_FR.properties 2012-08-14 12:26:07 UTC (rev 1043) @@ -16,6 +16,7 @@ Project\ %s\ doesn't\ exists\ \!=Le projet %s n'existe pas \! Selection\ %s\ already\ exists=La sélection %s existe déjà \! Selection\ %s\ doesn't\ exists\ \!=La sélection %s n'existe pas \! +Species\ %s\ already\ exists\ in\ current\ selection=L'espèce %s existe déjà dans la sélection.\nVous devez effectuer la fusion avec l'espèce déjà présente. Species\ %s\ doesn't\ exist\ in\ referential=L'espèce %s n'existe pas dans le référentiel Wrong\ header\ detected\ in\ file\ %s.\ Found\ \:\ %s,\ expected\ %s=Mauvais entête de fichier détecté dans\n%s. Corrigez les entêtes et relancez la création du projet.\n\nTrouvé \:\n\t%s\nAttendu \:\n\t%s. Wrong\ header\ detected\ in\ file\ %s.\ Found\ \:\ %s,\ expected\ %s\ or\ %s=Mauvais entête de fichier détecté dans %s. Corrigez les entêtes et relancez la création du projet.\n\nTrouvé \:\n\t%s\nAttendu \:\n\t%s\nou \:\n\t%s. 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 2012-08-14 09:26:57 UTC (rev 1042) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionHandler.java 2012-08-14 12:26:07 UTC (rev 1043) @@ -56,6 +56,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jdesktop.swingx.combobox.ListComboBoxModel; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.nuiton.math.matrix.MatrixND; @@ -653,7 +654,7 @@ // affiche le menu contextuel si au moins 2 especes selectionnées int[] selectedRows = view.getFilteredSpeciesList().getSelectedIndices(); - if (selectedRows.length > 1) { + if (selectedRows.length > 0) { // merge menu JMenuItem fusionMenu = new JMenuItem(_("coser.ui.selection.speciesMenuFusion")); fusionMenu.addActionListener(new ActionListener() { @@ -663,9 +664,7 @@ } }); popupMenu.add(fusionMenu); - } - - if (selectedRows.length > 0) { + // graph JMenuItem graphMenu = new JMenuItem(_("coser.ui.selection.details.displayDiffCatchLengthGraph")); graphMenu.addActionListener(new ActionListener() { @@ -688,8 +687,6 @@ }); popupMenu.add(selectAllMenu); - - // unselect all menu JMenuItem unselectAllMenu = new JMenuItem(_("coser.ui.common.unselectAll")); unselectAllMenu.addActionListener(new ActionListener() { @@ -761,17 +758,23 @@ * * @param view parent view */ - protected void showSpeciesMergeDialog(SelectionDetailsView view) { + public void showSpeciesMergeDialog(SelectionDetailsView view) { + Project project = view.getContextValue(Project.class); SpeciesFusionDialog speciesFusionDialog = new SpeciesFusionDialog(view); speciesFusionDialog.setHandler(SelectionHandler.this); - // pre fill new speci name with first selected species name + // fill species combo box with reftax species list + Map<String, String> reftaxSpecies = project.getRefTaxSpeciesMap(); + ListComboBoxModel<String> speciesComboModel = new ListComboBoxModel<String>(new ArrayList<String>(reftaxSpecies.keySet())); + speciesFusionDialog.getSpeciesCombo().setModel(speciesComboModel); + speciesFusionDialog.getSpeciesCombo().setRenderer(new SpeciesListRenderer(reftaxSpecies)); + + // init selected element String firstSelected = (String)view.getFilteredSpeciesList().getSelectedValue(); - speciesFusionDialog.getNewSpeciesNameField().setText(firstSelected); + speciesFusionDialog.getSpeciesCombo().setSelectedItem(firstSelected); speciesFusionDialog.setLocationRelativeTo(view); speciesFusionDialog.setVisible(true); - } /** @@ -1041,41 +1044,36 @@ // TODO echatellier 20101021 attention a ce que la selection // ne change pas (la fenetre est modale pour l'instant) - String newSpeciesName = view.getNewSpeciesNameField().getText(); + String newSpeciesCode = (String)view.getSpeciesCombo().getSelectedItem(); String comment = view.getCommentField().getText(); Project project = view.getContextValue(Project.class); Selection selection = view.getContextValue(Selection.class); ProjectService projectService = view.getContextValue(ProjectService.class); - boolean newSpeciesExist = projectService.isSpeciesNameExist(project, newSpeciesName); - if (!newSpeciesExist) { - JOptionPane.showMessageDialog(view, _("coser.ui.selection.invalidFusionName"), - _("coser.ui.selection.fusionError"), JOptionPane.ERROR_MESSAGE); - view.getNewSpeciesNameField().requestFocus(); + SelectionDetailsView parent = view.getContextValue(SelectionDetailsView.class, JAXXUtil.PARENT); + Object[] selectedSpecies = parent.getFilteredSpeciesList().getSelectedValues(); + String[] speciesCodes = new String[selectedSpecies.length]; + for (int i = 0 ; i < selectedSpecies.length ; ++i) { + String singleSelectedSpecies = (String)selectedSpecies[i]; + speciesCodes[i] = singleSelectedSpecies; } - else { - SelectionDetailsView parent = view.getContextValue(SelectionDetailsView.class, JAXXUtil.PARENT); - Object[] selectedSpecies = parent.getFilteredSpeciesList().getSelectedValues(); - String[] speciesNames = new String[selectedSpecies.length]; - for (int i = 0 ; i < selectedSpecies.length ; ++i) { - String singleSelectedSpecies = (String)selectedSpecies[i]; - speciesNames[i] = singleSelectedSpecies; - } - try { - projectService.mergeSpecies(project, selection, newSpeciesName, comment, speciesNames); - } - catch (CoserBusinessException ex) { - throw new CoserException("Can't merge species", ex); - } + try { + projectService.mergeSpecies(project, selection, newSpeciesCode, comment, speciesCodes); updateSelectionSpecies(parent); // supprime la selection apres fusion (demande utilisateur) parent.getFilteredSpeciesListSelectionModel().clearSelection(); - view.dispose(); + JOptionPane.showMessageDialog(view, _("coser.ui.selection.speciesMerged"), _("coser.ui.selection.selectionTitle"), JOptionPane.INFORMATION_MESSAGE); } + catch (CoserBusinessException ex) { + JOptionPane.showMessageDialog(view, ex.getMessage(), + _("coser.ui.selection.fusion.title"), JOptionPane.ERROR_MESSAGE); + } + + view.dispose(); } /** Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SpeciesFusionDialog.jaxx =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SpeciesFusionDialog.jaxx 2012-08-14 09:26:57 UTC (rev 1042) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SpeciesFusionDialog.jaxx 2012-08-14 12:26:07 UTC (rev 1043) @@ -5,7 +5,7 @@ $Id$ $HeadURL$ %% - Copyright (C) 2010 Ifremer, Codelutin, Chatellier Eric + Copyright (C) 2010 - 2012 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 @@ -35,7 +35,7 @@ <JLabel text="coser.ui.selection.fusion.name" /> </cell> <cell weightx="1" fill="horizontal"> - <JTextField id="newSpeciesNameField" /> + <JComboBox id="speciesCombo" /> </cell> </row> <row> Modified: trunk/coser-ui/src/main/resources/i18n/coser-ui_en_GB.properties =================================================================== --- trunk/coser-ui/src/main/resources/i18n/coser-ui_en_GB.properties 2012-08-14 09:26:57 UTC (rev 1042) +++ trunk/coser-ui/src/main/resources/i18n/coser-ui_en_GB.properties 2012-08-14 12:26:07 UTC (rev 1043) @@ -228,8 +228,6 @@ coser.ui.selection.fusion.description=Species merge. Fill new species name with name existing in referential. coser.ui.selection.fusion.name=New name \: coser.ui.selection.fusion.title=Merge -coser.ui.selection.fusionError=Merge error -coser.ui.selection.invalidFusionName=Selection fusion name not found in referential \! coser.ui.selection.maturitySpecies=L4 \: Species with maturity (%d/%d) coser.ui.selection.nonJustifiedMaturity=Maturity species list is not all selected.\nYou must justify this selection with a comment. coser.ui.selection.nonJustifiedOccurenceDensity=Filtered list selection doesn't match filter selection.\nYou must justify this selection with a comment. Modified: trunk/coser-ui/src/main/resources/i18n/coser-ui_fr_FR.properties =================================================================== --- trunk/coser-ui/src/main/resources/i18n/coser-ui_fr_FR.properties 2012-08-14 09:26:57 UTC (rev 1042) +++ trunk/coser-ui/src/main/resources/i18n/coser-ui_fr_FR.properties 2012-08-14 12:26:07 UTC (rev 1043) @@ -228,8 +228,6 @@ coser.ui.selection.fusion.description=Fusion d'espèces. Veuillez renseigner un nouveau nom présent dans le référentiel. coser.ui.selection.fusion.name=Nouveau nom \: coser.ui.selection.fusion.title=Fusion -coser.ui.selection.fusionError=Erreur de fusion -coser.ui.selection.invalidFusionName=Le nom de fusion choisit n'est pas présent de le référentiel \! coser.ui.selection.maturitySpecies=L4 \: Espèces avec maturité (%d/%d) coser.ui.selection.nonJustifiedMaturity=La liste espèces avec maturité n'est pas entièrement sélectionnée.\nVous devez justifier cette sélection par un commentaire. coser.ui.selection.nonJustifiedOccurenceDensity=La sélection de la liste filtrée ne correspond pas à la sélection opérée par le filtre.\nVous devez justifier cette sélection par un commentaire.