This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository tutti. See http://git.codelutin.com/tutti.git commit 793f199fe5247dcdd4cbb6e7f2674dfbfe56c176 Author: Tony CHEMIT <chemit@codelutin.com> Date: Sat Feb 6 09:19:36 2016 +0100 Pouvoir ajouter/supprimer en utilisant un double click ou la touche entrée (See #7929) --- .../swing/content/protocol/zones/ZoneEditorUI.jaxx | 7 +- .../protocol/zones/ZoneEditorUIHandler.java | 153 ++++++++++++--------- .../protocol/zones/actions/AddStratasAction.java | 4 +- .../zones/actions/RemoveStratasAction.java | 51 ++++--- 4 files changed, 125 insertions(+), 90 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 bffbf34..8b881b2 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 @@ -55,7 +55,9 @@ <cell weightx='0.5' weighty='1' fill='both'> <JScrollPane onFocusGained='availableStratasTree.requestFocus()'> <!-- List of the available stratas and substratas --> - <JTree id='availableStratasTree' onValueChanged="availableStratasTree.expandPath(event.getNewLeadSelectionPath())"/> + <JTree id='availableStratasTree' onValueChanged="availableStratasTree.expandPath(event.getNewLeadSelectionPath())" + onMouseClicked="handler.onMouseClickedOnAvailableStratas(event)" + onKeyPressed="handler.onKeyPressedOnAvailableStratas(event)"/> <!--onFocusGained='handler.selectFirstRowIfNoSelection(event)'--> <!--onMouseClicked='handler.onSelectedListClicked(event)'--> <!--onKeyPressed='handler.onKeyPressedOnSelectedList(event)'/>--> @@ -72,7 +74,8 @@ <cell weightx='0.5' weighty='1' fill='both'> <JScrollPane onFocusGained='zonesTree.requestFocus()'> <!-- List of the zones --> - <JTree id='zonesTree' onMouseClicked="handler.autoSelectNodeInTree(event, zonePopupMenu)"/> + <JTree id='zonesTree' onMouseClicked="handler.onMouseClickedPressedOnZones(event, zonePopupMenu)" + onKeyPressed="handler.onKeyPressedOnZones(event)"/> <!--onFocusGained='handler.selectFirstRowIfNoSelection(event)'--> <!--onMouseClicked='handler.onUniverseListClicked(event)'--> <!--onKeyPressed='handler.onKeyPressedOnUniverseList(event)'--> 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 aacdb84..62aa35c 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 @@ -31,6 +31,7 @@ import javax.swing.event.TreeSelectionListener; import javax.swing.tree.TreeModel; import javax.swing.tree.TreePath; import java.awt.Point; +import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; @@ -48,86 +49,90 @@ public class ZoneEditorUIHandler extends AbstractTuttiUIHandler<EditProtocolUIMo /** Logger. */ private static final Log log = LogFactory.getLog(ZoneEditorUIHandler.class); - protected final PropertyChangeListener labelChangeListener = new PropertyChangeListener() { + protected final PropertyChangeListener labelChangeListener; - @Override - public void propertyChange(PropertyChangeEvent evt) { + protected final PropertyChangeListener stratasChangeListener; - ZoneUIModel zone = (ZoneUIModel) evt.getSource(); - ZonesTreeModel zonesTreeModel = (ZonesTreeModel) getUI().getZonesTree().getModel(); - zonesTreeModel.zoneLabelChanged(zone); - } - }; - - protected final PropertyChangeListener stratasChangeListener = new PropertyChangeListener() { + protected final PropertyChangeListener zoneSubStratasChangeListener; - @Override - public void propertyChange(PropertyChangeEvent evt) { + protected final PropertyChangeListener availableSubStratasChangeListener; - ZoneUIModel zone = (ZoneUIModel) evt.getSource(); + public ZoneEditorUIHandler() { - Collection<StrataUIModel> newStratas = (Collection<StrataUIModel>) evt.getNewValue(); - Collection<StrataUIModel> oldStratas = (Collection<StrataUIModel>) evt.getOldValue(); - - Collection<StrataUIModel> stratasToAdd = new ArrayList<>(newStratas); - stratasToAdd.removeAll(oldStratas); + availableSubStratasChangeListener = new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { - Collection<StrataUIModel> stratasToRemove = new ArrayList<>(oldStratas); - stratasToRemove.removeAll(newStratas); + StrataUIModel strata = (StrataUIModel) evt.getSource(); - stratasToRemove.forEach(strata -> strata.removePropertyChangeListener(StrataUIModel.PROPERTY_SUBSTRATA, - zoneSubStratasChangeListener)); - stratasToAdd.forEach(strata -> strata.addPropertyChangeListener(StrataUIModel.PROPERTY_SUBSTRATA, - zoneSubStratasChangeListener)); + Collection<SubStrataUIModel> newSubStratas = (Collection<SubStrataUIModel>) evt.getNewValue(); + Collection<SubStrataUIModel> oldSubStratas = (Collection<SubStrataUIModel>) evt.getOldValue(); - ZonesTreeModel zonesTreeModel = (ZonesTreeModel) getUI().getZonesTree().getModel(); - zonesTreeModel.updateStratas(zone, stratasToAdd, stratasToRemove); - } - }; + Collection<SubStrataUIModel> subStratasToAdd = new ArrayList<>(newSubStratas); + subStratasToAdd.removeAll(oldSubStratas); - protected final PropertyChangeListener zoneSubStratasChangeListener = new PropertyChangeListener() { + Collection<SubStrataUIModel> subStratasToRemove = new ArrayList<>(oldSubStratas); + subStratasToRemove.removeAll(newSubStratas); - @Override - public void propertyChange(PropertyChangeEvent evt) { + StratasTreeModel stratasTreeModel = (StratasTreeModel) ZoneEditorUIHandler.this.getUI().getAvailableStratasTree().getModel(); + stratasTreeModel.updateSubStratas(strata, subStratasToAdd, subStratasToRemove); - StrataUIModel strata = (StrataUIModel) evt.getSource(); + } + }; + zoneSubStratasChangeListener = new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { - Collection<SubStrataUIModel> newSubStratas = (Collection<SubStrataUIModel>) evt.getNewValue(); - Collection<SubStrataUIModel> oldSubStratas = (Collection<SubStrataUIModel>) evt.getOldValue(); + StrataUIModel strata = (StrataUIModel) evt.getSource(); - Collection<SubStrataUIModel> subStratasToAdd = new ArrayList<>(newSubStratas); - subStratasToAdd.removeAll(oldSubStratas); + Collection<SubStrataUIModel> newSubStratas = (Collection<SubStrataUIModel>) evt.getNewValue(); + Collection<SubStrataUIModel> oldSubStratas = (Collection<SubStrataUIModel>) evt.getOldValue(); - Collection<SubStrataUIModel> subStratasToRemove = new ArrayList<>(oldSubStratas); - subStratasToRemove.removeAll(newSubStratas); + Collection<SubStrataUIModel> subStratasToAdd = new ArrayList<>(newSubStratas); + subStratasToAdd.removeAll(oldSubStratas); - ZonesTreeModel zonesTreeModel = (ZonesTreeModel) getUI().getZonesTree().getModel(); - zonesTreeModel.updateSubStratas(strata, subStratasToAdd, subStratasToRemove); + Collection<SubStrataUIModel> subStratasToRemove = new ArrayList<>(oldSubStratas); + subStratasToRemove.removeAll(newSubStratas); - } - }; + ZonesTreeModel zonesTreeModel = (ZonesTreeModel) ZoneEditorUIHandler.this.getUI().getZonesTree().getModel(); + zonesTreeModel.updateSubStratas(strata, subStratasToAdd, subStratasToRemove); - protected final PropertyChangeListener availableSubStratasChangeListener = new PropertyChangeListener() { + } + }; + labelChangeListener = new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { - @Override - public void propertyChange(PropertyChangeEvent evt) { + ZoneUIModel zone = (ZoneUIModel) evt.getSource(); + ZonesTreeModel zonesTreeModel = (ZonesTreeModel) ZoneEditorUIHandler.this.getUI().getZonesTree().getModel(); + zonesTreeModel.zoneLabelChanged(zone); + } + }; + stratasChangeListener = new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { - StrataUIModel strata = (StrataUIModel) evt.getSource(); + ZoneUIModel zone = (ZoneUIModel) evt.getSource(); - Collection<SubStrataUIModel> newSubStratas = (Collection<SubStrataUIModel>) evt.getNewValue(); - Collection<SubStrataUIModel> oldSubStratas = (Collection<SubStrataUIModel>) evt.getOldValue(); + Collection<StrataUIModel> newStratas = (Collection<StrataUIModel>) evt.getNewValue(); + Collection<StrataUIModel> oldStratas = (Collection<StrataUIModel>) evt.getOldValue(); - Collection<SubStrataUIModel> subStratasToAdd = new ArrayList<>(newSubStratas); - subStratasToAdd.removeAll(oldSubStratas); + Collection<StrataUIModel> stratasToAdd = new ArrayList<>(newStratas); + stratasToAdd.removeAll(oldStratas); - Collection<SubStrataUIModel> subStratasToRemove = new ArrayList<>(oldSubStratas); - subStratasToRemove.removeAll(newSubStratas); + Collection<StrataUIModel> stratasToRemove = new ArrayList<>(oldStratas); + stratasToRemove.removeAll(newStratas); - StratasTreeModel stratasTreeModel = (StratasTreeModel) getUI().getAvailableStratasTree().getModel(); - stratasTreeModel.updateSubStratas(strata, subStratasToAdd, subStratasToRemove); + stratasToRemove.forEach(strata -> strata.removePropertyChangeListener(StrataUIModel.PROPERTY_SUBSTRATA, + zoneSubStratasChangeListener)); + stratasToAdd.forEach(strata -> strata.addPropertyChangeListener(StrataUIModel.PROPERTY_SUBSTRATA, + zoneSubStratasChangeListener)); - } - }; + ZonesTreeModel zonesTreeModel = (ZonesTreeModel) ZoneEditorUIHandler.this.getUI().getZonesTree().getModel(); + zonesTreeModel.updateStratas(zone, stratasToAdd, stratasToRemove); + } + }; + } @Override public void afterInit(ZoneEditorUI zoneEditorUI) { @@ -281,11 +286,24 @@ public class ZoneEditorUIHandler extends AbstractTuttiUIHandler<EditProtocolUIMo stratasChangeListener)); } - public void autoSelectNodeInTree(MouseEvent e, JPopupMenu popup) { + public void onKeyPressedOnZones(KeyEvent e) { + + if (e.getKeyCode()== KeyEvent.VK_ENTER && getUI().getRemoveButton().isEnabled()) { + getContext().getActionEngine().runAction(getUI().getRemoveButton()); + } + } + + public void onKeyPressedOnAvailableStratas(KeyEvent e) { + + if (e.getKeyCode()== KeyEvent.VK_ENTER && getUI().getAddButton().isEnabled()) { + getContext().getActionEngine().runAction(getUI().getAddButton()); + } + } + - boolean rightClick = SwingUtilities.isRightMouseButton(e); + public void onMouseClickedPressedOnZones(MouseEvent e, JPopupMenu popup) { - if (rightClick || SwingUtilities.isLeftMouseButton(e)) { + if (SwingUtilities.isRightMouseButton(e)) { // get the coordinates of the mouse click Point p = e.getPoint(); @@ -299,13 +317,20 @@ public class ZoneEditorUIHandler extends AbstractTuttiUIHandler<EditProtocolUIMo log.debug("At point [" + p + "] found Row " + rowIndex); } - if (rightClick) { + source.setSelectionRow(rowIndex); - source.setSelectionRow(rowIndex); + // on right click show popup + popup.show(source, e.getX(), e.getY()); - // on right click show popup - popup.show(source, e.getX(), e.getY()); - } + } else if (e.getClickCount() == 2 && getUI().getRemoveButton().isEnabled()) { + getContext().getActionEngine().runAction(getUI().getRemoveButton()); + } + } + + public void onMouseClickedOnAvailableStratas(MouseEvent mouseEvent) { + + if (mouseEvent.getClickCount() == 2 && getUI().getAddButton().isEnabled()) { + getContext().getActionEngine().runAction(getUI().getAddButton()); } } 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 e6e689b..5d5b730 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 @@ -70,8 +70,8 @@ public class AddStratasAction extends SimpleActionSupport<ZoneEditorUI> { } Collection<SubStrata> alreadyAddedSubStratas = stratasToAdd.stream() - .map(strata -> strata.getSubstrata()) - .flatMap(c -> c.stream()) + .map(StrataUIModel::getSubstrata) + .flatMap(Collection::stream) .collect(Collectors.toSet()); subStratasToAdd.removeAll(alreadyAddedSubStratas); 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 93a8cdf..094230f 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 @@ -41,11 +41,12 @@ public class RemoveStratasAction extends SimpleActionSupport<ZoneEditorUI> { Set<StrataUIModel> stratasToRemove = new HashSet<>(); Set<SubStrataUIModel> subStratasToRemove = new HashSet<>(); - for (TreePath treePath : selectedStratas) { + if (selectedStratas!=null) { + for (TreePath treePath : selectedStratas) { - Object node = treePath.getLastPathComponent(); + Object node = treePath.getLastPathComponent(); - if (node instanceof ZoneNode) { + if (node instanceof ZoneNode) { // ZoneUIModel zone = ((ZoneNode) node).getZone(); // if (log.isInfoEnabled()) { @@ -53,32 +54,38 @@ public class RemoveStratasAction extends SimpleActionSupport<ZoneEditorUI> { // } // stratasToRemove.addAll(zone.getStrata()); - } else if (node instanceof StrataNode) { + } else if (node instanceof StrataNode) { - StrataUIModel strata = ((StrataNode) node).getStrata(); - if (log.isInfoEnabled()) { - log.info("remove strata " + strata.getLabel()); - } - stratasToRemove.add(strata); + StrataUIModel strata = ((StrataNode) node).getStrata(); + if (log.isInfoEnabled()) { + log.info("remove strata " + strata.getLabel()); + } + stratasToRemove.add(strata); - } else if (node instanceof SubStrataNode) { - SubStrataUIModel subStrata = ((SubStrataNode) node).getSubstrata(); - if (log.isInfoEnabled()) { - log.info("remove subtrata " + subStrata.getLabel() + " from " + subStrata.getStrata()); + } else if (node instanceof SubStrataNode) { + SubStrataUIModel subStrata = ((SubStrataNode) node).getSubstrata(); + if (log.isInfoEnabled()) { + log.info("remove subtrata " + subStrata.getLabel() + " from " + subStrata.getStrata()); + } + subStratasToRemove.add(subStrata); } - subStratasToRemove.add(subStrata); + } - } + Collection<SubStrata> alreadyRemovedSubStratas = stratasToRemove.stream() + .map(StrataUIModel::getSubstrata) + .flatMap(Collection::stream) + .collect(Collectors.toSet()); - Collection<SubStrata> alreadyRemovedSubStratas = stratasToRemove.stream() - .map(strata->strata.getSubstrata()) - .flatMap(c -> c.stream()) - .collect(Collectors.toSet()); + subStratasToRemove.removeAll(alreadyRemovedSubStratas); - subStratasToRemove.removeAll(alreadyRemovedSubStratas); + zoneEditorUI.getModel().removeStratasFromZone(stratasToRemove); + zoneEditorUI.getModel().removeSubStratasFromZone(subStratasToRemove); + + // select zone path + zonesTree.setSelectionPath(selectedStratas[0].getParentPath()); + + } - zoneEditorUI.getModel().removeStratasFromZone(stratasToRemove); - zoneEditorUI.getModel().removeSubStratasFromZone(subStratasToRemove); } } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.