This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository observe. See http://git.codelutin.com/observe.git commit ac49cd8e841eb07e79b497bb4d53e667950b3f6b Author: Kevin Morin <morin@codelutin.com> Date: Mon Nov 16 16:34:41 2015 +0100 actions de déplcement des routes et marées (refs #7622) --- .../actions/ChangeRouteTripActionListener.java | 91 ++++++++++++++++ .../actions/ChangeTripProgramActionListener.java | 74 +++++-------- .../ui/tree/actions/NodeChangeActionListener.java | 115 +++++++++++++++++++++ 3 files changed, 232 insertions(+), 48 deletions(-) diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/tree/actions/ChangeRouteTripActionListener.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/tree/actions/ChangeRouteTripActionListener.java new file mode 100644 index 0000000..23bdd99 --- /dev/null +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/tree/actions/ChangeRouteTripActionListener.java @@ -0,0 +1,91 @@ +package fr.ird.observe.ui.tree.actions; + +/* + * #%L + * ObServe :: Swing + * %% + * Copyright (C) 2008 - 2015 IRD, Codelutin, Tony Chemit + * %% + * 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 fr.ird.observe.ObserveSwingApplicationContext; +import fr.ird.observe.db.ObserveSwingDataSource; +import fr.ird.observe.services.dto.seine.TripSeineDto; +import fr.ird.observe.services.service.seine.RouteService; +import fr.ird.observe.ui.DecoratorService; +import fr.ird.observe.ui.tree.ObserveNode; +import fr.ird.observe.ui.tree.ObserveTreeHelper; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * Created on 1/9/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.11 + */ +public class ChangeRouteTripActionListener extends NodeChangeActionListener { + + /** Logger. */ + private static final Log log = LogFactory.getLog(ChangeRouteTripActionListener.class); + + public ChangeRouteTripActionListener(ObserveTreeHelper treeHelper, + ObserveSwingDataSource dataSource, + String routeId, + String tripId) { + super(treeHelper, dataSource, routeId, tripId); + } + + @Override + protected ObserveNode getParentNode(ObserveNode node) { + return node.getParent().getParent(); + } + + @Override + protected ObserveNode getNewParentNode(ObserveNode grandParentNode, String parentNodeId) { + ObserveNode tripNode = getTreeHelper().getChild(grandParentNode, parentNodeId); + String routesNodeId = DecoratorService.getPropertyLabel(ObserveTreeHelper.TREE_NODE_PREFIX, + TripSeineDto.PROPERTY_ROUTE); + ObserveNode routesNode = getTreeHelper().getChild(tripNode, routesNodeId); + return routesNode; + } + + @Override + protected void closeParent(String oldParentId) { + ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get(); + applicationContext.getOpenDataManager().closeTripSeine(oldParentId); + } + + @Override + protected int moveNodeToParent(String nodeId, String parentNodeId) { + int position; + + ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get(); + + RouteService service = applicationContext.newService(RouteService.class); + position = service.moveRouteToTripSeine(nodeId, parentNodeId); + + return position; + } + + @Override + protected void openParent(String parentNodeId, String grandParentNodeId) { + ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get(); + applicationContext.getOpenDataManager().openTripSeine(grandParentNodeId, parentNodeId); + } +} diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/tree/actions/ChangeTripProgramActionListener.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/tree/actions/ChangeTripProgramActionListener.java index cdf5587..b41f3c4 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/tree/actions/ChangeTripProgramActionListener.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/tree/actions/ChangeTripProgramActionListener.java @@ -33,83 +33,61 @@ import fr.ird.observe.ui.tree.ObserveTreeHelper; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - /** * Created on 1/9/15. * * @author Tony Chemit - chemit@codelutin.com * @since 3.11 */ -public class ChangeTripProgramActionListener implements ActionListener { +public class ChangeTripProgramActionListener extends NodeChangeActionListener { /** Logger. */ private static final Log log = LogFactory.getLog(ChangeTripProgramActionListener.class); - private final String tripId; - - private final String programId; - - private final ObserveTreeHelper treeHelper; - - private final ObserveSwingDataSource dataSource; - public ChangeTripProgramActionListener(ObserveTreeHelper treeHelper, ObserveSwingDataSource dataSource, String tripId, String programId) { - this.tripId = tripId; - this.programId = programId; - this.treeHelper = treeHelper; - this.dataSource = dataSource; + super(treeHelper, dataSource, tripId, programId); } @Override - public void actionPerformed(ActionEvent event) { + protected ObserveNode getParentNode(ObserveNode node) { + return node.getParent(); + } - ObserveNode tripNode = treeHelper.getSelectedNode(); - ObserveNode rootNode = treeHelper.getRootNode(); - ObserveNode newProgramNode = treeHelper.getChild(rootNode, programId); - String oldProgramId = tripNode.getParent().getId(); - ObserveNode oldProgramNode = treeHelper.getChild(rootNode, oldProgramId); + @Override + protected ObserveNode getNewParentNode(ObserveNode grandParentNode, String parentNodeId) { + return getTreeHelper().getChild(grandParentNode, parentNodeId); + } + @Override + protected void closeParent(String oldParentId) { ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get(); + applicationContext.getOpenDataManager().closeProgram(oldParentId); + } - applicationContext.getOpenDataManager().closeProgram(oldProgramId); - + @Override + protected int moveNodeToParent(String nodeId, String parentNodeId) { int position; - if (IdDtos.isTripLonglineId(tripId)) { + ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get(); + + if (IdDtos.isTripLonglineId(nodeId)) { TripLonglineService service = applicationContext.newService(TripLonglineService.class); - position = service.moveTripLonglineToProgram(tripId, programId); + position = service.moveTripLonglineToProgram(nodeId, parentNodeId); } else { TripSeineService service = applicationContext.newService(TripSeineService.class); - position = service.moveTripSeineToProgram(tripId, programId); + position = service.moveTripSeineToProgram(nodeId, parentNodeId); } - treeHelper.removeNode(tripNode); - - ObserveNode newTripNode = treeHelper.getChild(newProgramNode, tripId); - - if (newTripNode == null) { - - // create it - if (log.isInfoEnabled()) { - log.info("Insert trip node: "); - } - treeHelper.insertNode(newProgramNode, tripNode, position); - newTripNode = tripNode; - } - - applicationContext.getOpenDataManager().openProgram(programId); - - treeHelper.reloadNode(oldProgramNode, true); - treeHelper.reloadNode(newProgramNode, true); -// treeHelper.refreshNode(oldProgramNode, true); -// treeHelper.refreshNode(newProgramNode, true); - treeHelper.selectNode(newTripNode); + return position; + } + @Override + protected void openParent(String parentNodeId, String grandParentNodeId) { + ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get(); + applicationContext.getOpenDataManager().openProgram(parentNodeId); } } diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/tree/actions/NodeChangeActionListener.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/tree/actions/NodeChangeActionListener.java new file mode 100644 index 0000000..ad4320f --- /dev/null +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/tree/actions/NodeChangeActionListener.java @@ -0,0 +1,115 @@ +package fr.ird.observe.ui.tree.actions; + +/* + * #%L + * ObServe :: Swing + * %% + * Copyright (C) 2008 - 2015 IRD, Codelutin, Tony Chemit + * %% + * 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 fr.ird.observe.db.ObserveSwingDataSource; +import fr.ird.observe.ui.tree.ObserveNode; +import fr.ird.observe.ui.tree.ObserveTreeHelper; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +/** + * Created on 1/9/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.11 + */ +public abstract class NodeChangeActionListener implements ActionListener { + + /** Logger. */ + private static final Log log = LogFactory.getLog(NodeChangeActionListener.class); + + private final String nodeId; + + private final String parentNodeId; + + private final ObserveTreeHelper treeHelper; + + private final ObserveSwingDataSource dataSource; + + public NodeChangeActionListener(ObserveTreeHelper treeHelper, + ObserveSwingDataSource dataSource, + String nodeId, + String parentNodeId) { + this.nodeId = nodeId; + this.parentNodeId = parentNodeId; + this.treeHelper = treeHelper; + this.dataSource = dataSource; + } + + @Override + public void actionPerformed(ActionEvent event) { + + ObserveNode node = treeHelper.getSelectedNode(); + ObserveNode oldParentNode = getParentNode(node); + String oldParentId = oldParentNode.getId(); + ObserveNode grandParentNode = oldParentNode.getParent(); + String grandParentNodeId = grandParentNode.getId(); + ObserveNode newParentNode = getNewParentNode(grandParentNode, parentNodeId); + + closeParent(oldParentId); + + int position = moveNodeToParent(nodeId, parentNodeId); + + treeHelper.removeNode(node); + + ObserveNode newNode = treeHelper.getChild(newParentNode, nodeId); + + if (newNode == null) { + + // create it + if (log.isInfoEnabled()) { + log.info("Insert node: "); + } + treeHelper.insertNode(newParentNode, node, position); + newNode = node; + } + + openParent(parentNodeId, grandParentNodeId); + + treeHelper.reloadNode(grandParentNode, true); +// treeHelper.reloadNode(newParentNode, true); +// treeHelper.refreshNode(oldParentNode, true); +// treeHelper.refreshNode(newParentNode, true); + treeHelper.selectNode(newNode); + + } + + public ObserveTreeHelper getTreeHelper() { + return treeHelper; + } + + protected abstract ObserveNode getParentNode(ObserveNode node); + + protected abstract ObserveNode getNewParentNode(ObserveNode grandParentNode, String parentNodeId); + + protected abstract void closeParent(String oldParentId); + + protected abstract int moveNodeToParent(String nodeId, String parentNodeId); + + protected abstract void openParent(String parentNodeId, String grandParentNodeId); +} -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.