r481 - in trunk: . coser-business/src/main/java/fr/ifremer/coser coser-business/src/main/java/fr/ifremer/coser/services coser-ui/src/main/java/fr/ifremer/coser coser-ui/src/main/java/fr/ifremer/coser/ui/result
Author: chatellier Date: 2011-01-06 17:04:05 +0000 (Thu, 06 Jan 2011) New Revision: 481 Log: Ajout de la combo des zones disponible dans l'ui des resultats Added: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/ZoneComboBoxModel.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/ZoneComboBoxRenderer.java Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/CoserBusinessConfig.java trunk/coser-business/src/main/java/fr/ifremer/coser/services/WebService.java trunk/coser-ui/src/main/java/fr/ifremer/coser/Coser.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/SelectionAddResultDialog.jaxx trunk/pom.xml Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/CoserBusinessConfig.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/CoserBusinessConfig.java 2011-01-06 15:47:26 UTC (rev 480) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/CoserBusinessConfig.java 2011-01-06 17:04:05 UTC (rev 481) @@ -167,7 +167,7 @@ WEB_SERVER_DIRECTORY("coser.web.server.directory", _("coser.config.web.server.directory.description"), "${" + DATABASE_DIRECTORY.key + "}" + File.separator + "web", String.class, false, false), WEB_PROJECTS_DIRECTORY("coser.web.projects.directory", _("coser.config.web.projects.directory.description"), "${" + WEB_SERVER_DIRECTORY.key + "}" + File.separator + "projects", String.class, false, false), WEB_MATCH_INDICATORS("coser.web.matchindicators.file", _("coser.config.web.matchindicators.file.description"), "${" + WEB_SERVER_DIRECTORY.key + "}" + File.separator + "matchindicators.csv", String.class, false, false), - WEB_MATCH_ZONES("coser.web.matchzones.file", _("coser.config.web.matchzones.file.description"), "${" + WEB_SERVER_DIRECTORY.key + "}" + File.separator + "correspondancezones.txt", String.class, false, false); + WEB_MATCH_ZONES("coser.web.matchzones.file", _("coser.config.web.matchzones.file.description"), "${" + WEB_SERVER_DIRECTORY.key + "}" + File.separator + "matchzones.csv", String.class, false, false); protected String key; protected String description; 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-01-06 15:47:26 UTC (rev 480) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/services/WebService.java 2011-01-06 17:04:05 UTC (rev 481) @@ -74,8 +74,11 @@ protected ProjectService projectService; /** Indicator map (id, locale > translation) (etat du service). */ - protected MultiKeyMap indicatorMap; + protected MultiKeyMap indicatorsMap; + /** Zones map (id > zone, subzone) (etat du service). */ + protected Map<String, String[]> zonesMap; + public WebService(CoserBusinessConfig config) { this.config = config; @@ -87,28 +90,52 @@ * Charge les indicateurs disponible depuis le fichier des indicateurs. * (indid, indname) * - * @return default indicators + * @return indicators map * @throws CoserBusinessException */ - protected MultiKeyMap getDefaultIndicators() throws CoserBusinessException { + public MultiKeyMap getIndicatorsMap() throws CoserBusinessException { - if (indicatorMap == null) { - indicatorMap = new MultiKeyMap(); - File indicatorFile = config.getMatchIndicatorsFile(); - DataStorage indicatorStorage = importService.loadCSVFile(indicatorFile); - Iterator<String[]> iteratorInd = indicatorStorage.iterator(true); - while(iteratorInd.hasNext()) { + if (indicatorsMap == null) { + indicatorsMap = new MultiKeyMap(); + File indicatorsFile = config.getMatchIndicatorsFile(); + DataStorage indicatorsStorage = importService.loadCSVFile(indicatorsFile); + Iterator<String[]> iteratorInd = indicatorsStorage.iterator(true); + while (iteratorInd.hasNext()) { // "id";"label_fr";"label_en" String[] indicator = iteratorInd.next(); - indicatorMap.put(indicator[0], "fr", indicator[1]); - indicatorMap.put(indicator[0], "en", indicator[2]); + indicatorsMap.put(indicator[0], "fr", indicator[1]); + indicatorsMap.put(indicator[0], "en", indicator[2]); } } - return indicatorMap; + return indicatorsMap; } /** + * Charge les zones disponibles depuis le fichier des zones. + * (zoneid, zonename) + * + * @return zones map + * @throws CoserBusinessException + */ + public Map<String, String[]> getZonesMap() throws CoserBusinessException { + + if (zonesMap == null) { + zonesMap = new HashMap<String, String[]>(); + File zoneFile = config.getMatchZonesFile(); + DataStorage zonesStorage = importService.loadCSVFile(zoneFile); + Iterator<String[]> iteratorZones = zonesStorage.iterator(true); + while (iteratorZones.hasNext()) { + // "id";"zone";"subzone";"periode";"serie";"comment";"map" + String[] zone = iteratorZones.next(); + zonesMap.put(zone[0], new String[]{zone[1], zone[2]}); + } + } + + return zonesMap; + } + + /** * Traite le fichier uploade par l'application client et l'enregistre * dans le stockage coté web. * @@ -435,7 +462,7 @@ protected Map<String, String> getRsufiResultIndicators(Project project, Selection selection, RSufiResult rsufiResult, String species, String locale) throws CoserBusinessException { - MultiKeyMap defaultIndicators = getDefaultIndicators(); + MultiKeyMap defaultIndicators = getIndicatorsMap(); Map<String, String> result = new HashMap<String, String>(); Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/Coser.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/Coser.java 2011-01-06 15:47:26 UTC (rev 480) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/Coser.java 2011-01-06 17:04:05 UTC (rev 481) @@ -42,6 +42,7 @@ import fr.ifremer.coser.services.ImportService; import fr.ifremer.coser.services.ProjectService; import fr.ifremer.coser.services.PublicationService; +import fr.ifremer.coser.services.WebService; import fr.ifremer.coser.ui.CoserFrame; import fr.ifremer.coser.ui.util.ErrorHelper; @@ -139,6 +140,7 @@ context.setContextValue(new ImportService(coserConfig)); context.setContextValue(new ControlService(coserConfig)); context.setContextValue(new PublicationService(coserConfig)); + context.setContextValue(new WebService(coserConfig)); // init frame with session reloading CoserFrame frame = new CoserFrame(context); 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 2011-01-06 15:47:26 UTC (rev 480) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/SelectionAddResultDialog.jaxx 2011-01-06 17:04:05 UTC (rev 481) @@ -66,10 +66,9 @@ <JLabel text="coser.ui.result.zone" /> </cell> <cell fill="horizontal" columns="2"> - <JTextField id="resultZone" /> - <javax.swing.text.Document javaBean="resultZone.getDocument()" - onInsertUpdate='getRsufiResult().setZone(resultZone.getText())' - onRemoveUpdate='getRsufiResult().setZone(resultZone.getText())' /> + <JComboBox id="resultZoneCombo" model="{new ZoneComboBoxModel(this)}" + renderer="{new ZoneComboBoxRenderer()}" + onActionPerformed='getRsufiResult().setZone((String)resultZoneCombo.getSelectedItem())'/> </cell> </row> <row> @@ -122,7 +121,8 @@ <JLabel text="coser.ui.result.publishResult" /> </cell> <cell fill="horizontal" columns="2"> - <JCheckBox id="publishResultCheckBox" /> + <JCheckBox id="publishResultCheckBox" + onActionPerformed="getRsufiResult().setPublishResult(publishResultCheckBox.isSelected())"/> </cell> </row> <row> Added: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/ZoneComboBoxModel.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/ZoneComboBoxModel.java (rev 0) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/ZoneComboBoxModel.java 2011-01-06 17:04:05 UTC (rev 481) @@ -0,0 +1,85 @@ +/* + * #%L + * + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 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.util.ArrayList; +import java.util.List; +import java.util.Map; + +import javax.swing.DefaultComboBoxModel; + +import fr.ifremer.coser.CoserBusinessException; +import fr.ifremer.coser.CoserException; +import fr.ifremer.coser.services.WebService; + +/** + * Zone combo box model. + * Contains zone list defined in "matchzone" file common to web side and client + * side. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class ZoneComboBoxModel extends DefaultComboBoxModel { + + /** serialVersionUID. */ + private static final long serialVersionUID = 4452070553401468762L; + + public SelectionAddResultDialog view; + + public List<String> zonesIds; + + public Map<String, String[]> zonesMap; + + public ZoneComboBoxModel(SelectionAddResultDialog view) { + this.view = view; + + WebService webService = view.getContextValue(WebService.class); + try { + zonesMap = webService.getZonesMap(); + zonesIds = new ArrayList<String>(zonesMap.keySet()); + } catch (CoserBusinessException ex) { + throw new CoserException("Can't get zone list", ex); + } + } + + @Override + public int getSize() { + return zonesIds.size(); + } + + @Override + public Object getElementAt(int index) { + return zonesIds.get(index); + } + + public String[] getZone(String zoneId) { + return zonesMap.get(zoneId); + } +} Property changes on: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/ZoneComboBoxModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/ZoneComboBoxRenderer.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/ZoneComboBoxRenderer.java (rev 0) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/ZoneComboBoxRenderer.java 2011-01-06 17:04:05 UTC (rev 481) @@ -0,0 +1,64 @@ +/* + * #%L + * + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 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.awt.Component; + +import javax.swing.DefaultListCellRenderer; +import javax.swing.JList; + +/** + * Zone list combo renderer (display zone name for zone id). + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class ZoneComboBoxRenderer extends DefaultListCellRenderer { + + /** serialVersionUID. */ + private static final long serialVersionUID = -8231189755539976714L; + + @Override + public Component getListCellRendererComponent(JList list, Object value, + int index, boolean isSelected, boolean cellHasFocus) { + + String zoneId = (String)value; + ZoneComboBoxModel model = (ZoneComboBoxModel)list.getModel(); + String[] zoneInfo = model.getZone(zoneId); + String zoneName = null; + if (zoneInfo != null) { + zoneName = zoneInfo[0] + " - " + zoneInfo[1]; + } + else { + zoneName = zoneId; + } + return super.getListCellRendererComponent(list, zoneName, index, isSelected, + cellHasFocus); + } +} Property changes on: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/ZoneComboBoxRenderer.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2011-01-06 15:47:26 UTC (rev 480) +++ trunk/pom.xml 2011-01-06 17:04:05 UTC (rev 481) @@ -75,7 +75,7 @@ <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> - <version>2.0</version> + <version>2.0.1</version> <scope>compile</scope> </dependency>
participants (1)
-
chatellier@users.labs.libre-entreprise.org