09/19: ajout des listeners sur les strates et sous strates (refs #7929)
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7929_editeur_de_zone in repository tutti. See http://git.codelutin.com/tutti.git commit 3cbf075d1be41de84bd93df0f1031b40de2ec92a Author: Kevin Morin <morin@codelutin.com> Date: Thu Jan 28 19:22:03 2016 +0100 ajout des listeners sur les strates et sous strates (refs #7929) --- .../swing/content/protocol/zones/ZoneEditorUI.jaxx | 1 + .../protocol/zones/ZoneEditorUIHandler.java | 136 +++++++++++++---- .../content/protocol/zones/ZoneEditorUIModel.java | 165 ++++++++++++--------- .../protocol/zones/actions/AddStratasAction.java | 51 +++++-- .../protocol/zones/actions/CreateZoneAction.java | 10 +- .../zones/actions/RemoveStratasAction.java | 58 +++++++- .../resources/i18n/tutti-ui-swing_fr_FR.properties | 2 +- 7 files changed, 299 insertions(+), 124 deletions(-) diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/zones/ZoneEditorUI.jaxx b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/zones/ZoneEditorUI.jaxx index 29fdd33..18129bb 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/zones/ZoneEditorUI.jaxx +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/zones/ZoneEditorUI.jaxx @@ -3,6 +3,7 @@ implements='fr.ifremer.tutti.ui.swing.util.TuttiUI<ZoneEditorUIModel, ZoneEditorUIHandler>'> <import> + fr.ifremer.tutti.ui.swing.content.protocol.zones.tree.ZoneEditorTreeCellRenderer fr.ifremer.tutti.ui.swing.util.TuttiUI fr.ifremer.tutti.ui.swing.util.TuttiUIUtil </import> diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/zones/ZoneEditorUIHandler.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/zones/ZoneEditorUIHandler.java index 31147ea..80a630c 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/zones/ZoneEditorUIHandler.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/zones/ZoneEditorUIHandler.java @@ -3,13 +3,16 @@ package fr.ifremer.tutti.ui.swing.content.protocol.zones; import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; import fr.ifremer.tutti.persistence.entities.protocol.Strata; -import fr.ifremer.tutti.persistence.entities.protocol.Stratas; import fr.ifremer.tutti.persistence.entities.protocol.SubStrata; -import fr.ifremer.tutti.persistence.entities.protocol.SubStratas; import fr.ifremer.tutti.persistence.entities.protocol.Zone; import fr.ifremer.tutti.persistence.entities.referential.TuttiLocation; import fr.ifremer.tutti.persistence.entities.referential.TuttiLocations; import fr.ifremer.tutti.service.PersistenceService; +import fr.ifremer.tutti.ui.swing.content.protocol.zones.models.StrataUIModel; +import fr.ifremer.tutti.ui.swing.content.protocol.zones.models.SubStrataUIModel; +import fr.ifremer.tutti.ui.swing.content.protocol.zones.models.ZoneUIModel; +import fr.ifremer.tutti.ui.swing.content.protocol.zones.tree.StratasTreeModel; +import fr.ifremer.tutti.ui.swing.content.protocol.zones.tree.ZonesTreeModel; import fr.ifremer.tutti.ui.swing.util.AbstractTuttiUIHandler; import jaxx.runtime.validator.swing.SwingValidator; import org.apache.commons.logging.Log; @@ -22,6 +25,7 @@ import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.util.ArrayList; import java.util.Collection; +import java.util.HashSet; import java.util.List; import java.util.stream.Collectors; @@ -38,16 +42,76 @@ public class ZoneEditorUIHandler extends AbstractTuttiUIHandler<ZoneEditorUIMode @Override public void propertyChange(PropertyChangeEvent evt) { + ZoneUIModel zone = (ZoneUIModel) evt.getSource(); - Collection<Strata> stratas = (Collection<Strata>) evt.getNewValue(); - if (log.isInfoEnabled()) { - log.info("stratas " + stratas); - } + Collection<StrataUIModel> newStratas = (Collection<StrataUIModel>) evt.getNewValue(); + Collection<StrataUIModel> oldStratas = (Collection<StrataUIModel>) evt.getOldValue(); + + Collection<StrataUIModel> stratasToAdd = new ArrayList<>(newStratas); + stratasToAdd.removeAll(oldStratas); + + Collection<StrataUIModel> stratasToRemove = new ArrayList<>(oldStratas); + stratasToRemove.removeAll(newStratas); + + stratasToRemove.forEach(strata -> strata.removePropertyChangeListener(StrataUIModel.PROPERTY_SUBSTRATA, + zoneSubStratasChangeListener)); + stratasToAdd.forEach(strata -> strata.addPropertyChangeListener(StrataUIModel.PROPERTY_SUBSTRATA, + zoneSubStratasChangeListener)); + + ZonesTreeModel zonesTreeModel = (ZonesTreeModel) getUI().getZonesTree().getModel(); + zonesTreeModel.updateStratas(zone, stratasToAdd, stratasToRemove); + zonesTreeModel.reload(); + } + }; + + protected final PropertyChangeListener zoneSubStratasChangeListener = new PropertyChangeListener() { + + @Override + public void propertyChange(PropertyChangeEvent evt) { + + StrataUIModel strata = (StrataUIModel) evt.getSource(); + + Collection<SubStrataUIModel> newSubStratas = (Collection<SubStrataUIModel>) evt.getNewValue(); + Collection<SubStrataUIModel> oldSubStratas = (Collection<SubStrataUIModel>) evt.getOldValue(); + + Collection<SubStrataUIModel> subStratasToAdd = new ArrayList<>(newSubStratas); + subStratasToAdd.removeAll(oldSubStratas); + + Collection<SubStrataUIModel> subStratasToRemove = new ArrayList<>(oldSubStratas); + subStratasToRemove.removeAll(newSubStratas); ZonesTreeModel zonesTreeModel = (ZonesTreeModel) getUI().getZonesTree().getModel(); - zonesTreeModel.setStratas(zone, stratas); + zonesTreeModel.updateSubStratas(strata, subStratasToAdd, subStratasToRemove); zonesTreeModel.reload(); + + } + }; + + protected final PropertyChangeListener availableSubStratasChangeListener = new PropertyChangeListener() { + + @Override + public void propertyChange(PropertyChangeEvent evt) { + + StrataUIModel strata = (StrataUIModel) evt.getSource(); + + Collection<SubStrataUIModel> newSubStratas = (Collection<SubStrataUIModel>) evt.getNewValue(); + Collection<SubStrataUIModel> oldSubStratas = (Collection<SubStrataUIModel>) evt.getOldValue(); + + Collection<SubStrataUIModel> subStratasToAdd = new ArrayList<>(newSubStratas); + subStratasToAdd.removeAll(oldSubStratas); + + Collection<SubStrataUIModel> subStratasToRemove = new ArrayList<>(oldSubStratas); + subStratasToRemove.removeAll(newSubStratas); + + if (log.isInfoEnabled()) { + log.info("substrata to remove : " + subStratasToRemove); + } + + StratasTreeModel stratasTreeModel = (StratasTreeModel) getUI().getAvailableStratasTree().getModel(); + stratasTreeModel.updateSubStratas(strata, subStratasToAdd, subStratasToRemove); + stratasTreeModel.reload(); + } }; @@ -72,23 +136,24 @@ public class ZoneEditorUIHandler extends AbstractTuttiUIHandler<ZoneEditorUIMode updateZonesTreeModel(zonesToAdd, zonesToRemove); - zonesToRemove.forEach(zone -> zone.removePropertyChangeListener(ZoneUIModel.PROPERTY_STRATA, - stratasChangeListener)); - zonesToAdd.forEach(zone -> zone.addPropertyChangeListener(ZoneUIModel.PROPERTY_STRATA, - stratasChangeListener)); }); - getModel().addPropertyChangeListener(ZoneEditorUIModel.PROPERTY_AVAILABLE_STRATAS, - evt -> { + getModel().addPropertyChangeListener(ZoneEditorUIModel.PROPERTY_AVAILABLE_STRATAS, evt -> { - List<Strata> oldAvailableStratas = (List<Strata>) evt.getOldValue(); + Collection<StrataUIModel> oldAvailableStratas = (Collection<StrataUIModel>) evt.getOldValue(); + if (log.isInfoEnabled()) { + log.info("oldAvailableStratas " + oldAvailableStratas); + } - List<Strata> newAvailableStratas = (List<Strata> ) evt.getNewValue(); + Collection<StrataUIModel> newAvailableStratas = (Collection<StrataUIModel> ) evt.getNewValue(); + if (log.isInfoEnabled()) { + log.info("newAvailableStratas " + newAvailableStratas); + } - Collection<Strata> stratasToAdd = new ArrayList<>(newAvailableStratas); + Collection<StrataUIModel> stratasToAdd = new ArrayList<>(newAvailableStratas); stratasToAdd.removeAll(oldAvailableStratas); - Collection<Strata> stratasToRemove = new ArrayList<>(oldAvailableStratas); + Collection<StrataUIModel> stratasToRemove = new ArrayList<>(oldAvailableStratas); stratasToRemove.removeAll(newAvailableStratas); updateAvailableStratasTreeModel(stratasToAdd, stratasToRemove); @@ -160,22 +225,19 @@ public class ZoneEditorUIHandler extends AbstractTuttiUIHandler<ZoneEditorUIMode programStratasAndSubstratas.remove(strataLocation, subStrataLocation)); }); - List<Strata> availableStratas = new ArrayList<>(); + Collection<StrataUIModel> availableStratas = new ArrayList<>(); programStratasAndSubstratas.keySet().forEach(strataLocation -> { - Strata strata = Stratas.newStrata(); - strata.setLocation(strataLocation); + StrataUIModel strata = new StrataUIModel(strataLocation); - List<SubStrata> subStratas = programStratasAndSubstratas.get(strataLocation) - .stream() - .map(subStrataLocation -> { - SubStrata subStrata = SubStratas.newSubStrata(); - subStrata.setLocation(subStrataLocation); - return subStrata; - }) - .collect(Collectors.toList()); + Collection<TuttiLocation> subStrataLocations = new HashSet<>(programStratasAndSubstratas.get(strataLocation)); + subStrataLocations.remove(null); + List<SubStrata> subStratas = subStrataLocations.stream() + .map(subStrataLocation -> new SubStrataUIModel(subStrataLocation)) + .collect(Collectors.toList()); strata.setSubstrata(subStratas); + availableStratas.add(strata); }); getModel().setAvailableStratas(availableStratas); @@ -198,11 +260,16 @@ public class ZoneEditorUIHandler extends AbstractTuttiUIHandler<ZoneEditorUIMode zonesTreeModel.addZones(zonesToAdd); + zonesToRemove.forEach(zone -> zone.removePropertyChangeListener(ZoneUIModel.PROPERTY_STRATA, + stratasChangeListener)); + zonesToAdd.forEach(zone -> zone.addPropertyChangeListener(ZoneUIModel.PROPERTY_STRATA, + stratasChangeListener)); + zonesTreeModel.reload(); } - protected void updateAvailableStratasTreeModel(Collection<Strata> stratasToAdd, - Collection<Strata> stratasToRemove) { + protected void updateAvailableStratasTreeModel(Collection<StrataUIModel> stratasToAdd, + Collection<StrataUIModel> stratasToRemove) { JTree availableStratasTree = getUI().getAvailableStratasTree(); StratasTreeModel availableStratasTreeModel = (StratasTreeModel) availableStratasTree.getModel(); @@ -211,6 +278,15 @@ public class ZoneEditorUIHandler extends AbstractTuttiUIHandler<ZoneEditorUIMode availableStratasTreeModel.addStratas(stratasToAdd); + if (log.isInfoEnabled()) { + log.info("add ppcl to " + stratasToAdd); + } + + stratasToRemove.forEach(strata -> strata.removePropertyChangeListener(StrataUIModel.PROPERTY_SUBSTRATA, + availableSubStratasChangeListener)); + stratasToAdd.forEach(strata -> strata.addPropertyChangeListener(StrataUIModel.PROPERTY_SUBSTRATA, + availableSubStratasChangeListener)); + availableStratasTreeModel.reload(); } diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/zones/ZoneEditorUIModel.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/zones/ZoneEditorUIModel.java index c212888..dc98b25 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/zones/ZoneEditorUIModel.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/zones/ZoneEditorUIModel.java @@ -2,7 +2,9 @@ package fr.ifremer.tutti.ui.swing.content.protocol.zones; import fr.ifremer.tutti.persistence.entities.protocol.Strata; import fr.ifremer.tutti.persistence.entities.protocol.SubStrata; -import fr.ifremer.tutti.persistence.entities.referential.TuttiLocation; +import fr.ifremer.tutti.ui.swing.content.protocol.zones.models.StrataUIModel; +import fr.ifremer.tutti.ui.swing.content.protocol.zones.models.SubStrataUIModel; +import fr.ifremer.tutti.ui.swing.content.protocol.zones.models.ZoneUIModel; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jdesktop.beans.AbstractSerializableBean; @@ -26,97 +28,60 @@ public class ZoneEditorUIModel extends AbstractSerializableBean { public static final String PROPERTY_ZONES = "zones"; - protected Map<SubStrata, Strata> strataBySubstrata; + protected final Map<SubStrata, StrataUIModel> strataBySubstrata = new HashMap<>(); - protected final List<Strata> availableStratas = new ArrayList<>(); + protected final List<StrataUIModel> availableStratas = new ArrayList<>(); protected final List<ZoneUIModel> zones = new ArrayList<>(); - public List<Strata> getAvailableStratas() { + public List<StrataUIModel> getAvailableStratas() { return availableStratas; } - public void setAvailableStratas(List<Strata> availableStratas) { + public void setAvailableStratas(Collection<StrataUIModel> availableStratas) { this.availableStratas.clear(); addAllAvailableStratas(availableStratas); - strataBySubstrata = new HashMap<>(); - for (Strata strata : availableStratas) { - for (SubStrata substrata : strata.getSubstrata()) { - strataBySubstrata.put(substrata, strata); - } - } + strataBySubstrata.clear(); + updateStrataBySubStrata(availableStratas); } - public void addAllAvailableStratas(List<Strata> availableStratas) { + public void addAllAvailableStratas(Collection<StrataUIModel> availableStratas) { Object oldValue = copyAvailableStratas(); this.availableStratas.addAll(availableStratas); - firePropertyChange(PROPERTY_AVAILABLE_STRATAS, oldValue, availableStratas); - } - - public void addAvailableStratas(Collection<TuttiLocation> stratasAndSubStratas) { - -// Object oldValue = copyAvailableStratas(); -// -// Collection<TuttiLocation> substratas = stratasAndSubStratas.stream() -// .filter(location -> strataBySubstrata.containsKey(location)) -// .collect(Collectors.toSet()); -// -// Collection<TuttiLocation> stratas = new HashSet<>(stratasAndSubStratas); -// stratas.removeAll(substratas); -// -// stratas.forEach(strata -> { -// -// Collection<TuttiLocation> strataSubstratas = -// strataBySubstrata.entrySet() -// .stream() -// .filter(entry->entry.getValue().equals(strata)) -// .map(Map.Entry::getKey) -// .collect(Collectors.toSet()); -// -// substratas.removeAll(strataSubstratas); -// availableStratas.putAll(strata, strataSubstratas); -// -// }); -// -// substratas.forEach(substrata -> { -// availableStratas.put(strataBySubstrata.get(substrata), substrata); -// }); -// -// firePropertyChange(PROPERTY_AVAILABLE_STRATAS, oldValue, availableStratas); + updateStrataBySubStrata(availableStratas); + firePropertyChange(PROPERTY_AVAILABLE_STRATAS, oldValue, getAvailableStratas()); } - public void removeAvailableStratas(Collection<Strata> stratas) { + public void removeAvailableStratas(Collection<StrataUIModel> stratas) { Object oldValue = copyAvailableStratas(); availableStratas.removeAll(stratas); - firePropertyChange(PROPERTY_AVAILABLE_STRATAS, oldValue, availableStratas); + firePropertyChange(PROPERTY_AVAILABLE_STRATAS, oldValue, getAvailableStratas()); } - public void removeAvailableSubStratas(Collection<SubStrata> subStratas, Strata strata) { -// -// Object oldValue = copyAvailableStratas(); -// -// Collection<TuttiLocation> substratas = stratasAndSubStratas.stream() -// .filter(location -> strataBySubstrata.containsKey(location)) -// .collect(Collectors.toSet()); -// -// Collection<TuttiLocation> stratas = new HashSet<>(stratasAndSubStratas); -// stratas.removeAll(substratas); -// -// stratas.forEach(strata -> { -// availableStratas.removeAll(strata); -// }); -// -// substratas.forEach(substrata -> { -// availableStratas.remove(strataBySubstrata.get(substrata), substrata); -// }); -// -// firePropertyChange(PROPERTY_AVAILABLE_STRATAS, oldValue, availableStratas); -// + public void removeAvailableSubStratas(Collection<SubStrataUIModel> subStratas) { + Object oldValue = copyAvailableStratas(); + + subStratas.forEach(subStrata -> { + + StrataUIModel strata = strataBySubstrata.get(subStrata); + if (log.isInfoEnabled()) { + log.info("remove " + subStrata); + } + strata.removeSubstrata(subStrata); + + if (strata.isSubstrataEmpty()) { + availableStratas.remove(strata); + } + + }); + + firePropertyChange(PROPERTY_AVAILABLE_STRATAS, oldValue, getAvailableStratas()); + } public List<ZoneUIModel> getZones() { @@ -142,21 +107,73 @@ public class ZoneEditorUIModel extends AbstractSerializableBean { firePropertyChange(PROPERTY_ZONES, oldValue, zones); } - public void moveStratasToZone(Collection<Strata> stratas, ZoneUIModel zone) { + public void moveStratasToZone(Collection<StrataUIModel> stratas, ZoneUIModel zone) { + if (log.isInfoEnabled()) { + log.info("stratas " + stratas); + } + + zone.addAllStrata(new ArrayList<>(stratas)); removeAvailableStratas(stratas); + } + public void removeStratasFromZone(Collection<StrataUIModel> stratas) { if (log.isInfoEnabled()) { log.info("stratas " + stratas); } -// Collection<TuttiLocation> substratas = stratasAndSubStratas.stream() -// .filter(location -> strataBySubstrata.containsKey(location)) -// .collect(Collectors.toSet()); + stratas.forEach(strata -> strata.getZone().removeStrata(strata)); + addAllAvailableStratas(stratas); + } + + public void moveSubStratasToZone(Collection<SubStrataUIModel> subStratas, ZoneUIModel zone) { + if (log.isInfoEnabled()) { + log.info("substrats " + subStratas); + } + + subStratas.forEach(subStrata -> { + StrataUIModel strata = strataBySubstrata.get(subStrata); + + Strata zoneStrata = zone.getStrata(strata); + + if (zoneStrata == null) { + zoneStrata = new StrataUIModel(strata.getLocation()); + zone.addStrata(zoneStrata); + } + + zoneStrata.addSubstrata(subStrata); + + }); + + removeAvailableSubStratas(subStratas); + + } + + public void removeSubStratasFromZone(Collection<SubStrataUIModel> subStratas) { + if (log.isInfoEnabled()) { + log.info("subStratas " + subStratas); + } + + subStratas.forEach(subStrata -> { + StrataUIModel strata = strataBySubstrata.get(subStrata); + + //TODO remove substrata from zone +// StrataUIModel zoneStrata = +// strata.removeSubstrata(subStrata); +// strata.getZone().removeStrata(strata) - zone.addAllStrata(stratas); + strata.addSubstrata(subStrata); + }); } - protected List<Strata> copyAvailableStratas() { + protected List<StrataUIModel> copyAvailableStratas() { return new ArrayList<>(availableStratas); } + + protected void updateStrataBySubStrata(Collection<StrataUIModel> availableStratas) { + for (StrataUIModel strata : availableStratas) { + for (SubStrata substrata : strata.getSubstrata()) { + strataBySubstrata.put(substrata, strata); + } + } + } } diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/zones/actions/AddStratasAction.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/zones/actions/AddStratasAction.java index 1392528..b7930e7 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/zones/actions/AddStratasAction.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/zones/actions/AddStratasAction.java @@ -1,18 +1,23 @@ package fr.ifremer.tutti.ui.swing.content.protocol.zones.actions; -import fr.ifremer.tutti.persistence.entities.protocol.Strata; +import fr.ifremer.tutti.persistence.entities.protocol.SubStrata; import fr.ifremer.tutti.ui.swing.content.protocol.zones.ZoneEditorUI; -import fr.ifremer.tutti.ui.swing.content.protocol.zones.ZoneUIModel; -import fr.ifremer.tutti.ui.swing.content.protocol.zones.nodes.ZoneNode; +import fr.ifremer.tutti.ui.swing.content.protocol.zones.models.StrataUIModel; +import fr.ifremer.tutti.ui.swing.content.protocol.zones.models.SubStrataUIModel; +import fr.ifremer.tutti.ui.swing.content.protocol.zones.models.ZoneUIModel; +import fr.ifremer.tutti.ui.swing.content.protocol.zones.tree.StrataNode; +import fr.ifremer.tutti.ui.swing.content.protocol.zones.tree.SubStrataNode; +import fr.ifremer.tutti.ui.swing.content.protocol.zones.tree.ZoneNode; import fr.ifremer.tutti.ui.swing.util.actions.SimpleActionSupport; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import javax.swing.JTree; -import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.TreePath; +import java.util.Collection; import java.util.HashSet; import java.util.Set; +import java.util.stream.Collectors; /** * @author Kevin Morin (Code Lutin) @@ -38,20 +43,40 @@ public class AddStratasAction extends SimpleActionSupport<ZoneEditorUI> { ZoneNode zoneNode = (ZoneNode) selectedZonePath.getLastPathComponent(); ZoneUIModel selectedZone = zoneNode.getZone(); - Set<Strata> locationsToAdd = new HashSet<>(); + Set<StrataUIModel> stratasToAdd = new HashSet<>(); + Set<SubStrataUIModel> subStratasToAdd = new HashSet<>(); for (TreePath treePath : selectedStratas) { -//FIXME - DefaultMutableTreeNode node = (DefaultMutableTreeNode) treePath.getLastPathComponent(); - Strata location = (Strata) node.getUserObject(); -// if (log.isInfoEnabled()) { -// log.info("add location " + location.getLabel()); -// } - locationsToAdd.add(location); + + Object node = treePath.getLastPathComponent(); + + if (node instanceof StrataNode) { + + StrataUIModel strata = ((StrataNode) node).getStrata(); + if (log.isInfoEnabled()) { + log.info("add strata " + strata.getLabel()); + } + stratasToAdd.add(strata); + + } else if (node instanceof SubStrataNode) { + SubStrataUIModel subStrata = ((SubStrataNode) node).getSubstrata(); + if (log.isInfoEnabled()) { + log.info("add subtrata " + subStrata.getLabel()); + } + subStratasToAdd.add(subStrata); + } } - zoneEditorUI.getModel().moveStratasToZone(locationsToAdd, selectedZone); + Collection<SubStrata> alreadyAddedSubStratas = stratasToAdd.stream() + .map(strata->strata.getSubstrata()) + .flatMap(c -> c.stream()) + .collect(Collectors.toSet()); + + subStratasToAdd.removeAll(alreadyAddedSubStratas); + + zoneEditorUI.getModel().moveStratasToZone(stratasToAdd, selectedZone); + zoneEditorUI.getModel().moveSubStratasToZone(subStratasToAdd, selectedZone); } } diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/zones/actions/CreateZoneAction.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/zones/actions/CreateZoneAction.java index af2c00b..9be290a 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/zones/actions/CreateZoneAction.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/zones/actions/CreateZoneAction.java @@ -1,7 +1,7 @@ package fr.ifremer.tutti.ui.swing.content.protocol.zones.actions; import fr.ifremer.tutti.ui.swing.content.protocol.zones.ZoneEditorUI; -import fr.ifremer.tutti.ui.swing.content.protocol.zones.ZoneUIModel; +import fr.ifremer.tutti.ui.swing.content.protocol.zones.models.ZoneUIModel; import fr.ifremer.tutti.ui.swing.util.actions.SimpleActionSupport; import javax.swing.JOptionPane; @@ -23,8 +23,10 @@ public class CreateZoneAction extends SimpleActionSupport<ZoneEditorUI> { String zoneLabel = JOptionPane.showInputDialog(t("tutti.zoneEditor.createZone.message")); - ZoneUIModel zone = new ZoneUIModel(); - zone.setLabel(zoneLabel); - zoneEditorUI.getModel().addZone(zone); + if (zoneLabel != null) { + ZoneUIModel zone = new ZoneUIModel(); + zone.setLabel(zoneLabel); + zoneEditorUI.getModel().addZone(zone); + } } } diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/zones/actions/RemoveStratasAction.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/zones/actions/RemoveStratasAction.java index 041c64b..582d278 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/zones/actions/RemoveStratasAction.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/zones/actions/RemoveStratasAction.java @@ -1,9 +1,21 @@ package fr.ifremer.tutti.ui.swing.content.protocol.zones.actions; +import fr.ifremer.tutti.persistence.entities.protocol.SubStrata; import fr.ifremer.tutti.ui.swing.content.protocol.zones.ZoneEditorUI; +import fr.ifremer.tutti.ui.swing.content.protocol.zones.models.StrataUIModel; +import fr.ifremer.tutti.ui.swing.content.protocol.zones.models.SubStrataUIModel; +import fr.ifremer.tutti.ui.swing.content.protocol.zones.tree.StrataNode; +import fr.ifremer.tutti.ui.swing.content.protocol.zones.tree.SubStrataNode; import fr.ifremer.tutti.ui.swing.util.actions.SimpleActionSupport; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; -import javax.swing.tree.DefaultTreeModel; +import javax.swing.JTree; +import javax.swing.tree.TreePath; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; +import java.util.stream.Collectors; /** * @author Kevin Morin (Code Lutin) @@ -11,12 +23,54 @@ import javax.swing.tree.DefaultTreeModel; */ public class RemoveStratasAction extends SimpleActionSupport<ZoneEditorUI> { + /** Logger. */ + private static final Log log = LogFactory.getLog(RemoveStratasAction.class); + public RemoveStratasAction(ZoneEditorUI zoneEditorUI) { super(zoneEditorUI); } @Override protected void onActionPerformed(ZoneEditorUI zoneEditorUI) { - ((DefaultTreeModel) zoneEditorUI.getAvailableStratasTree().getModel()).reload(); + + JTree availableStratasTree = zoneEditorUI.getAvailableStratasTree(); + + JTree zonesTree = zoneEditorUI.getZonesTree(); + TreePath[] selectedStratas = zonesTree.getSelectionPaths(); + + Set<StrataUIModel> stratasToRemove = new HashSet<>(); + Set<SubStrataUIModel> subStratasToRemove = new HashSet<>(); + + for (TreePath treePath : selectedStratas) { + + Object node = treePath.getLastPathComponent(); + + if (node instanceof StrataNode) { + + StrataUIModel strata = ((StrataNode) node).getStrata(); + if (log.isInfoEnabled()) { + log.info("add strata " + strata.getLabel()); + } + stratasToRemove.add(strata); + + } else if (node instanceof SubStrataNode) { + SubStrataUIModel subStrata = ((SubStrataNode) node).getSubstrata(); + if (log.isInfoEnabled()) { + log.info("add subtrata " + subStrata.getLabel()); + } + subStratasToRemove.add(subStrata); + } + + } + + Collection<SubStrata> alreadyRemovedSubStratas = stratasToRemove.stream() + .map(strata->strata.getSubstrata()) + .flatMap(c -> c.stream()) + .collect(Collectors.toSet()); + + subStratasToRemove.removeAll(alreadyRemovedSubStratas); + + zoneEditorUI.getModel().removeStratasFromZone(stratasToRemove); + zoneEditorUI.getModel().removeSubStratasFromZone(subStratasToRemove); } } diff --git a/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties b/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties index 7e8bc0e..91180c9 100644 --- a/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties +++ b/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties @@ -2174,4 +2174,4 @@ tutti.vesselUseFeatureTable.action.removeCaracteristic.tip=Supprimer la caracté tutti.vesselUseFeatureTable.table.header.key=Caractéristique tutti.vesselUseFeatureTable.table.header.value=Valeur tutti.vesselUseFeatureTable.title=Autres paramètres -tutti.zoneEditor.createZone.message= +tutti.zoneEditor.createZone.message=Libellé de la nouvelle zone -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
participants (1)
-
codelutin.com scm