r924 - in trunk: coser-business/src/main/java/fr/ifremer/coser/command coser-business/src/main/java/fr/ifremer/coser/services coser-business/src/main/resources/i18n coser-ui/src/main/java/fr/ifremer/coser coser-ui/src/main/java/fr/ifremer/coser/ui 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/selection/replay coser-ui/src/main/resources/i18n
Author: echatellier Date: 2011-12-22 14:56:04 +0100 (Thu, 22 Dec 2011) New Revision: 924 Url: http://forge.codelutin.com/repositories/revision/coser/924 Log: #304: Pouvoir rejouer une s?\195?\169lection Added: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/replay/ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/replay/CommandListModel.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/replay/CommandListRenderer.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/replay/SelectionByProjectTreeModel.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/replay/SelectionReplayHandler.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/replay/SelectionReplayView.jaxx Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/command/Command.java trunk/coser-business/src/main/java/fr/ifremer/coser/command/DeleteLineCommand.java trunk/coser-business/src/main/java/fr/ifremer/coser/command/MergeSpeciesCommand.java trunk/coser-business/src/main/java/fr/ifremer/coser/command/ModifyFieldCommand.java trunk/coser-business/src/main/java/fr/ifremer/coser/services/ProjectService.java trunk/coser-business/src/main/java/fr/ifremer/coser/services/WebService.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/Coser.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/CoserFrameHandler.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/SelectionsListMenuItem.java 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/SelectionRsufiView.jaxx trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/model/MaturitySpeciesListModel.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/model/SpeciesTypesListModel.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/model/YearListModel.java 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/command/Command.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/command/Command.java 2011-12-21 10:41:47 UTC (rev 923) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/command/Command.java 2011-12-22 13:56:04 UTC (rev 924) @@ -131,4 +131,14 @@ * @return log representation */ public abstract String getLogString(AbstractDataContainer container); + + /** + * Return human readable string for ui display (used in selection replay, + * and undo redo commands). + * + * @param container rarement utile, mais dans certains cas, sert a avoir les + * vrais valeur de champs au lieu des noms techniques + * @return string description (i18n) + */ + public abstract String getDescription(AbstractDataContainer container); } Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/command/DeleteLineCommand.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/command/DeleteLineCommand.java 2011-12-21 10:41:47 UTC (rev 923) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/command/DeleteLineCommand.java 2011-12-22 13:56:04 UTC (rev 924) @@ -30,6 +30,8 @@ import java.util.ArrayList; import java.util.List; +import org.apache.commons.lang3.StringUtils; + import fr.ifremer.coser.CoserBusinessException; import fr.ifremer.coser.CoserConstants.Category; import fr.ifremer.coser.CoserUtils; @@ -185,6 +187,15 @@ } @Override + public String getDescription(AbstractDataContainer container) { + String desc = _("coser.business.command.deleteline.desc", _(category.getTranslationKey()), lineNumber); + if (StringUtils.isNotBlank(comment)) { + desc += " (" + comment + ")"; + } + return desc; + } + + @Override public String toString() { return "Delete line " + lineNumber + " on " + category; } Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/command/MergeSpeciesCommand.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/command/MergeSpeciesCommand.java 2011-12-21 10:41:47 UTC (rev 923) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/command/MergeSpeciesCommand.java 2011-12-22 13:56:04 UTC (rev 924) @@ -395,9 +395,18 @@ String speciesAsString = StringUtils.join(speciesNames, ", "); return _("coser.business.command.mergespecies.log", newSpecyName, speciesAsString); } - + @Override + public String getDescription(AbstractDataContainer container) { + String desc = _("coser.business.command.mergespecies.desc", newSpecyName, speciesNames.length); + if (StringUtils.isNotBlank(comment)) { + desc += " (" + comment + ")"; + } + return desc; + } + + @Override public String toString() { - return "Merge species to " + newSpecyName; + return "Merge species to " + newSpecyName; } } Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/command/ModifyFieldCommand.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/command/ModifyFieldCommand.java 2011-12-21 10:41:47 UTC (rev 923) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/command/ModifyFieldCommand.java 2011-12-22 13:56:04 UTC (rev 924) @@ -33,6 +33,7 @@ import org.apache.commons.beanutils.PropertyUtils; import org.apache.commons.lang.ArrayUtils; +import org.apache.commons.lang.StringUtils; import fr.ifremer.coser.CoserBusinessException; import fr.ifremer.coser.CoserUtils; @@ -221,16 +222,21 @@ } @Override - public String toString() { - return "Modify field " + fieldName + " on line " + lineNumber; - } - - @Override public String getLogString(AbstractDataContainer container) { String realFieldName = getRealFieldName(container); return _("coser.business.command.modifyfield.log", _(category.getTranslationKey()), lineNumber, realFieldName, currentValue, newValue); } + @Override + public String getDescription(AbstractDataContainer container) { + String realFieldName = getRealFieldName(container); + String desc = _("coser.business.command.modifyfield.desc", _(category.getTranslationKey()), lineNumber, realFieldName, currentValue, newValue); + if (StringUtils.isNotBlank(comment)) { + desc += " (" + comment + ")"; + } + return desc; + } + /** * Look for real field name. * @@ -269,4 +275,9 @@ String realFieldName = dataStorage.get(0)[index + 1]; return realFieldName; } + + @Override + public String toString() { + return "Modify field " + fieldName + " on line " + lineNumber; + } } 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 2011-12-21 10:41:47 UTC (rev 923) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/services/ProjectService.java 2011-12-22 13:56:04 UTC (rev 924) @@ -283,6 +283,7 @@ try { outputStream = new FileOutputStream(propertiesFile); props.store(outputStream, null); + outputStream.close(); if (log.isDebugEnabled()) { log.debug("Saving project properties file : " + propertiesFile); @@ -453,6 +454,7 @@ inputStream = new FileInputStream(controlPropertiesFile); props.load(inputStream); control.fromProperties(props); + inputStream.close(); if (log.isDebugEnabled()) { log.debug("Read control properties file : " + controlPropertiesFile); @@ -485,6 +487,7 @@ inputStream = new FileInputStream(selectionPropertiesFile); props.load(inputStream); selection.fromProperties(props); + inputStream.close(); if (log.isDebugEnabled()) { log.debug("Read selection properties file : " + selectionPropertiesFile); @@ -514,6 +517,7 @@ inputStream = new FileInputStream(projectPropertiesFile); props.load(inputStream); project.fromProperties(props, mapsDirectory); + inputStream.close(); if (log.isDebugEnabled()) { log.debug("Read project properties file : " + projectPropertiesFile); @@ -582,6 +586,7 @@ inputStream = new FileInputStream(resultPropertiesFile); props.load(inputStream); rsufiResult.fromProperties(props); + inputStream.close(); if (log.isDebugEnabled()) { log.debug("Read result properties file : " + resultPropertiesFile); @@ -685,6 +690,7 @@ Properties props = new Properties(); inputStream = new FileInputStream(controlPropertiesFile); props.load(inputStream); + inputStream.close(); List<Command> commands = getHistoryCommandsFromProperties(props, "control.commands"); control.setHistoryCommand(commands); @@ -763,7 +769,8 @@ Properties props = new Properties(); inputStream = new FileInputStream(selectionPropertiesFile); props.load(inputStream); - + inputStream.close(); + List<Command> commands = getHistoryCommandsFromProperties(props, "selection.commands"); selection.setHistoryCommand(commands); @@ -829,6 +836,7 @@ try { outputStream = new FileOutputStream(propertiesFile); props.store(outputStream, null); + outputStream.close(); if (log.isDebugEnabled()) { log.debug("Saving control properties file : " + propertiesFile); @@ -900,6 +908,7 @@ selectionStream = new FileInputStream(selectionFile); props.load(selectionStream); selection.fromProperties(props); + selectionStream.close(); } catch (IOException ex) { throw new CoserBusinessException("Can't read selection properties file", ex); } @@ -1018,6 +1027,7 @@ try { outputStream = new FileOutputStream(propertiesFile); props.store(outputStream, null); + outputStream.close(); if (log.isDebugEnabled()) { log.debug("Saving selection properties file : " + propertiesFile); @@ -1160,12 +1170,14 @@ Properties props = rsufiResult.toProperties(); outputStream = new FileOutputStream(propertiesFile); props.store(outputStream, null); - + outputStream.close(); if (log.isDebugEnabled()) { log.debug("Saving result properties file : " + propertiesFile); } } catch (IOException ex) { throw new CoserBusinessException("Can't save result properties file", ex); + } finally { + IOUtils.closeQuietly(outputStream); } } @@ -2922,4 +2934,93 @@ return hauls; } + + /** + * Retourne une map de toutes les selections par projet dans le but de + * selectionner une selection pour la rejouer dans l'ui. + * + * @return all selections + */ + public SortedMap<String, List<String>> getSelectionByProject() { + SortedMap<String, List<String>> selectionByProject = new TreeMap<String, List<String>>(); + + // parcours des resultats disponibles + File projectsDirectory = config.getProjectsDirectory(); + File[] projectFiles = projectsDirectory.listFiles(); + if (projectFiles != null) { + for (File projectFile : projectFiles) { + if (projectFile.isDirectory()) { + File selectionsDirectory = new File(projectFile, CoserConstants.STORAGE_SELECTION_DIRECTORY); + File[] selectionFiles = selectionsDirectory.listFiles(); + + // selection iteration + if (selectionFiles != null) { + String projectName = projectFile.getName(); + for (File selectionFile : selectionFiles) { + if (selectionFile.isDirectory()) { + + List<String> selections = selectionByProject.get(projectName); + if (selections == null) { + selections = new ArrayList<String>(); + selectionByProject.put(projectName, selections); + } + selections.add(selectionFile.getName()); + } + } + } + } + } + } + + return selectionByProject; + } + + /** + * Open selection (without opening associated project) without associated + * data (just properties info). + * Selection history commands are loaded too (for replay). + * + * @param projectName project containing selection + * @param selectionName selection name to open in project + * @return opened selection + * @throws CoserBusinessException + */ + public Selection openSelection(String projectName, String selectionName) throws CoserBusinessException { + File projectsDirectory = config.getProjectsDirectory(); + File projectDirectory = new File(projectsDirectory, projectName); + if (!projectDirectory.isDirectory()) { + throw new CoserBusinessException(_("Project %s doesn't exists !", projectName)); + } + File selectionsDirectory = new File(projectDirectory, CoserConstants.STORAGE_SELECTION_DIRECTORY); + File selectionDirectory = new File(selectionsDirectory, selectionName); + if (!projectDirectory.isDirectory()) { + throw new CoserBusinessException(_("Selection %s doesn't exists !", projectName)); + } + + Selection selection = new Selection(); + selection.setName(selectionName); + + // relecture des informations de la selection (properties) + File selectionPropertiesFile = new File(selectionDirectory, selectionName + ".selection"); + InputStream inputStream = null; + try { + Properties props = new Properties(); + inputStream = new FileInputStream(selectionPropertiesFile); + props.load(inputStream); + selection.fromProperties(props); + + List<Command> commands = getHistoryCommandsFromProperties(props, "selection.commands"); + selection.setHistoryCommand(commands); + + if (log.isDebugEnabled()) { + log.debug("Read selection properties file : " + selectionPropertiesFile); + } + } catch (IOException ex) { + throw new CoserBusinessException("Can't read selection properties file", ex); + } + finally { + IOUtils.closeQuietly(inputStream); + } + return selection; + } } Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/services/WebService.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/services/WebService.java 2011-12-21 10:41:47 UTC (rev 923) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/services/WebService.java 2011-12-22 13:56:04 UTC (rev 924) @@ -1937,7 +1937,8 @@ public File getMapFileAsPDF(String survey, String species) throws CoserBusinessException { File result = null; - + + OutputStream os = null; try { // render freemarker template File mapFile = getMapFile(survey, species); @@ -1956,7 +1957,7 @@ // render template output as pdf result = File.createTempFile("coserpdf", ".pdf"); result.deleteOnExit(); - OutputStream os = new FileOutputStream(result); + os = new FileOutputStream(result); ITextRenderer renderer = new ITextRenderer(); renderer.setDocument(document, null); @@ -1971,6 +1972,8 @@ throw new CoserBusinessException("Can't generate pdf with map", ex); } catch (DocumentException ex) { throw new CoserBusinessException("Can't generate pdf with map", ex); + } finally { + IOUtils.closeQuietly(os); } return result; } @@ -2100,8 +2103,9 @@ File result = null; + OutputStream os = null; + try { - // get some info to put into pdf Date updateDate = getLastDataUpdateDate(); String surveyName = projectService.getProjectSurveyName(resultDirectory, rSufiResult); @@ -2123,7 +2127,7 @@ // render template output as pdf result = File.createTempFile("coserdecharge-", ".pdf"); result.deleteOnExit(); - OutputStream os = new FileOutputStream(result); + os = new FileOutputStream(result); ITextRenderer renderer = new ITextRenderer(); renderer.setDocument(document, null); @@ -2137,6 +2141,8 @@ throw new CoserBusinessException("Can't generate decharge file", ex); } catch (DocumentException ex) { throw new CoserBusinessException("Can't generate decharge file", ex); + } finally { + IOUtils.closeQuietly(os); } return result; @@ -2278,6 +2284,7 @@ } } + OutputStream os = null; try { // render freemarker template // FIXME chatellier 20110506 a remplacer par un vrai @@ -2303,7 +2310,7 @@ // render template output as pdf result = File.createTempFile("cosermetainfo-", ".pdf"); result.deleteOnExit(); - OutputStream os = new FileOutputStream(result); + os = new FileOutputStream(result); ITextRenderer renderer = new ITextRenderer(); renderer.setDocument(document, null); @@ -2317,6 +2324,8 @@ throw new CoserBusinessException("Can't generate meta info file", ex); } catch (DocumentException ex) { throw new CoserBusinessException("Can't generate meta info file", ex); + } finally { + IOUtils.closeQuietly(os); } return result; 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 2011-12-21 10:41:47 UTC (rev 923) +++ trunk/coser-business/src/main/resources/i18n/coser-business_en_GB.properties 2011-12-22 13:56:04 UTC (rev 924) @@ -15,6 +15,7 @@ Project\ %s\ already\ exist= Project\ %s\ doesn't\ exists\ \!= Selection\ %s\ already\ exists= +Selection\ %s\ doesn't\ exists\ \!= 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 @@ -26,8 +27,11 @@ coser.business.category.strata=Strata coser.business.category.typeEspece=Species type code coser.business.chart.compareCatchLengthNumberTitle=Comparison of numbers in Catch and Length (%s) +coser.business.command.deleteline.desc=File %s, line %s deleted coser.business.command.deleteline.log=In file %s, line %s has been deleted +coser.business.command.mergespecies.desc=Merge %2$s species into "%1$s" coser.business.command.mergespecies.log=Species "%2$s" has been merged to "%1$s" +coser.business.command.modifyfield.desc=File %1$s, %3$s field modification (line %2$s) coser.business.command.modifyfield.log=In file %s at line %s, field "%s" value as been modify from "%s" to "%s" coser.business.common.length=Length coser.business.common.number=Number 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 2011-12-21 10:41:47 UTC (rev 923) +++ trunk/coser-business/src/main/resources/i18n/coser-business_fr_FR.properties 2011-12-22 13:56:04 UTC (rev 924) @@ -15,6 +15,7 @@ Project\ %s\ already\ exist=Le projet %s existe déjà \! 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\ \!= 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. @@ -26,8 +27,11 @@ coser.business.category.strata=Strates coser.business.category.typeEspece=Code type des espèces coser.business.chart.compareCatchLengthNumberTitle=Comparaison des nombres dans Capture et Taille (%s) +coser.business.command.deleteline.desc=Fichier %s, suppression de la ligne %s coser.business.command.deleteline.log=Dans le fichier %s, la ligne %s a été supprimée +coser.business.command.mergespecies.desc=%2$s espèces ont été fusionnées en "%1$s" coser.business.command.mergespecies.log=Les espèces "%2$s" ont été fusionnées en "%1$s" +coser.business.command.modifyfield.desc=Fichier %1$s, modification du champ "%3$s" (ligne %2$s) coser.business.command.modifyfield.log=Dans le ficher %s à la ligne %s, le champs "%s" est passé de la valeur "%s" à "%s" coser.business.common.length=Taille coser.business.common.number=Nombre Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/Coser.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/Coser.java 2011-12-21 10:41:47 UTC (rev 923) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/Coser.java 2011-12-22 13:56:04 UTC (rev 924) @@ -40,6 +40,7 @@ import com.bbn.openmap.MapBean; +import fr.ifremer.coser.services.CommandService; import fr.ifremer.coser.services.ControlService; import fr.ifremer.coser.services.ImportService; import fr.ifremer.coser.services.ProjectService; @@ -146,6 +147,7 @@ context.setContextValue(session); context.setContextValue(new ProjectService(coserConfig)); context.setContextValue(new ImportService(coserConfig)); + context.setContextValue(new CommandService(coserConfig)); context.setContextValue(new ControlService(coserConfig)); context.setContextValue(new PublicationService(coserConfig)); context.setContextValue(new WebService(coserConfig)); 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 2011-12-21 10:41:47 UTC (rev 923) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/CoserFrameHandler.java 2011-12-22 13:56:04 UTC (rev 924) @@ -36,7 +36,6 @@ import java.net.URI; import java.util.Locale; -import javax.swing.JFileChooser; import javax.swing.JOptionPane; import javax.swing.JScrollPane; import javax.swing.JTextArea; @@ -73,6 +72,8 @@ import fr.ifremer.coser.ui.result.SelectUploadResultView; import fr.ifremer.coser.ui.selection.SelectionHandler; import fr.ifremer.coser.ui.selection.SelectionView; +import fr.ifremer.coser.ui.selection.replay.SelectionReplayHandler; +import fr.ifremer.coser.ui.selection.replay.SelectionReplayView; import fr.ifremer.coser.ui.widgets.LookAndFeelViewMenuItem; /** @@ -427,10 +428,37 @@ ProjectService projectService = view.getContextValue(ProjectService.class); Project project = view.getContextValue(Project.class); Selection selection = project.getSelections().get(selectionName); - + setWaitCursor(view); try { project = projectService.loadSelectionData(project, selection); + + // fix la restauration de la selection + // seule le 1er onglet doit etre selectionné + // sinon, le SwingSession remettra celui à la fermeture + showSelectionView(selection, 0); + + } catch (CoserBusinessException ex) { + throw new CoserException("Can't reload selection data", ex); + } + finally { + setDefaultCursor(view); + } + } + + /** + * Show selection view to open selection. + * + * Used in selection replay. Selection already exists and is already loaded + * into memory. + * + * @param selection selection to open + * @param selectedTab onglet a selectionner apres l'ouverture + */ + public void showSelectionView(Selection selection, int selectedTab) { + + setWaitCursor(view); + try { view.setContextValue(selection); SelectionView selectionView = new SelectionView(view); @@ -438,7 +466,7 @@ // fix, binding not working ? selectionView.getSelectionDetailsTab().getValidatorSelection().setBean(selection); - + SelectionHandler handler = new SelectionHandler(); selectionView.setHandler(handler); handler.initView(selectionView.getSelectionDetailsTab()); @@ -448,13 +476,10 @@ SwingSession session = (SwingSession)view.getContextValue(SwingSession.class); session.add(selectionView); - // fix la restauration de la selection - // seule le 1er onglet doit etre selectionné - selectionView.setSelectedIndex(0); + // selection du bon onglet + selectionView.setSelectedIndex(selectedTab); setMainComponent(selectionView); - } catch (CoserBusinessException ex) { - throw new CoserException("Can't reload selection data", ex); } finally { setDefaultCursor(view); @@ -486,51 +511,11 @@ * Apply it, and display report to user. */ public void replaySelection() { - - ProjectService projectService = view.getContextValue(ProjectService.class); - Project project = view.getContextValue(Project.class); - CoserConfig config = view.getContextValue(CoserConfig.class); - - JFileChooser selectionChooser = new JFileChooser(config.getProjectsDirectory()); - selectionChooser.setFileFilter(new SelectionFileFilter()); - selectionChooser.setMultiSelectionEnabled(false); - - int result = selectionChooser.showOpenDialog(view); - if (result == JFileChooser.APPROVE_OPTION) { - File selectionFile = selectionChooser.getSelectedFile(); - - try { - Selection selection = projectService.initProjectSelectionFromFile(project, selectionFile); - - view.setContextValue(selection); - - SelectionView selectionView = new SelectionView(view); - selectionView.setSelection(selection); - // fix, binding not working ? - selectionView.getSelectionDetailsTab().getValidatorSelection().setBean(selection); - - SelectionHandler handler = new SelectionHandler(); - selectionView.setHandler(handler); - handler.initView(selectionView.getSelectionDetailsTab()); - // FIXME chatellier 20101126 il faut faire un mix de init && reload - handler.initSelection(selectionView); - - // restore session size - SwingSession session = (SwingSession)view.getContextValue(SwingSession.class); - session.add(selectionView); - - // fix la restauration de la selection - // seule le 1er onglet doit etre selectionné - selectionView.setSelectedIndex(0); - - setMainComponent(selectionView); - } - catch (Exception ex) { - JOptionPane.showMessageDialog(view, ex.getMessage(), - _("coser.ui.selection.replayerror"), JOptionPane.ERROR_MESSAGE); - throw new CoserException("Can't replay selection", ex); - } - } + SelectionReplayView replayView = new SelectionReplayView((JAXXContext)view); + SelectionReplayHandler handler = replayView.getHandler(); + handler.initReplayView(replayView); + replayView.setLocationRelativeTo(view); + replayView.setVisible(true); } /** Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/SelectionsListMenuItem.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/SelectionsListMenuItem.java 2011-12-21 10:41:47 UTC (rev 923) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/SelectionsListMenuItem.java 2011-12-22 13:56:04 UTC (rev 924) @@ -130,14 +130,13 @@ newMenuItem.addActionListener(this); add(newMenuItem); - /* replay selection - chatellier disabled since 20110315 never implemented + // replay selection JMenuItem replayMenuItem = new JMenuItem(_("coser.ui.mainframe.menu.data.replaySelection")); // les chaines ne doivent pas poser pb, on ne peut pas // avoir de selection avec espace replayMenuItem.setActionCommand("replay selection"); replayMenuItem.addActionListener(this); - add(replayMenuItem);*/ + add(replayMenuItem); } } } 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 2011-12-21 10:41:47 UTC (rev 923) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionDetailsView.jaxx 2011-12-22 13:56:04 UTC (rev 924) @@ -43,7 +43,7 @@ selectedSpeciesListModel.addListDataListener((CoserListSelectionModel)selectedSpeciesList.getSelectionModel()); } ]]></script> - + <SelectionHandler id="handler" javaBean="null" /> <Boolean id="creationState" javaBean="false" /> @@ -59,7 +59,7 @@ uiClass="jaxx.runtime.validator.swing.ui.ImageValidationUI" errorTableModel="errorsTableModel"> <field name="name" component="detailsSelectionNameField" /> - <field name="description" component="detailsDescription" /> + <field name="description" component="detailsDescriptionSP" /> </BeanValidator> <row> @@ -98,7 +98,7 @@ <JLabel text="coser.ui.selection.details.description" /> </cell> <cell weightx="1" fill="horizontal" columns="3"> - <JScrollPane> + <JScrollPane id="detailsDescriptionSP"> <JTextArea id="detailsDescription" text="{getSelection().getDescription()}" rows="3" /> </JScrollPane> <javax.swing.text.Document javaBean="detailsDescription.getDocument()" @@ -111,7 +111,7 @@ <JLabel text="coser.ui.selection.details.comment" /> </cell> <cell anchor="north" fill="horizontal" weighty="1" columns="3"> - <JScrollPane> + <JScrollPane id="detailsCommentSP"> <JTextArea id="detailsComment" text="{getSelection().getComment()}" rows="3" /> <javax.swing.text.Document javaBean="detailsComment.getDocument()" onInsertUpdate='getSelection().setComment(detailsComment.getText())' 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 2011-12-21 10:41:47 UTC (rev 923) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionHandler.java 2011-12-22 13:56:04 UTC (rev 924) @@ -732,19 +732,19 @@ public void saveSelection(SelectionDetailsView view) { Project project = view.getContextValue(Project.class); Selection selection = view.getContextValue(Selection.class); - ProjectService service = view.getContextValue(ProjectService.class); + ProjectService projectService = view.getContextValue(ProjectService.class); SelectionView selectionView = view.getParentContainer(SelectionView.class); try { if (view.isCreationState()) { - service.createProjectSelection(project, selection); + projectService.createProjectSelection(project, selection); selectionView.setCreationState(false); JOptionPane.showMessageDialog(view, _("coser.ui.selection.selectionCreated"), _("coser.ui.selection.selectionTitle"), JOptionPane.INFORMATION_MESSAGE); } else { - service.saveProjectSelection(project, selection); + projectService.saveProjectSelection(project, selection); JOptionPane.showMessageDialog(view, _("coser.ui.selection.selectionSaved"), _("coser.ui.selection.selectionTitle"), JOptionPane.INFORMATION_MESSAGE); Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionRsufiView.jaxx =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionRsufiView.jaxx 2011-12-21 10:41:47 UTC (rev 923) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionRsufiView.jaxx 2011-12-22 13:56:04 UTC (rev 924) @@ -31,7 +31,7 @@ ]]></script> <SelectionHandler id="handler" javaBean="null" /> <row> - <cell weightx="1" fill="horizontal" > + <cell weightx="1" fill="horizontal"> <Table border='{BorderFactory.createTitledBorder(_("coser.ui.result.extractDataTitle"))}'> <row> <cell> Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/model/MaturitySpeciesListModel.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/model/MaturitySpeciesListModel.java 2011-12-21 10:41:47 UTC (rev 923) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/model/MaturitySpeciesListModel.java 2011-12-22 13:56:04 UTC (rev 924) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2010 Ifremer, Codelutin, Chatellier Eric + * Copyright (C) 2010 - 2011 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 Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/model/SpeciesTypesListModel.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/model/SpeciesTypesListModel.java 2011-12-21 10:41:47 UTC (rev 923) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/model/SpeciesTypesListModel.java 2011-12-22 13:56:04 UTC (rev 924) @@ -3,7 +3,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2010 Ifremer, Codelutin, Chatellier Eric + * Copyright (C) 2010 - 2011 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 @@ -55,7 +55,6 @@ protected Map<String, String> typesComments; public SpeciesTypesListModel(SelectionDetailsView view) { - super(); this.view = view; } Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/model/YearListModel.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/model/YearListModel.java 2011-12-21 10:41:47 UTC (rev 923) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/model/YearListModel.java 2011-12-22 13:56:04 UTC (rev 924) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2010 Ifremer, Codelutin, Chatellier Eric + * Copyright (C) 2010 - 2011 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 @@ -48,16 +48,13 @@ protected List<String> years; - public YearListModel() { - super(); - } - public List<String> getYears() { return years; } public void setYears(List<String> years) { this.years = years; + fireContentsChanged(this, 0, years.size()); } /* Added: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/replay/CommandListModel.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/replay/CommandListModel.java (rev 0) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/replay/CommandListModel.java 2011-12-22 13:56:04 UTC (rev 924) @@ -0,0 +1,79 @@ +/* + * #%L + * Coser :: UI + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 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.replay; + +import java.util.ArrayList; +import java.util.List; + +import javax.swing.AbstractListModel; + +import fr.ifremer.coser.command.Command; + +/** + * Command model. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class CommandListModel extends AbstractListModel { + + /** serialVersionUID. */ + private static final long serialVersionUID = -4769109927915812519L; + + protected List<Command> commands = new ArrayList<Command>(); + + public List<Command> getCommands() { + return commands; + } + + public void setCommands(List<Command> commands) { + this.commands = commands; + fireContentsChanged(this, 0, commands.size()); + } + + /* + * @see javax.swing.ListModel#getSize() + */ + @Override + public int getSize() { + int result = 0; + if (commands != null) { + result = commands.size(); + } + return result; + } + + /* + * @see javax.swing.ListModel#getElementAt(int) + */ + @Override + public Object getElementAt(int index) { + return commands.get(index); + } +} Property changes on: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/replay/CommandListModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/replay/CommandListRenderer.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/replay/CommandListRenderer.java (rev 0) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/replay/CommandListRenderer.java 2011-12-22 13:56:04 UTC (rev 924) @@ -0,0 +1,62 @@ +/* + * #%L + * + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 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.replay; + +import java.awt.Component; + +import javax.swing.DefaultListCellRenderer; +import javax.swing.JList; + +import fr.ifremer.coser.command.Command; + +/** + * List cell renderer for command (display command description). + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class CommandListRenderer extends DefaultListCellRenderer { + + /** serialVersionUID. */ + private static final long serialVersionUID = 6780656602646606040L; + + @Override + public Component getListCellRendererComponent(JList list, Object value, + int index, boolean isSelected, boolean cellHasFocus) { + + Command command = (Command)value; + + // can be null here. Renderer is currently used only un selection + // replay where merge command don't use container to get desc + String commandDesc = command.getDescription(null); + + return super.getListCellRendererComponent(list, commandDesc, index, + isSelected, cellHasFocus); + } +} Property changes on: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/replay/CommandListRenderer.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/replay/SelectionByProjectTreeModel.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/replay/SelectionByProjectTreeModel.java (rev 0) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/replay/SelectionByProjectTreeModel.java 2011-12-22 13:56:04 UTC (rev 924) @@ -0,0 +1,124 @@ +/* + * #%L + * + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 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.replay; + +import java.util.ArrayList; +import java.util.List; +import java.util.SortedMap; + +import javax.swing.event.TreeModelListener; +import javax.swing.tree.TreeModel; +import javax.swing.tree.TreePath; + +/** + * TreeModel that display all selections in all projects. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class SelectionByProjectTreeModel implements TreeModel { + + protected SortedMap<String, List<String>> selectionsByProject; + protected List<String> projects; + + public SelectionByProjectTreeModel(SortedMap<String, List<String>> selectionsByProject) { + this.selectionsByProject = selectionsByProject; + this.projects = new ArrayList<String>(selectionsByProject.keySet()); + } + + @Override + public Object getRoot() { + return "root"; + } + + @Override + public Object getChild(Object parent, int index) { + + Object child = null; + + if (parent == getRoot()) { + child = projects.get(index); + } else if (parent instanceof String) { + if (projects.contains(parent)) { + child = selectionsByProject.get(parent).get(index); + } + } + + return child; + } + + @Override + public int getChildCount(Object parent) { + + int count = 0; + + if (parent == getRoot()) { + count = projects.size(); + } else if (parent instanceof String) { + if (projects.contains(parent)) { + count = selectionsByProject.get(parent).size(); + } + } + + return count; + } + + @Override + public boolean isLeaf(Object node) { + return getChildCount(node) == 0; + } + + @Override + public void valueForPathChanged(TreePath path, Object newValue) { + + } + + @Override + public int getIndexOfChild(Object parent, Object child) { + int indexOf = -1; + if (parent == getRoot()) { + indexOf = projects.indexOf(child); + } else if (parent instanceof String) { + if (projects.contains(parent)) { + indexOf = selectionsByProject.get(parent).indexOf(child); + } + } + return indexOf; + } + + @Override + public void addTreeModelListener(TreeModelListener l) { + + } + + @Override + public void removeTreeModelListener(TreeModelListener l) { + + } +} Property changes on: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/replay/SelectionByProjectTreeModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/replay/SelectionReplayHandler.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/replay/SelectionReplayHandler.java (rev 0) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/replay/SelectionReplayHandler.java 2011-12-22 13:56:04 UTC (rev 924) @@ -0,0 +1,391 @@ +/* + * #%L + * + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 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.replay; + +import static org.nuiton.i18n.I18n._; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.SortedMap; + +import javax.swing.JOptionPane; +import javax.swing.tree.TreePath; + +import jaxx.runtime.JAXXUtil; + +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import fr.ifremer.coser.CoserBusinessException; +import fr.ifremer.coser.CoserException; +import fr.ifremer.coser.bean.Project; +import fr.ifremer.coser.bean.Selection; +import fr.ifremer.coser.command.Command; +import fr.ifremer.coser.services.CommandService; +import fr.ifremer.coser.services.ProjectService; +import fr.ifremer.coser.ui.CoserFrame; +import fr.ifremer.coser.ui.common.CommonHandler; +import fr.ifremer.coser.ui.util.CoserListSelectionModel; + +/** + * Specific handler for selection replay view. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class SelectionReplayHandler extends CommonHandler { + + private static final Log log = LogFactory.getLog(SelectionReplayHandler.class); + + /** + * Init view by displaying all selection available in all project. + * + * @param view view to init + */ + public void initReplayView(SelectionReplayView view) { + ProjectService projectService = view.getContextValue(ProjectService.class); + SortedMap<String, List<String>> selectionsByProject = projectService.getSelectionByProject(); + + SelectionByProjectTreeModel treeModel = new SelectionByProjectTreeModel(selectionsByProject); + view.getSelectionByProjectTree().setModel(treeModel); + } + + /** + * Validation de la selection a rejouer (etape 1). + * + * @param view view + */ + public void validSelectionChoice(SelectionReplayView view) { + ProjectService projectService = view.getContextValue(ProjectService.class); + Project project = view.getContextValue(Project.class); + TreePath selectedSelection = view.getSelectionByProjectTree().getSelectionPath(); + + try { + setWaitCursor(view); + + String selectionName = (String)selectedSelection.getLastPathComponent(); + String projectName = (String)selectedSelection.getParentPath().getLastPathComponent(); + + // load selection + Selection replayedSelection = projectService.openSelection(projectName, selectionName); + view.setReplayedSelection(replayedSelection); + + // load current new selection + Selection selection = projectService.initProjectSelection(project); + view.setSelection(selection); + // hack, binding won't work + view.getValidatorSelection().setBean(selection); + + // init next step + view.getYearsListModel().setYears(selection.getAllYears()); + ((CoserListSelectionModel)view.getYearsList().getSelectionModel()).setSelectedObjects(replayedSelection.getSelectedYears()); + + // affichage d'un message si la selection de liste n'est pas + // cohérente + Collection<String> remaindYear = CollectionUtils.subtract(replayedSelection.getSelectedYears(), selection.getAllYears()); + if (!remaindYear.isEmpty()) { + String yearsAsString = StringUtils.join(remaindYear, ", "); + String message = _("coser.ui.selection.replay.missingyears", yearsAsString); + view.getMessageArea2().setText(message); + } + + view.getWizardLayout().show(view.getWizardPanel(), "step2"); + } catch (CoserBusinessException ex) { + throw new CoserException("Can't load selection properties", ex); + } finally { + setDefaultCursor(view); + } + } + + /** + * Validation des années sélectionnées (etape 2) + * + * @param view view + */ + public void validSelectionYears(SelectionReplayView view) { + ProjectService projectService = view.getContextValue(ProjectService.class); + Project project = view.getContextValue(Project.class); + Selection selection = view.getSelection(); + Selection replayedSelection = view.getReplayedSelection(); + + try { + setWaitCursor(view); + + // get selected zones as list + Object[] selectedDates = view.getYearsList().getSelectedValues(); + List<String> years = new ArrayList<String>(selectedDates.length); + for (Object selectedDate : selectedDates) { + years.add((String)selectedDate); + } + + if (log.isDebugEnabled()) { + log.debug("Refreshing strata list"); + } + + // filterDataYearsAndGetStrata do selection.setSelectedYears(years); + // don't set yourself + List<String> strata = projectService.filterDataYearsAndGetStrata(project, selection, years); + view.getStrataListModel().setStrata(strata); + + ((CoserListSelectionModel)view.getStrataList().getSelectionModel()).setSelectedObjects(replayedSelection.getSelectedStrata()); + + if (log.isDebugEnabled()) { + log.debug("Strata list refreshed"); + } + + // affichage d'un message si la selection de liste n'est pas + // cohérente + Collection<String> remaindStrata = CollectionUtils.subtract(replayedSelection.getSelectedStrata(), strata); + if (!remaindStrata.isEmpty()) { + String strataAsString = StringUtils.join(remaindStrata, ", "); + String message = _("coser.ui.selection.replay.missingstrata", strataAsString); + view.getMessageArea3().setText(message); + } + + view.getWizardLayout().show(view.getWizardPanel(), "step3"); + + } catch (CoserBusinessException ex) { + throw new CoserException("Can't save selected years", ex); + } finally { + setDefaultCursor(view); + } + } + + /** + * Validation des strates (étape 3). + * + * @param view view + */ + public void validSelectionStrata(SelectionReplayView view) { + ProjectService projectService = view.getContextValue(ProjectService.class); + Project project = view.getContextValue(Project.class); + Selection selection = view.getSelection(); + Selection replayedSelection = view.getReplayedSelection(); + + try { + setWaitCursor(view); + + if (log.isDebugEnabled()) { + log.debug("Strata list selection changed, updating species list"); + } + + // get selected zones as list + Object[] selectedStrata = view.getStrataList().getSelectedValues(); + List<String> strata = new ArrayList<String>(selectedStrata.length); + for (Object selectedStratum : selectedStrata) { + strata.add((String)selectedStratum); + } + + // do selection.setSelectedStrata(strata); + projectService.filterDataStrata(project, selection, strata); + + // init next step + List<Command> commands = replayedSelection.getHistoryCommand(); + if (CollectionUtils.isNotEmpty(commands)) { + view.getCommandListModel().setCommands(commands); + view.getWizardLayout().show(view.getWizardPanel(), "step4"); + } else { + // appel de la prochaine etape pour initialiser la liste + validSelectionCommand(view); + } + + } finally { + setDefaultCursor(view); + } + } + + /** + * Validation des commands (fusion, etc...). + * + * @param view view + */ + public void validSelectionCommand(SelectionReplayView view) { + ProjectService projectService = view.getContextValue(ProjectService.class); + CommandService commandService = view.getContextValue(CommandService.class); + Project project = view.getContextValue(Project.class); + Selection selection = view.getSelection(); + Selection replayedSelection = view.getReplayedSelection(); + + try { + setWaitCursor(view); + + // replay all commands + List<Command> commands = view.getCommandListModel().getCommands(); + if (commands != null) { // can be + for (Command command : commands) { + if (log.isDebugEnabled()) { + log.debug("Replay command " + command); + } + commandService.doAction(command, project, selection); + } + } + + // init next step + List<String> currentSpecies = projectService.getProjectSpecies(project, selection, null); + view.getSelectedSpeciesListModel().setSpecies(currentSpecies); + ((CoserListSelectionModel)view.getSelectedSpeciesList().getSelectionModel()).setSelectedObjects(replayedSelection.getSelectedSpecies()); + + // affichage d'un message si la selection de liste n'est pas + // cohérente + Collection<String> remaindSpecies = CollectionUtils.subtract(replayedSelection.getSelectedSpecies(), currentSpecies); + if (!remaindSpecies.isEmpty()) { + String speciesAsString = StringUtils.join(remaindSpecies, ", "); + String message = _("coser.ui.selection.replay.missingspecies", speciesAsString); + view.getMessageArea5().setText(message); + } + + view.getWizardLayout().show(view.getWizardPanel(), "step5"); + + } catch (CoserBusinessException ex) { + throw new CoserException("Can't replay species merge command", ex); + } finally { + setDefaultCursor(view); + } + } + + /** + * Validation des strates. + * + * @param view view + */ + public void validSelectionSpecies(SelectionReplayView view) { + ProjectService projectService = view.getContextValue(ProjectService.class); + Project project = view.getContextValue(Project.class); + Selection selection = view.getSelection(); + + try { + setWaitCursor(view); + + // get selected species + // get selected zones as list + Object[] selectedSpeciesArr = view.getSelectedSpeciesList().getSelectedValues(); + List<String> selectedSpecies = new ArrayList<String>(selectedSpeciesArr.length); + for (Object selectedSingleSpecies : selectedSpeciesArr) { + selectedSpecies.add((String)selectedSingleSpecies); + } + projectService.filterDataSpecies(project, selection, selectedSpecies); + + // init next step + view.getWizardLayout().show(view.getWizardPanel(), "step6"); + + } finally { + setDefaultCursor(view); + } + } + + /** + * Validation finale de la selection. + * + * @param view view + */ + public void validSelectionInfos(SelectionReplayView view) { + ProjectService projectService = view.getContextValue(ProjectService.class); + Project project = view.getContextValue(Project.class); + Selection selection = view.getSelection(); + + try { + setWaitCursor(view); + + projectService.createProjectSelection(project, selection); + + // autochargement de la selection dans la fenetre parente + CoserFrame parent = view.getContextValue(CoserFrame.class, JAXXUtil.PARENT); + // autoselection de l'onglet "listes" + parent.getHandler().showSelectionView(selection, 1); + + JOptionPane.showMessageDialog(view, _("coser.ui.selection.selectionCreated"), + _("coser.ui.selection.replay.replayTitle"), JOptionPane.INFORMATION_MESSAGE); + + // hide current frame + view.dispose(); + + } catch (CoserBusinessException ex) { + if (log.isErrorEnabled()) { + log.error("Can't save selection", ex); + } + JOptionPane.showMessageDialog(view, ex.getMessage(), _("coser.ui.selection.saveError"), + JOptionPane.ERROR_MESSAGE); + } finally { + setDefaultCursor(view); + } + } + + /** + * Validation des étapes 1 a la dernière. + * + * @param view view + */ + public void finishSelection1toFinal(SelectionReplayView view) { + validSelectionChoice(view); + finishSelection2toFinal(view); + } + + /** + * Validation des étapes 2 a la dernière. + * + * @param view view + */ + public void finishSelection2toFinal(SelectionReplayView view) { + validSelectionYears(view); + finishSelection3toFinal(view); + } + + /** + * Validation des étapes 3 a la dernière. + * + * @param view view + */ + public void finishSelection3toFinal(SelectionReplayView view) { + validSelectionStrata(view); + finishSelection4toFinal(view); + } + + /** + * Validation des étapes 4 a la dernière. + * + * @param view view + */ + public void finishSelection4toFinal(SelectionReplayView view) { + validSelectionCommand(view); + finishSelection5toFinal(view); + } + + /** + * Validation des étapes 5 a la dernière. + * (ne valide pas la dernière : infos de selection obligatoires) + * + * @param view view + */ + public void finishSelection5toFinal(SelectionReplayView view) { + validSelectionSpecies(view); + } +} Property changes on: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/replay/SelectionReplayHandler.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/replay/SelectionReplayView.jaxx =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/replay/SelectionReplayView.jaxx (rev 0) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/replay/SelectionReplayView.jaxx 2011-12-22 13:56:04 UTC (rev 924) @@ -0,0 +1,284 @@ +<JDialog title="coser.ui.selection.replay.replayTitle" width="500" height="450"> + + <import> + fr.ifremer.coser.ui.selection.model.SpeciesListModel + fr.ifremer.coser.ui.selection.model.SpeciesTypesListModel + fr.ifremer.coser.ui.selection.model.StrataListModel + fr.ifremer.coser.ui.selection.model.YearListModel + fr.ifremer.coser.ui.util.CoserListSelectionModel + </import> + + <Table> + <SelectionReplayHandler id="handler" /> + <fr.ifremer.coser.bean.Selection id="selection" javaBean="null" /> + <fr.ifremer.coser.bean.Selection id="replayedSelection" javaBean="null" /> + + <jaxx.runtime.validator.swing.SwingValidatorMessageTableModel id='errorsTableModel' + onTableChanged='validSelectionInfosButton.setEnabled(getErrorsTableModel().getRowCount() == 0)'/> + <BeanValidator id='validatorSelection' bean='selection' + uiClass="jaxx.runtime.validator.swing.ui.ImageValidationUI" + errorTableModel="errorsTableModel"> + <field name="name" component="detailsSelectionNameField" /> + <field name="description" component="detailsDescriptionSP" /> + </BeanValidator> + + <row> + <cell weightx="1" weighty="1" fill="both"> + <CardLayout id="wizardLayout" /> + <JPanel id="wizardPanel" layout="{wizardLayout}"> + + <!-- Step 1 : selection choice --> + <Table constraints='"step1"'> + <row> + <cell weightx="1" fill="horizontal" columns="3"> + <JLabel text="coser.ui.selection.replay.chooseselection" /> + </cell> + </row> + <row> + <cell weightx="1" weighty="1" fill="both" columns="3"> + <JScrollPane> + <JTree id="selectionByProjectTree" rootVisible="false" showsRootHandles="true" + onValueChanged="validSelectionButton.setEnabled(selectionByProjectTree.getSelectionPath() != null && selectionByProjectTree.getSelectionPath().getPathCount() == 3);"/> + </JScrollPane> + </cell> + </row> + <row> + <cell weightx="1" fill="horizontal" columns="3"> + <JTextArea id="messageArea1" rows="3" editable="false" /> + </cell> + </row> + <row> + <cell weightx="1" anchor="west"> + <JButton text="coser.ui.common.cancel" + onActionPerformed="dispose()" /> + </cell> + <cell weightx="1" anchor="east"> + <JButton id="validSelectionButton" text="coser.ui.common.next" + enabled="false" + onActionPerformed="getHandler().validSelectionChoice(this)" /> + </cell> + <cell> + <JButton text="coser.ui.common.finish" + enabled="{validSelectionButton.isEnabled()}" + onActionPerformed="getHandler().finishSelection1toFinal(this)" /> + </cell> + </row> + </Table> + + <!-- Step 2 : Year choice --> + <Table constraints='"step2"'> + <row> + <cell weightx="1" fill="horizontal" columns="3"> + <JLabel text="coser.ui.selection.replay.chooseyears" /> + </cell> + </row> + <row> + <cell weightx="1" weighty="1" fill="both" columns="3"> + <JScrollPane> + <YearListModel id="yearsListModel" /> + <JList id="yearsList" model="{yearsListModel}" + selectionModel="{new CoserListSelectionModel(yearsList.getSelectionModel(), yearsListModel)}" + onValueChanged="validYearsButton.setEnabled(yearsList.getSelectedIndex() != -1)"/> + </JScrollPane> + </cell> + </row> + <row> + <cell weightx="1" fill="horizontal" columns="3"> + <JTextArea id="messageArea2" rows="3" editable="false" /> + </cell> + </row> + <row> + <cell weightx="1" anchor="west"> + <JButton text="coser.ui.common.cancel" + onActionPerformed="dispose()" /> + </cell> + <cell weightx="1" anchor="east"> + <JButton id="validYearsButton" text="coser.ui.common.next" + enabled="false" + onActionPerformed="getHandler().validSelectionYears(this)" /> + </cell> + <cell> + <JButton text="coser.ui.common.finish" + enabled="{validYearsButton.isEnabled()}" + onActionPerformed="getHandler().finishSelection2toFinal(this)" /> + </cell> + </row> + </Table> + + <!-- Step 3 : Strata choice --> + <Table constraints='"step3"'> + <row> + <cell weightx="1" fill="horizontal" columns="3"> + <JLabel text="coser.ui.selection.replay.choosestrata" /> + </cell> + </row> + <row> + <cell weightx="1" weighty="1" fill="both" columns="3"> + <JScrollPane> + <StrataListModel id="strataListModel" /> + <JList id="strataList" model="{strataListModel}" + selectionModel="{new CoserListSelectionModel(strataList.getSelectionModel(), strataListModel)}" + onValueChanged='validStrataButton.setEnabled(strataList.getSelectedIndex() != -1)'/> + </JScrollPane> + </cell> + </row> + <row> + <cell weightx="1" fill="horizontal" columns="3"> + <JTextArea id="messageArea3" rows="3" editable="false" /> + </cell> + </row> + <row> + <cell weightx="1" anchor="west"> + <JButton text="coser.ui.common.cancel" + onActionPerformed="dispose()" /> + </cell> + <cell weightx="1" anchor="east"> + <JButton id="validStrataButton" text="coser.ui.common.next" + enabled="false" + onActionPerformed="getHandler().validSelectionStrata(this)" /> + </cell> + <cell> + <JButton text="coser.ui.common.finish" + enabled="{validStrataButton.isEnabled()}" + onActionPerformed="getHandler().finishSelection3toFinal(this)" /> + </cell> + </row> + </Table> + + <!-- Step 4 : Data modification --> + <Table constraints='"step4"'> + <row> + <cell weightx="1" fill="horizontal" columns="3"> + <JLabel text="coser.ui.selection.replay.commands" /> + </cell> + </row> + <row> + <cell weightx="1" weighty="1" fill="both" columns="3"> + <JScrollPane> + <fr.ifremer.coser.ui.selection.replay.CommandListModel id="commandListModel" /> + <JList id="commandList" model="{commandListModel}" + cellRenderer="{new fr.ifremer.coser.ui.selection.replay.CommandListRenderer()}"/> + </JScrollPane> + </cell> + </row> + <row> + <cell weightx="1" fill="horizontal" columns="3"> + <JTextArea id="messageArea4" rows="3" editable="false" /> + </cell> + </row> + <row> + <cell weightx="1" anchor="west"> + <JButton text="coser.ui.common.cancel" + onActionPerformed="dispose()" /> + </cell> + <cell weightx="1" anchor="east"> + <JButton id="validCommandButton" text="coser.ui.common.next" + onActionPerformed="getHandler().validSelectionCommand(this)" /> + </cell> + <cell> + <JButton text="coser.ui.common.finish" + enabled="{validCommandButton.isEnabled()}" + onActionPerformed="getHandler().finishSelection4toFinal(this)" /> + </cell> + </row> + </Table> + + <!-- Step 5 : Species selection --> + <Table constraints='"step5"'> + <row> + <cell weightx="1" fill="horizontal" columns="3"> + <JLabel text="coser.ui.selection.replay.choosespecies" /> + </cell> + </row> + <row> + <cell weightx="1" weighty="1" fill="both" columns="3"> + <JScrollPane> + <SpeciesListModel id="selectedSpeciesListModel" /> + <JList id="selectedSpeciesList" model="{selectedSpeciesListModel}" + selectionModel="{new CoserListSelectionModel(selectedSpeciesList.getSelectionModel(), selectedSpeciesListModel)}" + onValueChanged='validSpeciesButton.setEnabled(selectedSpeciesList.getSelectedIndex() != -1)'/> + </JScrollPane> + </cell> + </row> + <row> + <cell weightx="1" fill="horizontal" columns="3"> + <JTextArea id="messageArea5" rows="3" editable="false" /> + </cell> + </row> + <row> + <cell weightx="1" anchor="west"> + <JButton text="coser.ui.common.cancel" + onActionPerformed="dispose()" /> + </cell> + <cell weightx="1" anchor="east"> + <JButton id="validSpeciesButton" text="coser.ui.common.next" + enabled="false" + onActionPerformed="getHandler().validSelectionSpecies(this)" /> + </cell> + <cell> + <JButton text="coser.ui.common.finish" + enabled="{validSpeciesButton.isEnabled()}" + onActionPerformed="getHandler().finishSelection5toFinal(this)" /> + </cell> + </row> + </Table> + + <!-- Step 6 : Final name & description --> + <Table constraints='"step6"'> + <row weightx="1" fill="horizontal" columns="2"> + <cell><JLabel text="coser.ui.selection.replay.selectioninfos" /></cell> + </row> + <row> + <cell anchor="west"> + <JLabel text="coser.ui.selection.details.name" /> + </cell> + <cell weightx="1" fill="horizontal"> + <JTextField id="detailsSelectionNameField" text="{getSelection().getName()}" /> + <javax.swing.text.Document javaBean="detailsSelectionNameField.getDocument()" + onInsertUpdate='getSelection().setName(detailsSelectionNameField.getText())' + onRemoveUpdate='getSelection().setName(detailsSelectionNameField.getText())' /> + </cell> + </row> + <row> + <cell anchor="west"> + <JLabel text="coser.ui.selection.details.description" /> + </cell> + <cell weightx="1" fill="horizontal"> + <JScrollPane id="detailsDescriptionSP"> + <JTextArea id="detailsDescription" text="{getSelection().getDescription()}" rows="3" /> + </JScrollPane> + <javax.swing.text.Document javaBean="detailsDescription.getDocument()" + onInsertUpdate='getSelection().setDescription(detailsDescription.getText())' + onRemoveUpdate='getSelection().setDescription(detailsDescription.getText())' /> + </cell> + </row> + <row> + <cell anchor="northwest"> + <JLabel text="coser.ui.selection.details.comment" /> + </cell> + <cell anchor="north" fill="horizontal" weighty="1"> + <JScrollPane> + <JTextArea id="detailsComment" text="{getSelection().getComment()}" rows="3" /> + <javax.swing.text.Document javaBean="detailsComment.getDocument()" + onInsertUpdate='getSelection().setComment(detailsComment.getText())' + onRemoveUpdate='getSelection().setComment(detailsComment.getText())' /> + </JScrollPane> + </cell> + </row> + <row> + <cell anchor="west"> + <JButton text="coser.ui.common.cancel" + onActionPerformed="dispose()" /> + </cell> + <cell anchor="east"> + <JButton id="validSelectionInfosButton" text="coser.ui.selection.details.saveSelection" + enabled="false" + onActionPerformed="getHandler().validSelectionInfos(this)" /> + </cell> + </row> + </Table> + </JPanel> + </cell> + </row> + </Table> +</JDialog> \ No newline at end of file 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 2011-12-21 10:41:47 UTC (rev 923) +++ trunk/coser-ui/src/main/resources/i18n/coser-ui_en_GB.properties 2011-12-22 13:56:04 UTC (rev 924) @@ -7,6 +7,8 @@ coser.ui.about.about=<html><b>Coser</b><br /><br />Version %s<br /><br />Usefull links \:<ul><li><a href\="http\://maven-site.forge.codelutin.com/coser/">Documentation</a></li><li><a href\="http\://forge.codelutin.com/projects/coser/issues">Bug report</a></li></ul><br /><br />Copyright 2010 - 2011 <a href\="http\://www.ifremer.fr">Ifremer</a>, <a href\="http\://www.codelutin.com">Code Lutin</a><html> coser.ui.about.title=About Coser coser.ui.common.cancel=Cancel +coser.ui.common.finish=Finish +coser.ui.common.next=Next coser.ui.common.no=No coser.ui.common.selectAll=Select all coser.ui.common.selectAll.short=All @@ -213,7 +215,16 @@ coser.ui.selection.occurrenceDensitySpecies=L2 \: Filtered species (%d/%d) coser.ui.selection.occurrencedensityrenderer=<html>%s<span style\='font-size\:85%%;color\:gray;'>(Occ\=%.2f, Dens\=%.2f)</span></html> coser.ui.selection.reloadcontroldata=Reload controled data -coser.ui.selection.replayerror=Replay error +coser.ui.selection.replay.chooseselection=Choose selection to replay \: +coser.ui.selection.replay.choosespecies=Choose species to keep \: +coser.ui.selection.replay.choosestrata=Choose strata to keep \: +coser.ui.selection.replay.chooseyears=Choose years to keep \: +coser.ui.selection.replay.commands=Command list to replay \: +coser.ui.selection.replay.missingspecies=Some species are missing in current selection \: %s +coser.ui.selection.replay.missingstrata=Some strata are missing in current selection \: %s +coser.ui.selection.replay.missingyears=Some years are missing in current selection \: %s +coser.ui.selection.replay.replayTitle=Replay selection +coser.ui.selection.replay.selectioninfos=Selection information \: coser.ui.selection.rsufidataextracted=RSufi data extracted. coser.ui.selection.saveError=Save error coser.ui.selection.selection.requiredDescription=Selection description is required 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 2011-12-21 10:41:47 UTC (rev 923) +++ trunk/coser-ui/src/main/resources/i18n/coser-ui_fr_FR.properties 2011-12-22 13:56:04 UTC (rev 924) @@ -7,6 +7,8 @@ coser.ui.about.about=<html><b>Coser</b><br /><br />Version %s<br /><br />Liens utiles \:<ul><li><a href\="http\://maven-site.forge.codelutin.com/coser/">Documentation</a></li><li><a href\="http\://forge.codelutin.com/projects/coser/issues">Rapport de bug</a></li></ul><br /><br />Copyright 2010 - 2011 <a href\="http\://www.ifremer.fr">Ifremer</a>, <a href\="http\://www.codelutin.com">Code Lutin</a><html> coser.ui.about.title=À propos de Coser coser.ui.common.cancel=Annuler +coser.ui.common.finish=Terminer +coser.ui.common.next=Suivant coser.ui.common.no=Non coser.ui.common.selectAll=Sélectionner tout coser.ui.common.selectAll.short=Tout @@ -213,7 +215,16 @@ coser.ui.selection.occurrenceDensitySpecies=L2 \: Espèces filtrées (%d/%d) coser.ui.selection.occurrencedensityrenderer=<html>%s<span style\='font-size\:85%%;color\:gray;'>(Occ\=%.2f, Dens\=%.2f)</span></html> coser.ui.selection.reloadcontroldata=Recharger les données contrôlées -coser.ui.selection.replayerror=Erreur de reapplication +coser.ui.selection.replay.chooseselection=Choisissez la sélection à rejouer \: +coser.ui.selection.replay.choosespecies=Choisissez les espèces à conserver \: +coser.ui.selection.replay.choosestrata=Choisissez les strates à conserver \: +coser.ui.selection.replay.chooseyears=Choisissez les années à conserver \: +coser.ui.selection.replay.commands=Liste de toutes les commandes à rejouer \: +coser.ui.selection.replay.missingspecies=Certaines espèces de la séléction à rejouer sont manquantes \: %s +coser.ui.selection.replay.missingstrata=Certaines strates de la séléction à rejouer sont manquantes \: %s +coser.ui.selection.replay.missingyears=Certaines années de la séléction à rejouer sont manquantes \: %s +coser.ui.selection.replay.replayTitle=Rejouer une sélection +coser.ui.selection.replay.selectioninfos=Information sur la sélection \: coser.ui.selection.rsufidataextracted=Données RSufi extraites. coser.ui.selection.saveError=Erreur de sauvegarde coser.ui.selection.selection.requiredDescription=La description de la sélection est requise
participants (1)
-
echatellier@users.forge.codelutin.com