Author: kmorin Date: 2013-03-07 11:40:39 +0100 (Thu, 07 Mar 2013) New Revision: 561 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/561 Log: fixes #2013 [PROTOCOLE] - Caract?\195?\169ristiques - supprimer une caract?\195?\169ristique s?\195?\169lectionn?\195?\169e des autres onglets Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIHandler.java Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIHandler.java 2013-03-07 10:30:55 UTC (rev 560) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/EditProtocolUIHandler.java 2013-03-07 10:40:39 UTC (rev 561) @@ -10,21 +10,22 @@ * %% * 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 + * 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 + * + * 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.ezware.oxbow.swingbits.util.Preconditions; +import com.google.common.base.Predicate; import com.google.common.collect.Lists; import com.google.common.collect.Multimap; import fr.ifremer.tutti.persistence.entities.TuttiEntities; @@ -62,6 +63,9 @@ import java.util.Collection; import java.util.List; import java.util.Map; +import javax.swing.JTabbedPane; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; import static org.nuiton.i18n.I18n._; @@ -297,21 +301,74 @@ initDoubleList(EditProtocolUIModel.PROPERTY_LENGTH_CLASSES_PMFM_ID, ui.getLengthClassesList(), Lists.newArrayList(model.getCaracteristics()), - model.getLengthClassesPmfmId()); + model.getLengthClassesPmfmId(), + new Predicate<Caracteristic>() { + public boolean apply(Caracteristic input) { + boolean result = !ui.getGearUseFeatureList().getModel().getSelected().contains(input); + result &= !ui.getVesselUseFeatureList().getModel().getSelected().contains(input); + return result; + } + }); + initDoubleList(EditProtocolUIModel.PROPERTY_GEAR_USE_FEATURE_PMFM_ID, ui.getGearUseFeatureList(), Lists.newArrayList(model.getCaracteristics()), - model.getGearUseFeaturePmfmId()); + model.getGearUseFeaturePmfmId(), + new Predicate<Caracteristic>() { + public boolean apply(Caracteristic input) { + boolean result = !ui.getLengthClassesList().getModel().getSelected().contains(input); + result &= !ui.getVesselUseFeatureList().getModel().getSelected().contains(input); + return result; + } + }); + initDoubleList(EditProtocolUIModel.PROPERTY_VESSEL_USE_FEATURE_PMFM_ID, ui.getVesselUseFeatureList(), Lists.newArrayList(model.getCaracteristics()), - model.getVesselUseFeaturePmfmId()); + model.getVesselUseFeaturePmfmId(), + new Predicate<Caracteristic>() { + public boolean apply(Caracteristic input) { + boolean result = !ui.getGearUseFeatureList().getModel().getSelected().contains(input); + result &= !ui.getLengthClassesList().getModel().getSelected().contains(input); + return result; + } + }); + // if new protocol can already cancel his creation model.setModify(model.isCreate()); + ui.getCaracteristicPane().addChangeListener(new ChangeListener() { + + public void stateChanged(ChangeEvent e) { + JTabbedPane tabPanel = (JTabbedPane) e.getSource(); + int selectedIndex = tabPanel.getSelectedIndex(); + BeanDoubleList<Caracteristic> selectedDoubleList; + log.debug("selected " + selectedIndex); + switch (selectedIndex) { + case 0: + selectedDoubleList = ui.getLengthClassesList(); + break; + + case 1: + selectedDoubleList = ui.getGearUseFeatureList(); + break; + + case 2: + selectedDoubleList = ui.getVesselUseFeatureList(); + break; + + default: + selectedDoubleList = null; + } + if (selectedDoubleList != null) { + selectedDoubleList.getHandler().refreshFilteredElements(); + } + } + }); + dialog = new SelectSpeciesUI(ui); } @@ -439,7 +496,8 @@ protected void initDoubleList(String propertyId, BeanDoubleList<Caracteristic> widget, List<Caracteristic> availableCaracteristics, - List<String> selectedCaracteristics) { + List<String> selectedCaracteristics, + Predicate<Caracteristic> filter) { initBeanList(widget, availableCaracteristics, Lists.<Caracteristic>newArrayList()); @@ -450,6 +508,8 @@ widget.putClientProperty("_updateListener", listener); widget.putClientProperty("_updateListenerId", propertyId); listener.select(selectedCaracteristics); + + widget.getHandler().addFilter(filter); } protected void selectLengthClasses(List<String> ids, JComboBox comboBox) {