r782 - in trunk: tutti-service/src/main/java/fr/ifremer/tutti/service tutti-service/src/main/java/fr/ifremer/tutti/service/config tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/config tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor
Author: tchemit Date: 2013-04-15 18:37:54 +0200 (Mon, 15 Apr 2013) New Revision: 782 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/782 Log: fixes #2290: [PROTOCOLE] Le protocole n'est plus s?\195?\169lectionn?\195?\169 au d?\195?\169marrage de l'application fixes #2291: [PROTOCOLE] Un protocole est s?\195?\169lectionn?\195?\169 mais dans le titre on ne le voit pas refs #1875: [IMP/EXP] - Export des donn?\195?\169es de campagne : format g?\195?\169n?\195?\169rique (ajout dans la configuration du pays de l'export) Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/TuttiLocationTableCell.java Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/TuttiDataContext.java trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/config/TuttiServiceConfigOption.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/MainUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/config/TuttiConfigUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/VesselTableCell.java Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/TuttiDataContext.java =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/TuttiDataContext.java 2013-04-15 16:12:04 UTC (rev 781) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/TuttiDataContext.java 2013-04-15 16:37:54 UTC (rev 782) @@ -186,8 +186,7 @@ public void clearContext() { program = null; cruise = null; - protocolId = null; - fishingOperationId = null; + fishingOperation = null; resetProtocol(); resetVessels(); resetGears(); @@ -209,6 +208,12 @@ } setProtocolId(null); + } else { + if (log.isInfoEnabled()) { + log.info("protocolId valid: " + getProtocolId()); + } + + setProtocolId(getProtocolId()); } } Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/config/TuttiServiceConfigOption.java =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/config/TuttiServiceConfigOption.java 2013-04-15 16:12:04 UTC (rev 781) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/config/TuttiServiceConfigOption.java 2013-04-15 16:37:54 UTC (rev 782) @@ -71,7 +71,7 @@ "tutti.export.countryId", n_("tutti.config.option.export.countryId.description"), "12", - char.class), + String.class), // TRANSIENT CONFIG VERSION( Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/MainUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/MainUIHandler.java 2013-04-15 16:12:04 UTC (rev 781) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/MainUIHandler.java 2013-04-15 16:37:54 UTC (rev 782) @@ -512,8 +512,7 @@ if (context.isCruiseFilled()) { // selected cruise - Cruise cruise; - cruise = getDataContext().getCruise(); + Cruise cruise = getDataContext().getCruise(); if (cruise != null) { title += _("tutti.main.title.selectedCruise", cruise.getName()); @@ -525,29 +524,27 @@ title += _("tutti.main.title.noSelectedCruise"); } - title += " / "; + } else { - if (context.isProtocolFilled()) { + // no program selected (so neither cruise) - // selected protocol - TuttiProtocol protocol = getDataContext().getProtocol(); + title = _("tutti.main.title.noSelectedProgram"); - log.fatal(protocol.getId() + " " + protocol.getName()); + } - title += _("tutti.main.title.selectedProtocol", protocol.getName()); - } else { + title += " / "; - // no selected protocol + if (context.isProtocolFilled()) { - title += _("tutti.main.title.noSelectedProtocol"); - } + // selected protocol + TuttiProtocol protocol = getDataContext().getProtocol(); + title += _("tutti.main.title.selectedProtocol", protocol.getName()); } else { - // no program selected (so neither cruise) + // no selected protocol - title = _("tutti.main.title.noSelectedProgram"); - + title += _("tutti.main.title.noSelectedProtocol"); } } else { Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/config/TuttiConfigUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/config/TuttiConfigUIHandler.java 2013-04-15 16:12:04 UTC (rev 781) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/config/TuttiConfigUIHandler.java 2013-04-15 16:37:54 UTC (rev 782) @@ -34,6 +34,7 @@ import fr.ifremer.tutti.ui.swing.util.AbstractTuttiUIHandler; import fr.ifremer.tutti.ui.swing.util.TuttiUI; import fr.ifremer.tutti.ui.swing.util.action.TuttiActionHelper; +import fr.ifremer.tutti.ui.swing.util.editor.TuttiLocationTableCell; import fr.ifremer.tutti.ui.swing.util.editor.VesselTableCell; import jaxx.runtime.SwingUtil; import jaxx.runtime.swing.config.ConfigUI; @@ -137,6 +138,11 @@ .setOptionEditor(vesselTableCellComponent.getNewTableCellEditor()) .setOptionRenderer(vesselTableCellComponent.getNewTableCellRenderer()); + TuttiLocationTableCell tuttiLocationTableCellComponent = new TuttiLocationTableCell(context); + helper.addOption(TuttiServiceConfigOption.EXPORT_COUNTRY_ID) + .setOptionEditor(tuttiLocationTableCellComponent.getNewTableCellEditor()) + .setOptionRenderer(tuttiLocationTableCellComponent.getNewTableCellRenderer()); + SampleOrderIdsTableCell comp = new SampleOrderIdsTableCell(context); TableCellEditor sampleOrderEditor = comp.getNewTableCellEditor(); Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/TuttiLocationTableCell.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/TuttiLocationTableCell.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/TuttiLocationTableCell.java 2013-04-15 16:37:54 UTC (rev 782) @@ -0,0 +1,166 @@ +package fr.ifremer.tutti.ui.swing.util.editor; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer + * %% + * 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% + */ + +import com.google.common.collect.Lists; +import fr.ifremer.tutti.persistence.entities.TuttiEntities; +import fr.ifremer.tutti.persistence.entities.referential.TuttiLocation; +import fr.ifremer.tutti.service.DecoratorService; +import fr.ifremer.tutti.ui.swing.TuttiUIContext; +import jaxx.runtime.swing.editor.bean.BeanFilterableComboBox; +import org.nuiton.util.decorator.Decorator; +import org.nuiton.util.decorator.JXPathDecorator; + +import javax.swing.DefaultCellEditor; +import javax.swing.DefaultListCellRenderer; +import javax.swing.JComboBox; +import javax.swing.JList; +import javax.swing.JTable; +import javax.swing.table.DefaultTableCellRenderer; +import javax.swing.table.TableCellEditor; +import javax.swing.table.TableCellRenderer; +import java.awt.Component; +import java.awt.event.ActionEvent; +import java.awt.event.MouseEvent; +import java.util.EventObject; +import java.util.List; +import java.util.Map; + +/** + * To edit a {@link TuttiLocation}. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.4 + */ +public class TuttiLocationTableCell { + + protected Decorator<TuttiLocation> decorator; + + protected List<TuttiLocation> entities; + + protected Map<String, TuttiLocation> entityMap; + + public TuttiLocationTableCell(TuttiUIContext context) { + DecoratorService decoratorService = context.getDecoratorService(); + decorator = decoratorService.getDecoratorByType(TuttiLocation.class); + + entities = Lists.newArrayList(context.getPersistenceService().getAllCountry()); + entityMap = TuttiEntities.splitById(entities); + } + + public TableCellEditor getNewTableCellEditor() { + return new TuttiLocationTableCellEditor(); + } + + public TableCellRenderer getNewTableCellRenderer() { + return new TuttiLocationTableCellRenderer(); + } + + protected class TuttiLocationTableCellEditor extends DefaultCellEditor { + + private static final long serialVersionUID = 1L; + + protected TuttiLocationTableCellEditor() { + super(new JComboBox()); + + final BeanFilterableComboBox<TuttiLocation> component = new BeanFilterableComboBox<TuttiLocation>(); + component.setI18nPrefix("tutti.property."); + component.setShowReset(true); + setClickCountToStart(1); + + editorComponent = component; + delegate = new DefaultCellEditor.EditorDelegate() { + private static final long serialVersionUID = 1L; + + @Override + public void setValue(Object value) { + if (value != null && String.class.isInstance(value)) { + value = entityMap.get(value); + } + component.setSelectedItem(value); + } + + @Override + public Object getCellEditorValue() { + String result = null; + Object selectedItem = component.getSelectedItem(); + if (TuttiLocation.class.isInstance(selectedItem)) { + TuttiLocation entity = (TuttiLocation) component.getSelectedItem(); + if (entity != null) { + result = entity.getId(); + } + } + return result; + } + + @Override + public boolean shouldSelectCell(EventObject anEvent) { + if (anEvent instanceof MouseEvent) { + MouseEvent e = (MouseEvent) anEvent; + return e.getID() != MouseEvent.MOUSE_DRAGGED; + } + return true; + } + + @Override + public boolean stopCellEditing() { + if (component.isEditable()) { + // Commit edited value. + component.getCombobox().actionPerformed( + new ActionEvent(TuttiLocationTableCellEditor.this, 0, "")); + } + return super.stopCellEditing(); + } + }; + + component.init((JXPathDecorator<TuttiLocation>) decorator, entities); + } + + class TuttiLocationListCellRenderer extends DefaultListCellRenderer { + + private static final long serialVersionUID = 1L; + + @Override + public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { + return super.getListCellRendererComponent(list, decorator.toString(value), index, isSelected, cellHasFocus); + } + } + } + + protected class TuttiLocationTableCellRenderer extends DefaultTableCellRenderer { + + private static final long serialVersionUID = 1L; + + @Override + public Component getTableCellRendererComponent(JTable table, Object value, + boolean isSelected, boolean hasFocus, + int row, int column) { + + String entityId = String.valueOf(value); + TuttiLocation entity = entityMap.get(entityId); + return super.getTableCellRendererComponent(table, decorator.toString(entity), isSelected, hasFocus, row, column); + } + } +} \ No newline at end of file Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/TuttiLocationTableCell.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/VesselTableCell.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/VesselTableCell.java 2013-04-15 16:12:04 UTC (rev 781) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/VesselTableCell.java 2013-04-15 16:37:54 UTC (rev 782) @@ -56,17 +56,17 @@ protected Decorator<Vessel> decorator; - protected List<Vessel> vessels; + protected List<Vessel> entities; - protected Map<String, Vessel> vesselMap; + protected Map<String, Vessel> entityMap; public VesselTableCell(TuttiUIContext context) { DecoratorService decoratorService = context.getDecoratorService(); decorator = decoratorService.getDecoratorByType(Vessel.class); - vessels = Lists.newArrayList(context.getDataContext().getFishingVessels()); - vessels.addAll(context.getDataContext().getScientificVessels()); - vesselMap = TuttiEntities.splitById(vessels); + entities = Lists.newArrayList(context.getDataContext().getFishingVessels()); + entities.addAll(context.getDataContext().getScientificVessels()); + entityMap = TuttiEntities.splitById(entities); } public TableCellEditor getNewTableCellEditor() { @@ -96,7 +96,7 @@ @Override public void setValue(Object value) { if (value != null && String.class.isInstance(value)) { - value = vesselMap.get(value); + value = entityMap.get(value); } component.setSelectedItem(value); } @@ -134,7 +134,7 @@ } }; - component.init((JXPathDecorator<Vessel>) decorator, vessels); + component.init((JXPathDecorator<Vessel>) decorator, entities); } class VesselListCellRenderer extends DefaultListCellRenderer { @@ -158,7 +158,7 @@ int row, int column) { String vesselId = String.valueOf(value); - Vessel vessel = vesselMap.get(vesselId); + Vessel vessel = entityMap.get(vesselId); return super.getTableCellRendererComponent(table, decorator.toString(vessel), isSelected, hasFocus, row, column); } }
participants (1)
-
tchemit@users.forge.codelutin.com