Tony CHEMIT pushed to branch develop-5.x at ultreiaio / ird-observe Commits: 1c750803 by Tony CHEMIT at 2017-06-12T17:37:32+02:00 Problème d'UI/menu contextuel lors du déplacement d'items (routes, activités) (See #768) - - - - - 26 changed files: - application-swing/src/main/java/fr/ird/observe/application/swing/ui/ObserveMainUI.jaxx - + application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/MoveActivityLonglineUIAction.java - application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/MoveActivityLonglinesUIAction.java - + application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/MoveActivitySeineUIAction.java - application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/MoveActivitySeinesUIAction.java - + application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/MoveMultipleDataUIActionSupport.java - + application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/MoveRouteUIAction.java - application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/MoveRoutesUIAction.java - + application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/MoveSingleDataUIActionSupport.java - + application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/MoveTripLonglineUIAction.java - application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/MoveTripLonglinesUIAction.java - + application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/MoveTripSeineUIAction.java - application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/MoveTripSeinesUIAction.java - application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/menu/MoveTripNodeMenuPopulator.java → application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/MoveTripUIAction.java - application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/MoveTripsUIAction.java - application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/ObserveNavigationTreeShowPopupAction.java - − application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/actions/ChangeActivityRouteActionListener.java - − application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/actions/ChangeActivityTripActionListener.java - − application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/actions/ChangeRouteTripActionListener.java - − application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/actions/ChangeTripProgramActionListener.java - − application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/actions/NodeChangeActionListener.java - − application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/menu/MoveActivityLonglineNodeMenuPopulator.java - − application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/menu/MoveActivitySeineNodeMenuPopulator.java - − application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/menu/MoveNodeMenuPopulator.java - − application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/menu/MoveRouteNodeMenuPopulator.java - application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/node/ObserveNode.java Changes: ===================================== application-swing/src/main/java/fr/ird/observe/application/swing/ui/ObserveMainUI.jaxx ===================================== --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/ObserveMainUI.jaxx +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/ObserveMainUI.jaxx @@ -86,7 +86,7 @@ <JPopupMenu id='scopeDownPopup'/> <JPopupMenu id='navigationPopup'> <JMenuItem id="navigationNoAction"/> - <JMenu id="navigationMoveAction"/> + <JMenuItem id="navigationMoveAction"/> <JMenuItem id="navigationOpenAction"/> <JMenuItem id="navigationCloseAction"/> <JMenuItem id="navigationDeleteAction"/> ===================================== application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/MoveActivityLonglineUIAction.java ===================================== --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/MoveActivityLonglineUIAction.java @@ -0,0 +1,123 @@ +/* + * #%L + * ObServe :: Application Swing + * %% + * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io + * %% + * 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% + */ +package fr.ird.observe.application.swing.ui.actions.shared; + +import fr.ird.observe.application.swing.ObserveOpenDataManager; +import fr.ird.observe.application.swing.ObserveSwingApplicationContext; +import fr.ird.observe.application.swing.decoration.ObserveI18nDecoratorHelper; +import fr.ird.observe.application.swing.decoration.decorators.DataReferenceDecorator; +import fr.ird.observe.application.swing.ui.ObserveMainUI; +import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; +import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; +import fr.ird.observe.application.swing.ui.tree.node.TripLonglineNode; +import fr.ird.observe.application.swing.ui.util.DecoratedNodeEntity; +import fr.ird.observe.services.ObserveServicesProvider; +import fr.ird.observe.services.dto.longline.ActivityLonglineDto; +import fr.ird.observe.services.dto.longline.TripLonglineDto; +import java.util.Optional; +import javax.swing.JOptionPane; + + +import static org.nuiton.i18n.I18n.n; +import static org.nuiton.i18n.I18n.t; + +/** + * Action pour changer le programme d'une ou plusieurs marée dans la liste. + * + * @author Tony Chemit - dev@ultreia.io + * @since 5.0 + */ +public class MoveActivityLonglineUIAction extends MoveSingleDataUIActionSupport { + + private static final long serialVersionUID = 1L; + + public static final String ACTION_NAME = "moveActivityLongline"; + + public MoveActivityLonglineUIAction(ObserveMainUI mainUI) { + super(mainUI, + ACTION_NAME, + n("observe.navigationMenu.move.activityLongline"), + n("observe.navigationMenu.move.activityLongline"), + "move-activities" + ); + } + + @Override + Optional<String> getNewParentId(ObserveMainUI mainUI, ObserveNode oldParentNode) { + return chooseNewTripLongline(mainUI, oldParentNode); + } + + @Override + int moveData(ObserveServicesProvider servicesProvider, ObserveOpenDataManager openDataManager, String oldParentId, String newParentId, String dataId) { + + return servicesProvider.newActivityLonglineService().moveActivityLonglineToTripLongline(dataId, newParentId); + } + + @Override + void closeNode(ObserveOpenDataManager openDataManager, String dataId) { + if (openDataManager.isOpenActivityLongline(dataId)) { + openDataManager.closeActivityLongline(dataId); + } + } + + @Override + ObserveNode getNewParentNode(ObserveTreeHelper treeHelper, ObserveNode grandParentNode, String newParentId) { + ObserveNode tripLonglineNode = treeHelper.getChild(grandParentNode, newParentId); + String activitiesNodeId = ObserveI18nDecoratorHelper.getTypePluralI18nKey(ActivityLonglineDto.class); + return treeHelper.getChild(tripLonglineNode, activitiesNodeId); + } + + static Optional<String> chooseNewTripLongline(ObserveMainUI ui, ObserveNode oldParentNode) { + + ObserveNode programNode = oldParentNode.getParent(); + String oldTripLonglineId = oldParentNode.getId(); + int tripLonglineNb = programNode.getChildCount(); + + ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get(); + DataReferenceDecorator<TripLonglineDto> decorator = applicationContext.getDecoratorService().getDataReferenceDecorator(TripLonglineDto.class); + + //on crée un tableau avec une marée en moins car on ne propose pas la marée actuelle + DecoratedNodeEntity[] decoratedTripLonglines = new DecoratedNodeEntity[tripLonglineNb - 1]; + + int j = 0; + for (int i = 0; i < tripLonglineNb; i++) { + + TripLonglineNode tripLonglineNode = (TripLonglineNode) programNode.getChildAt(i); + + String tripLonglineId = tripLonglineNode.getId(); + + if (!oldTripLonglineId.equals(tripLonglineId)) { + decoratedTripLonglines[j++] = DecoratedNodeEntity.newDecoratedNodeEntity(tripLonglineNode, decorator); + } + } + + Object decoratedTripLongline = JOptionPane.showInputDialog(ui, + t("observe.action.choose.tripLongline.message"), + t("observe.action.choose.tripLongline.title"), + JOptionPane.QUESTION_MESSAGE, + null, + decoratedTripLonglines, + null); + return Optional.ofNullable(decoratedTripLongline != null ? ((DecoratedNodeEntity) decoratedTripLongline).getId() : null); + } + +} ===================================== application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/MoveActivityLonglinesUIAction.java ===================================== --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/MoveActivityLonglinesUIAction.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/MoveActivityLonglinesUIAction.java @@ -24,31 +24,17 @@ package fr.ird.observe.application.swing.ui.actions.shared; import fr.ird.observe.application.swing.ObserveOpenDataManager; import fr.ird.observe.application.swing.ObserveSwingApplicationContext; import fr.ird.observe.application.swing.decoration.ObserveI18nDecoratorHelper; -import fr.ird.observe.application.swing.decoration.decorators.DataReferenceDecorator; import fr.ird.observe.application.swing.ui.ObserveMainUI; -import fr.ird.observe.application.swing.ui.content.ContentUI; import fr.ird.observe.application.swing.ui.content.list.impl.longline.ActivityLonglinesUI; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; -import fr.ird.observe.application.swing.ui.tree.node.TripLonglineNode; -import fr.ird.observe.application.swing.ui.util.DecoratedNodeEntity; -import fr.ird.observe.services.dto.DataReference; +import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; +import fr.ird.observe.services.ObserveServicesProvider; import fr.ird.observe.services.dto.longline.ActivityLonglineDto; -import fr.ird.observe.services.dto.longline.TripLonglineDto; -import fr.ird.observe.services.service.longline.ActivityLonglineService; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import javax.swing.JComponent; -import javax.swing.JOptionPane; -import javax.swing.SwingUtilities; -import java.awt.event.ActionEvent; import java.util.List; import java.util.Optional; -import java.util.stream.Collectors; + import static org.nuiton.i18n.I18n.n; -import static org.nuiton.i18n.I18n.t; /** * Action pour changer le programme d'une ou plusieurs marée dans la liste. @@ -56,15 +42,10 @@ import static org.nuiton.i18n.I18n.t; * @author Kevin Morin (Code Lutin) * @since 5.0 */ -public class MoveActivityLonglinesUIAction extends AbstractUIAction { +public class MoveActivityLonglinesUIAction extends MoveMultipleDataUIActionSupport<ActivityLonglinesUI> { private static final long serialVersionUID = 1L; - /** - * Logger. - */ - private static final Log log = LogFactory.getLog(MoveActivityLonglinesUIAction.class); - public static final String ACTION_NAME = "moveActivityLonglines"; public MoveActivityLonglinesUIAction(ObserveMainUI mainUI) { @@ -72,95 +53,23 @@ public class MoveActivityLonglinesUIAction extends AbstractUIAction { ACTION_NAME, n("observe.content.action.move.activities.longline"), n("observe.content.action.move.activities.longline.tip"), - "move-activities" + "move-activities", + ActivityLonglinesUI.class ); } @Override - public void actionPerformed(final ActionEvent e) { - - SwingUtilities.invokeLater(() -> { - JComponent c = (JComponent) e.getSource(); - ContentUI<?> ui = (ContentUI<?>) - c.getClientProperty("ui"); - if (ui == null) { - throw new IllegalStateException( - "could not find client property " + - "ui on component" + c); - } - - if (!(ui instanceof ActivityLonglinesUI)) { - throw new IllegalStateException("Can not come here!"); - } - ActivityLonglinesUI activityLonglinesUI = (ActivityLonglinesUI) ui; - - - // get current triplongline id - ObserveTreeHelper treeHelper = getMainUI().getTreeHelper(); - ObserveNode oldActivitiesNode = treeHelper.getSelectedNode(); - ObserveNode oldTripLonglineNode = oldActivitiesNode.getParent(); - - // choose the new tripLongline - String tripLonglineId = chooseNewTripLongline(ui, oldTripLonglineNode); - - if (tripLonglineId != null) { - - if (log.isInfoEnabled()) { - log.info("Will move activities to trip: " + tripLonglineId); - } - // change the tripLongline of the selected activities - List<DataReference<ActivityLonglineDto>> selectedDatas = activityLonglinesUI.getModel().getSelectedDatas(); - List<String> activityIds = selectedDatas.stream() - .map(DataReference.ID_FUNCTION) - .collect(Collectors.toList()); - ActivityLonglineService service = ObserveSwingApplicationContext.get().getMainDataSourceServicesProvider().newActivityLonglineService(); -// List<Integer> positions = - service.moveActivityLonglinesToTripLongline(activityIds, tripLonglineId); - - // update the tree - updateTree(oldActivitiesNode, tripLonglineId, activityIds); - } - - }); - + List<Integer> moveData(List<String> dataIds, String newParentId, ObserveServicesProvider servicesProvider) { + return servicesProvider.newActivityLonglineService().moveActivityLonglinesToTripLongline(dataIds, newParentId); } - protected String chooseNewTripLongline(ContentUI<?> ui, ObserveNode oldTripLonglineNode) { - ObserveNode programNode = oldTripLonglineNode.getParent(); - String oldTripLonglineId = oldTripLonglineNode.getId(); - int tripLonglineNb = programNode.getChildCount(); - - ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get(); - DataReferenceDecorator<TripLonglineDto> decorator = applicationContext.getDecoratorService().getDataReferenceDecorator(TripLonglineDto.class); - - //on crée un tableau avec une marée en moins car on ne propose pas la marée actuelle - DecoratedNodeEntity[] decoratedTripLonglines = new DecoratedNodeEntity[tripLonglineNb - 1]; - - int j = 0; - for (int i = 0; i < tripLonglineNb; i++) { - - TripLonglineNode tripLonglineNode = (TripLonglineNode) programNode.getChildAt(i); - - String tripLonglineId = tripLonglineNode.getId(); - - if (!oldTripLonglineId.equals(tripLonglineId)) { - decoratedTripLonglines[j++] = DecoratedNodeEntity.newDecoratedNodeEntity(tripLonglineNode, decorator); - } - } - - Object decoratedTripLongline = JOptionPane.showInputDialog(ui, - t("observe.action.choose.tripLongline.message"), - t("observe.action.choose.tripLongline.title"), - JOptionPane.QUESTION_MESSAGE, - null, - decoratedTripLonglines, - null); - return decoratedTripLongline != null ? ((DecoratedNodeEntity) decoratedTripLongline).getId() : null; + @Override + Optional<String> getNewParentId(ObserveMainUI mainUI, ObserveNode oldParentNode) { + return MoveActivityLonglineUIAction.chooseNewTripLongline(getMainUI(), oldParentNode); } - protected void updateTree(ObserveNode oldActivitiesNode, - String tripLonglineId, - List<String> activityIds) { + @Override + void updateUI(ActivityLonglinesUI ui, ObserveNode oldActivitiesNode, String tripLonglineId, List<String> activityIds, List<Integer> positions) { ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get(); ObserveOpenDataManager openDataManager = applicationContext.getOpenDataManager(); @@ -179,9 +88,7 @@ public class MoveActivityLonglinesUIAction extends AbstractUIAction { .findFirst(); // If so, we close it to avoid ending up with an open activity into a closed trip. - if (openActivity.isPresent()) { - openDataManager.closeActivityLongline(openActivity.get()); - } + openActivity.ifPresent(openDataManager::closeActivityLongline); // Let's reload the sub tree of each activities node. // As the change have already be done in database, we just call the child loaders to regenerate the activities nodes sub trees ===================================== application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/MoveActivitySeineUIAction.java ===================================== --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/MoveActivitySeineUIAction.java @@ -0,0 +1,123 @@ +/* + * #%L + * ObServe :: Application Swing + * %% + * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io + * %% + * 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% + */ +package fr.ird.observe.application.swing.ui.actions.shared; + +import fr.ird.observe.application.swing.ObserveOpenDataManager; +import fr.ird.observe.application.swing.ObserveSwingApplicationContext; +import fr.ird.observe.application.swing.decoration.ObserveI18nDecoratorHelper; +import fr.ird.observe.application.swing.decoration.decorators.DataReferenceDecorator; +import fr.ird.observe.application.swing.ui.ObserveMainUI; +import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; +import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; +import fr.ird.observe.application.swing.ui.tree.node.RouteSeineNode; +import fr.ird.observe.application.swing.ui.util.DecoratedNodeEntity; +import fr.ird.observe.services.ObserveServicesProvider; +import fr.ird.observe.services.dto.seine.ActivitySeineDto; +import fr.ird.observe.services.dto.seine.RouteDto; +import java.util.Optional; +import javax.swing.JOptionPane; + + +import static org.nuiton.i18n.I18n.n; +import static org.nuiton.i18n.I18n.t; + +/** + * Action pour changer le programme d'une ou plusieurs marée dans la liste. + * + * @author Tony Chemit - dev@ultreia.io + * @since 5.0 + */ +public class MoveActivitySeineUIAction extends MoveSingleDataUIActionSupport { + + private static final long serialVersionUID = 1L; + + public static final String ACTION_NAME = "moveActivitySeine"; + + public MoveActivitySeineUIAction(ObserveMainUI mainUI) { + super(mainUI, + ACTION_NAME, + n("observe.navigationMenu.move.activitySeine"), + n("observe.navigationMenu.move.activitySeine"), + "move-activities" + ); + } + + @Override + Optional<String> getNewParentId(ObserveMainUI mainUI, ObserveNode oldParentNode) { + return chooseNewRoute(mainUI, oldParentNode); + } + + @Override + int moveData(ObserveServicesProvider servicesProvider, ObserveOpenDataManager openDataManager, String oldParentId, String newParentId, String dataId) { + return servicesProvider.newActivitySeineService().moveActivitySeineToRoute(dataId, newParentId); + } + + @Override + void closeNode(ObserveOpenDataManager openDataManager, String dataId) { + if (openDataManager.isOpenActivitySeine(dataId)) { + openDataManager.closeActivitySeine(dataId); + } + } + + @Override + ObserveNode getNewParentNode(ObserveTreeHelper treeHelper, ObserveNode grandParentNode, String newParentId) { + ObserveNode routeNode = treeHelper.getChild(grandParentNode, newParentId); + String activitiesNodeId = ObserveI18nDecoratorHelper.getTypePluralI18nKey(ActivitySeineDto.class); + return treeHelper.getChild(routeNode, activitiesNodeId); + } + + static Optional<String> chooseNewRoute(ObserveMainUI mainUI, ObserveNode oldParentNode) { + + ObserveNode routesNode = oldParentNode.getParent(); + String oldRouteId = oldParentNode.getId(); + int routeNb = routesNode.getChildCount(); + + ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get(); + DataReferenceDecorator<RouteDto> decorator = applicationContext.getDecoratorService().getDataReferenceDecorator(RouteDto.class); + + //on crée un tableau avec une route en moins car on ne propose pas la route actuel + DecoratedNodeEntity[] decoratedRoutes = new DecoratedNodeEntity[routeNb - 1]; + + int j = 0; + for (int i = 0; i < routeNb; i++) { + + RouteSeineNode routeNode = (RouteSeineNode) routesNode.getChildAt(i); + + String routeId = routeNode.getId(); + + if (!oldRouteId.equals(routeId)) { + decoratedRoutes[j++] = DecoratedNodeEntity.newDecoratedNodeEntity(routeNode, decorator); + } + } + + Object decoratedRoute = JOptionPane.showInputDialog(mainUI, + t("observe.action.choose.route.message"), + t("observe.action.choose.route.title"), + JOptionPane.QUESTION_MESSAGE, + null, + decoratedRoutes, + null); + + return Optional.ofNullable(decoratedRoute != null ? ((DecoratedNodeEntity) decoratedRoute).getId() : null); + } + +} ===================================== application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/MoveActivitySeinesUIAction.java ===================================== --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/MoveActivitySeinesUIAction.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/MoveActivitySeinesUIAction.java @@ -24,32 +24,17 @@ package fr.ird.observe.application.swing.ui.actions.shared; import fr.ird.observe.application.swing.ObserveOpenDataManager; import fr.ird.observe.application.swing.ObserveSwingApplicationContext; import fr.ird.observe.application.swing.decoration.ObserveI18nDecoratorHelper; -import fr.ird.observe.application.swing.decoration.decorators.DataReferenceDecorator; import fr.ird.observe.application.swing.ui.ObserveMainUI; -import fr.ird.observe.application.swing.ui.content.ContentUI; import fr.ird.observe.application.swing.ui.content.list.impl.seine.ActivitySeinesUI; -import fr.ird.observe.application.swing.ui.content.list.impl.seine.ActivitySeinesUIModel; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; -import fr.ird.observe.application.swing.ui.tree.node.RouteSeineNode; -import fr.ird.observe.application.swing.ui.util.DecoratedNodeEntity; -import fr.ird.observe.services.dto.DataReference; +import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; +import fr.ird.observe.services.ObserveServicesProvider; import fr.ird.observe.services.dto.seine.ActivitySeineDto; -import fr.ird.observe.services.dto.seine.RouteDto; -import fr.ird.observe.services.service.seine.ActivitySeineService; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import javax.swing.JComponent; -import javax.swing.JOptionPane; -import javax.swing.SwingUtilities; -import java.awt.event.ActionEvent; import java.util.List; import java.util.Optional; -import java.util.stream.Collectors; + import static org.nuiton.i18n.I18n.n; -import static org.nuiton.i18n.I18n.t; /** * Action pour changer le programme d'une ou plusieurs marée dans la liste. @@ -57,15 +42,10 @@ import static org.nuiton.i18n.I18n.t; * @author Kevin Morin (Code Lutin) * @since 5.0 */ -public class MoveActivitySeinesUIAction extends AbstractUIAction { +public class MoveActivitySeinesUIAction extends MoveMultipleDataUIActionSupport<ActivitySeinesUI> { private static final long serialVersionUID = 1L; - /** - * Logger. - */ - private static final Log log = LogFactory.getLog(MoveActivitySeinesUIAction.class); - public static final String ACTION_NAME = "moveActivitySeines"; public MoveActivitySeinesUIAction(ObserveMainUI mainUI) { @@ -73,115 +53,46 @@ public class MoveActivitySeinesUIAction extends AbstractUIAction { ACTION_NAME, n("observe.content.action.move.activities.seine"), n("observe.content.action.move.activities.seine.tip"), - "move-activities" + "move-activities", + ActivitySeinesUI.class ); } @Override - public void actionPerformed(final ActionEvent e) { - - SwingUtilities.invokeLater(() -> { - JComponent c = (JComponent) e.getSource(); - ContentUI<?> ui = (ContentUI<?>) - c.getClientProperty("ui"); - if (ui == null) { - throw new IllegalStateException( - "could not find client property " + - "ui on component" + c); - } - - if (!(ui instanceof ActivitySeinesUI)) { - throw new IllegalStateException("Can not come here!"); - } - - // get current route id - ObserveTreeHelper treeHelper = getMainUI().getTreeHelper(); - ObserveNode oldActivitiesNode = treeHelper.getSelectedNode(); - ObserveNode oldRouteNode = oldActivitiesNode.getParent(); - - // choose the new route - String routeId = chooseNewRoute(ui, oldRouteNode); - - if (routeId != null) { - // change the route of the selected activities - List<DataReference<ActivitySeineDto>> selectedDatas = ((ActivitySeinesUIModel) ui.getModel()).getSelectedDatas(); - List<String> activityIds = selectedDatas.stream() - .map(DataReference.ID_FUNCTION) - .collect(Collectors.toList()) ; - ActivitySeineService service = ObserveSwingApplicationContext.get().getMainDataSourceServicesProvider().newActivitySeineService(); - List<Integer> positions = service.moveActivitySeinesToRoute(activityIds, routeId); - - // update the tree - updateTree(oldActivitiesNode, routeId, activityIds); - } - - }); - + Optional<String> getNewParentId(ObserveMainUI mainUI, ObserveNode oldParentNode) { + return MoveActivitySeineUIAction.chooseNewRoute(getMainUI(), oldParentNode); } - protected String chooseNewRoute(ContentUI<?> ui, ObserveNode oldRouteNode) { - ObserveNode routesNode = oldRouteNode.getParent(); - String oldRouteId = oldRouteNode.getId(); - int routeNb = routesNode.getChildCount(); - - ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get(); - DataReferenceDecorator<RouteDto> decorator = applicationContext.getDecoratorService().getDataReferenceDecorator(RouteDto.class); - - //on crée un tableau avec une route en moins car on ne propose pas la route actuel - DecoratedNodeEntity[] decoratedRoutes = new DecoratedNodeEntity[routeNb - 1]; - - int j = 0; - for (int i = 0; i < routeNb; i++) { - - RouteSeineNode routeNode = (RouteSeineNode) routesNode.getChildAt(i); - - String routeId = routeNode.getId(); - - if (!oldRouteId.equals(routeId)) { - decoratedRoutes[j++] = DecoratedNodeEntity.newDecoratedNodeEntity(routeNode, decorator); - } - } - - Object decoratedRoute = JOptionPane.showInputDialog(ui, - t("observe.action.choose.route.message"), - t("observe.action.choose.route.title"), - JOptionPane.QUESTION_MESSAGE, - null, - decoratedRoutes, - null); - - return decoratedRoute != null ? ((DecoratedNodeEntity) decoratedRoute).getId() : null; + @Override + List<Integer> moveData(List<String> dataIds, String newParentId, ObserveServicesProvider servicesProvider) { + return servicesProvider.newActivitySeineService().moveActivitySeinesToRoute(dataIds, newParentId); } - protected void updateTree(ObserveNode oldActivitiesNode, - String routeId, - List<String> activityIds) { + @Override + void updateUI(ActivitySeinesUI ui, ObserveNode oldParentNode, String newParentId, List<String> dataIds, List<Integer> positions) { ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get(); ObserveOpenDataManager openDataManager = applicationContext.getOpenDataManager(); ObserveTreeHelper treeHelper = getMainUI().getTreeHelper(); - ObserveNode oldRouteNode = oldActivitiesNode.getParent(); + ObserveNode oldRouteNode = oldParentNode.getParent(); ObserveNode routesNode = oldRouteNode.getParent(); - ObserveNode tripNode = routesNode.getParent(); - ObserveNode newRouteNode = treeHelper.getChild(routesNode, routeId); + ObserveNode newRouteNode = treeHelper.getChild(routesNode, newParentId); String activitiesNodeId = ObserveI18nDecoratorHelper.getTypePluralI18nKey(ActivitySeineDto.class); ObserveNode newActivitiesNode = treeHelper.getChild(newRouteNode, activitiesNodeId); // Let's check if we're moving an open activity - Optional<String> openActivity = activityIds + Optional<String> openActivity = dataIds .stream() .filter(openDataManager::isOpenActivitySeine) .findFirst(); // If so, we close it to avoid ending up with an open activity into a closed route. - if (openActivity.isPresent()) { - openDataManager.closeActivitySeine(openActivity.get()); - } + openActivity.ifPresent(openDataManager::closeActivitySeine); // Let's reload the sub tree of each activities node. // As the change have already be done in database, we just call the child loaders to regenerate the activities nodes sub trees - treeHelper.reloadNodeSubTree(oldActivitiesNode, true); + treeHelper.reloadNodeSubTree(oldParentNode, true); treeHelper.reloadNodeSubTree(newActivitiesNode, true); // Let's put the focus on the activities node which received the activities ===================================== application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/MoveMultipleDataUIActionSupport.java ===================================== --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/MoveMultipleDataUIActionSupport.java @@ -0,0 +1,69 @@ +package fr.ird.observe.application.swing.ui.actions.shared; + +import fr.ird.observe.application.swing.ObserveSwingApplicationContext; +import fr.ird.observe.application.swing.ui.ObserveMainUI; +import fr.ird.observe.application.swing.ui.content.ContentUI; +import fr.ird.observe.application.swing.ui.content.list.ContentListUI; +import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; +import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; +import fr.ird.observe.services.ObserveServicesProvider; +import fr.ird.observe.services.dto.DataReference; +import java.awt.event.ActionEvent; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; +import javax.swing.JComponent; + +/** + * Created by tchemit on 12/06/17. + * + * @author Tony Chemit - dev@tchemit.fr + */ +public abstract class MoveMultipleDataUIActionSupport<U extends ContentListUI<?, ?>> extends AbstractUIAction { + + private final Class<U> uiType; + + MoveMultipleDataUIActionSupport(ObserveMainUI mainUI, String actionId, String label, String shortDescription, String actionIcon, Class<U> uiType) { + super(mainUI, actionId, label, shortDescription, actionIcon); + this.uiType = uiType; + } + + @Override + public final void actionPerformed(ActionEvent e) { + + JComponent c = (JComponent) e.getSource(); + ContentUI<?> ui1 = (ContentUI<?>) c.getClientProperty("ui"); + if (ui1 == null) { + throw new IllegalStateException("could not find client property ui on component" + c); + } + if (!uiType.isAssignableFrom(ui1.getClass())) { + throw new IllegalStateException("Can not come here!"); + } + + @SuppressWarnings("unchecked") U ui = (U) ui1; + + ObserveTreeHelper treeHelper = getMainUI().getTreeHelper(); + ObserveNode node = treeHelper.getSelectedNode(); + + ObserveNode oldParentNode = node.getParent().isRoot() ? node : node.getParent(); + + Optional<String> optionalNewParentId = getNewParentId(getMainUI(), oldParentNode); + + if (optionalNewParentId.isPresent()) { + + List<String> dataIds = ui.getModel().getSelectedDatas().stream().map(DataReference.ID_FUNCTION).collect(Collectors.toList()); + + List<Integer> positions = moveData(dataIds, optionalNewParentId.get(), ObserveSwingApplicationContext.get().getMainDataSourceServicesProvider()); + + updateUI(ui, node, optionalNewParentId.get(), dataIds, positions); + } + + } + + abstract Optional<String> getNewParentId(ObserveMainUI mainUI, ObserveNode oldParentNode); + + abstract List<Integer> moveData(List<String> dataIds, String newParentId, ObserveServicesProvider servicesProvider); + + abstract void updateUI(U ui, ObserveNode oldParentNode, String newParentId, List<String> dataIds, List<Integer> positions); + +} ===================================== application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/MoveRouteUIAction.java ===================================== --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/MoveRouteUIAction.java @@ -0,0 +1,121 @@ +/* + * #%L + * ObServe :: Application Swing + * %% + * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io + * %% + * 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% + */ +package fr.ird.observe.application.swing.ui.actions.shared; + +import fr.ird.observe.application.swing.ObserveOpenDataManager; +import fr.ird.observe.application.swing.ObserveSwingApplicationContext; +import fr.ird.observe.application.swing.decoration.ObserveI18nDecoratorHelper; +import fr.ird.observe.application.swing.decoration.decorators.DataReferenceDecorator; +import fr.ird.observe.application.swing.ui.ObserveMainUI; +import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; +import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; +import fr.ird.observe.application.swing.ui.tree.node.TripSeineNode; +import fr.ird.observe.application.swing.ui.util.DecoratedNodeEntity; +import fr.ird.observe.services.ObserveServicesProvider; +import fr.ird.observe.services.dto.seine.RouteDto; +import fr.ird.observe.services.dto.seine.TripSeineDto; +import java.util.Optional; +import javax.swing.JOptionPane; + + +import static org.nuiton.i18n.I18n.n; +import static org.nuiton.i18n.I18n.t; + +/** + * Action pour changer le programme d'une ou plusieurs marée dans la liste. + * + * @author Tony Chemit - dev@ultreia.io + * @since 5.0 + */ +public class MoveRouteUIAction extends MoveSingleDataUIActionSupport { + + private static final long serialVersionUID = 1L; + + public static final String ACTION_NAME = "moveRoute"; + + public MoveRouteUIAction(ObserveMainUI mainUI) { + super(mainUI, + ACTION_NAME, + n("observe.navigationMenu.move.route"), + n("observe.navigationMenu.move.route"), + "move-routes" + ); + } + + @Override + Optional<String> getNewParentId(ObserveMainUI mainUI, ObserveNode oldParentNode) { + return chooseNewTripSeine(mainUI, oldParentNode); + } + + @Override + int moveData(ObserveServicesProvider servicesProvider, ObserveOpenDataManager openDataManager, String oldParentId, String newParentId, String dataId) { + return servicesProvider.newRouteService().moveRouteToTripSeine(dataId, newParentId); + } + + @Override + void closeNode(ObserveOpenDataManager openDataManager, String dataId) { + if (openDataManager.isOpenRoute(dataId)) { + openDataManager.closeRoute(dataId); + } + } + + @Override + ObserveNode getNewParentNode(ObserveTreeHelper treeHelper, ObserveNode grandParentNode, String newParentId) { + ObserveNode tripNode = treeHelper.getChild(grandParentNode, newParentId); + String routesNodeId = ObserveI18nDecoratorHelper.getTypePluralI18nKey(RouteDto.class); + return treeHelper.getChild(tripNode, routesNodeId); + } + + static Optional<String> chooseNewTripSeine(ObserveMainUI mainUI, ObserveNode oldTripSeineNode) { + ObserveNode programNode = oldTripSeineNode.getParent(); + String oldTripSeineId = oldTripSeineNode.getId(); + int tripSeineNb = programNode.getChildCount(); + + ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get(); + DataReferenceDecorator<TripSeineDto> decorator = applicationContext.getDecoratorService().getDataReferenceDecorator(TripSeineDto.class); + + //on crée un tableau avec une marée en moins car on ne propose pas la marée actuel + DecoratedNodeEntity[] decoratedTripSeines = new DecoratedNodeEntity[tripSeineNb - 1]; + + int j = 0; + for (int i = 0; i < tripSeineNb; i++) { + + TripSeineNode tripSeineNode = (TripSeineNode) programNode.getChildAt(i); + + String tripSeineId = tripSeineNode.getId(); + + if (!oldTripSeineId.equals(tripSeineId)) { + decoratedTripSeines[j++] = DecoratedNodeEntity.newDecoratedNodeEntity(tripSeineNode, decorator); + } + } + + Object decoratedTripSeine = JOptionPane.showInputDialog(mainUI, + t("observe.action.choose.tripSeine.message"), + t("observe.action.choose.tripSeine.title"), + JOptionPane.QUESTION_MESSAGE, + null, + decoratedTripSeines, + null); + return Optional.ofNullable(decoratedTripSeine != null ? ((DecoratedNodeEntity) decoratedTripSeine).getId() : null); + } + +} ===================================== application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/MoveRoutesUIAction.java ===================================== --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/MoveRoutesUIAction.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/MoveRoutesUIAction.java @@ -24,31 +24,17 @@ package fr.ird.observe.application.swing.ui.actions.shared; import fr.ird.observe.application.swing.ObserveOpenDataManager; import fr.ird.observe.application.swing.ObserveSwingApplicationContext; import fr.ird.observe.application.swing.decoration.ObserveI18nDecoratorHelper; -import fr.ird.observe.application.swing.decoration.decorators.DataReferenceDecorator; import fr.ird.observe.application.swing.ui.ObserveMainUI; -import fr.ird.observe.application.swing.ui.content.ContentUI; import fr.ird.observe.application.swing.ui.content.list.impl.seine.RoutesUI; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; -import fr.ird.observe.application.swing.ui.tree.node.TripSeineNode; -import fr.ird.observe.application.swing.ui.util.DecoratedNodeEntity; -import fr.ird.observe.services.dto.DataReference; +import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; +import fr.ird.observe.services.ObserveServicesProvider; import fr.ird.observe.services.dto.seine.RouteDto; -import fr.ird.observe.services.dto.seine.TripSeineDto; -import fr.ird.observe.services.service.seine.RouteService; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import javax.swing.JComponent; -import javax.swing.JOptionPane; -import javax.swing.SwingUtilities; -import java.awt.event.ActionEvent; import java.util.List; import java.util.Optional; -import java.util.stream.Collectors; + import static org.nuiton.i18n.I18n.n; -import static org.nuiton.i18n.I18n.t; /** * Action pour changer le programme d'une ou plusieurs marée dans la liste. @@ -56,15 +42,10 @@ import static org.nuiton.i18n.I18n.t; * @author Kevin Morin (Code Lutin) * @since 5.0 */ -public class MoveRoutesUIAction extends AbstractUIAction { +public class MoveRoutesUIAction extends MoveMultipleDataUIActionSupport<RoutesUI> { private static final long serialVersionUID = 1L; - /** - * Logger. - */ - private static final Log log = LogFactory.getLog(MoveRoutesUIAction.class); - public static final String ACTION_NAME = "moveRoutes"; public MoveRoutesUIAction(ObserveMainUI mainUI) { @@ -72,88 +53,23 @@ public class MoveRoutesUIAction extends AbstractUIAction { ACTION_NAME, n("observe.content.action.move.routes"), n("observe.content.action.move.routes.tip"), - "move-routes" + "move-routes", + RoutesUI.class ); } @Override - public void actionPerformed(final ActionEvent e) { - - SwingUtilities.invokeLater(() -> { - JComponent c = (JComponent) e.getSource(); - ContentUI<?> ui = (ContentUI<?>) - c.getClientProperty("ui"); - if (ui == null) { - throw new IllegalStateException( - "could not find client property " + - "ui on component" + c); - } - - if (!(ui instanceof RoutesUI)) { - throw new IllegalStateException("Can not come here!"); - } - - RoutesUI theUi = (RoutesUI) ui; - - // get current tripseine id - ObserveTreeHelper treeHelper = getMainUI().getTreeHelper(); - ObserveNode oldRoutesNode = treeHelper.getSelectedNode(); - ObserveNode oldTripSeineNode = oldRoutesNode.getParent(); - - // choose the new tripseine - String tripSeineId = chooseNewTripSeine(theUi, oldTripSeineNode); - - if (tripSeineId != null) { - // change the tripseine of the selected routes - List<DataReference<RouteDto>> selectedDatas = theUi.getModel().getSelectedDatas(); - List<String> routeIds = selectedDatas.stream().map(DataReference.ID_FUNCTION).collect(Collectors.toList()); - RouteService service = ObserveSwingApplicationContext.get().getMainDataSourceServicesProvider().newRouteService(); - List<Integer> positions = service.moveRoutesToTripSeine(routeIds, tripSeineId); - - // update the tree - updateTree(oldRoutesNode, tripSeineId, routeIds); - } - - }); - + Optional<String> getNewParentId(ObserveMainUI mainUI, ObserveNode oldParentNode) { + return MoveRouteUIAction.chooseNewTripSeine(getMainUI(), oldParentNode); } - protected String chooseNewTripSeine(ContentUI<?> ui, ObserveNode oldTripSeineNode) { - ObserveNode programNode = oldTripSeineNode.getParent(); - String oldTripSeineId = oldTripSeineNode.getId(); - int tripSeineNb = programNode.getChildCount(); - - ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get(); - DataReferenceDecorator<TripSeineDto> decorator = applicationContext.getDecoratorService().getDataReferenceDecorator(TripSeineDto.class); - - //on crée un tableau avec une marée en moins car on ne propose pas la marée actuel - DecoratedNodeEntity[] decoratedTripSeines = new DecoratedNodeEntity[tripSeineNb - 1]; - - int j = 0; - for (int i = 0; i < tripSeineNb; i++) { - - TripSeineNode tripSeineNode = (TripSeineNode) programNode.getChildAt(i); - - String tripSeineId = tripSeineNode.getId(); - - if (!oldTripSeineId.equals(tripSeineId)) { - decoratedTripSeines[j++] = DecoratedNodeEntity.newDecoratedNodeEntity(tripSeineNode, decorator); - } - } - - Object decoratedTripSeine = JOptionPane.showInputDialog(ui, - t("observe.action.choose.tripSeine.message"), - t("observe.action.choose.tripSeine.title"), - JOptionPane.QUESTION_MESSAGE, - null, - decoratedTripSeines, - null); - return decoratedTripSeine != null ? ((DecoratedNodeEntity) decoratedTripSeine).getId() : null; + @Override + List<Integer> moveData(List<String> dataIds, String newParentId, ObserveServicesProvider servicesProvider) { + return ObserveSwingApplicationContext.get().getMainDataSourceServicesProvider().newRouteService().moveRoutesToTripSeine(dataIds, newParentId); } - protected void updateTree(ObserveNode oldRoutesNode, - String tripSeineId, - List<String> routeIds) { + @Override + void updateUI(RoutesUI ui, ObserveNode oldRoutesNode, String tripSeineId, List<String> routeIds, List<Integer> positions) { ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get(); ObserveOpenDataManager openDataManager = applicationContext.getOpenDataManager(); @@ -172,9 +88,7 @@ public class MoveRoutesUIAction extends AbstractUIAction { .findFirst(); // If so, we close it to avoid ending up with an open route into a closed trip. - if (openRoute.isPresent()) { - openDataManager.closeRoute(openRoute.get()); - } + openRoute.ifPresent(openDataManager::closeRoute); // Let's reload the sub tree of each routes node. // As the change have already be done in database, we just call the child loaders to regenerate the routes nodes sub trees ===================================== application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/MoveSingleDataUIActionSupport.java ===================================== --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/MoveSingleDataUIActionSupport.java @@ -0,0 +1,71 @@ +package fr.ird.observe.application.swing.ui.actions.shared; + +import fr.ird.observe.application.swing.ObserveOpenDataManager; +import fr.ird.observe.application.swing.ObserveSwingApplicationContext; +import fr.ird.observe.application.swing.ui.ObserveMainUI; +import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; +import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; +import fr.ird.observe.services.ObserveServicesProvider; +import java.awt.event.ActionEvent; +import java.util.Optional; + +/** + * Created by tchemit on 12/06/17. + * + * @author Tony Chemit - dev@tchemit.fr + */ +public abstract class MoveSingleDataUIActionSupport extends AbstractUIAction { + + MoveSingleDataUIActionSupport(ObserveMainUI mainUI, String actionId, String label, String shortDescription, String actionIcon) { + super(mainUI, actionId, label, shortDescription, actionIcon); + } + + @Override + public final void actionPerformed(ActionEvent e) { + + ObserveTreeHelper treeHelper = getMainUI().getTreeHelper(); + ObserveNode node = treeHelper.getSelectedNode(); + ObserveNode oldParentNode = node.getParent().getParent().equals(node.getRoot()) ? node.getParent() : node.getParent().getParent(); + Optional<String> optionalNewParentId = getNewParentId(getMainUI(), oldParentNode); + + optionalNewParentId.ifPresent(newParentId -> apply(oldParentNode, node.getId(), newParentId)); + } + + abstract Optional<String> getNewParentId(ObserveMainUI mainUI, ObserveNode oldParentNode); + + private void apply(ObserveNode oldParentNode, String dataId, String newParentId) { + + ObserveTreeHelper treeHelper = getMainUI().getTreeHelper(); + + ObserveNode node = treeHelper.getSelectedNode(); + ObserveNode grandParentNode = oldParentNode.getParent(); + ObserveNode newParentNode = getNewParentNode(getMainUI().getTreeHelper(), grandParentNode, newParentId); + + closeNode(ObserveSwingApplicationContext.get().getOpenDataManager(), node.getId()); + + int position = moveData(ObserveSwingApplicationContext.get().getMainDataSourceServicesProvider(), ObserveSwingApplicationContext.get().getOpenDataManager(), oldParentNode.getId(), newParentId, dataId); + + treeHelper.selectNode(newParentNode); + + treeHelper.removeNode(node); + + ObserveNode newNode = treeHelper.getChild(newParentNode, dataId); + + if (newNode == null) { + + treeHelper.insertNode(newParentNode, node, position); + newNode = node; + } + + treeHelper.refreshNode(oldParentNode, false); + treeHelper.refreshNode(newParentNode, false); + treeHelper.selectNode(newNode); + + } + + abstract int moveData(ObserveServicesProvider servicesProvider, ObserveOpenDataManager openDataManager, String oldParentId, String newParentId, String dataId); + + abstract void closeNode(ObserveOpenDataManager openDataManager, String dataId); + + abstract ObserveNode getNewParentNode(ObserveTreeHelper treeHelper, ObserveNode grandParentNode, String newParentId); +} ===================================== application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/MoveTripLonglineUIAction.java ===================================== --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/MoveTripLonglineUIAction.java @@ -0,0 +1,50 @@ +package fr.ird.observe.application.swing.ui.actions.shared; + +/*- + * #%L + * ObServe :: Application Swing + * %% + * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io + * %% + * 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.application.swing.ObserveOpenDataManager; +import fr.ird.observe.application.swing.ui.ObserveMainUI; +import fr.ird.observe.services.ObserveServicesProvider; +import fr.ird.observe.services.dto.constants.GearType; + +/** + * @author Tony Chemit - dev@tchemit.fr + * @since 5.0 + */ +public class MoveTripLonglineUIAction extends MoveTripUIAction { + + private static final long serialVersionUID = 1L; + + public static final String ACTION_NAME = "moveTripLongline"; + + public MoveTripLonglineUIAction(ObserveMainUI mainUI) { + super(mainUI, ACTION_NAME, GearType.longline); + } + + @Override + int moveData(ObserveServicesProvider servicesProvider, ObserveOpenDataManager openDataManager, String oldParentId, String newParentId, String dataId) { + int position = servicesProvider.newTripLonglineService().moveTripLonglineToProgram(dataId, newParentId); + super.moveData(servicesProvider, openDataManager, oldParentId, newParentId, dataId); + return position; + } +} ===================================== application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/MoveTripLonglinesUIAction.java ===================================== --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/MoveTripLonglinesUIAction.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/MoveTripLonglinesUIAction.java @@ -22,18 +22,13 @@ package fr.ird.observe.application.swing.ui.actions.shared; * #L% */ -import fr.ird.observe.application.swing.ObserveSwingApplicationContext; -import fr.ird.observe.services.dto.DataReference; -import fr.ird.observe.services.dto.constants.GearType; -import fr.ird.observe.services.dto.longline.TripLonglineDto; -import fr.ird.observe.services.service.longline.TripLonglineService; import fr.ird.observe.application.swing.ui.ObserveMainUI; -import fr.ird.observe.application.swing.ui.content.ContentUI; import fr.ird.observe.application.swing.ui.content.list.impl.longline.TripLonglinesUI; import fr.ird.observe.application.swing.ui.content.list.impl.longline.TripLonglinesUIModel; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - +import fr.ird.observe.services.ObserveServicesProvider; +import fr.ird.observe.services.dto.DataReference; +import fr.ird.observe.services.dto.constants.GearType; +import fr.ird.observe.services.dto.longline.TripLonglineDto; import java.util.ArrayList; import java.util.List; @@ -41,43 +36,24 @@ import java.util.List; * @author Kevin Morin (Code Lutin) * @since 5.0 */ -public class MoveTripLonglinesUIAction extends MoveTripsUIAction<TripLonglineDto> { +public class MoveTripLonglinesUIAction extends MoveTripsUIAction<TripLonglinesUI> { private static final long serialVersionUID = 1L; - /** - * Logger. - */ - private static final Log log = LogFactory.getLog(MoveTripLonglinesUIAction.class); - public static final String ACTION_NAME = "moveTripLonglines"; public MoveTripLonglinesUIAction(ObserveMainUI mainUI) { - super(mainUI, ACTION_NAME); - } - - @Override - protected void checkUIClass(ContentUI<?> ui) throws IllegalStateException { - if (!(ui instanceof TripLonglinesUI)) { - throw new IllegalStateException("Can not come here!"); - } - } - - @Override - protected GearType getGearType(ContentUI<?> ui) { - return GearType.longline; + super(mainUI, ACTION_NAME, GearType.longline, TripLonglinesUI.class); } @Override - protected List<Integer> getPositions(List<String> tripIds, String programId) { - TripLonglineService service = ObserveSwingApplicationContext.get().getMainDataSourceServicesProvider().newTripLonglineService(); - return service.moveTripLonglinesToProgram(tripIds, programId); + List<Integer> moveData(List<String> dataIds, String newParentId, ObserveServicesProvider servicesProvider) { + return servicesProvider.newTripLonglineService().moveTripLonglinesToProgram(dataIds, newParentId); } @Override - protected void updateModelData(ContentUI<?> ui) { - TripLonglinesUI tripLonglinesUI = (TripLonglinesUI) ui; - TripLonglinesUIModel model = tripLonglinesUI.getModel(); + protected void updateModelData(TripLonglinesUI ui) { + TripLonglinesUIModel model = ui.getModel(); List<DataReference<TripLonglineDto>> data = new ArrayList<>(model.getData()); data.removeAll(model.getSelectedDatas()); model.setData(data); ===================================== application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/MoveTripSeineUIAction.java ===================================== --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/MoveTripSeineUIAction.java @@ -0,0 +1,50 @@ +package fr.ird.observe.application.swing.ui.actions.shared; + +/*- + * #%L + * ObServe :: Application Swing + * %% + * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io + * %% + * 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.application.swing.ObserveOpenDataManager; +import fr.ird.observe.application.swing.ui.ObserveMainUI; +import fr.ird.observe.services.ObserveServicesProvider; +import fr.ird.observe.services.dto.constants.GearType; + +/** + * @author Tony Chemit - dev@tchemit.fr + * @since 5.0 + */ +public class MoveTripSeineUIAction extends MoveTripUIAction { + + private static final long serialVersionUID = 1L; + + public static final String ACTION_NAME = "moveTripSeine"; + + public MoveTripSeineUIAction(ObserveMainUI mainUI) { + super(mainUI, ACTION_NAME, GearType.seine); + } + + @Override + int moveData(ObserveServicesProvider servicesProvider, ObserveOpenDataManager openDataManager, String oldParentId, String newParentId, String dataId) { + int position = servicesProvider.newTripSeineService().moveTripSeineToProgram(dataId, newParentId); + super.moveData(servicesProvider, openDataManager, oldParentId, newParentId, dataId); + return position; + } +} ===================================== application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/MoveTripSeinesUIAction.java ===================================== --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/MoveTripSeinesUIAction.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/MoveTripSeinesUIAction.java @@ -23,17 +23,14 @@ package fr.ird.observe.application.swing.ui.actions.shared; */ import fr.ird.observe.application.swing.ObserveSwingApplicationContext; +import fr.ird.observe.application.swing.ui.ObserveMainUI; +import fr.ird.observe.application.swing.ui.content.list.impl.seine.TripSeinesUI; +import fr.ird.observe.application.swing.ui.content.list.impl.seine.TripSeinesUIModel; +import fr.ird.observe.services.ObserveServicesProvider; import fr.ird.observe.services.dto.DataReference; import fr.ird.observe.services.dto.constants.GearType; import fr.ird.observe.services.dto.seine.TripSeineDto; import fr.ird.observe.services.service.seine.TripSeineService; -import fr.ird.observe.application.swing.ui.ObserveMainUI; -import fr.ird.observe.application.swing.ui.content.ContentUI; -import fr.ird.observe.application.swing.ui.content.list.impl.seine.TripSeinesUI; -import fr.ird.observe.application.swing.ui.content.list.impl.seine.TripSeinesUIModel; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - import java.util.ArrayList; import java.util.List; @@ -41,43 +38,24 @@ import java.util.List; * @author Kevin Morin (Code Lutin) * @since 5.0 */ -public class MoveTripSeinesUIAction extends MoveTripsUIAction<TripSeineDto> { +public class MoveTripSeinesUIAction extends MoveTripsUIAction<TripSeinesUI> { private static final long serialVersionUID = 1L; - /** - * Logger. - */ - private static final Log log = LogFactory.getLog(MoveTripSeinesUIAction.class); - public static final String ACTION_NAME = "moveTripSeines"; public MoveTripSeinesUIAction(ObserveMainUI mainUI) { - super(mainUI, ACTION_NAME); - } - - @Override - protected void checkUIClass(ContentUI<?> ui) throws IllegalStateException { - if (!(ui instanceof TripSeinesUI)) { - throw new IllegalStateException("Can not come here!"); - } - } - - @Override - protected GearType getGearType(ContentUI<?> ui) { - return GearType.seine; + super(mainUI, ACTION_NAME, GearType.seine, TripSeinesUI.class); } @Override - protected List<Integer> getPositions(List<String> tripIds, String programId) { - TripSeineService service = ObserveSwingApplicationContext.get().getMainDataSourceServicesProvider().newTripSeineService(); - return service.moveTripSeinesToProgram(tripIds, programId); + List<Integer> moveData(List<String> dataIds, String newParentId, ObserveServicesProvider servicesProvider) { + return servicesProvider.newTripSeineService().moveTripSeinesToProgram(dataIds, newParentId); } @Override - protected void updateModelData(ContentUI<?> ui) { - TripSeinesUI tripSeinesUI = (TripSeinesUI) ui; - TripSeinesUIModel model = tripSeinesUI.getModel(); + protected void updateModelData(TripSeinesUI ui) { + TripSeinesUIModel model = ui.getModel(); List<DataReference<TripSeineDto>> data = new ArrayList<>(model.getData()); data.removeAll(model.getSelectedDatas()); model.setData(data); ===================================== application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/menu/MoveTripNodeMenuPopulator.java → application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/MoveTripUIAction.java ===================================== --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/menu/MoveTripNodeMenuPopulator.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/MoveTripUIAction.java @@ -1,6 +1,4 @@ -package fr.ird.observe.application.swing.ui.tree.menu; - -/*- +/* * #%L * ObServe :: Application Swing * %% @@ -8,7 +6,7 @@ package fr.ird.observe.application.swing.ui.tree.menu; * %% * 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, @@ -16,64 +14,96 @@ package fr.ird.observe.application.swing.ui.tree.menu; * 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% */ +package fr.ird.observe.application.swing.ui.actions.shared; +import fr.ird.observe.application.swing.ObserveOpenDataManager; import fr.ird.observe.application.swing.ObserveSwingApplicationContext; -import fr.ird.observe.application.swing.db.ObserveSwingDataSource; -import fr.ird.observe.services.dto.IdHelper; -import fr.ird.observe.services.dto.constants.GearType; -import fr.ird.observe.services.dto.referential.ProgramDto; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; +import fr.ird.observe.application.swing.decoration.decorators.ReferentialReferenceDecorator; +import fr.ird.observe.application.swing.ui.ObserveMainUI; import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; +import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; import fr.ird.observe.application.swing.ui.tree.node.ProgramLonglineNode; import fr.ird.observe.application.swing.ui.tree.node.ProgramSeineNode; -import fr.ird.observe.application.swing.ui.tree.actions.ChangeTripProgramActionListener; -import fr.ird.observe.application.swing.ui.tree.actions.NodeChangeActionListener; import fr.ird.observe.application.swing.ui.util.DecoratedNodeEntity; -import fr.ird.observe.application.swing.decoration.decorators.ReferentialReferenceDecorator; - +import fr.ird.observe.services.ObserveServicesProvider; +import fr.ird.observe.services.dto.IdHelper; +import fr.ird.observe.services.dto.constants.GearType; +import fr.ird.observe.services.dto.referential.ProgramDto; import java.util.ArrayList; import java.util.List; +import java.util.Optional; +import javax.swing.JOptionPane; + + +import static org.nuiton.i18n.I18n.n; +import static org.nuiton.i18n.I18n.t; /** - * @author Kevin Morin (Code Lutin) + * Action pour changer le programme d'une ou plusieurs marée dans la liste. + * + * @author Tony Chemit - dev@tchemit.fr * @since 5.0 */ -public class MoveTripNodeMenuPopulator extends MoveNodeMenuPopulator { +public abstract class MoveTripUIAction extends MoveSingleDataUIActionSupport { + + private static final long serialVersionUID = 1L; + + public static final String ACTION_NAME = "moveTrip"; + + private final GearType gearType; + + MoveTripUIAction(ObserveMainUI mainUI, String actionName, GearType gearType) { + super(mainUI, + actionName, + n("observe.navigationMenu.move.trip"), + n("observe.navigationMenu.move.trip"), + "move-trips" + ); + this.gearType = gearType; + } @Override - public NodeChangeActionListener createChangeActionListener(ObserveTreeHelper treeHelper, - ObserveSwingDataSource dataSource, - String id, - String parentId) { - return new ChangeTripProgramActionListener(treeHelper, dataSource, id, parentId); + Optional<String> getNewParentId(ObserveMainUI mainUI, ObserveNode oldParentNode) { + return chooseNewProgram(mainUI, gearType, oldParentNode.getId()); } @Override - public List<DecoratedNodeEntity> getPossibleParentNodes(ObserveNode tripNode, ObserveTreeHelper treeHelper) { + int moveData(ObserveServicesProvider servicesProvider, ObserveOpenDataManager openDataManager, String oldParentId, String newParentId, String dataId) { - // noeud du programme parent - ObserveNode parentNode = tripNode.getParent(); + // Close old program and open new program + if (openDataManager.isOpen(dataId)) { + openDataManager.closeProgram(oldParentId); + openDataManager.openProgram(newParentId); + } - // programmes du même type que le noeud de marée, sans le parent actuel - List<DecoratedNodeEntity> possibleParents = new ArrayList<>(); + // hum, we do NOT use this value (concrete classes define it) + return 0; + } - // noeud longline ? - GearType gearType = IdHelper.isLonglineId(tripNode.getId()) ? GearType.longline : GearType.seine; + @Override + void closeNode(ObserveOpenDataManager openDataManager, String dataId) { + // Don't do anything : trip should stay open when being transferred + } - // racine - ObserveNode rootNode = treeHelper.getRootNode(); + @Override + ObserveNode getNewParentNode(ObserveTreeHelper treeHelper, ObserveNode grandParentNode, String newParentId) { + return treeHelper.getChild(grandParentNode, newParentId); + } - createPossibleParents(parentNode.getId(), possibleParents, gearType, rootNode); + static Optional<String> chooseNewProgram(ObserveMainUI mainUI, GearType gearType, String oldProgramId) { - return possibleParents; - } + ObserveTreeHelper treeHelper = mainUI.getTreeHelper(); + + // racine + ObserveNode rootNode = treeHelper.getRootNode(); - public static void createPossibleParents(String oldProgramId, List<DecoratedNodeEntity> possibleParents, GearType gearType, ObserveNode rootNode) { + //on crée un tableau avec un programme en moins car on ne propose pas le programme actuel + List<DecoratedNodeEntity> decoratedProgramList = new ArrayList<>(); ReferentialReferenceDecorator<ProgramDto> programDecorator = ObserveSwingApplicationContext.get().getDecoratorService().getReferentialReferenceDecorator(ProgramDto.class); @@ -89,17 +119,30 @@ public class MoveTripNodeMenuPopulator extends MoveNodeMenuPopulator { if (programNode instanceof ProgramSeineNode && GearType.seine == gearType) { ProgramSeineNode node = (ProgramSeineNode) programNode; - possibleParents.add(DecoratedNodeEntity.newDecoratedNodeEntity(node, programDecorator)); + decoratedProgramList.add(DecoratedNodeEntity.newDecoratedNodeEntity(node, programDecorator)); } else if (programNode instanceof ProgramLonglineNode && GearType.longline == gearType) { ProgramLonglineNode node = (ProgramLonglineNode) programNode; - possibleParents.add(DecoratedNodeEntity.newDecoratedNodeEntity(node, programDecorator)); + decoratedProgramList.add(DecoratedNodeEntity.newDecoratedNodeEntity(node, programDecorator)); } } } + + DecoratedNodeEntity[] decoratedPrograms = + decoratedProgramList.toArray(new DecoratedNodeEntity[decoratedProgramList.size()]); + + DecoratedNodeEntity decoratedProgram = (DecoratedNodeEntity) JOptionPane.showInputDialog(mainUI, + t("observe.action.choose.program.message"), + t("observe.action.choose.program.title"), + JOptionPane.QUESTION_MESSAGE, + null, + decoratedPrograms, + null); + + return Optional.ofNullable(decoratedProgram == null ? null : decoratedProgram.getId()); } } ===================================== application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/MoveTripsUIAction.java ===================================== --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/MoveTripsUIAction.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/MoveTripsUIAction.java @@ -23,29 +23,18 @@ package fr.ird.observe.application.swing.ui.actions.shared; import fr.ird.observe.application.swing.ObserveOpenDataManager; import fr.ird.observe.application.swing.ObserveSwingApplicationContext; -import fr.ird.observe.services.dto.DataDto; -import fr.ird.observe.services.dto.DataReference; -import fr.ird.observe.services.dto.constants.GearType; import fr.ird.observe.application.swing.ui.ObserveMainUI; -import fr.ird.observe.application.swing.ui.content.ContentUI; -import fr.ird.observe.application.swing.ui.content.list.ContentListUIModel; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; +import fr.ird.observe.application.swing.ui.content.list.ContentListUI; import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; -import fr.ird.observe.application.swing.ui.tree.menu.MoveTripNodeMenuPopulator; -import fr.ird.observe.application.swing.ui.util.DecoratedNodeEntity; +import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; +import fr.ird.observe.services.dto.constants.GearType; +import java.util.List; +import java.util.Optional; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import javax.swing.JComponent; -import javax.swing.JOptionPane; -import javax.swing.SwingUtilities; -import java.awt.event.ActionEvent; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; import static org.nuiton.i18n.I18n.n; -import static org.nuiton.i18n.I18n.t; /** * Action pour changer le programme d'une ou plusieurs marée dans la liste. @@ -53,118 +42,55 @@ import static org.nuiton.i18n.I18n.t; * @author Kevin Morin (Code Lutin) * @since 5.0 */ -public abstract class MoveTripsUIAction<T extends DataDto> extends AbstractUIAction { +public abstract class MoveTripsUIAction<U extends ContentListUI<?, ?>> extends MoveMultipleDataUIActionSupport<U> { private static final long serialVersionUID = 1L; - /** - * Logger. - */ private static final Log log = LogFactory.getLog(MoveTripsUIAction.class); public static final String ACTION_NAME = "moveTrips"; + private final GearType gearType; + + protected abstract void updateModelData(U ui); - public MoveTripsUIAction(ObserveMainUI mainUI, String actionName) { + MoveTripsUIAction(ObserveMainUI mainUI, String actionName, GearType gearType, Class<U> uiType) { super(mainUI, actionName, n("observe.content.action.move.trips"), n("observe.content.action.move.trips.tip"), - "move-trips" + "move-trips", + uiType ); + this.gearType = gearType; } @Override - public void actionPerformed(final ActionEvent e) { - - SwingUtilities.invokeLater(() -> { - JComponent c = (JComponent) e.getSource(); - ContentUI<?> ui = (ContentUI<?>) - c.getClientProperty("ui"); - if (ui == null) { - throw new IllegalStateException( - "could not find client property " + - "ui on component" + c); - } - - checkUIClass(ui); - - // get current program id - ObserveTreeHelper treeHelper = getMainUI().getTreeHelper(); - ObserveNode oldProgramNode = treeHelper.getSelectedNode(); - String oldProgramId = oldProgramNode.getId(); - - // choose the new program - String programId = chooseNewProgram(ui, oldProgramId); - - if (programId != null) { - - // change the program of the selected trips - List<DataReference<T>> selectedDatas = ((ContentListUIModel) ui.getModel()).getSelectedDatas(); - List<String> tripIds = selectedDatas.stream().map(DataReference.ID_FUNCTION).collect(Collectors.toList()); - List<Integer> positions = getPositions(tripIds, programId); - - // update the tree - updateTree(ui, oldProgramNode, oldProgramId, programId, tripIds, positions); - } - - }); - + Optional<String> getNewParentId(ObserveMainUI mainUI, ObserveNode oldParentNode) { + return MoveTripUIAction.chooseNewProgram(getMainUI(), gearType, oldParentNode.getId()); } - protected String chooseNewProgram(ContentUI<?> ui, String oldProgramId) { - - ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get(); - - ObserveTreeHelper treeHelper = getMainUI().getTreeHelper(); - - GearType geartype = getGearType(ui); - - // racine - ObserveNode rootNode = treeHelper.getRootNode(); - - //on crée un tableau avec un programme en moins car on ne propose pas le programme actuel - List<DecoratedNodeEntity> decoratedProgramList = new ArrayList<>(); - - MoveTripNodeMenuPopulator.createPossibleParents(oldProgramId, decoratedProgramList, geartype, rootNode); - - DecoratedNodeEntity[] decoratedPrograms = - decoratedProgramList.toArray(new DecoratedNodeEntity[decoratedProgramList.size()]); - - DecoratedNodeEntity decoratedProgram = (DecoratedNodeEntity) JOptionPane.showInputDialog(ui, - t("observe.action.choose.program.message"), - t("observe.action.choose.program.title"), - JOptionPane.QUESTION_MESSAGE, - null, - decoratedPrograms, - null); - - return decoratedProgram == null ? null : decoratedProgram.getId(); - } + @Override + void updateUI(U ui, ObserveNode oldParentNode, String newParentId, List<String> dataIds, List<Integer> positions) { - protected void updateTree(ContentUI<?> ui, - ObserveNode oldProgramNode, - String oldProgramId, - String programId, - List<String> tripIds, - List<Integer> positions) { + String oldProgramId = oldParentNode.getId(); ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get(); ObserveOpenDataManager openDataManager = applicationContext.getOpenDataManager(); ObserveTreeHelper treeHelper = getMainUI().getTreeHelper(); ObserveNode rootNode = treeHelper.getRootNode(); - ObserveNode newProgramNode = treeHelper.getChild(rootNode, programId); + ObserveNode newProgramNode = treeHelper.getChild(rootNode, newParentId); for (int i = 0, s = positions.size(); i < s; i++) { - String tripId = tripIds.get(i); - ObserveNode tripNode = treeHelper.getChild(oldProgramNode, tripId); + String tripId = dataIds.get(i); + ObserveNode tripNode = treeHelper.getChild(oldParentNode, tripId); boolean wasOpen = tripNode.isOpen(); treeHelper.removeNode(tripNode); if (wasOpen) { openDataManager.closeProgram(oldProgramId); - openDataManager.openProgram(programId); + openDataManager.openProgram(newParentId); } ObserveNode newTripNode = treeHelper.getChild(newProgramNode, tripId); @@ -181,17 +107,9 @@ public abstract class MoveTripsUIAction<T extends DataDto> extends AbstractUIAct updateModelData(ui); - treeHelper.reloadNode(oldProgramNode, true); + treeHelper.reloadNode(oldParentNode, true); treeHelper.reloadNode(newProgramNode, true); treeHelper.selectNode(newProgramNode); } - protected abstract void checkUIClass(ContentUI<?> ui) throws IllegalStateException; - - protected abstract GearType getGearType(ContentUI<?> ui); - - protected abstract List<Integer> getPositions(List<String> tripIds, String programId); - - protected abstract void updateModelData(ContentUI<?> ui); - } ===================================== application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/ObserveNavigationTreeShowPopupAction.java ===================================== --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/ObserveNavigationTreeShowPopupAction.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/ObserveNavigationTreeShowPopupAction.java @@ -23,24 +23,23 @@ package fr.ird.observe.application.swing.ui.tree; */ import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableMap; import fr.ird.observe.application.swing.ObserveOpenDataManager; import fr.ird.observe.application.swing.ObserveSwingApplicationContext; import fr.ird.observe.application.swing.db.DataContext; -import fr.ird.observe.application.swing.db.ObserveSwingDataSource; +import fr.ird.observe.application.swing.ui.actions.shared.MoveActivityLonglineUIAction; +import fr.ird.observe.application.swing.ui.actions.shared.MoveActivitySeineUIAction; +import fr.ird.observe.application.swing.ui.actions.shared.MoveRouteUIAction; +import fr.ird.observe.application.swing.ui.actions.shared.MoveTripLonglineUIAction; +import fr.ird.observe.application.swing.ui.actions.shared.MoveTripSeineUIAction; import fr.ird.observe.application.swing.ui.content.ContentUI; import fr.ird.observe.application.swing.ui.content.open.ContentOpenableUI; -import fr.ird.observe.application.swing.ui.tree.menu.MoveActivityLonglineNodeMenuPopulator; -import fr.ird.observe.application.swing.ui.tree.menu.MoveActivitySeineNodeMenuPopulator; -import fr.ird.observe.application.swing.ui.tree.menu.MoveNodeMenuPopulator; -import fr.ird.observe.application.swing.ui.tree.menu.MoveRouteNodeMenuPopulator; -import fr.ird.observe.application.swing.ui.tree.menu.MoveTripNodeMenuPopulator; import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; -import fr.ird.observe.application.swing.ui.util.DecoratedNodeEntity; -import jaxx.runtime.SwingUtil; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; import javax.swing.JButton; import javax.swing.JMenuItem; import javax.swing.JPopupMenu; @@ -49,16 +48,8 @@ import javax.swing.JTree; import javax.swing.MenuElement; import javax.swing.SwingUtilities; import javax.swing.tree.TreePath; -import java.awt.Point; -import java.awt.Rectangle; -import java.awt.event.KeyAdapter; -import java.awt.event.KeyEvent; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.util.List; - -import static org.nuiton.i18n.I18n.n; -import static org.nuiton.i18n.I18n.t; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; /** * Created on 1/8/15. @@ -76,15 +67,6 @@ public class ObserveNavigationTreeShowPopupAction { private static final String ACTIVITY_SEINE_MENU_ITEMS = "activitySeine"; private static final String ACTIVITY_LONGLINE_MENU_ITEMS = "activityLongline"; - static { - n("observe.navigationMenu.move.trip"); - n("observe.navigationMenu.move.route"); - n("observe.navigationMenu.move.activitySeine"); - n("observe.navigationMenu.move.activityLongline"); - } - - private final ObserveTreeHelper treeHelper; - private final JPopupMenu popup; private final JTree tree; @@ -95,11 +77,8 @@ public class ObserveNavigationTreeShowPopupAction { private final JMenuItem moveAction; private final JMenuItem deleteAction; - private final ImmutableMap<String, MoveNodeMenuPopulator> moveNodeDataByNodeType; - public ObserveNavigationTreeShowPopupAction(ObserveTreeHelper treeHelper, JScrollPane pane, JPopupMenu popup) { - this.treeHelper = treeHelper; this.popup = popup; this.tree = treeHelper.getUI(); @@ -135,11 +114,6 @@ public class ObserveNavigationTreeShowPopupAction { this.moveAction = moveComponent; this.deleteAction = deleteActionComponent; - moveNodeDataByNodeType = ImmutableMap.of(TRIP_MENU_ITEMS, new MoveTripNodeMenuPopulator(), - ROUTE_MENU_ITEMS, new MoveRouteNodeMenuPopulator(), - ACTIVITY_SEINE_MENU_ITEMS, new MoveActivitySeineNodeMenuPopulator(), - ACTIVITY_LONGLINE_MENU_ITEMS, new MoveActivityLonglineNodeMenuPopulator()); - KeyAdapter keyAdapter = new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { @@ -163,7 +137,7 @@ public class ObserveNavigationTreeShowPopupAction { pane.addMouseListener(mouseAdapter); } - protected void autoSelectNodeInTree(MouseEvent e) { + private void autoSelectNodeInTree(MouseEvent e) { boolean rightClick = SwingUtilities.isRightMouseButton(e); @@ -204,7 +178,7 @@ public class ObserveNavigationTreeShowPopupAction { } } - public void openNodeMenu(KeyEvent e) { + private void openNodeMenu(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_CONTEXT_MENU && !tree.isSelectionEmpty()) { @@ -226,7 +200,7 @@ public class ObserveNavigationTreeShowPopupAction { } } - protected void showPopup(int row, Point p) { + private void showPopup(int row, Point p) { if (log.isInfoEnabled()) { log.info("Will show popup from row: " + row); @@ -244,7 +218,7 @@ public class ObserveNavigationTreeShowPopupAction { } - protected void beforeOpenPopup(ObserveNode selectedNode) { + private void beforeOpenPopup(ObserveNode selectedNode) { // clean popup popup.removeAll(); @@ -295,64 +269,47 @@ public class ObserveNavigationTreeShowPopupAction { } } - protected void beforeOpenMenu(ObserveNode selectedNode, String nodeType) { + private void beforeOpenMenu(ObserveNode selectedNode, String nodeType) { if (log.isInfoEnabled()) { log.info("Will load popup for " + nodeType + " node."); } - MoveNodeMenuPopulator moveNodeData = moveNodeDataByNodeType.get(nodeType); - ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get(); + ContentUI<?> selectedContentUI = applicationContext.getContentUIManager().getSelectedContentUI(); if (selectedNode.isOpen()) { - closeAction.putClientProperty("ui", applicationContext.getContentUIManager().getSelectedContentUI()); + closeAction.putClientProperty("ui", selectedContentUI); popup.add(closeAction); } else { - openAction.putClientProperty("ui", applicationContext.getContentUIManager().getSelectedContentUI()); + openAction.putClientProperty("ui", selectedContentUI); popup.add(openAction); } - moveAction.setText(t("observe.navigationMenu.move." + nodeType)); - moveAction.setToolTipText(t("observe.navigationMenu.move." + nodeType)); - moveAction.setIcon(SwingUtil.getUIManagerActionIcon("move-" + nodeType)); - popup.add(moveAction); - - moveAction.removeAll(); - - // get the available program for the trip - - String id = selectedNode.getId(); - - ObserveSwingDataSource dataSource = treeHelper.getDataProvider().getDataSource(); - - List<DecoratedNodeEntity> possibleParentNodes = moveNodeData.getPossibleParentNodes(selectedNode, treeHelper); - - for (DecoratedNodeEntity possibleParent : possibleParentNodes) { - - String possibleParentId = possibleParent.getId(); - JMenuItem item = new JMenuItem(possibleParent.toString()); - item.setName(possibleParentId); - - - item.addActionListener(moveNodeData.createChangeActionListener(treeHelper, - dataSource, - id, - possibleParentId)); - - moveAction.add(item); + if (selectedNode.isTripSeineNode()) { + moveAction.setAction(new MoveTripSeineUIAction(applicationContext.getMainUI())); + } else if (selectedNode.isTripLonglineNode()) { + moveAction.setAction(new MoveTripLonglineUIAction(applicationContext.getMainUI())); + } else if (selectedNode.isRouteNode()) { + moveAction.setAction(new MoveRouteUIAction(applicationContext.getMainUI())); + } else if (selectedNode.isActivitySeineNode()) { + moveAction.setAction(new MoveActivitySeineUIAction(applicationContext.getMainUI())); + } else if (selectedNode.isActivityLonglineNode()) { + moveAction.setAction(new MoveActivityLonglineUIAction(applicationContext.getMainUI())); } - deleteAction.putClientProperty("ui", applicationContext.getContentUIManager().getSelectedContentUI()); + popup.add(moveAction); + + deleteAction.putClientProperty("ui", selectedContentUI); deleteAction.setEnabled(selectedNode.isOpen()); popup.add(deleteAction); } - protected boolean isRowSelected(int requiredRow) { + private boolean isRowSelected(int requiredRow) { boolean result = false; @@ -372,7 +329,7 @@ public class ObserveNavigationTreeShowPopupAction { } - protected int getLowestSelectedRowCount() { + private int getLowestSelectedRowCount() { Preconditions.checkState(!tree.isSelectionEmpty()); ===================================== application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/actions/ChangeActivityRouteActionListener.java deleted ===================================== --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/actions/ChangeActivityRouteActionListener.java +++ /dev/null @@ -1,87 +0,0 @@ -package fr.ird.observe.application.swing.ui.tree.actions; - -/* - * #%L - * ObServe :: Application Swing - * %% - * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io - * %% - * 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.application.swing.ObserveOpenDataManager; -import fr.ird.observe.application.swing.ObserveSwingApplicationContext; -import fr.ird.observe.application.swing.db.ObserveSwingDataSource; -import fr.ird.observe.application.swing.decoration.ObserveI18nDecoratorHelper; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; -import fr.ird.observe.services.dto.seine.ActivitySeineDto; -import fr.ird.observe.services.service.seine.ActivitySeineService; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * Created on 1/9/15. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 3.11 - */ -public class ChangeActivityRouteActionListener extends NodeChangeActionListener { - - /** Logger. */ - private static final Log log = LogFactory.getLog(ChangeActivityRouteActionListener.class); - - public ChangeActivityRouteActionListener(ObserveTreeHelper treeHelper, - ObserveSwingDataSource dataSource, - String activityId, - String routeId) { - super(treeHelper, activityId, routeId); - } - - @Override - protected void closeNode(String activityId) { - ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get(); - ObserveOpenDataManager openDataManager = applicationContext.getOpenDataManager(); - - if (openDataManager.isOpenActivitySeine(activityId)) { - openDataManager.closeActivitySeine(activityId); - } - } - - @Override - protected ObserveNode getParentNode(ObserveNode node) { - return node.getParent().getParent(); - } - - @Override - protected ObserveNode getNewParentNode(ObserveNode grandParentNode, String parentNodeId) { - ObserveNode routeNode = getTreeHelper().getChild(grandParentNode, parentNodeId); - String activitiesNodeId = ObserveI18nDecoratorHelper.getTypePluralI18nKey(ActivitySeineDto.class); - return getTreeHelper().getChild(routeNode, activitiesNodeId); - } - - @Override - protected int moveNodeToParent(String nodeId, String parentNodeId, String oldParentNodeId) { - int position; - - ActivitySeineService service = ObserveSwingApplicationContext.get().getMainDataSourceServicesProvider().newActivitySeineService(); - position = service.moveActivitySeineToRoute(nodeId, parentNodeId); - - return position; - } - -} ===================================== application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/actions/ChangeActivityTripActionListener.java deleted ===================================== --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/actions/ChangeActivityTripActionListener.java +++ /dev/null @@ -1,89 +0,0 @@ -package fr.ird.observe.application.swing.ui.tree.actions; - -/* - * #%L - * ObServe :: Application Swing - * %% - * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io - * %% - * 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.application.swing.ObserveOpenDataManager; -import fr.ird.observe.application.swing.ObserveSwingApplicationContext; -import fr.ird.observe.application.swing.db.ObserveSwingDataSource; -import fr.ird.observe.application.swing.decoration.ObserveI18nDecoratorHelper; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; -import fr.ird.observe.services.dto.longline.ActivityLonglineDto; -import fr.ird.observe.services.service.longline.ActivityLonglineService; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * Created on 1/9/15. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 3.11 - */ -public class ChangeActivityTripActionListener extends NodeChangeActionListener { - - /** Logger. */ - private static final Log log = LogFactory.getLog(ChangeActivityTripActionListener.class); - - public ChangeActivityTripActionListener(ObserveTreeHelper treeHelper, - ObserveSwingDataSource dataSource, - String activityId, - String tripLonglineId) { - super(treeHelper, activityId, tripLonglineId); - } - - @Override - protected void closeNode(String activityId) { - ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get(); - ObserveOpenDataManager openDataManager = applicationContext.getOpenDataManager(); - - if (openDataManager.isOpenActivityLongline(activityId)) { - openDataManager.closeActivityLongline(activityId); - } - } - - @Override - protected ObserveNode getParentNode(ObserveNode node) { - return node.getParent().getParent(); - } - - @Override - protected ObserveNode getNewParentNode(ObserveNode grandParentNode, String parentNodeId) { - ObserveNode tripLonglineNode = getTreeHelper().getChild(grandParentNode, parentNodeId); - String activitiesNodeId = ObserveI18nDecoratorHelper.getTypePluralI18nKey(ActivityLonglineDto.class); - return getTreeHelper().getChild(tripLonglineNode, activitiesNodeId); - } - - @Override - protected int moveNodeToParent(String nodeId, String parentNodeId, String oldParentNodeId) { - int position; - - ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get(); - - ActivityLonglineService service = applicationContext.getMainDataSourceServicesProvider().newActivityLonglineService(); - position = service.moveActivityLonglineToTripLongline(nodeId, parentNodeId); - - return position; - } - -} ===================================== application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/actions/ChangeRouteTripActionListener.java deleted ===================================== --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/actions/ChangeRouteTripActionListener.java +++ /dev/null @@ -1,86 +0,0 @@ -package fr.ird.observe.application.swing.ui.tree.actions; - -/* - * #%L - * ObServe :: Application Swing - * %% - * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io - * %% - * 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.application.swing.ObserveOpenDataManager; -import fr.ird.observe.application.swing.ObserveSwingApplicationContext; -import fr.ird.observe.application.swing.db.ObserveSwingDataSource; -import fr.ird.observe.application.swing.decoration.ObserveI18nDecoratorHelper; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; -import fr.ird.observe.services.dto.seine.RouteDto; -import fr.ird.observe.services.service.seine.RouteService; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * Created on 1/9/15. - * - * @author Tony Chemit - dev@tchemit.fr - * @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, routeId, tripId); - } - - @Override - protected void closeNode(String routeId) { - ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get(); - ObserveOpenDataManager openDataManager = applicationContext.getOpenDataManager(); - - if (openDataManager.isOpenRoute(routeId)) { - openDataManager.closeRoute(routeId); - } - } - - @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 = ObserveI18nDecoratorHelper.getTypePluralI18nKey(RouteDto.class); - return getTreeHelper().getChild(tripNode, routesNodeId); - } - - @Override - protected int moveNodeToParent(String nodeId, String parentNodeId, String oldParentNodeId) { - int position; - - RouteService service = ObserveSwingApplicationContext.get().getMainDataSourceServicesProvider().newRouteService(); - position = service.moveRouteToTripSeine(nodeId, parentNodeId); - - return position; - } -} ===================================== application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/actions/ChangeTripProgramActionListener.java deleted ===================================== --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/actions/ChangeTripProgramActionListener.java +++ /dev/null @@ -1,95 +0,0 @@ -package fr.ird.observe.application.swing.ui.tree.actions; - -/* - * #%L - * ObServe :: Application Swing - * %% - * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io - * %% - * 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.application.swing.ObserveOpenDataManager; -import fr.ird.observe.application.swing.ObserveSwingApplicationContext; -import fr.ird.observe.application.swing.db.ObserveSwingDataSource; -import fr.ird.observe.services.ObserveServicesProvider; -import fr.ird.observe.services.dto.IdHelper; -import fr.ird.observe.services.service.longline.TripLonglineService; -import fr.ird.observe.services.service.seine.TripSeineService; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * Created on 1/9/15. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 3.11 - */ -public class ChangeTripProgramActionListener extends NodeChangeActionListener { - - /** Logger. */ - private static final Log log = LogFactory.getLog(ChangeTripProgramActionListener.class); - - public ChangeTripProgramActionListener(ObserveTreeHelper treeHelper, - ObserveSwingDataSource dataSource, - String tripId, - String programId) { - super(treeHelper, tripId, programId); - } - - @Override - protected void closeNode(String tripId) { - // Don't do anything : trip should stay open when being transferred - } - - @Override - protected ObserveNode getParentNode(ObserveNode node) { - return node.getParent(); - } - - @Override - protected ObserveNode getNewParentNode(ObserveNode grandParentNode, String parentNodeId) { - return getTreeHelper().getChild(grandParentNode, parentNodeId); - } - - @Override - protected int moveNodeToParent(String nodeId, String parentNodeId, String oldParentNodeId) { - int position; - - ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get(); - ObserveServicesProvider servicesProvider = applicationContext.getMainDataSourceServicesProvider(); - if (IdHelper.isTripLonglineId(nodeId)) { - TripLonglineService service = servicesProvider.newTripLonglineService(); - position = service.moveTripLonglineToProgram(nodeId, parentNodeId); - - } else { - TripSeineService service = servicesProvider.newTripSeineService(); - position = service.moveTripSeineToProgram(nodeId, parentNodeId); - } - - // Close old program and open new program - ObserveOpenDataManager openDataManager = applicationContext.getOpenDataManager(); - if (openDataManager.isOpen(nodeId)) { - openDataManager.closeProgram(oldParentNodeId); - openDataManager.openProgram(parentNodeId); - } - - return position; - } -} ===================================== application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/actions/NodeChangeActionListener.java deleted ===================================== --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/actions/NodeChangeActionListener.java +++ /dev/null @@ -1,102 +0,0 @@ -package fr.ird.observe.application.swing.ui.tree.actions; - -/* - * #%L - * ObServe :: Application Swing - * %% - * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io - * %% - * 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.application.swing.ui.tree.node.ObserveNode; -import fr.ird.observe.application.swing.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 - dev@tchemit.fr - * @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; - - public NodeChangeActionListener(ObserveTreeHelper treeHelper, - String nodeId, - String parentNodeId) { - this.nodeId = nodeId; - this.parentNodeId = parentNodeId; - this.treeHelper = treeHelper; - } - - @Override - public void actionPerformed(ActionEvent event) { - - ObserveNode node = treeHelper.getSelectedNode(); - ObserveNode oldParentNode = getParentNode(node); - ObserveNode grandParentNode = oldParentNode.getParent(); - ObserveNode newParentNode = getNewParentNode(grandParentNode, parentNodeId); - - closeNode(node.getId()); - - int position = moveNodeToParent(nodeId, parentNodeId, oldParentNode.getId()); - - treeHelper.selectNode(newParentNode); - - 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; - } - - treeHelper.selectNode(newNode); - - } - - protected ObserveTreeHelper getTreeHelper() { - return treeHelper; - } - - protected abstract void closeNode(String nodeId); - - protected abstract ObserveNode getParentNode(ObserveNode node); - - protected abstract ObserveNode getNewParentNode(ObserveNode grandParentNode, String parentNodeId); - - protected abstract int moveNodeToParent(String nodeId, String parentNodeId, String oldParentNodeId); -} ===================================== application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/menu/MoveActivityLonglineNodeMenuPopulator.java deleted ===================================== --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/menu/MoveActivityLonglineNodeMenuPopulator.java +++ /dev/null @@ -1,85 +0,0 @@ -package fr.ird.observe.application.swing.ui.tree.menu; - -/*- - * #%L - * ObServe :: Application Swing - * %% - * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io - * %% - * 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.application.swing.db.ObserveSwingDataSource; -import fr.ird.observe.services.dto.IdHelper; -import fr.ird.observe.services.dto.longline.TripLonglineDto; -import fr.ird.observe.application.swing.decoration.DecoratorService; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; -import fr.ird.observe.application.swing.ui.tree.node.TripLonglineNode; -import fr.ird.observe.application.swing.ui.tree.actions.ChangeActivityTripActionListener; -import fr.ird.observe.application.swing.ui.tree.actions.NodeChangeActionListener; -import fr.ird.observe.application.swing.ui.util.DecoratedNodeEntity; -import fr.ird.observe.application.swing.decoration.decorators.DataReferenceDecorator; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author Kevin Morin (Code Lutin) - * @since 5.0 - */ -public class MoveActivityLonglineNodeMenuPopulator extends MoveNodeMenuPopulator { - - @Override - public NodeChangeActionListener createChangeActionListener(ObserveTreeHelper treeHelper, - ObserveSwingDataSource dataSource, - String id, - String parentId) { - return new ChangeActivityTripActionListener(treeHelper, dataSource, id, parentId); - } - - @Override - public List<DecoratedNodeEntity> getPossibleParentNodes(ObserveNode activityLonglineNode, ObserveTreeHelper treeHelper) { - - // noeud de marée parent - ObserveNode parentNode = activityLonglineNode.getParent().getParent(); - - // noeud de route de la marée sans le parent actuel - List<DecoratedNodeEntity> possibleParents = new ArrayList<>(); - - // noeud du programme - ObserveNode programNode = parentNode.getParent(); - - DecoratorService decoratorService = treeHelper.getTreeCellRenderer().getDecoratorService(); - DataReferenceDecorator<TripLonglineDto> tripDecorator = decoratorService.getDataReferenceDecorator(TripLonglineDto.class); - - for (int i = 0, n = programNode.getChildCount(); i < n; i++) { - - TripLonglineNode tripNode = (TripLonglineNode) programNode.getChildAt(i); - String tripId = tripNode.getId(); - - // si le noeud de marée n'est pas le même que le parent actuel - // si le noeud est bien un noeud de marée longline - if (!parentNode.equals(tripNode) && IdHelper.isTripLonglineId(tripId)) { - - possibleParents.add(DecoratedNodeEntity.newDecoratedNodeEntity(tripNode, tripDecorator)); - - } - } - - return possibleParents; - } -} ===================================== application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/menu/MoveActivitySeineNodeMenuPopulator.java deleted ===================================== --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/menu/MoveActivitySeineNodeMenuPopulator.java +++ /dev/null @@ -1,85 +0,0 @@ -package fr.ird.observe.application.swing.ui.tree.menu; - -/*- - * #%L - * ObServe :: Application Swing - * %% - * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io - * %% - * 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.application.swing.db.ObserveSwingDataSource; -import fr.ird.observe.services.dto.IdHelper; -import fr.ird.observe.services.dto.seine.RouteDto; -import fr.ird.observe.application.swing.decoration.DecoratorService; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; -import fr.ird.observe.application.swing.ui.tree.node.RouteSeineNode; -import fr.ird.observe.application.swing.ui.tree.actions.ChangeActivityRouteActionListener; -import fr.ird.observe.application.swing.ui.tree.actions.NodeChangeActionListener; -import fr.ird.observe.application.swing.ui.util.DecoratedNodeEntity; -import fr.ird.observe.application.swing.decoration.decorators.DataReferenceDecorator; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author Kevin Morin (Code Lutin) - * @since 5.0 - */ -public class MoveActivitySeineNodeMenuPopulator extends MoveNodeMenuPopulator { - - @Override - public NodeChangeActionListener createChangeActionListener(ObserveTreeHelper treeHelper, - ObserveSwingDataSource dataSource, - String id, - String parentId) { - return new ChangeActivityRouteActionListener(treeHelper, dataSource, id, parentId); - } - - @Override - public List<DecoratedNodeEntity> getPossibleParentNodes(ObserveNode activitySeineNode, ObserveTreeHelper treeHelper) { - - // noeud de route parent - ObserveNode parentNode = activitySeineNode.getParent().getParent(); - - // noeud de route de la marée sans le parent actuel - List<DecoratedNodeEntity> possibleParents = new ArrayList<>(); - - // noeud des routes de la marée - ObserveNode routesNode = parentNode.getParent(); - - DecoratorService decoratorService = treeHelper.getTreeCellRenderer().getDecoratorService(); - DataReferenceDecorator<RouteDto> routeDecorator = decoratorService.getDataReferenceDecorator(RouteDto.class); - - for (int i = 0, n = routesNode.getChildCount(); i < n; i++) { - - RouteSeineNode routeNode = (RouteSeineNode) routesNode.getChildAt(i); - String routeId = routeNode.getId(); - - // si le noeud de marée n'est pas le même que le parent actuel - // si le noeud est bien un noeud de marée seine - if (!parentNode.equals(routeNode) && IdHelper.isRouteId(routeId)) { - - possibleParents.add(DecoratedNodeEntity.newDecoratedNodeEntity(routeNode, routeDecorator)); - - } - } - - return possibleParents; - } -} ===================================== application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/menu/MoveNodeMenuPopulator.java deleted ===================================== --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/menu/MoveNodeMenuPopulator.java +++ /dev/null @@ -1,62 +0,0 @@ -package fr.ird.observe.application.swing.ui.tree.menu; - -/*- - * #%L - * ObServe :: Application Swing - * %% - * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io - * %% - * 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.application.swing.db.ObserveSwingDataSource; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; -import fr.ird.observe.application.swing.ui.tree.actions.NodeChangeActionListener; -import fr.ird.observe.application.swing.ui.util.DecoratedNodeEntity; - -import java.util.List; - -/** - * Objets pour créer les items du menu déplacer dans le menu contextuel de l'arbre - * - * @author Kevin Morin (Code Lutin) - * @since 5.0 - */ -public abstract class MoveNodeMenuPopulator { - - /** - * Crée une action pour déplacer le noeud quand on sélectionne le menu du nouveau parent - * @param treeHelper - * @param dataSource - * @param id - * @param parentId - * @return - */ - public abstract NodeChangeActionListener createChangeActionListener(ObserveTreeHelper treeHelper, - ObserveSwingDataSource dataSource, - String id, - String parentId); - - /** - * Récupère les parents dans lesquels on peut déplacer le noeud sélectionné - * @param node le noeud sélectionné - * @param treeHelper le treehelper - * @return une liste contenant les ids et les libellés des noeuds - */ - public abstract List<DecoratedNodeEntity> getPossibleParentNodes(ObserveNode node, ObserveTreeHelper treeHelper); - -} ===================================== application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/menu/MoveRouteNodeMenuPopulator.java deleted ===================================== --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/menu/MoveRouteNodeMenuPopulator.java +++ /dev/null @@ -1,85 +0,0 @@ -package fr.ird.observe.application.swing.ui.tree.menu; - -/*- - * #%L - * ObServe :: Application Swing - * %% - * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io - * %% - * 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.application.swing.db.ObserveSwingDataSource; -import fr.ird.observe.services.dto.IdHelper; -import fr.ird.observe.services.dto.seine.TripSeineDto; -import fr.ird.observe.application.swing.decoration.DecoratorService; -import fr.ird.observe.application.swing.ui.tree.node.ObserveNode; -import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; -import fr.ird.observe.application.swing.ui.tree.node.TripSeineNode; -import fr.ird.observe.application.swing.ui.tree.actions.ChangeRouteTripActionListener; -import fr.ird.observe.application.swing.ui.tree.actions.NodeChangeActionListener; -import fr.ird.observe.application.swing.ui.util.DecoratedNodeEntity; -import fr.ird.observe.application.swing.decoration.decorators.DataReferenceDecorator; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author Kevin Morin (Code Lutin) - * @since 5.0 - */ -public class MoveRouteNodeMenuPopulator extends MoveNodeMenuPopulator { - - @Override - public NodeChangeActionListener createChangeActionListener(ObserveTreeHelper treeHelper, - ObserveSwingDataSource dataSource, - String id, - String parentId) { - return new ChangeRouteTripActionListener(treeHelper, dataSource, id, parentId); - } - - @Override - public List<DecoratedNodeEntity> getPossibleParentNodes(ObserveNode routeNode, ObserveTreeHelper treeHelper) { - - // noeud de marée parent - ObserveNode parentNode = routeNode.getParent().getParent(); - - // noeud de marée du programme sans le parent actuel - List<DecoratedNodeEntity> possibleParents = new ArrayList<>(); - - // noeud du programme - ObserveNode programNode = parentNode.getParent(); - - DecoratorService decoratorService = treeHelper.getTreeCellRenderer().getDecoratorService(); - DataReferenceDecorator<TripSeineDto> tripDecorator = decoratorService.getDataReferenceDecorator(TripSeineDto.class); - - for (int i = 0, n = programNode.getChildCount(); i < n; i++) { - - TripSeineNode tripNode = (TripSeineNode) programNode.getChildAt(i); - String tripId = tripNode.getId(); - - // si le noeud de marée n'est pas le même que le parent actuel - // si le noeud est bien un noeud de marée seine - if (!parentNode.equals(tripNode) && IdHelper.isTripSeineId(tripId)) { - - possibleParents.add(DecoratedNodeEntity.newDecoratedNodeEntity(tripNode, tripDecorator)); - - } - } - - return possibleParents; - } -} ===================================== application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/node/ObserveNode.java ===================================== --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/node/ObserveNode.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/tree/node/ObserveNode.java @@ -105,6 +105,14 @@ public class ObserveNode extends NavTreeNode<ObserveNode> { || TripLonglineDto.class.isAssignableFrom(internalClass)); } + public boolean isTripSeineNode() { + return isDataNode() && TripSeineDto.class.isAssignableFrom(internalClass); + } + + public boolean isTripLonglineNode() { + return isDataNode() && TripLonglineDto.class.isAssignableFrom(internalClass); + } + public boolean isRouteNode() { return isDataNode() && RouteDto.class.isAssignableFrom(internalClass); } View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/commit/1c750803709da1fd7e55717d7727... --- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/commit/1c750803709da1fd7e55717d7727... You're receiving this email because of your account on gitlab.com.