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 0ff5002e3a03ae359d36f5bd04981d817e5c1990 Author: Kevin Morin <morin@codelutin.com> Date: Wed Jan 27 18:39:17 2016 +0100 creation de zones + déplacement des noeuds (refs #7929) --- .../swing/content/protocol/zones/ZoneEditorUI.jaxx | 22 +- .../swing/content/protocol/zones/ZoneEditorUI.jcss | 8 + .../protocol/zones/ZoneEditorUIHandler.java | 238 +++++++++++++-------- .../content/protocol/zones/ZoneEditorUIModel.java | 157 ++++++++------ .../protocol/zones/actions/AddStratasAction.java | 29 ++- .../protocol/zones/actions/CreateZoneAction.java | 30 +++ .../zones/actions/RemoveStratasAction.java | 2 +- .../resources/i18n/tutti-ui-swing_en_GB.properties | 1 + .../resources/i18n/tutti-ui-swing_fr_FR.properties | 1 + 9 files changed, 323 insertions(+), 165 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 ae21d09..29fdd33 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 @@ -19,10 +19,24 @@ <ZoneEditorUIModel id='model' javaBean='new ZoneEditorUIModel()'/> <row> + <cell> + <JToolBar id="zonesTreeToolBar"> + <JButton id="createZone"/> + </JToolBar> + </cell> + <cell> + <JLabel/> + </cell> + <cell> + <JToolBar id="availableStratasTreeToolBar"> + </JToolBar> + </cell> + </row> + <row> <cell weightx='0.5' weighty='1' fill='both'> - <JScrollPane onFocusGained='zoneTree.requestFocus()'> + <JScrollPane onFocusGained='zonesTree.requestFocus()'> <!-- List of the zones --> - <JTree id='zoneTree'/> + <JTree id='zonesTree'/> <!--onFocusGained='handler.selectFirstRowIfNoSelection(event)'--> <!--onMouseClicked='handler.onUniverseListClicked(event)'--> <!--onKeyPressed='handler.onKeyPressedOnUniverseList(event)'--> @@ -37,9 +51,9 @@ </cell> <cell weightx='0.5' weighty='1' fill='both'> - <JScrollPane onFocusGained='availableStratas.requestFocus()'> + <JScrollPane onFocusGained='availableStratasTree.requestFocus()'> <!-- List of the available stratas and substratas --> - <JTree id='availableStratas' onValueChanged="availableStratas.expandPath(event.getNewLeadSelectionPath())"/> + <JTree id='availableStratasTree' onValueChanged="availableStratasTree.expandPath(event.getNewLeadSelectionPath())"/> <!--onFocusGained='handler.selectFirstRowIfNoSelection(event)'--> <!--onMouseClicked='handler.onSelectedListClicked(event)'--> <!--onKeyPressed='handler.onKeyPressedOnSelectedList(event)'/>--> diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/zones/ZoneEditorUI.jcss b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/zones/ZoneEditorUI.jcss index f6b30e7..8c336fa 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/zones/ZoneEditorUI.jcss +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/zones/ZoneEditorUI.jcss @@ -4,14 +4,22 @@ JTree { scrollsOnExpand: true; rootVisible: false; showsRootHandles: false; + cellRenderer: {new ZoneEditorTreeCellRenderer()}; +} + +#createZone { + actionIcon: add; + _simpleAction: {fr.ifremer.tutti.ui.swing.content.protocol.zones.actions.CreateZoneAction.class}; } #addButton { text: "<<"; + enabled: {zonesTree.getSelectionCount() == 1}; _simpleAction: {fr.ifremer.tutti.ui.swing.content.protocol.zones.actions.AddStratasAction.class}; } #removeButton { text: ">>"; + enabled: {zonesTree.getSelectionCount() >= 1}; _simpleAction: {fr.ifremer.tutti.ui.swing.content.protocol.zones.actions.RemoveStratasAction.class}; } \ No newline at end of file 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 f46342a..31147ea 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 @@ -1,7 +1,14 @@ 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.util.AbstractTuttiUIHandler; import jaxx.runtime.validator.swing.SwingValidator; @@ -10,15 +17,13 @@ import org.apache.commons.logging.LogFactory; import javax.swing.JComponent; import javax.swing.JTree; -import javax.swing.tree.DefaultMutableTreeNode; -import javax.swing.tree.DefaultTreeCellRenderer; -import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreeModel; -import java.awt.Component; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; import java.util.ArrayList; import java.util.Collection; -import java.util.Enumeration; -import java.util.HashSet; +import java.util.List; +import java.util.stream.Collectors; /** * @author Kevin Morin (Code Lutin) @@ -29,127 +34,184 @@ public class ZoneEditorUIHandler extends AbstractTuttiUIHandler<ZoneEditorUIMode /** Logger. */ private static final Log log = LogFactory.getLog(ZoneEditorUIHandler.class); + protected final PropertyChangeListener stratasChangeListener = new PropertyChangeListener() { + + @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); + } + + ZonesTreeModel zonesTreeModel = (ZonesTreeModel) getUI().getZonesTree().getModel(); + zonesTreeModel.setStratas(zone, stratas); + zonesTreeModel.reload(); + } + }; + @Override public void afterInit(ZoneEditorUI zoneEditorUI) { initUI(zoneEditorUI); - getModel().addPropertyChangeListener(ZoneEditorUIModel.PROPERTY_AVAILABLE_STRATAS, + // init models + + getModel().addPropertyChangeListener(ZoneEditorUIModel.PROPERTY_ZONES, evt -> { - Multimap<TuttiLocation, TuttiLocation> oldAvailableStratas = - (Multimap<TuttiLocation, TuttiLocation>) evt.getOldValue(); + List<ZoneUIModel> newZones = (List<ZoneUIModel>) evt.getNewValue(); + List<ZoneUIModel> oldZones = (List<ZoneUIModel>) evt.getOldValue(); - Multimap<TuttiLocation, TuttiLocation> newAvailableStratas = - (Multimap<TuttiLocation, TuttiLocation>) evt.getNewValue(); + Collection<ZoneUIModel> zonesToAdd = new ArrayList<>(newZones); + zonesToAdd.removeAll(oldZones); - Collection<TuttiLocation> stratasToAdd = new ArrayList<>(newAvailableStratas.keySet()); - stratasToAdd.removeAll(oldAvailableStratas.keySet()); + Collection<ZoneUIModel> zonesToRemove = new ArrayList<>(oldZones); + zonesToRemove.removeAll(newZones); - Collection<TuttiLocation> stratasToRemove = new ArrayList<>(oldAvailableStratas.keySet()); - stratasToRemove.removeAll(newAvailableStratas.keySet()); + updateZonesTreeModel(zonesToAdd, zonesToRemove); - updateTreeModel(newAvailableStratas, oldAvailableStratas, stratasToAdd, stratasToRemove); + zonesToRemove.forEach(zone -> zone.removePropertyChangeListener(ZoneUIModel.PROPERTY_STRATA, + stratasChangeListener)); + zonesToAdd.forEach(zone -> zone.addPropertyChangeListener(ZoneUIModel.PROPERTY_STRATA, + stratasChangeListener)); }); - DefaultMutableTreeNode root = new DefaultMutableTreeNode(); - - TreeModel availableStratasTreeModel = new DefaultTreeModel(root); - - JTree availableStratasTree = ui.getAvailableStratas(); - availableStratasTree.setCellRenderer(new DefaultTreeCellRenderer() { - - @Override - public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { - super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus); - String text = "test"; - if (value instanceof DefaultMutableTreeNode) { - Object userObject = ((DefaultMutableTreeNode) value).getUserObject(); - if (userObject instanceof TuttiLocation) { - text = ((TuttiLocation) userObject).getLabel(); - } - } - setText(text); - return this; - } + getModel().addPropertyChangeListener(ZoneEditorUIModel.PROPERTY_AVAILABLE_STRATAS, + evt -> { + + List<Strata> oldAvailableStratas = (List<Strata>) evt.getOldValue(); + + List<Strata> newAvailableStratas = (List<Strata> ) evt.getNewValue(); + + Collection<Strata> stratasToAdd = new ArrayList<>(newAvailableStratas); + stratasToAdd.removeAll(oldAvailableStratas); + + Collection<Strata> stratasToRemove = new ArrayList<>(oldAvailableStratas); + stratasToRemove.removeAll(newAvailableStratas); + + updateAvailableStratasTreeModel(stratasToAdd, stratasToRemove); }); + + // init trees + + TreeModel availableStratasTreeModel = new StratasTreeModel(); + JTree availableStratasTree = ui.getAvailableStratasTree(); availableStratasTree.setModel(availableStratasTreeModel); - PersistenceService persistenceService = getPersistenceService(); + TreeModel zonesTreeModel = new ZonesTreeModel(); + JTree zonesTree = ui.getZonesTree(); + zonesTree.setModel(zonesTreeModel); - TuttiLocation programZone = getDataContext().getProgram().getZone(); + // get data - Multimap<TuttiLocation, TuttiLocation> programStratasAndSubstratas = - persistenceService.getAllFishingOperationStratasAndSubstratas(programZone.getId()); + initModel(); + } - getModel().setAvailableStratas(programStratasAndSubstratas); + @Override + public SwingValidator<ZoneEditorUIModel> getValidator() { + return null; } - protected void updateTreeModel(Multimap<TuttiLocation, TuttiLocation> newAvailableStratas, - Multimap<TuttiLocation, TuttiLocation> oldAvailableStratas, - Collection<TuttiLocation> stratasToAdd, - Collection<TuttiLocation> stratasToRemove) { + @Override + protected JComponent getComponentToFocus() { + return ui.getZonesTree(); + } - if (log.isInfoEnabled()) { - log.info("updateTrremodle"); - } + @Override + public void onCloseUI() { + getModel().getZones().forEach(zone -> zone.removePropertyChangeListener(ZoneUIModel.PROPERTY_STRATA, + stratasChangeListener)); + } - JTree availableStratas = getUI().getAvailableStratas(); - DefaultTreeModel availableStratasTreeModel = (DefaultTreeModel) availableStratas.getModel(); - DefaultMutableTreeNode root = (DefaultMutableTreeNode) availableStratasTreeModel.getRoot(); + protected void initModel() { + PersistenceService persistenceService = getPersistenceService(); - Enumeration rootChildren = root.children(); - Collection<DefaultMutableTreeNode> nodesToRemove = new HashSet<>(); - while (rootChildren.hasMoreElements()) { - DefaultMutableTreeNode strataNode = (DefaultMutableTreeNode) rootChildren.nextElement(); - if (log.isInfoEnabled()) { - log.info("root child " + ((TuttiLocation) strataNode.getUserObject()).getLabel()); - } - if (stratasToRemove.contains(strataNode.getUserObject())) { - if (log.isInfoEnabled()) { - log.info("remove " + ((TuttiLocation) strataNode.getUserObject()).getLabel()); - } - nodesToRemove.add(strataNode); - } + TuttiLocation programZone = getDataContext().getProgram().getZone(); + + Multimap<TuttiLocation, TuttiLocation> programStratasAndSubstratas = + HashMultimap.create(persistenceService.getAllFishingOperationStratasAndSubstratas(programZone.getId())); + //FIXME only for tests + TuttiLocation test = programStratasAndSubstratas.keySet().iterator().next(); + for (int i = 0 ; i < 5 ; i++) { + TuttiLocation location = TuttiLocations.newTuttiLocation(); + location.setId(i); + location.setLabel("substrata" + i); + programStratasAndSubstratas.put(test, location); } - nodesToRemove.forEach(strataNode -> root.remove(strataNode)); - stratasToAdd.forEach(strata -> { + Collection<Zone> zones = getDataContext().getProtocol().getZone(); + Collection<Strata> protocolStratas = zones.stream() + .map(zone -> zone.getStrata()) + .flatMap(stratas -> stratas.stream()) + .collect(Collectors.toSet()); - DefaultMutableTreeNode strataNode = new DefaultMutableTreeNode(strata, true); - root.add(strataNode); + protocolStratas.forEach(strata -> { - if (log.isInfoEnabled()) { - log.info("add strata node " + strata.getLabel()); - } + TuttiLocation strataLocation = strata.getLocation(); + + Collection<TuttiLocation> subStrataLocations = strata.getSubstrata() + .stream() + .map(subStrata -> subStrata.getLocation()) + .collect(Collectors.toSet()); - newAvailableStratas.get(strata).forEach(substrata -> { + subStrataLocations.forEach(subStrataLocation -> + programStratasAndSubstratas.remove(strataLocation, subStrataLocation)); + }); + + List<Strata> availableStratas = new ArrayList<>(); + programStratasAndSubstratas.keySet().forEach(strataLocation -> { - if (substrata != null) { - DefaultMutableTreeNode subStrataNode = new DefaultMutableTreeNode(substrata, false); - strataNode.add(subStrataNode); - log.info("add substrata node " + substrata.getLabel()); - } + Strata strata = Stratas.newStrata(); + strata.setLocation(strataLocation); - }); + List<SubStrata> subStratas = programStratasAndSubstratas.get(strataLocation) + .stream() + .map(subStrataLocation -> { + SubStrata subStrata = SubStratas.newSubStrata(); + subStrata.setLocation(subStrataLocation); + return subStrata; + }) + .collect(Collectors.toList()); + strata.setSubstrata(subStratas); }); - availableStratasTreeModel.reload(); - } + getModel().setAvailableStratas(availableStratas); - @Override - public SwingValidator<ZoneEditorUIModel> getValidator() { - return null; + List<ZoneUIModel> zoneModels = zones.stream() + .map(zone -> { + ZoneUIModel zoneUIModel = new ZoneUIModel(); + zoneUIModel.fromEntity(zone); + return zoneUIModel; + }) + .collect(Collectors.toList()); + getModel().setZones(zoneModels); } - @Override - protected JComponent getComponentToFocus() { - return ui.getZoneTree(); + protected void updateZonesTreeModel(Collection<ZoneUIModel> zonesToAdd, Collection<ZoneUIModel> zonesToRemove) { + JTree zonesTree = getUI().getZonesTree(); + ZonesTreeModel zonesTreeModel = (ZonesTreeModel) zonesTree.getModel(); + + zonesTreeModel.removeZones(zonesToRemove); + + zonesTreeModel.addZones(zonesToAdd); + + zonesTreeModel.reload(); } - @Override - public void onCloseUI() { + protected void updateAvailableStratasTreeModel(Collection<Strata> stratasToAdd, + Collection<Strata> stratasToRemove) { + + JTree availableStratasTree = getUI().getAvailableStratasTree(); + StratasTreeModel availableStratasTreeModel = (StratasTreeModel) availableStratasTree.getModel(); + + availableStratasTreeModel.removeStratas(stratasToRemove); + availableStratasTreeModel.addStratas(stratasToAdd); + + 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 9645011..c212888 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 @@ -1,8 +1,7 @@ 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.Zone; +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 org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -11,10 +10,8 @@ import org.jdesktop.beans.AbstractSerializableBean; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; /** * @author Kevin Morin (Code Lutin) @@ -29,101 +26,137 @@ public class ZoneEditorUIModel extends AbstractSerializableBean { public static final String PROPERTY_ZONES = "zones"; - protected Map<TuttiLocation, TuttiLocation> strataBySubstrata; + protected Map<SubStrata, Strata> strataBySubstrata; - protected final Multimap<TuttiLocation, TuttiLocation> availableStratas = HashMultimap.create(); + protected final List<Strata> availableStratas = new ArrayList<>(); - protected final List<Zone> zones = new ArrayList<>(); + protected final List<ZoneUIModel> zones = new ArrayList<>(); - public Multimap<TuttiLocation, TuttiLocation> getAvailableStratas() { + public List<Strata> getAvailableStratas() { return availableStratas; } - public void setAvailableStratas(Multimap<TuttiLocation, TuttiLocation> availableStratas) { + public void setAvailableStratas(List<Strata> availableStratas) { this.availableStratas.clear(); addAllAvailableStratas(availableStratas); strataBySubstrata = new HashMap<>(); - for (TuttiLocation stratas : availableStratas.keySet()) { - for (TuttiLocation substratas : availableStratas.get(stratas)) { - strataBySubstrata.put(substratas, stratas); + for (Strata strata : availableStratas) { + for (SubStrata substrata : strata.getSubstrata()) { + strataBySubstrata.put(substrata, strata); } } } - public void addAllAvailableStratas(Multimap<TuttiLocation, TuttiLocation> availableStratas) { + public void addAllAvailableStratas(List<Strata> availableStratas) { Object oldValue = copyAvailableStratas(); - this.availableStratas.putAll(availableStratas); + 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); +// 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); } - public void removeAvailableStratas(Collection<TuttiLocation> stratasAndSubStratas) { + public void removeAvailableStratas(Collection<Strata> stratas) { 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); - }); + availableStratas.removeAll(stratas); firePropertyChange(PROPERTY_AVAILABLE_STRATAS, oldValue, availableStratas); } - public List<Zone> getZones() { + 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 List<ZoneUIModel> getZones() { return zones; } - public void setZones(List<Zone> zones) { + public void setZones(List<ZoneUIModel> zones) { Object oldValue = getZones(); this.zones.clear(); this.zones.addAll(zones); firePropertyChange(PROPERTY_ZONES, oldValue, zones); } - protected Multimap<TuttiLocation, TuttiLocation> copyAvailableStratas() { - return HashMultimap.create(availableStratas); + public void addZone(ZoneUIModel zone) { + Object oldValue = new ArrayList<>(getZones()); + zones.add(zone); + firePropertyChange(PROPERTY_ZONES, oldValue, zones); + } + + public void removeZone(ZoneUIModel zone) { + Object oldValue = new ArrayList<>(getZones()); + zones.remove(zone); + firePropertyChange(PROPERTY_ZONES, oldValue, zones); + } + + public void moveStratasToZone(Collection<Strata> stratas, ZoneUIModel zone) { + removeAvailableStratas(stratas); + + if (log.isInfoEnabled()) { + log.info("stratas " + stratas); + } + +// Collection<TuttiLocation> substratas = stratasAndSubStratas.stream() +// .filter(location -> strataBySubstrata.containsKey(location)) +// .collect(Collectors.toSet()); + + zone.addAllStrata(stratas); + } + + protected List<Strata> copyAvailableStratas() { + return new ArrayList<>(availableStratas); } } 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 75ddcb5..1392528 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,7 +1,9 @@ package fr.ifremer.tutti.ui.swing.content.protocol.zones.actions; -import fr.ifremer.tutti.persistence.entities.referential.TuttiLocation; +import fr.ifremer.tutti.persistence.entities.protocol.Strata; 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.util.actions.SimpleActionSupport; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -28,21 +30,28 @@ public class AddStratasAction extends SimpleActionSupport<ZoneEditorUI> { @Override protected void onActionPerformed(ZoneEditorUI zoneEditorUI) { - JTree availableStratasTree = zoneEditorUI.getAvailableStratas(); - TreePath[] selectionPaths = availableStratasTree.getSelectionPaths(); + JTree availableStratasTree = zoneEditorUI.getAvailableStratasTree(); + TreePath[] selectedStratas = availableStratasTree.getSelectionPaths(); - Set<TuttiLocation> locationsToAdd = new HashSet<>(); + JTree zonesTree = zoneEditorUI.getZonesTree(); + TreePath selectedZonePath = zonesTree.getSelectionPath(); + ZoneNode zoneNode = (ZoneNode) selectedZonePath.getLastPathComponent(); + ZoneUIModel selectedZone = zoneNode.getZone(); - for (TreePath treePath : selectionPaths) { + Set<Strata> locationsToAdd = new HashSet<>(); + + for (TreePath treePath : selectedStratas) { +//FIXME DefaultMutableTreeNode node = (DefaultMutableTreeNode) treePath.getLastPathComponent(); - TuttiLocation location = (TuttiLocation) node.getUserObject(); - if (log.isInfoEnabled()) { - log.info("add location " + location.getLabel()); - } + Strata location = (Strata) node.getUserObject(); +// if (log.isInfoEnabled()) { +// log.info("add location " + location.getLabel()); +// } locationsToAdd.add(location); + } - zoneEditorUI.getModel().removeAvailableStratas(locationsToAdd); + zoneEditorUI.getModel().moveStratasToZone(locationsToAdd, 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 new file mode 100644 index 0000000..af2c00b --- /dev/null +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/zones/actions/CreateZoneAction.java @@ -0,0 +1,30 @@ +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.util.actions.SimpleActionSupport; + +import javax.swing.JOptionPane; + +import static org.nuiton.i18n.I18n.t; + +/** + * @author Kevin Morin (Code Lutin) + * @since 4.5 + */ +public class CreateZoneAction extends SimpleActionSupport<ZoneEditorUI> { + + public CreateZoneAction(ZoneEditorUI zoneEditorUI) { + super(zoneEditorUI); + } + + @Override + protected void onActionPerformed(ZoneEditorUI zoneEditorUI) { + + String zoneLabel = JOptionPane.showInputDialog(t("tutti.zoneEditor.createZone.message")); + + 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 4c7390f..041c64b 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 @@ -17,6 +17,6 @@ public class RemoveStratasAction extends SimpleActionSupport<ZoneEditorUI> { @Override protected void onActionPerformed(ZoneEditorUI zoneEditorUI) { - ((DefaultTreeModel) zoneEditorUI.getAvailableStratas().getModel()).reload(); + ((DefaultTreeModel) zoneEditorUI.getAvailableStratasTree().getModel()).reload(); } } diff --git a/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_en_GB.properties b/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_en_GB.properties index 73beba0..f058c04 100644 --- a/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_en_GB.properties +++ b/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_en_GB.properties @@ -2344,3 +2344,4 @@ tutti.vesselUseFeatureTable.action.removeCaracteristic.tip= tutti.vesselUseFeatureTable.table.header.key= tutti.vesselUseFeatureTable.table.header.value= tutti.vesselUseFeatureTable.title= +tutti.zoneEditor.createZone.message= 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 c6500ff..7e8bc0e 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,3 +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= -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.