Author: chatellier Date: 2010-12-01 16:27:39 +0000 (Wed, 01 Dec 2010) New Revision: 327 Log: Fin de l'impl?\195?\169mentation de l'ajout des r?\195?\169sultats Added: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/OtherDataFileListModel.java Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/bean/RSufiResult.java trunk/coser-business/src/main/java/fr/ifremer/coser/services/ProjectService.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/ResultTableModel.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/SelectionAddResultDialog.jaxx trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionHandler.java trunk/coser-ui/src/main/resources/fr/ifremer/coser/bean/RSufiResult-error-validation.xml 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/bean/RSufiResult.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/bean/RSufiResult.java 2010-12-01 16:26:53 UTC (rev 326) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/bean/RSufiResult.java 2010-12-01 16:27:39 UTC (rev 327) @@ -45,6 +45,16 @@ protected String rsufiVersion; + /** Utilisé seulement pour la validation (sinon, non valorisé). */ + protected String dataFile1Path; + + /** Utilisé seulement pour la validation (sinon, non valorisé). */ + protected String dataFile2Path; + + protected String dataFile1Name; + + protected String dataFile2Name; + public String getName() { return name; } @@ -64,12 +74,58 @@ this.rsufiVersion = rsufiVersion; getPropertyChangeSupport().firePropertyChange("name", oldValue, name); } - + + public String getDataFile1Path() { + return dataFile1Path; + } + + public void setDataFile1Path(String dataFile1Path) { + String oldValue = this.dataFile1Path; + this.dataFile1Path = dataFile1Path; + getPropertyChangeSupport().firePropertyChange("dataFile1Path", oldValue, dataFile1Path); + } + + public String getDataFile2Path() { + return dataFile2Path; + } + + public void setDataFile2Path(String dataFile2Path) { + String oldValue = this.dataFile2Path; + this.dataFile2Path = dataFile2Path; + getPropertyChangeSupport().firePropertyChange("dataFile2Path", oldValue, dataFile2Path); + } + + public String getDataFile1Name() { + return dataFile1Name; + } + + public void setDataFile1Name(String dataFile1Name) { + String oldValue = this.dataFile1Name; + this.dataFile1Name = dataFile1Name; + getPropertyChangeSupport().firePropertyChange("dataFile1Name", oldValue, dataFile1Name); + } + + public String getDataFile2Name() { + return dataFile2Name; + } + + public void setDataFile2Name(String dataFile2Name) { + String oldValue = this.dataFile2Name; + this.dataFile2Name = dataFile2Name; + getPropertyChangeSupport().firePropertyChange("dataFile2Name", oldValue, dataFile2Name); + } + public Properties toProperties() { Properties props = new Properties(); if (getRsufiVersion() != null) { props.setProperty("result.rsufiversion", getRsufiVersion()); } + if (getDataFile1Name() != null) { + props.setProperty("result.datafile1name", getDataFile1Name()); + } + if (getDataFile2Name() != null) { + props.setProperty("result.datafile2name", getDataFile2Name()); + } return props; } @@ -77,5 +133,11 @@ if (props.containsKey("result.rsufiversion")) { setRsufiVersion(props.getProperty("result.rsufiversion")); } + if (props.containsKey("result.datafile1name")) { + setDataFile1Name(props.getProperty("result.datafile1name")); + } + if (props.containsKey("result.datafile2name")) { + setDataFile2Name(props.getProperty("result.datafile2name")); + } } } 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-12-01 16:26:53 UTC (rev 326) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/services/ProjectService.java 2010-12-01 16:27:39 UTC (rev 327) @@ -896,10 +896,11 @@ * @param project project * @param selection selection * @param rsufiResult new result to save + * @param othersFiles others files and directory * @throws CoserBusinessException */ public void saveRsufiResults(Project project, Selection selection, - RSufiResult rsufiResult) throws CoserBusinessException { + RSufiResult rsufiResult, List<File> othersFiles) throws CoserBusinessException { File projectsDirectory = config.getProjectsDirectory(); File projectDirectory = new File(projectsDirectory, project.getName()); @@ -907,19 +908,38 @@ File selectionDirectory = new File(selectionsDirectory, selection.getName()); File resultsDirectory = new File(selectionDirectory, CoserConstants.STORAGE_RESULTS_DIRECTORY); File rsufiResultDirectory = new File(resultsDirectory, rsufiResult.getName()); - + // save it if (rsufiResultDirectory.exists()) { throw new CoserBusinessException(_("coser.business.result.rsufiResultAlreadyExists", rsufiResult.getName())); } else { rsufiResultDirectory.mkdirs(); - - // sauvegarde des informations du resultat (properties) - File propertiesFile = new File(rsufiResultDirectory, "result.properties"); - Properties props = rsufiResult.toProperties(); + OutputStream outputStream = null; try { + // sauvegarde des 2 fichiers obligatoires + File dataFile1 = new File(rsufiResult.getDataFile1Path()); + File dataFile2 = new File(rsufiResult.getDataFile2Path()); + rsufiResult.setDataFile1Name(dataFile1.getName()); + rsufiResult.setDataFile2Name(dataFile2.getName()); + FileUtils.copyFileToDirectory(dataFile1, rsufiResultDirectory); + FileUtils.copyFileToDirectory(dataFile2, rsufiResultDirectory); + + // sauvegarde des fichiers autre + File otherFilesDirectory = new File(rsufiResultDirectory, "others"); + for (File othersFile : othersFiles) { + if (othersFile.isDirectory()) { + FileUtils.copyDirectoryToDirectory(othersFile, otherFilesDirectory); + } + else { + FileUtils.copyFileToDirectory(othersFile, otherFilesDirectory); + } + } + + // sauvegarde des informations du resultat (properties) + File propertiesFile = new File(rsufiResultDirectory, "result.properties"); + Properties props = rsufiResult.toProperties(); outputStream = new FileOutputStream(propertiesFile); props.store(outputStream, null); @@ -932,13 +952,12 @@ finally { IOUtils.closeQuietly(outputStream); } - + List<RSufiResult> results = selection.getRsufiResults(); results.add(rsufiResult); // this way to fire change event (do not remove) selection.setRsufiResults(results); } - } /** Added: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/OtherDataFileListModel.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/OtherDataFileListModel.java (rev 0) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/OtherDataFileListModel.java 2010-12-01 16:27:39 UTC (rev 327) @@ -0,0 +1,79 @@ +/* + * #%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.result; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import javax.swing.AbstractListModel; + +/** + * Modele de list pour la list des fichiers et répertoire des fichiers + * additionnels. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class OtherDataFileListModel extends AbstractListModel { + + /** serialVersionUID. */ + private static final long serialVersionUID = -8652851018076968539L; + + protected List<File> otherFiles; + + public OtherDataFileListModel() { + otherFiles = new ArrayList<File>(); + } + + public List<File> getOtherFiles() { + return otherFiles; + } + + public void add(File file) { + otherFiles.add(file); + fireIntervalAdded(this, otherFiles.size() - 1, otherFiles.size() - 1); + } + + /* + * @see javax.swing.ListModel#getSize() + */ + @Override + public int getSize() { + return otherFiles.size(); + } + + /* + * @see javax.swing.ListModel#getElementAt(int) + */ + @Override + public Object getElementAt(int index) { + return otherFiles.get(index); + } +} Property changes on: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/OtherDataFileListModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/ResultTableModel.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/ResultTableModel.java 2010-12-01 16:26:53 UTC (rev 326) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/ResultTableModel.java 2010-12-01 16:27:39 UTC (rev 327) @@ -109,9 +109,12 @@ case 1: result = rsufiResult.getRsufiVersion(); break; - default: - result = "N/A"; + case 2: + result = rsufiResult.getDataFile1Name(); break; + case 3: + result = rsufiResult.getDataFile2Name(); + break; } return result; Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/SelectionAddResultDialog.jaxx =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/SelectionAddResultDialog.jaxx 2010-12-01 16:26:53 UTC (rev 326) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/SelectionAddResultDialog.jaxx 2010-12-01 16:27:39 UTC (rev 327) @@ -34,6 +34,8 @@ errorTableModel="errorsTableModel"> <field name="name" component="resultNameField" /> <field name="rsufiVersion" component="resultRsufiVersion" /> + <field name="dataFile1Path" component="dataFile1TextField" /> + <field name="dataFile2Path" component="dataFile2TextField" /> </BeanValidator> <row> @@ -63,10 +65,14 @@ <JLabel text="coser.ui.result.dataFile1" /> </cell> <cell weightx="1" fill="horizontal"> - <JTextField /> + <JTextField id="dataFile1TextField" /> + <javax.swing.text.Document javaBean="dataFile1TextField.getDocument()" + onInsertUpdate='getRsufiResult().setDataFile1Path(dataFile1TextField.getText())' + onRemoveUpdate='getRsufiResult().setDataFile1Path(dataFile1TextField.getText())' /> </cell> <cell fill="horizontal"> - <JButton text="coser.ui.common.selectFile" /> + <JButton text="coser.ui.common.selectFile" + onActionPerformed="getHandler().selectResultFile(this, dataFile1TextField)" /> </cell> </row> <row> @@ -74,10 +80,14 @@ <JLabel text="coser.ui.result.dataFile2" /> </cell> <cell fill="horizontal"> - <JTextField /> + <JTextField id="dataFile2TextField" /> + <javax.swing.text.Document javaBean="dataFile2TextField.getDocument()" + onInsertUpdate='getRsufiResult().setDataFile2Path(dataFile2TextField.getText())' + onRemoveUpdate='getRsufiResult().setDataFile2Path(dataFile2TextField.getText())' /> </cell> <cell fill="horizontal"> - <JButton text="coser.ui.common.selectFile" /> + <JButton text="coser.ui.common.selectFile" + onActionPerformed="getHandler().selectResultFile(this, dataFile2TextField)" /> </cell> </row> <row> @@ -88,7 +98,8 @@ <row> <cell columns="3" weighty="1" fill="both"> <JScrollPane> - <JList /> + <OtherDataFileListModel id="otherDataFileListModel" /> + <JList id="otherDataFileList" model="{otherDataFileListModel}"/> </JScrollPane> </cell> </row> @@ -97,7 +108,8 @@ <Table> <row> <cell> - <JButton text="coser.ui.result.addOtherDataFile" /> + <JButton text="coser.ui.result.addOtherDataFile" + onActionPerformed="getHandler().selectResultFileOrDirectory(this, otherDataFileList)"/> </cell> <cell weightx="1" anchor="east"> <JButton text="coser.ui.result.cancel" 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-12-01 16:26:53 UTC (rev 326) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionHandler.java 2010-12-01 16:27:39 UTC (rev 327) @@ -42,6 +42,7 @@ import java.util.Set; import javax.swing.JFileChooser; +import javax.swing.JList; import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JPopupMenu; @@ -82,6 +83,12 @@ private static final Log log = LogFactory.getLog(SelectionHandler.class); + /** File chooser de l'export de répertoire. */ + protected JFileChooser exportFileChooser; + + /** File chooser de l'ajout de fichier resultat. */ + protected JFileChooser resultFileChooser; + /** * Appelé sur un changement d'onglet dans l'interface de sélection. * @@ -779,10 +786,11 @@ Project project = view.getContextValue(Project.class); Selection selection = view.getContextValue(Selection.class); ProjectService projectService = view.getContextValue(ProjectService.class); - + List<File> otherFiles = view.getOtherDataFileListModel().getOtherFiles(); + RSufiResult newResult = view.getRsufiResult(); try { - projectService.saveRsufiResults(project, selection, newResult); + projectService.saveRsufiResults(project, selection, newResult, otherFiles); } catch (CoserBusinessException ex) { JOptionPane.showMessageDialog(view, ex.getMessage(), _("coser.ui.result.saveError"), JOptionPane.ERROR_MESSAGE); @@ -797,20 +805,22 @@ * * @return */ - protected JFileChooser getFileChooser() { - JFileChooser fileChooser = new JFileChooser(); - fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); - return fileChooser; + protected JFileChooser getExportFileChooser() { + if (exportFileChooser == null) { + exportFileChooser = new JFileChooser(); + exportFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + } + return exportFileChooser; } /** - * Extract data as RSufi format. + * Selectionne le dossier d'extraction. * * @param view view * @param textComponent text component to set selected directory */ public void selectOutputDirectory(SelectionRsufiView view, JTextField textComponent) { - JFileChooser selectFileChooser = getFileChooser(); + JFileChooser selectFileChooser = getExportFileChooser(); int result = selectFileChooser.showOpenDialog(view); if (result == JFileChooser.APPROVE_OPTION) { @@ -838,4 +848,52 @@ throw new CoserException("Can't extract rsufi files", ex); } } + + /** + * Retourne une unique instance du file chooser pour conserver + * le répertoire de sélection d'un appel sur l'autre. + * + * @return l'instance a utiliser + */ + protected JFileChooser getResultFileChooser() { + if (resultFileChooser == null) { + resultFileChooser = new JFileChooser(); + resultFileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); + } + return resultFileChooser; + } + + /** + * Select result file (file only). + * + * @param view view + * @param textComponent text component to set selected directory + */ + public void selectResultFile(SelectionAddResultDialog view, JTextField textComponent) { + JFileChooser selectFileChooser = getResultFileChooser(); + selectFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); + + int result = selectFileChooser.showOpenDialog(view); + if (result == JFileChooser.APPROVE_OPTION) { + File selectedFile = selectFileChooser.getSelectedFile(); + textComponent.setText(selectedFile.getAbsolutePath()); + } + } + + /** + * Select result file (file only). + * + * @param view view + * @param listComponent list component to set selected directory + */ + public void selectResultFileOrDirectory(SelectionAddResultDialog view, JList listComponent) { + JFileChooser selectFileChooser = getResultFileChooser(); + selectFileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); + + int result = selectFileChooser.showOpenDialog(view); + if (result == JFileChooser.APPROVE_OPTION) { + File selectedFile = selectFileChooser.getSelectedFile(); + view.getOtherDataFileListModel().add(selectedFile); + } + } } Modified: trunk/coser-ui/src/main/resources/fr/ifremer/coser/bean/RSufiResult-error-validation.xml =================================================================== --- trunk/coser-ui/src/main/resources/fr/ifremer/coser/bean/RSufiResult-error-validation.xml 2010-12-01 16:26:53 UTC (rev 326) +++ trunk/coser-ui/src/main/resources/fr/ifremer/coser/bean/RSufiResult-error-validation.xml 2010-12-01 16:27:39 UTC (rev 327) @@ -39,4 +39,16 @@ <message>coser.ui.result.requiredrsufiVersion</message> </field-validator> </field> + <field name="dataFile1Path"> + <field-validator type="requiredstring"> + <param name="trim">true</param> + <message>coser.ui.result.requireddataFile1Path</message> + </field-validator> + </field> + <field name="dataFile2Path"> + <field-validator type="requiredstring"> + <param name="trim">true</param> + <message>coser.ui.result.requireddataFile2Path</message> + </field-validator> + </field> </validators> 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 2010-12-01 16:26:53 UTC (rev 326) +++ trunk/coser-ui/src/main/resources/i18n/coser-ui_en_GB.properties 2010-12-01 16:27:39 UTC (rev 327) @@ -115,20 +115,22 @@ coser.ui.result.addOtherDataFile=Add file coser.ui.result.availableDataTitle=Available results \: coser.ui.result.cancel=Cancel -coser.ui.result.dataFile1=Data file 1 \: -coser.ui.result.dataFile2=Data file 2 \: +coser.ui.result.dataFile1=ESTPOPind file \: +coser.ui.result.dataFile2=ESTCOMind file \: coser.ui.result.extractDataButton=Extract as Rsufi format coser.ui.result.extractDataLabel=Extraction directory \: coser.ui.result.extractDataTitle=Extract RSufi data coser.ui.result.newResult=New Result coser.ui.result.otherDataFile=Other files \: +coser.ui.result.requireddataFile1Path= +coser.ui.result.requireddataFile2Path= coser.ui.result.requiredname=Result name is required coser.ui.result.requiredrsufiVersion=Rsufi version is required coser.ui.result.resultName=Result name \: coser.ui.result.rsufiVersion=RSufi version \: coser.ui.result.saveError=Save error -coser.ui.result.table.dataFile1=Data file 1 -coser.ui.result.table.dataFile2=Data file 2 +coser.ui.result.table.dataFile1=ESTPOPind file +coser.ui.result.table.dataFile2=ESTCOMind file coser.ui.result.table.resultName=Result name coser.ui.result.table.rsufiVersion=RSufi Version coser.ui.result.validNewResult=Add this result 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 2010-12-01 16:26:53 UTC (rev 326) +++ trunk/coser-ui/src/main/resources/i18n/coser-ui_fr_FR.properties 2010-12-01 16:27:39 UTC (rev 327) @@ -115,20 +115,22 @@ coser.ui.result.addOtherDataFile=Ajouter un fichier coser.ui.result.availableDataTitle=R\u00E9sultats disponibles coser.ui.result.cancel=Annuler -coser.ui.result.dataFile1=Fichier r\u00E9sultat 1 \: -coser.ui.result.dataFile2=Fichier r\u00E9sultat 2 \: +coser.ui.result.dataFile1=Fichier ESTPOPind \: +coser.ui.result.dataFile2=Fichier ESTCOMind \: coser.ui.result.extractDataButton=Extraire au format RSufi coser.ui.result.extractDataLabel=Dossier d'extraction \: coser.ui.result.extractDataTitle=Extraction des donn\u00E9es RSufi coser.ui.result.newResult=Nouveau r\u00E9sultat coser.ui.result.otherDataFile=Autre fichiers \: +coser.ui.result.requireddataFile1Path= +coser.ui.result.requireddataFile2Path= coser.ui.result.requiredname=Le nom du r\u00E9sultat est requis coser.ui.result.requiredrsufiVersion=Le champ 'rsufiVersion' est requis coser.ui.result.resultName=Nom du r\u00E9sultat \: coser.ui.result.rsufiVersion=Version de RSufi \: coser.ui.result.saveError=Erreur de sauvegarde -coser.ui.result.table.dataFile1=Fichier de donn\u00E9es 1 -coser.ui.result.table.dataFile2=Fichier de donn\u00E9es 2 +coser.ui.result.table.dataFile1=Fichier ESTPOPind +coser.ui.result.table.dataFile2=Fichier ESTCOMind coser.ui.result.table.resultName=Nom du r\u00E9sultat coser.ui.result.table.rsufiVersion=Version de RSufi coser.ui.result.validNewResult=Ajouter le r\u00E9sultat @@ -139,7 +141,7 @@ coser.ui.selection.details.comment=Commentaire \: coser.ui.selection.details.dates=Ann\u00E9es \: coser.ui.selection.details.description=Description \: -coser.ui.selection.details.displayDiffCatchLengthGraphTip=Affiche les graphiques des diff\u00E9rences captures/tailles pour les esp\u00E8ces s�ctionn�. +coser.ui.selection.details.displayDiffCatchLengthGraphTip=Affiche les graphiques des diff\u00E9rences captures/tailles pour les esp\u00E8ces s\uFFFDlectionn\uFFFDes. coser.ui.selection.details.filteredSpecies=Esp\u00E8ces filtr\u00E9es (%d/%d) \: coser.ui.selection.details.name=Nom de la s\u00E9lection \: coser.ui.selection.details.removeFromSelectedListTip=Retire les esp\u00E8ces s\u00E9lectionn\u00E9es de la liste des esp\u00E8ces s\u00E9lectionn\u00E9es