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
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:
| ... | ... | @@ -86,7 +86,7 @@ |
| 86 | 86 |
<JPopupMenu id='scopeDownPopup'/>
|
| 87 | 87 |
<JPopupMenu id='navigationPopup'>
|
| 88 | 88 |
<JMenuItem id="navigationNoAction"/>
|
| 89 |
- <JMenu id="navigationMoveAction"/>
|
|
| 89 |
+ <JMenuItem id="navigationMoveAction"/>
|
|
| 90 | 90 |
<JMenuItem id="navigationOpenAction"/>
|
| 91 | 91 |
<JMenuItem id="navigationCloseAction"/>
|
| 92 | 92 |
<JMenuItem id="navigationDeleteAction"/>
|
| 1 |
+/*
|
|
| 2 |
+ * #%L
|
|
| 3 |
+ * ObServe :: Application Swing
|
|
| 4 |
+ * %%
|
|
| 5 |
+ * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io
|
|
| 6 |
+ * %%
|
|
| 7 |
+ * This program is free software: you can redistribute it and/or modify
|
|
| 8 |
+ * it under the terms of the GNU General Public License as
|
|
| 9 |
+ * published by the Free Software Foundation, either version 3 of the
|
|
| 10 |
+ * License, or (at your option) any later version.
|
|
| 11 |
+ *
|
|
| 12 |
+ * This program is distributed in the hope that it will be useful,
|
|
| 13 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 14 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 15 |
+ * GNU General Public License for more details.
|
|
| 16 |
+ *
|
|
| 17 |
+ * You should have received a copy of the GNU General Public
|
|
| 18 |
+ * License along with this program. If not, see
|
|
| 19 |
+ * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 20 |
+ * #L%
|
|
| 21 |
+ */
|
|
| 22 |
+package fr.ird.observe.application.swing.ui.actions.shared;
|
|
| 23 |
+ |
|
| 24 |
+import fr.ird.observe.application.swing.ObserveOpenDataManager;
|
|
| 25 |
+import fr.ird.observe.application.swing.ObserveSwingApplicationContext;
|
|
| 26 |
+import fr.ird.observe.application.swing.decoration.ObserveI18nDecoratorHelper;
|
|
| 27 |
+import fr.ird.observe.application.swing.decoration.decorators.DataReferenceDecorator;
|
|
| 28 |
+import fr.ird.observe.application.swing.ui.ObserveMainUI;
|
|
| 29 |
+import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper;
|
|
| 30 |
+import fr.ird.observe.application.swing.ui.tree.node.ObserveNode;
|
|
| 31 |
+import fr.ird.observe.application.swing.ui.tree.node.TripLonglineNode;
|
|
| 32 |
+import fr.ird.observe.application.swing.ui.util.DecoratedNodeEntity;
|
|
| 33 |
+import fr.ird.observe.services.ObserveServicesProvider;
|
|
| 34 |
+import fr.ird.observe.services.dto.longline.ActivityLonglineDto;
|
|
| 35 |
+import fr.ird.observe.services.dto.longline.TripLonglineDto;
|
|
| 36 |
+import java.util.Optional;
|
|
| 37 |
+import javax.swing.JOptionPane;
|
|
| 38 |
+ |
|
| 39 |
+ |
|
| 40 |
+import static org.nuiton.i18n.I18n.n;
|
|
| 41 |
+import static org.nuiton.i18n.I18n.t;
|
|
| 42 |
+ |
|
| 43 |
+/**
|
|
| 44 |
+ * Action pour changer le programme d'une ou plusieurs marée dans la liste.
|
|
| 45 |
+ *
|
|
| 46 |
+ * @author Tony Chemit - dev@ultreia.io
|
|
| 47 |
+ * @since 5.0
|
|
| 48 |
+ */
|
|
| 49 |
+public class MoveActivityLonglineUIAction extends MoveSingleDataUIActionSupport {
|
|
| 50 |
+ |
|
| 51 |
+ private static final long serialVersionUID = 1L;
|
|
| 52 |
+ |
|
| 53 |
+ public static final String ACTION_NAME = "moveActivityLongline";
|
|
| 54 |
+ |
|
| 55 |
+ public MoveActivityLonglineUIAction(ObserveMainUI mainUI) {
|
|
| 56 |
+ super(mainUI,
|
|
| 57 |
+ ACTION_NAME,
|
|
| 58 |
+ n("observe.navigationMenu.move.activityLongline"),
|
|
| 59 |
+ n("observe.navigationMenu.move.activityLongline"),
|
|
| 60 |
+ "move-activities"
|
|
| 61 |
+ );
|
|
| 62 |
+ }
|
|
| 63 |
+ |
|
| 64 |
+ @Override
|
|
| 65 |
+ Optional<String> getNewParentId(ObserveMainUI mainUI, ObserveNode oldParentNode) {
|
|
| 66 |
+ return chooseNewTripLongline(mainUI, oldParentNode);
|
|
| 67 |
+ }
|
|
| 68 |
+ |
|
| 69 |
+ @Override
|
|
| 70 |
+ int moveData(ObserveServicesProvider servicesProvider, ObserveOpenDataManager openDataManager, String oldParentId, String newParentId, String dataId) {
|
|
| 71 |
+ |
|
| 72 |
+ return servicesProvider.newActivityLonglineService().moveActivityLonglineToTripLongline(dataId, newParentId);
|
|
| 73 |
+ }
|
|
| 74 |
+ |
|
| 75 |
+ @Override
|
|
| 76 |
+ void closeNode(ObserveOpenDataManager openDataManager, String dataId) {
|
|
| 77 |
+ if (openDataManager.isOpenActivityLongline(dataId)) {
|
|
| 78 |
+ openDataManager.closeActivityLongline(dataId);
|
|
| 79 |
+ }
|
|
| 80 |
+ }
|
|
| 81 |
+ |
|
| 82 |
+ @Override
|
|
| 83 |
+ ObserveNode getNewParentNode(ObserveTreeHelper treeHelper, ObserveNode grandParentNode, String newParentId) {
|
|
| 84 |
+ ObserveNode tripLonglineNode = treeHelper.getChild(grandParentNode, newParentId);
|
|
| 85 |
+ String activitiesNodeId = ObserveI18nDecoratorHelper.getTypePluralI18nKey(ActivityLonglineDto.class);
|
|
| 86 |
+ return treeHelper.getChild(tripLonglineNode, activitiesNodeId);
|
|
| 87 |
+ }
|
|
| 88 |
+ |
|
| 89 |
+ static Optional<String> chooseNewTripLongline(ObserveMainUI ui, ObserveNode oldParentNode) {
|
|
| 90 |
+ |
|
| 91 |
+ ObserveNode programNode = oldParentNode.getParent();
|
|
| 92 |
+ String oldTripLonglineId = oldParentNode.getId();
|
|
| 93 |
+ int tripLonglineNb = programNode.getChildCount();
|
|
| 94 |
+ |
|
| 95 |
+ ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get();
|
|
| 96 |
+ DataReferenceDecorator<TripLonglineDto> decorator = applicationContext.getDecoratorService().getDataReferenceDecorator(TripLonglineDto.class);
|
|
| 97 |
+ |
|
| 98 |
+ //on crée un tableau avec une marée en moins car on ne propose pas la marée actuelle
|
|
| 99 |
+ DecoratedNodeEntity[] decoratedTripLonglines = new DecoratedNodeEntity[tripLonglineNb - 1];
|
|
| 100 |
+ |
|
| 101 |
+ int j = 0;
|
|
| 102 |
+ for (int i = 0; i < tripLonglineNb; i++) {
|
|
| 103 |
+ |
|
| 104 |
+ TripLonglineNode tripLonglineNode = (TripLonglineNode) programNode.getChildAt(i);
|
|
| 105 |
+ |
|
| 106 |
+ String tripLonglineId = tripLonglineNode.getId();
|
|
| 107 |
+ |
|
| 108 |
+ if (!oldTripLonglineId.equals(tripLonglineId)) {
|
|
| 109 |
+ decoratedTripLonglines[j++] = DecoratedNodeEntity.newDecoratedNodeEntity(tripLonglineNode, decorator);
|
|
| 110 |
+ }
|
|
| 111 |
+ }
|
|
| 112 |
+ |
|
| 113 |
+ Object decoratedTripLongline = JOptionPane.showInputDialog(ui,
|
|
| 114 |
+ t("observe.action.choose.tripLongline.message"),
|
|
| 115 |
+ t("observe.action.choose.tripLongline.title"),
|
|
| 116 |
+ JOptionPane.QUESTION_MESSAGE,
|
|
| 117 |
+ null,
|
|
| 118 |
+ decoratedTripLonglines,
|
|
| 119 |
+ null);
|
|
| 120 |
+ return Optional.ofNullable(decoratedTripLongline != null ? ((DecoratedNodeEntity) decoratedTripLongline).getId() : null);
|
|
| 121 |
+ }
|
|
| 122 |
+ |
|
| 123 |
+}
|
| ... | ... | @@ -24,31 +24,17 @@ package fr.ird.observe.application.swing.ui.actions.shared; |
| 24 | 24 |
import fr.ird.observe.application.swing.ObserveOpenDataManager;
|
| 25 | 25 |
import fr.ird.observe.application.swing.ObserveSwingApplicationContext;
|
| 26 | 26 |
import fr.ird.observe.application.swing.decoration.ObserveI18nDecoratorHelper;
|
| 27 |
-import fr.ird.observe.application.swing.decoration.decorators.DataReferenceDecorator;
|
|
| 28 | 27 |
import fr.ird.observe.application.swing.ui.ObserveMainUI;
|
| 29 |
-import fr.ird.observe.application.swing.ui.content.ContentUI;
|
|
| 30 | 28 |
import fr.ird.observe.application.swing.ui.content.list.impl.longline.ActivityLonglinesUI;
|
| 31 |
-import fr.ird.observe.application.swing.ui.tree.node.ObserveNode;
|
|
| 32 | 29 |
import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper;
|
| 33 |
-import fr.ird.observe.application.swing.ui.tree.node.TripLonglineNode;
|
|
| 34 |
-import fr.ird.observe.application.swing.ui.util.DecoratedNodeEntity;
|
|
| 35 |
-import fr.ird.observe.services.dto.DataReference;
|
|
| 30 |
+import fr.ird.observe.application.swing.ui.tree.node.ObserveNode;
|
|
| 31 |
+import fr.ird.observe.services.ObserveServicesProvider;
|
|
| 36 | 32 |
import fr.ird.observe.services.dto.longline.ActivityLonglineDto;
|
| 37 |
-import fr.ird.observe.services.dto.longline.TripLonglineDto;
|
|
| 38 |
-import fr.ird.observe.services.service.longline.ActivityLonglineService;
|
|
| 39 |
-import org.apache.commons.logging.Log;
|
|
| 40 |
-import org.apache.commons.logging.LogFactory;
|
|
| 41 |
- |
|
| 42 |
-import javax.swing.JComponent;
|
|
| 43 |
-import javax.swing.JOptionPane;
|
|
| 44 |
-import javax.swing.SwingUtilities;
|
|
| 45 |
-import java.awt.event.ActionEvent;
|
|
| 46 | 33 |
import java.util.List;
|
| 47 | 34 |
import java.util.Optional;
|
| 48 |
-import java.util.stream.Collectors;
|
|
| 35 |
+ |
|
| 49 | 36 |
|
| 50 | 37 |
import static org.nuiton.i18n.I18n.n;
|
| 51 |
-import static org.nuiton.i18n.I18n.t;
|
|
| 52 | 38 |
|
| 53 | 39 |
/**
|
| 54 | 40 |
* 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; |
| 56 | 42 |
* @author Kevin Morin (Code Lutin)
|
| 57 | 43 |
* @since 5.0
|
| 58 | 44 |
*/
|
| 59 |
-public class MoveActivityLonglinesUIAction extends AbstractUIAction {
|
|
| 45 |
+public class MoveActivityLonglinesUIAction extends MoveMultipleDataUIActionSupport<ActivityLonglinesUI> {
|
|
| 60 | 46 |
|
| 61 | 47 |
private static final long serialVersionUID = 1L;
|
| 62 | 48 |
|
| 63 |
- /**
|
|
| 64 |
- * Logger.
|
|
| 65 |
- */
|
|
| 66 |
- private static final Log log = LogFactory.getLog(MoveActivityLonglinesUIAction.class);
|
|
| 67 |
- |
|
| 68 | 49 |
public static final String ACTION_NAME = "moveActivityLonglines";
|
| 69 | 50 |
|
| 70 | 51 |
public MoveActivityLonglinesUIAction(ObserveMainUI mainUI) {
|
| ... | ... | @@ -72,95 +53,23 @@ public class MoveActivityLonglinesUIAction extends AbstractUIAction { |
| 72 | 53 |
ACTION_NAME,
|
| 73 | 54 |
n("observe.content.action.move.activities.longline"),
|
| 74 | 55 |
n("observe.content.action.move.activities.longline.tip"),
|
| 75 |
- "move-activities"
|
|
| 56 |
+ "move-activities",
|
|
| 57 |
+ ActivityLonglinesUI.class
|
|
| 76 | 58 |
);
|
| 77 | 59 |
}
|
| 78 | 60 |
|
| 79 | 61 |
@Override
|
| 80 |
- public void actionPerformed(final ActionEvent e) {
|
|
| 81 |
- |
|
| 82 |
- SwingUtilities.invokeLater(() -> {
|
|
| 83 |
- JComponent c = (JComponent) e.getSource();
|
|
| 84 |
- ContentUI<?> ui = (ContentUI<?>)
|
|
| 85 |
- c.getClientProperty("ui");
|
|
| 86 |
- if (ui == null) {
|
|
| 87 |
- throw new IllegalStateException(
|
|
| 88 |
- "could not find client property " +
|
|
| 89 |
- "ui on component" + c);
|
|
| 90 |
- }
|
|
| 91 |
- |
|
| 92 |
- if (!(ui instanceof ActivityLonglinesUI)) {
|
|
| 93 |
- throw new IllegalStateException("Can not come here!");
|
|
| 94 |
- }
|
|
| 95 |
- ActivityLonglinesUI activityLonglinesUI = (ActivityLonglinesUI) ui;
|
|
| 96 |
- |
|
| 97 |
- |
|
| 98 |
- // get current triplongline id
|
|
| 99 |
- ObserveTreeHelper treeHelper = getMainUI().getTreeHelper();
|
|
| 100 |
- ObserveNode oldActivitiesNode = treeHelper.getSelectedNode();
|
|
| 101 |
- ObserveNode oldTripLonglineNode = oldActivitiesNode.getParent();
|
|
| 102 |
- |
|
| 103 |
- // choose the new tripLongline
|
|
| 104 |
- String tripLonglineId = chooseNewTripLongline(ui, oldTripLonglineNode);
|
|
| 105 |
- |
|
| 106 |
- if (tripLonglineId != null) {
|
|
| 107 |
- |
|
| 108 |
- if (log.isInfoEnabled()) {
|
|
| 109 |
- log.info("Will move activities to trip: " + tripLonglineId);
|
|
| 110 |
- }
|
|
| 111 |
- // change the tripLongline of the selected activities
|
|
| 112 |
- List<DataReference<ActivityLonglineDto>> selectedDatas = activityLonglinesUI.getModel().getSelectedDatas();
|
|
| 113 |
- List<String> activityIds = selectedDatas.stream()
|
|
| 114 |
- .map(DataReference.ID_FUNCTION)
|
|
| 115 |
- .collect(Collectors.toList());
|
|
| 116 |
- ActivityLonglineService service = ObserveSwingApplicationContext.get().getMainDataSourceServicesProvider().newActivityLonglineService();
|
|
| 117 |
-// List<Integer> positions =
|
|
| 118 |
- service.moveActivityLonglinesToTripLongline(activityIds, tripLonglineId);
|
|
| 119 |
- |
|
| 120 |
- // update the tree
|
|
| 121 |
- updateTree(oldActivitiesNode, tripLonglineId, activityIds);
|
|
| 122 |
- }
|
|
| 123 |
- |
|
| 124 |
- });
|
|
| 125 |
- |
|
| 62 |
+ List<Integer> moveData(List<String> dataIds, String newParentId, ObserveServicesProvider servicesProvider) {
|
|
| 63 |
+ return servicesProvider.newActivityLonglineService().moveActivityLonglinesToTripLongline(dataIds, newParentId);
|
|
| 126 | 64 |
}
|
| 127 | 65 |
|
| 128 |
- protected String chooseNewTripLongline(ContentUI<?> ui, ObserveNode oldTripLonglineNode) {
|
|
| 129 |
- ObserveNode programNode = oldTripLonglineNode.getParent();
|
|
| 130 |
- String oldTripLonglineId = oldTripLonglineNode.getId();
|
|
| 131 |
- int tripLonglineNb = programNode.getChildCount();
|
|
| 132 |
- |
|
| 133 |
- ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get();
|
|
| 134 |
- DataReferenceDecorator<TripLonglineDto> decorator = applicationContext.getDecoratorService().getDataReferenceDecorator(TripLonglineDto.class);
|
|
| 135 |
- |
|
| 136 |
- //on crée un tableau avec une marée en moins car on ne propose pas la marée actuelle
|
|
| 137 |
- DecoratedNodeEntity[] decoratedTripLonglines = new DecoratedNodeEntity[tripLonglineNb - 1];
|
|
| 138 |
- |
|
| 139 |
- int j = 0;
|
|
| 140 |
- for (int i = 0; i < tripLonglineNb; i++) {
|
|
| 141 |
- |
|
| 142 |
- TripLonglineNode tripLonglineNode = (TripLonglineNode) programNode.getChildAt(i);
|
|
| 143 |
- |
|
| 144 |
- String tripLonglineId = tripLonglineNode.getId();
|
|
| 145 |
- |
|
| 146 |
- if (!oldTripLonglineId.equals(tripLonglineId)) {
|
|
| 147 |
- decoratedTripLonglines[j++] = DecoratedNodeEntity.newDecoratedNodeEntity(tripLonglineNode, decorator);
|
|
| 148 |
- }
|
|
| 149 |
- }
|
|
| 150 |
- |
|
| 151 |
- Object decoratedTripLongline = JOptionPane.showInputDialog(ui,
|
|
| 152 |
- t("observe.action.choose.tripLongline.message"),
|
|
| 153 |
- t("observe.action.choose.tripLongline.title"),
|
|
| 154 |
- JOptionPane.QUESTION_MESSAGE,
|
|
| 155 |
- null,
|
|
| 156 |
- decoratedTripLonglines,
|
|
| 157 |
- null);
|
|
| 158 |
- return decoratedTripLongline != null ? ((DecoratedNodeEntity) decoratedTripLongline).getId() : null;
|
|
| 66 |
+ @Override
|
|
| 67 |
+ Optional<String> getNewParentId(ObserveMainUI mainUI, ObserveNode oldParentNode) {
|
|
| 68 |
+ return MoveActivityLonglineUIAction.chooseNewTripLongline(getMainUI(), oldParentNode);
|
|
| 159 | 69 |
}
|
| 160 | 70 |
|
| 161 |
- protected void updateTree(ObserveNode oldActivitiesNode,
|
|
| 162 |
- String tripLonglineId,
|
|
| 163 |
- List<String> activityIds) {
|
|
| 71 |
+ @Override
|
|
| 72 |
+ void updateUI(ActivityLonglinesUI ui, ObserveNode oldActivitiesNode, String tripLonglineId, List<String> activityIds, List<Integer> positions) {
|
|
| 164 | 73 |
|
| 165 | 74 |
ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get();
|
| 166 | 75 |
ObserveOpenDataManager openDataManager = applicationContext.getOpenDataManager();
|
| ... | ... | @@ -179,9 +88,7 @@ public class MoveActivityLonglinesUIAction extends AbstractUIAction { |
| 179 | 88 |
.findFirst();
|
| 180 | 89 |
|
| 181 | 90 |
// If so, we close it to avoid ending up with an open activity into a closed trip.
|
| 182 |
- if (openActivity.isPresent()) {
|
|
| 183 |
- openDataManager.closeActivityLongline(openActivity.get());
|
|
| 184 |
- }
|
|
| 91 |
+ openActivity.ifPresent(openDataManager::closeActivityLongline);
|
|
| 185 | 92 |
|
| 186 | 93 |
// Let's reload the sub tree of each activities node.
|
| 187 | 94 |
// As the change have already be done in database, we just call the child loaders to regenerate the activities nodes sub trees
|
| 1 |
+/*
|
|
| 2 |
+ * #%L
|
|
| 3 |
+ * ObServe :: Application Swing
|
|
| 4 |
+ * %%
|
|
| 5 |
+ * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io
|
|
| 6 |
+ * %%
|
|
| 7 |
+ * This program is free software: you can redistribute it and/or modify
|
|
| 8 |
+ * it under the terms of the GNU General Public License as
|
|
| 9 |
+ * published by the Free Software Foundation, either version 3 of the
|
|
| 10 |
+ * License, or (at your option) any later version.
|
|
| 11 |
+ *
|
|
| 12 |
+ * This program is distributed in the hope that it will be useful,
|
|
| 13 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 14 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 15 |
+ * GNU General Public License for more details.
|
|
| 16 |
+ *
|
|
| 17 |
+ * You should have received a copy of the GNU General Public
|
|
| 18 |
+ * License along with this program. If not, see
|
|
| 19 |
+ * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 20 |
+ * #L%
|
|
| 21 |
+ */
|
|
| 22 |
+package fr.ird.observe.application.swing.ui.actions.shared;
|
|
| 23 |
+ |
|
| 24 |
+import fr.ird.observe.application.swing.ObserveOpenDataManager;
|
|
| 25 |
+import fr.ird.observe.application.swing.ObserveSwingApplicationContext;
|
|
| 26 |
+import fr.ird.observe.application.swing.decoration.ObserveI18nDecoratorHelper;
|
|
| 27 |
+import fr.ird.observe.application.swing.decoration.decorators.DataReferenceDecorator;
|
|
| 28 |
+import fr.ird.observe.application.swing.ui.ObserveMainUI;
|
|
| 29 |
+import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper;
|
|
| 30 |
+import fr.ird.observe.application.swing.ui.tree.node.ObserveNode;
|
|
| 31 |
+import fr.ird.observe.application.swing.ui.tree.node.RouteSeineNode;
|
|
| 32 |
+import fr.ird.observe.application.swing.ui.util.DecoratedNodeEntity;
|
|
| 33 |
+import fr.ird.observe.services.ObserveServicesProvider;
|
|
| 34 |
+import fr.ird.observe.services.dto.seine.ActivitySeineDto;
|
|
| 35 |
+import fr.ird.observe.services.dto.seine.RouteDto;
|
|
| 36 |
+import java.util.Optional;
|
|
| 37 |
+import javax.swing.JOptionPane;
|
|
| 38 |
+ |
|
| 39 |
+ |
|
| 40 |
+import static org.nuiton.i18n.I18n.n;
|
|
| 41 |
+import static org.nuiton.i18n.I18n.t;
|
|
| 42 |
+ |
|
| 43 |
+/**
|
|
| 44 |
+ * Action pour changer le programme d'une ou plusieurs marée dans la liste.
|
|
| 45 |
+ *
|
|
| 46 |
+ * @author Tony Chemit - dev@ultreia.io
|
|
| 47 |
+ * @since 5.0
|
|
| 48 |
+ */
|
|
| 49 |
+public class MoveActivitySeineUIAction extends MoveSingleDataUIActionSupport {
|
|
| 50 |
+ |
|
| 51 |
+ private static final long serialVersionUID = 1L;
|
|
| 52 |
+ |
|
| 53 |
+ public static final String ACTION_NAME = "moveActivitySeine";
|
|
| 54 |
+ |
|
| 55 |
+ public MoveActivitySeineUIAction(ObserveMainUI mainUI) {
|
|
| 56 |
+ super(mainUI,
|
|
| 57 |
+ ACTION_NAME,
|
|
| 58 |
+ n("observe.navigationMenu.move.activitySeine"),
|
|
| 59 |
+ n("observe.navigationMenu.move.activitySeine"),
|
|
| 60 |
+ "move-activities"
|
|
| 61 |
+ );
|
|
| 62 |
+ }
|
|
| 63 |
+ |
|
| 64 |
+ @Override
|
|
| 65 |
+ Optional<String> getNewParentId(ObserveMainUI mainUI, ObserveNode oldParentNode) {
|
|
| 66 |
+ return chooseNewRoute(mainUI, oldParentNode);
|
|
| 67 |
+ }
|
|
| 68 |
+ |
|
| 69 |
+ @Override
|
|
| 70 |
+ int moveData(ObserveServicesProvider servicesProvider, ObserveOpenDataManager openDataManager, String oldParentId, String newParentId, String dataId) {
|
|
| 71 |
+ return servicesProvider.newActivitySeineService().moveActivitySeineToRoute(dataId, newParentId);
|
|
| 72 |
+ }
|
|
| 73 |
+ |
|
| 74 |
+ @Override
|
|
| 75 |
+ void closeNode(ObserveOpenDataManager openDataManager, String dataId) {
|
|
| 76 |
+ if (openDataManager.isOpenActivitySeine(dataId)) {
|
|
| 77 |
+ openDataManager.closeActivitySeine(dataId);
|
|
| 78 |
+ }
|
|
| 79 |
+ }
|
|
| 80 |
+ |
|
| 81 |
+ @Override
|
|
| 82 |
+ ObserveNode getNewParentNode(ObserveTreeHelper treeHelper, ObserveNode grandParentNode, String newParentId) {
|
|
| 83 |
+ ObserveNode routeNode = treeHelper.getChild(grandParentNode, newParentId);
|
|
| 84 |
+ String activitiesNodeId = ObserveI18nDecoratorHelper.getTypePluralI18nKey(ActivitySeineDto.class);
|
|
| 85 |
+ return treeHelper.getChild(routeNode, activitiesNodeId);
|
|
| 86 |
+ }
|
|
| 87 |
+ |
|
| 88 |
+ static Optional<String> chooseNewRoute(ObserveMainUI mainUI, ObserveNode oldParentNode) {
|
|
| 89 |
+ |
|
| 90 |
+ ObserveNode routesNode = oldParentNode.getParent();
|
|
| 91 |
+ String oldRouteId = oldParentNode.getId();
|
|
| 92 |
+ int routeNb = routesNode.getChildCount();
|
|
| 93 |
+ |
|
| 94 |
+ ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get();
|
|
| 95 |
+ DataReferenceDecorator<RouteDto> decorator = applicationContext.getDecoratorService().getDataReferenceDecorator(RouteDto.class);
|
|
| 96 |
+ |
|
| 97 |
+ //on crée un tableau avec une route en moins car on ne propose pas la route actuel
|
|
| 98 |
+ DecoratedNodeEntity[] decoratedRoutes = new DecoratedNodeEntity[routeNb - 1];
|
|
| 99 |
+ |
|
| 100 |
+ int j = 0;
|
|
| 101 |
+ for (int i = 0; i < routeNb; i++) {
|
|
| 102 |
+ |
|
| 103 |
+ RouteSeineNode routeNode = (RouteSeineNode) routesNode.getChildAt(i);
|
|
| 104 |
+ |
|
| 105 |
+ String routeId = routeNode.getId();
|
|
| 106 |
+ |
|
| 107 |
+ if (!oldRouteId.equals(routeId)) {
|
|
| 108 |
+ decoratedRoutes[j++] = DecoratedNodeEntity.newDecoratedNodeEntity(routeNode, decorator);
|
|
| 109 |
+ }
|
|
| 110 |
+ }
|
|
| 111 |
+ |
|
| 112 |
+ Object decoratedRoute = JOptionPane.showInputDialog(mainUI,
|
|
| 113 |
+ t("observe.action.choose.route.message"),
|
|
| 114 |
+ t("observe.action.choose.route.title"),
|
|
| 115 |
+ JOptionPane.QUESTION_MESSAGE,
|
|
| 116 |
+ null,
|
|
| 117 |
+ decoratedRoutes,
|
|
| 118 |
+ null);
|
|
| 119 |
+ |
|
| 120 |
+ return Optional.ofNullable(decoratedRoute != null ? ((DecoratedNodeEntity) decoratedRoute).getId() : null);
|
|
| 121 |
+ }
|
|
| 122 |
+ |
|
| 123 |
+}
|
| ... | ... | @@ -24,32 +24,17 @@ package fr.ird.observe.application.swing.ui.actions.shared; |
| 24 | 24 |
import fr.ird.observe.application.swing.ObserveOpenDataManager;
|
| 25 | 25 |
import fr.ird.observe.application.swing.ObserveSwingApplicationContext;
|
| 26 | 26 |
import fr.ird.observe.application.swing.decoration.ObserveI18nDecoratorHelper;
|
| 27 |
-import fr.ird.observe.application.swing.decoration.decorators.DataReferenceDecorator;
|
|
| 28 | 27 |
import fr.ird.observe.application.swing.ui.ObserveMainUI;
|
| 29 |
-import fr.ird.observe.application.swing.ui.content.ContentUI;
|
|
| 30 | 28 |
import fr.ird.observe.application.swing.ui.content.list.impl.seine.ActivitySeinesUI;
|
| 31 |
-import fr.ird.observe.application.swing.ui.content.list.impl.seine.ActivitySeinesUIModel;
|
|
| 32 |
-import fr.ird.observe.application.swing.ui.tree.node.ObserveNode;
|
|
| 33 | 29 |
import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper;
|
| 34 |
-import fr.ird.observe.application.swing.ui.tree.node.RouteSeineNode;
|
|
| 35 |
-import fr.ird.observe.application.swing.ui.util.DecoratedNodeEntity;
|
|
| 36 |
-import fr.ird.observe.services.dto.DataReference;
|
|
| 30 |
+import fr.ird.observe.application.swing.ui.tree.node.ObserveNode;
|
|
| 31 |
+import fr.ird.observe.services.ObserveServicesProvider;
|
|
| 37 | 32 |
import fr.ird.observe.services.dto.seine.ActivitySeineDto;
|
| 38 |
-import fr.ird.observe.services.dto.seine.RouteDto;
|
|
| 39 |
-import fr.ird.observe.services.service.seine.ActivitySeineService;
|
|
| 40 |
-import org.apache.commons.logging.Log;
|
|
| 41 |
-import org.apache.commons.logging.LogFactory;
|
|
| 42 |
- |
|
| 43 |
-import javax.swing.JComponent;
|
|
| 44 |
-import javax.swing.JOptionPane;
|
|
| 45 |
-import javax.swing.SwingUtilities;
|
|
| 46 |
-import java.awt.event.ActionEvent;
|
|
| 47 | 33 |
import java.util.List;
|
| 48 | 34 |
import java.util.Optional;
|
| 49 |
-import java.util.stream.Collectors;
|
|
| 35 |
+ |
|
| 50 | 36 |
|
| 51 | 37 |
import static org.nuiton.i18n.I18n.n;
|
| 52 |
-import static org.nuiton.i18n.I18n.t;
|
|
| 53 | 38 |
|
| 54 | 39 |
/**
|
| 55 | 40 |
* 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; |
| 57 | 42 |
* @author Kevin Morin (Code Lutin)
|
| 58 | 43 |
* @since 5.0
|
| 59 | 44 |
*/
|
| 60 |
-public class MoveActivitySeinesUIAction extends AbstractUIAction {
|
|
| 45 |
+public class MoveActivitySeinesUIAction extends MoveMultipleDataUIActionSupport<ActivitySeinesUI> {
|
|
| 61 | 46 |
|
| 62 | 47 |
private static final long serialVersionUID = 1L;
|
| 63 | 48 |
|
| 64 |
- /**
|
|
| 65 |
- * Logger.
|
|
| 66 |
- */
|
|
| 67 |
- private static final Log log = LogFactory.getLog(MoveActivitySeinesUIAction.class);
|
|
| 68 |
- |
|
| 69 | 49 |
public static final String ACTION_NAME = "moveActivitySeines";
|
| 70 | 50 |
|
| 71 | 51 |
public MoveActivitySeinesUIAction(ObserveMainUI mainUI) {
|
| ... | ... | @@ -73,115 +53,46 @@ public class MoveActivitySeinesUIAction extends AbstractUIAction { |
| 73 | 53 |
ACTION_NAME,
|
| 74 | 54 |
n("observe.content.action.move.activities.seine"),
|
| 75 | 55 |
n("observe.content.action.move.activities.seine.tip"),
|
| 76 |
- "move-activities"
|
|
| 56 |
+ "move-activities",
|
|
| 57 |
+ ActivitySeinesUI.class
|
|
| 77 | 58 |
);
|
| 78 | 59 |
}
|
| 79 | 60 |
|
| 80 | 61 |
@Override
|
| 81 |
- public void actionPerformed(final ActionEvent e) {
|
|
| 82 |
- |
|
| 83 |
- SwingUtilities.invokeLater(() -> {
|
|
| 84 |
- JComponent c = (JComponent) e.getSource();
|
|
| 85 |
- ContentUI<?> ui = (ContentUI<?>)
|
|
| 86 |
- c.getClientProperty("ui");
|
|
| 87 |
- if (ui == null) {
|
|
| 88 |
- throw new IllegalStateException(
|
|
| 89 |
- "could not find client property " +
|
|
| 90 |
- "ui on component" + c);
|
|
| 91 |
- }
|
|
| 92 |
- |
|
| 93 |
- if (!(ui instanceof ActivitySeinesUI)) {
|
|
| 94 |
- throw new IllegalStateException("Can not come here!");
|
|
| 95 |
- }
|
|
| 96 |
- |
|
| 97 |
- // get current route id
|
|
| 98 |
- ObserveTreeHelper treeHelper = getMainUI().getTreeHelper();
|
|
| 99 |
- ObserveNode oldActivitiesNode = treeHelper.getSelectedNode();
|
|
| 100 |
- ObserveNode oldRouteNode = oldActivitiesNode.getParent();
|
|
| 101 |
- |
|
| 102 |
- // choose the new route
|
|
| 103 |
- String routeId = chooseNewRoute(ui, oldRouteNode);
|
|
| 104 |
- |
|
| 105 |
- if (routeId != null) {
|
|
| 106 |
- // change the route of the selected activities
|
|
| 107 |
- List<DataReference<ActivitySeineDto>> selectedDatas = ((ActivitySeinesUIModel) ui.getModel()).getSelectedDatas();
|
|
| 108 |
- List<String> activityIds = selectedDatas.stream()
|
|
| 109 |
- .map(DataReference.ID_FUNCTION)
|
|
| 110 |
- .collect(Collectors.toList()) ;
|
|
| 111 |
- ActivitySeineService service = ObserveSwingApplicationContext.get().getMainDataSourceServicesProvider().newActivitySeineService();
|
|
| 112 |
- List<Integer> positions = service.moveActivitySeinesToRoute(activityIds, routeId);
|
|
| 113 |
- |
|
| 114 |
- // update the tree
|
|
| 115 |
- updateTree(oldActivitiesNode, routeId, activityIds);
|
|
| 116 |
- }
|
|
| 117 |
- |
|
| 118 |
- });
|
|
| 119 |
- |
|
| 62 |
+ Optional<String> getNewParentId(ObserveMainUI mainUI, ObserveNode oldParentNode) {
|
|
| 63 |
+ return MoveActivitySeineUIAction.chooseNewRoute(getMainUI(), oldParentNode);
|
|
| 120 | 64 |
}
|
| 121 | 65 |
|
| 122 |
- protected String chooseNewRoute(ContentUI<?> ui, ObserveNode oldRouteNode) {
|
|
| 123 |
- ObserveNode routesNode = oldRouteNode.getParent();
|
|
| 124 |
- String oldRouteId = oldRouteNode.getId();
|
|
| 125 |
- int routeNb = routesNode.getChildCount();
|
|
| 126 |
- |
|
| 127 |
- ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get();
|
|
| 128 |
- DataReferenceDecorator<RouteDto> decorator = applicationContext.getDecoratorService().getDataReferenceDecorator(RouteDto.class);
|
|
| 129 |
- |
|
| 130 |
- //on crée un tableau avec une route en moins car on ne propose pas la route actuel
|
|
| 131 |
- DecoratedNodeEntity[] decoratedRoutes = new DecoratedNodeEntity[routeNb - 1];
|
|
| 132 |
- |
|
| 133 |
- int j = 0;
|
|
| 134 |
- for (int i = 0; i < routeNb; i++) {
|
|
| 135 |
- |
|
| 136 |
- RouteSeineNode routeNode = (RouteSeineNode) routesNode.getChildAt(i);
|
|
| 137 |
- |
|
| 138 |
- String routeId = routeNode.getId();
|
|
| 139 |
- |
|
| 140 |
- if (!oldRouteId.equals(routeId)) {
|
|
| 141 |
- decoratedRoutes[j++] = DecoratedNodeEntity.newDecoratedNodeEntity(routeNode, decorator);
|
|
| 142 |
- }
|
|
| 143 |
- }
|
|
| 144 |
- |
|
| 145 |
- Object decoratedRoute = JOptionPane.showInputDialog(ui,
|
|
| 146 |
- t("observe.action.choose.route.message"),
|
|
| 147 |
- t("observe.action.choose.route.title"),
|
|
| 148 |
- JOptionPane.QUESTION_MESSAGE,
|
|
| 149 |
- null,
|
|
| 150 |
- decoratedRoutes,
|
|
| 151 |
- null);
|
|
| 152 |
- |
|
| 153 |
- return decoratedRoute != null ? ((DecoratedNodeEntity) decoratedRoute).getId() : null;
|
|
| 66 |
+ @Override
|
|
| 67 |
+ List<Integer> moveData(List<String> dataIds, String newParentId, ObserveServicesProvider servicesProvider) {
|
|
| 68 |
+ return servicesProvider.newActivitySeineService().moveActivitySeinesToRoute(dataIds, newParentId);
|
|
| 154 | 69 |
}
|
| 155 | 70 |
|
| 156 |
- protected void updateTree(ObserveNode oldActivitiesNode,
|
|
| 157 |
- String routeId,
|
|
| 158 |
- List<String> activityIds) {
|
|
| 71 |
+ @Override
|
|
| 72 |
+ void updateUI(ActivitySeinesUI ui, ObserveNode oldParentNode, String newParentId, List<String> dataIds, List<Integer> positions) {
|
|
| 159 | 73 |
|
| 160 | 74 |
ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get();
|
| 161 | 75 |
ObserveOpenDataManager openDataManager = applicationContext.getOpenDataManager();
|
| 162 | 76 |
ObserveTreeHelper treeHelper = getMainUI().getTreeHelper();
|
| 163 | 77 |
|
| 164 |
- ObserveNode oldRouteNode = oldActivitiesNode.getParent();
|
|
| 78 |
+ ObserveNode oldRouteNode = oldParentNode.getParent();
|
|
| 165 | 79 |
ObserveNode routesNode = oldRouteNode.getParent();
|
| 166 |
- ObserveNode tripNode = routesNode.getParent();
|
|
| 167 |
- ObserveNode newRouteNode = treeHelper.getChild(routesNode, routeId);
|
|
| 80 |
+ ObserveNode newRouteNode = treeHelper.getChild(routesNode, newParentId);
|
|
| 168 | 81 |
String activitiesNodeId = ObserveI18nDecoratorHelper.getTypePluralI18nKey(ActivitySeineDto.class);
|
| 169 | 82 |
ObserveNode newActivitiesNode = treeHelper.getChild(newRouteNode, activitiesNodeId);
|
| 170 | 83 |
|
| 171 | 84 |
// Let's check if we're moving an open activity
|
| 172 |
- Optional<String> openActivity = activityIds
|
|
| 85 |
+ Optional<String> openActivity = dataIds
|
|
| 173 | 86 |
.stream()
|
| 174 | 87 |
.filter(openDataManager::isOpenActivitySeine)
|
| 175 | 88 |
.findFirst();
|
| 176 | 89 |
|
| 177 | 90 |
// If so, we close it to avoid ending up with an open activity into a closed route.
|
| 178 |
- if (openActivity.isPresent()) {
|
|
| 179 |
- openDataManager.closeActivitySeine(openActivity.get());
|
|
| 180 |
- }
|
|
| 91 |
+ openActivity.ifPresent(openDataManager::closeActivitySeine);
|
|
| 181 | 92 |
|
| 182 | 93 |
// Let's reload the sub tree of each activities node.
|
| 183 | 94 |
// As the change have already be done in database, we just call the child loaders to regenerate the activities nodes sub trees
|
| 184 |
- treeHelper.reloadNodeSubTree(oldActivitiesNode, true);
|
|
| 95 |
+ treeHelper.reloadNodeSubTree(oldParentNode, true);
|
|
| 185 | 96 |
treeHelper.reloadNodeSubTree(newActivitiesNode, true);
|
| 186 | 97 |
|
| 187 | 98 |
// Let's put the focus on the activities node which received the activities
|
| 1 |
+package fr.ird.observe.application.swing.ui.actions.shared;
|
|
| 2 |
+ |
|
| 3 |
+import fr.ird.observe.application.swing.ObserveSwingApplicationContext;
|
|
| 4 |
+import fr.ird.observe.application.swing.ui.ObserveMainUI;
|
|
| 5 |
+import fr.ird.observe.application.swing.ui.content.ContentUI;
|
|
| 6 |
+import fr.ird.observe.application.swing.ui.content.list.ContentListUI;
|
|
| 7 |
+import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper;
|
|
| 8 |
+import fr.ird.observe.application.swing.ui.tree.node.ObserveNode;
|
|
| 9 |
+import fr.ird.observe.services.ObserveServicesProvider;
|
|
| 10 |
+import fr.ird.observe.services.dto.DataReference;
|
|
| 11 |
+import java.awt.event.ActionEvent;
|
|
| 12 |
+import java.util.List;
|
|
| 13 |
+import java.util.Optional;
|
|
| 14 |
+import java.util.stream.Collectors;
|
|
| 15 |
+import javax.swing.JComponent;
|
|
| 16 |
+ |
|
| 17 |
+/**
|
|
| 18 |
+ * Created by tchemit on 12/06/17.
|
|
| 19 |
+ *
|
|
| 20 |
+ * @author Tony Chemit - dev@tchemit.fr
|
|
| 21 |
+ */
|
|
| 22 |
+public abstract class MoveMultipleDataUIActionSupport<U extends ContentListUI<?, ?>> extends AbstractUIAction {
|
|
| 23 |
+ |
|
| 24 |
+ private final Class<U> uiType;
|
|
| 25 |
+ |
|
| 26 |
+ MoveMultipleDataUIActionSupport(ObserveMainUI mainUI, String actionId, String label, String shortDescription, String actionIcon, Class<U> uiType) {
|
|
| 27 |
+ super(mainUI, actionId, label, shortDescription, actionIcon);
|
|
| 28 |
+ this.uiType = uiType;
|
|
| 29 |
+ }
|
|
| 30 |
+ |
|
| 31 |
+ @Override
|
|
| 32 |
+ public final void actionPerformed(ActionEvent e) {
|
|
| 33 |
+ |
|
| 34 |
+ JComponent c = (JComponent) e.getSource();
|
|
| 35 |
+ ContentUI<?> ui1 = (ContentUI<?>) c.getClientProperty("ui");
|
|
| 36 |
+ if (ui1 == null) {
|
|
| 37 |
+ throw new IllegalStateException("could not find client property ui on component" + c);
|
|
| 38 |
+ }
|
|
| 39 |
+ if (!uiType.isAssignableFrom(ui1.getClass())) {
|
|
| 40 |
+ throw new IllegalStateException("Can not come here!");
|
|
| 41 |
+ }
|
|
| 42 |
+ |
|
| 43 |
+ @SuppressWarnings("unchecked") U ui = (U) ui1;
|
|
| 44 |
+ |
|
| 45 |
+ ObserveTreeHelper treeHelper = getMainUI().getTreeHelper();
|
|
| 46 |
+ ObserveNode node = treeHelper.getSelectedNode();
|
|
| 47 |
+ |
|
| 48 |
+ ObserveNode oldParentNode = node.getParent().isRoot() ? node : node.getParent();
|
|
| 49 |
+ |
|
| 50 |
+ Optional<String> optionalNewParentId = getNewParentId(getMainUI(), oldParentNode);
|
|
| 51 |
+ |
|
| 52 |
+ if (optionalNewParentId.isPresent()) {
|
|
| 53 |
+ |
|
| 54 |
+ List<String> dataIds = ui.getModel().getSelectedDatas().stream().map(DataReference.ID_FUNCTION).collect(Collectors.toList());
|
|
| 55 |
+ |
|
| 56 |
+ List<Integer> positions = moveData(dataIds, optionalNewParentId.get(), ObserveSwingApplicationContext.get().getMainDataSourceServicesProvider());
|
|
| 57 |
+ |
|
| 58 |
+ updateUI(ui, node, optionalNewParentId.get(), dataIds, positions);
|
|
| 59 |
+ }
|
|
| 60 |
+ |
|
| 61 |
+ }
|
|
| 62 |
+ |
|
| 63 |
+ abstract Optional<String> getNewParentId(ObserveMainUI mainUI, ObserveNode oldParentNode);
|
|
| 64 |
+ |
|
| 65 |
+ abstract List<Integer> moveData(List<String> dataIds, String newParentId, ObserveServicesProvider servicesProvider);
|
|
| 66 |
+ |
|
| 67 |
+ abstract void updateUI(U ui, ObserveNode oldParentNode, String newParentId, List<String> dataIds, List<Integer> positions);
|
|
| 68 |
+ |
|
| 69 |
+}
|
| 1 |
+/*
|
|
| 2 |
+ * #%L
|
|
| 3 |
+ * ObServe :: Application Swing
|
|
| 4 |
+ * %%
|
|
| 5 |
+ * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io
|
|
| 6 |
+ * %%
|
|
| 7 |
+ * This program is free software: you can redistribute it and/or modify
|
|
| 8 |
+ * it under the terms of the GNU General Public License as
|
|
| 9 |
+ * published by the Free Software Foundation, either version 3 of the
|
|
| 10 |
+ * License, or (at your option) any later version.
|
|
| 11 |
+ *
|
|
| 12 |
+ * This program is distributed in the hope that it will be useful,
|
|
| 13 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 14 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 15 |
+ * GNU General Public License for more details.
|
|
| 16 |
+ *
|
|
| 17 |
+ * You should have received a copy of the GNU General Public
|
|
| 18 |
+ * License along with this program. If not, see
|
|
| 19 |
+ * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 20 |
+ * #L%
|
|
| 21 |
+ */
|
|
| 22 |
+package fr.ird.observe.application.swing.ui.actions.shared;
|
|
| 23 |
+ |
|
| 24 |
+import fr.ird.observe.application.swing.ObserveOpenDataManager;
|
|
| 25 |
+import fr.ird.observe.application.swing.ObserveSwingApplicationContext;
|
|
| 26 |
+import fr.ird.observe.application.swing.decoration.ObserveI18nDecoratorHelper;
|
|
| 27 |
+import fr.ird.observe.application.swing.decoration.decorators.DataReferenceDecorator;
|
|
| 28 |
+import fr.ird.observe.application.swing.ui.ObserveMainUI;
|
|
| 29 |
+import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper;
|
|
| 30 |
+import fr.ird.observe.application.swing.ui.tree.node.ObserveNode;
|
|
| 31 |
+import fr.ird.observe.application.swing.ui.tree.node.TripSeineNode;
|
|
| 32 |
+import fr.ird.observe.application.swing.ui.util.DecoratedNodeEntity;
|
|
| 33 |
+import fr.ird.observe.services.ObserveServicesProvider;
|
|
| 34 |
+import fr.ird.observe.services.dto.seine.RouteDto;
|
|
| 35 |
+import fr.ird.observe.services.dto.seine.TripSeineDto;
|
|
| 36 |
+import java.util.Optional;
|
|
| 37 |
+import javax.swing.JOptionPane;
|
|
| 38 |
+ |
|
| 39 |
+ |
|
| 40 |
+import static org.nuiton.i18n.I18n.n;
|
|
| 41 |
+import static org.nuiton.i18n.I18n.t;
|
|
| 42 |
+ |
|
| 43 |
+/**
|
|
| 44 |
+ * Action pour changer le programme d'une ou plusieurs marée dans la liste.
|
|
| 45 |
+ *
|
|
| 46 |
+ * @author Tony Chemit - dev@ultreia.io
|
|
| 47 |
+ * @since 5.0
|
|
| 48 |
+ */
|
|
| 49 |
+public class MoveRouteUIAction extends MoveSingleDataUIActionSupport {
|
|
| 50 |
+ |
|
| 51 |
+ private static final long serialVersionUID = 1L;
|
|
| 52 |
+ |
|
| 53 |
+ public static final String ACTION_NAME = "moveRoute";
|
|
| 54 |
+ |
|
| 55 |
+ public MoveRouteUIAction(ObserveMainUI mainUI) {
|
|
| 56 |
+ super(mainUI,
|
|
| 57 |
+ ACTION_NAME,
|
|
| 58 |
+ n("observe.navigationMenu.move.route"),
|
|
| 59 |
+ n("observe.navigationMenu.move.route"),
|
|
| 60 |
+ "move-routes"
|
|
| 61 |
+ );
|
|
| 62 |
+ }
|
|
| 63 |
+ |
|
| 64 |
+ @Override
|
|
| 65 |
+ Optional<String> getNewParentId(ObserveMainUI mainUI, ObserveNode oldParentNode) {
|
|
| 66 |
+ return chooseNewTripSeine(mainUI, oldParentNode);
|
|
| 67 |
+ }
|
|
| 68 |
+ |
|
| 69 |
+ @Override
|
|
| 70 |
+ int moveData(ObserveServicesProvider servicesProvider, ObserveOpenDataManager openDataManager, String oldParentId, String newParentId, String dataId) {
|
|
| 71 |
+ return servicesProvider.newRouteService().moveRouteToTripSeine(dataId, newParentId);
|
|
| 72 |
+ }
|
|
| 73 |
+ |
|
| 74 |
+ @Override
|
|
| 75 |
+ void closeNode(ObserveOpenDataManager openDataManager, String dataId) {
|
|
| 76 |
+ if (openDataManager.isOpenRoute(dataId)) {
|
|
| 77 |
+ openDataManager.closeRoute(dataId);
|
|
| 78 |
+ }
|
|
| 79 |
+ }
|
|
| 80 |
+ |
|
| 81 |
+ @Override
|
|
| 82 |
+ ObserveNode getNewParentNode(ObserveTreeHelper treeHelper, ObserveNode grandParentNode, String newParentId) {
|
|
| 83 |
+ ObserveNode tripNode = treeHelper.getChild(grandParentNode, newParentId);
|
|
| 84 |
+ String routesNodeId = ObserveI18nDecoratorHelper.getTypePluralI18nKey(RouteDto.class);
|
|
| 85 |
+ return treeHelper.getChild(tripNode, routesNodeId);
|
|
| 86 |
+ }
|
|
| 87 |
+ |
|
| 88 |
+ static Optional<String> chooseNewTripSeine(ObserveMainUI mainUI, ObserveNode oldTripSeineNode) {
|
|
| 89 |
+ ObserveNode programNode = oldTripSeineNode.getParent();
|
|
| 90 |
+ String oldTripSeineId = oldTripSeineNode.getId();
|
|
| 91 |
+ int tripSeineNb = programNode.getChildCount();
|
|
| 92 |
+ |
|
| 93 |
+ ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get();
|
|
| 94 |
+ DataReferenceDecorator<TripSeineDto> decorator = applicationContext.getDecoratorService().getDataReferenceDecorator(TripSeineDto.class);
|
|
| 95 |
+ |
|
| 96 |
+ //on crée un tableau avec une marée en moins car on ne propose pas la marée actuel
|
|
| 97 |
+ DecoratedNodeEntity[] decoratedTripSeines = new DecoratedNodeEntity[tripSeineNb - 1];
|
|
| 98 |
+ |
|
| 99 |
+ int j = 0;
|
|
| 100 |
+ for (int i = 0; i < tripSeineNb; i++) {
|
|
| 101 |
+ |
|
| 102 |
+ TripSeineNode tripSeineNode = (TripSeineNode) programNode.getChildAt(i);
|
|
| 103 |
+ |
|
| 104 |
+ String tripSeineId = tripSeineNode.getId();
|
|
| 105 |
+ |
|
| 106 |
+ if (!oldTripSeineId.equals(tripSeineId)) {
|
|
| 107 |
+ decoratedTripSeines[j++] = DecoratedNodeEntity.newDecoratedNodeEntity(tripSeineNode, decorator);
|
|
| 108 |
+ }
|
|
| 109 |
+ }
|
|
| 110 |
+ |
|
| 111 |
+ Object decoratedTripSeine = JOptionPane.showInputDialog(mainUI,
|
|
| 112 |
+ t("observe.action.choose.tripSeine.message"),
|
|
| 113 |
+ t("observe.action.choose.tripSeine.title"),
|
|
| 114 |
+ JOptionPane.QUESTION_MESSAGE,
|
|
| 115 |
+ null,
|
|
| 116 |
+ decoratedTripSeines,
|
|
| 117 |
+ null);
|
|
| 118 |
+ return Optional.ofNullable(decoratedTripSeine != null ? ((DecoratedNodeEntity) decoratedTripSeine).getId() : null);
|
|
| 119 |
+ }
|
|
| 120 |
+ |
|
| 121 |
+}
|
| ... | ... | @@ -24,31 +24,17 @@ package fr.ird.observe.application.swing.ui.actions.shared; |
| 24 | 24 |
import fr.ird.observe.application.swing.ObserveOpenDataManager;
|
| 25 | 25 |
import fr.ird.observe.application.swing.ObserveSwingApplicationContext;
|
| 26 | 26 |
import fr.ird.observe.application.swing.decoration.ObserveI18nDecoratorHelper;
|
| 27 |
-import fr.ird.observe.application.swing.decoration.decorators.DataReferenceDecorator;
|
|
| 28 | 27 |
import fr.ird.observe.application.swing.ui.ObserveMainUI;
|
| 29 |
-import fr.ird.observe.application.swing.ui.content.ContentUI;
|
|
| 30 | 28 |
import fr.ird.observe.application.swing.ui.content.list.impl.seine.RoutesUI;
|
| 31 |
-import fr.ird.observe.application.swing.ui.tree.node.ObserveNode;
|
|
| 32 | 29 |
import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper;
|
| 33 |
-import fr.ird.observe.application.swing.ui.tree.node.TripSeineNode;
|
|
| 34 |
-import fr.ird.observe.application.swing.ui.util.DecoratedNodeEntity;
|
|
| 35 |
-import fr.ird.observe.services.dto.DataReference;
|
|
| 30 |
+import fr.ird.observe.application.swing.ui.tree.node.ObserveNode;
|
|
| 31 |
+import fr.ird.observe.services.ObserveServicesProvider;
|
|
| 36 | 32 |
import fr.ird.observe.services.dto.seine.RouteDto;
|
| 37 |
-import fr.ird.observe.services.dto.seine.TripSeineDto;
|
|
| 38 |
-import fr.ird.observe.services.service.seine.RouteService;
|
|
| 39 |
-import org.apache.commons.logging.Log;
|
|
| 40 |
-import org.apache.commons.logging.LogFactory;
|
|
| 41 |
- |
|
| 42 |
-import javax.swing.JComponent;
|
|
| 43 |
-import javax.swing.JOptionPane;
|
|
| 44 |
-import javax.swing.SwingUtilities;
|
|
| 45 |
-import java.awt.event.ActionEvent;
|
|
| 46 | 33 |
import java.util.List;
|
| 47 | 34 |
import java.util.Optional;
|
| 48 |
-import java.util.stream.Collectors;
|
|
| 35 |
+ |
|
| 49 | 36 |
|
| 50 | 37 |
import static org.nuiton.i18n.I18n.n;
|
| 51 |
-import static org.nuiton.i18n.I18n.t;
|
|
| 52 | 38 |
|
| 53 | 39 |
/**
|
| 54 | 40 |
* 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; |
| 56 | 42 |
* @author Kevin Morin (Code Lutin)
|
| 57 | 43 |
* @since 5.0
|
| 58 | 44 |
*/
|
| 59 |
-public class MoveRoutesUIAction extends AbstractUIAction {
|
|
| 45 |
+public class MoveRoutesUIAction extends MoveMultipleDataUIActionSupport<RoutesUI> {
|
|
| 60 | 46 |
|
| 61 | 47 |
private static final long serialVersionUID = 1L;
|
| 62 | 48 |
|
| 63 |
- /**
|
|
| 64 |
- * Logger.
|
|
| 65 |
- */
|
|
| 66 |
- private static final Log log = LogFactory.getLog(MoveRoutesUIAction.class);
|
|
| 67 |
- |
|
| 68 | 49 |
public static final String ACTION_NAME = "moveRoutes";
|
| 69 | 50 |
|
| 70 | 51 |
public MoveRoutesUIAction(ObserveMainUI mainUI) {
|
| ... | ... | @@ -72,88 +53,23 @@ public class MoveRoutesUIAction extends AbstractUIAction { |
| 72 | 53 |
ACTION_NAME,
|
| 73 | 54 |
n("observe.content.action.move.routes"),
|
| 74 | 55 |
n("observe.content.action.move.routes.tip"),
|
| 75 |
- "move-routes"
|
|
| 56 |
+ "move-routes",
|
|
| 57 |
+ RoutesUI.class
|
|
| 76 | 58 |
);
|
| 77 | 59 |
}
|
| 78 | 60 |
|
| 79 | 61 |
@Override
|
| 80 |
- public void actionPerformed(final ActionEvent e) {
|
|
| 81 |
- |
|
| 82 |
- SwingUtilities.invokeLater(() -> {
|
|
| 83 |
- JComponent c = (JComponent) e.getSource();
|
|
| 84 |
- ContentUI<?> ui = (ContentUI<?>)
|
|
| 85 |
- c.getClientProperty("ui");
|
|
| 86 |
- if (ui == null) {
|
|
| 87 |
- throw new IllegalStateException(
|
|
| 88 |
- "could not find client property " +
|
|
| 89 |
- "ui on component" + c);
|
|
| 90 |
- }
|
|
| 91 |
- |
|
| 92 |
- if (!(ui instanceof RoutesUI)) {
|
|
| 93 |
- throw new IllegalStateException("Can not come here!");
|
|
| 94 |
- }
|
|
| 95 |
- |
|
| 96 |
- RoutesUI theUi = (RoutesUI) ui;
|
|
| 97 |
- |
|
| 98 |
- // get current tripseine id
|
|
| 99 |
- ObserveTreeHelper treeHelper = getMainUI().getTreeHelper();
|
|
| 100 |
- ObserveNode oldRoutesNode = treeHelper.getSelectedNode();
|
|
| 101 |
- ObserveNode oldTripSeineNode = oldRoutesNode.getParent();
|
|
| 102 |
- |
|
| 103 |
- // choose the new tripseine
|
|
| 104 |
- String tripSeineId = chooseNewTripSeine(theUi, oldTripSeineNode);
|
|
| 105 |
- |
|
| 106 |
- if (tripSeineId != null) {
|
|
| 107 |
- // change the tripseine of the selected routes
|
|
| 108 |
- List<DataReference<RouteDto>> selectedDatas = theUi.getModel().getSelectedDatas();
|
|
| 109 |
- List<String> routeIds = selectedDatas.stream().map(DataReference.ID_FUNCTION).collect(Collectors.toList());
|
|
| 110 |
- RouteService service = ObserveSwingApplicationContext.get().getMainDataSourceServicesProvider().newRouteService();
|
|
| 111 |
- List<Integer> positions = service.moveRoutesToTripSeine(routeIds, tripSeineId);
|
|
| 112 |
- |
|
| 113 |
- // update the tree
|
|
| 114 |
- updateTree(oldRoutesNode, tripSeineId, routeIds);
|
|
| 115 |
- }
|
|
| 116 |
- |
|
| 117 |
- });
|
|
| 118 |
- |
|
| 62 |
+ Optional<String> getNewParentId(ObserveMainUI mainUI, ObserveNode oldParentNode) {
|
|
| 63 |
+ return MoveRouteUIAction.chooseNewTripSeine(getMainUI(), oldParentNode);
|
|
| 119 | 64 |
}
|
| 120 | 65 |
|
| 121 |
- protected String chooseNewTripSeine(ContentUI<?> ui, ObserveNode oldTripSeineNode) {
|
|
| 122 |
- ObserveNode programNode = oldTripSeineNode.getParent();
|
|
| 123 |
- String oldTripSeineId = oldTripSeineNode.getId();
|
|
| 124 |
- int tripSeineNb = programNode.getChildCount();
|
|
| 125 |
- |
|
| 126 |
- ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get();
|
|
| 127 |
- DataReferenceDecorator<TripSeineDto> decorator = applicationContext.getDecoratorService().getDataReferenceDecorator(TripSeineDto.class);
|
|
| 128 |
- |
|
| 129 |
- //on crée un tableau avec une marée en moins car on ne propose pas la marée actuel
|
|
| 130 |
- DecoratedNodeEntity[] decoratedTripSeines = new DecoratedNodeEntity[tripSeineNb - 1];
|
|
| 131 |
- |
|
| 132 |
- int j = 0;
|
|
| 133 |
- for (int i = 0; i < tripSeineNb; i++) {
|
|
| 134 |
- |
|
| 135 |
- TripSeineNode tripSeineNode = (TripSeineNode) programNode.getChildAt(i);
|
|
| 136 |
- |
|
| 137 |
- String tripSeineId = tripSeineNode.getId();
|
|
| 138 |
- |
|
| 139 |
- if (!oldTripSeineId.equals(tripSeineId)) {
|
|
| 140 |
- decoratedTripSeines[j++] = DecoratedNodeEntity.newDecoratedNodeEntity(tripSeineNode, decorator);
|
|
| 141 |
- }
|
|
| 142 |
- }
|
|
| 143 |
- |
|
| 144 |
- Object decoratedTripSeine = JOptionPane.showInputDialog(ui,
|
|
| 145 |
- t("observe.action.choose.tripSeine.message"),
|
|
| 146 |
- t("observe.action.choose.tripSeine.title"),
|
|
| 147 |
- JOptionPane.QUESTION_MESSAGE,
|
|
| 148 |
- null,
|
|
| 149 |
- decoratedTripSeines,
|
|
| 150 |
- null);
|
|
| 151 |
- return decoratedTripSeine != null ? ((DecoratedNodeEntity) decoratedTripSeine).getId() : null;
|
|
| 66 |
+ @Override
|
|
| 67 |
+ List<Integer> moveData(List<String> dataIds, String newParentId, ObserveServicesProvider servicesProvider) {
|
|
| 68 |
+ return ObserveSwingApplicationContext.get().getMainDataSourceServicesProvider().newRouteService().moveRoutesToTripSeine(dataIds, newParentId);
|
|
| 152 | 69 |
}
|
| 153 | 70 |
|
| 154 |
- protected void updateTree(ObserveNode oldRoutesNode,
|
|
| 155 |
- String tripSeineId,
|
|
| 156 |
- List<String> routeIds) {
|
|
| 71 |
+ @Override
|
|
| 72 |
+ void updateUI(RoutesUI ui, ObserveNode oldRoutesNode, String tripSeineId, List<String> routeIds, List<Integer> positions) {
|
|
| 157 | 73 |
|
| 158 | 74 |
ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get();
|
| 159 | 75 |
ObserveOpenDataManager openDataManager = applicationContext.getOpenDataManager();
|
| ... | ... | @@ -172,9 +88,7 @@ public class MoveRoutesUIAction extends AbstractUIAction { |
| 172 | 88 |
.findFirst();
|
| 173 | 89 |
|
| 174 | 90 |
// If so, we close it to avoid ending up with an open route into a closed trip.
|
| 175 |
- if (openRoute.isPresent()) {
|
|
| 176 |
- openDataManager.closeRoute(openRoute.get());
|
|
| 177 |
- }
|
|
| 91 |
+ openRoute.ifPresent(openDataManager::closeRoute);
|
|
| 178 | 92 |
|
| 179 | 93 |
// Let's reload the sub tree of each routes node.
|
| 180 | 94 |
// As the change have already be done in database, we just call the child loaders to regenerate the routes nodes sub trees
|
| 1 |
+package fr.ird.observe.application.swing.ui.actions.shared;
|
|
| 2 |
+ |
|
| 3 |
+import fr.ird.observe.application.swing.ObserveOpenDataManager;
|
|
| 4 |
+import fr.ird.observe.application.swing.ObserveSwingApplicationContext;
|
|
| 5 |
+import fr.ird.observe.application.swing.ui.ObserveMainUI;
|
|
| 6 |
+import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper;
|
|
| 7 |
+import fr.ird.observe.application.swing.ui.tree.node.ObserveNode;
|
|
| 8 |
+import fr.ird.observe.services.ObserveServicesProvider;
|
|
| 9 |
+import java.awt.event.ActionEvent;
|
|
| 10 |
+import java.util.Optional;
|
|
| 11 |
+ |
|
| 12 |
+/**
|
|
| 13 |
+ * Created by tchemit on 12/06/17.
|
|
| 14 |
+ *
|
|
| 15 |
+ * @author Tony Chemit - dev@tchemit.fr
|
|
| 16 |
+ */
|
|
| 17 |
+public abstract class MoveSingleDataUIActionSupport extends AbstractUIAction {
|
|
| 18 |
+ |
|
| 19 |
+ MoveSingleDataUIActionSupport(ObserveMainUI mainUI, String actionId, String label, String shortDescription, String actionIcon) {
|
|
| 20 |
+ super(mainUI, actionId, label, shortDescription, actionIcon);
|
|
| 21 |
+ }
|
|
| 22 |
+ |
|
| 23 |
+ @Override
|
|
| 24 |
+ public final void actionPerformed(ActionEvent e) {
|
|
| 25 |
+ |
|
| 26 |
+ ObserveTreeHelper treeHelper = getMainUI().getTreeHelper();
|
|
| 27 |
+ ObserveNode node = treeHelper.getSelectedNode();
|
|
| 28 |
+ ObserveNode oldParentNode = node.getParent().getParent().equals(node.getRoot()) ? node.getParent() : node.getParent().getParent();
|
|
| 29 |
+ Optional<String> optionalNewParentId = getNewParentId(getMainUI(), oldParentNode);
|
|
| 30 |
+ |
|
| 31 |
+ optionalNewParentId.ifPresent(newParentId -> apply(oldParentNode, node.getId(), newParentId));
|
|
| 32 |
+ }
|
|
| 33 |
+ |
|
| 34 |
+ abstract Optional<String> getNewParentId(ObserveMainUI mainUI, ObserveNode oldParentNode);
|
|
| 35 |
+ |
|
| 36 |
+ private void apply(ObserveNode oldParentNode, String dataId, String newParentId) {
|
|
| 37 |
+ |
|
| 38 |
+ ObserveTreeHelper treeHelper = getMainUI().getTreeHelper();
|
|
| 39 |
+ |
|
| 40 |
+ ObserveNode node = treeHelper.getSelectedNode();
|
|
| 41 |
+ ObserveNode grandParentNode = oldParentNode.getParent();
|
|
| 42 |
+ ObserveNode newParentNode = getNewParentNode(getMainUI().getTreeHelper(), grandParentNode, newParentId);
|
|
| 43 |
+ |
|
| 44 |
+ closeNode(ObserveSwingApplicationContext.get().getOpenDataManager(), node.getId());
|
|
| 45 |
+ |
|
| 46 |
+ int position = moveData(ObserveSwingApplicationContext.get().getMainDataSourceServicesProvider(), ObserveSwingApplicationContext.get().getOpenDataManager(), oldParentNode.getId(), newParentId, dataId);
|
|
| 47 |
+ |
|
| 48 |
+ treeHelper.selectNode(newParentNode);
|
|
| 49 |
+ |
|
| 50 |
+ treeHelper.removeNode(node);
|
|
| 51 |
+ |
|
| 52 |
+ ObserveNode newNode = treeHelper.getChild(newParentNode, dataId);
|
|
| 53 |
+ |
|
| 54 |
+ if (newNode == null) {
|
|
| 55 |
+ |
|
| 56 |
+ treeHelper.insertNode(newParentNode, node, position);
|
|
| 57 |
+ newNode = node;
|
|
| 58 |
+ }
|
|
| 59 |
+ |
|
| 60 |
+ treeHelper.refreshNode(oldParentNode, false);
|
|
| 61 |
+ treeHelper.refreshNode(newParentNode, false);
|
|
| 62 |
+ treeHelper.selectNode(newNode);
|
|
| 63 |
+ |
|
| 64 |
+ }
|
|
| 65 |
+ |
|
| 66 |
+ abstract int moveData(ObserveServicesProvider servicesProvider, ObserveOpenDataManager openDataManager, String oldParentId, String newParentId, String dataId);
|
|
| 67 |
+ |
|
| 68 |
+ abstract void closeNode(ObserveOpenDataManager openDataManager, String dataId);
|
|
| 69 |
+ |
|
| 70 |
+ abstract ObserveNode getNewParentNode(ObserveTreeHelper treeHelper, ObserveNode grandParentNode, String newParentId);
|
|
| 71 |
+}
|
| 1 |
+package fr.ird.observe.application.swing.ui.actions.shared;
|
|
| 2 |
+ |
|
| 3 |
+/*-
|
|
| 4 |
+ * #%L
|
|
| 5 |
+ * ObServe :: Application Swing
|
|
| 6 |
+ * %%
|
|
| 7 |
+ * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io
|
|
| 8 |
+ * %%
|
|
| 9 |
+ * This program is free software: you can redistribute it and/or modify
|
|
| 10 |
+ * it under the terms of the GNU General Public License as
|
|
| 11 |
+ * published by the Free Software Foundation, either version 3 of the
|
|
| 12 |
+ * License, or (at your option) any later version.
|
|
| 13 |
+ *
|
|
| 14 |
+ * This program is distributed in the hope that it will be useful,
|
|
| 15 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 |
+ * GNU General Public License for more details.
|
|
| 18 |
+ *
|
|
| 19 |
+ * You should have received a copy of the GNU General Public
|
|
| 20 |
+ * License along with this program. If not, see
|
|
| 21 |
+ * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 |
+ * #L%
|
|
| 23 |
+ */
|
|
| 24 |
+ |
|
| 25 |
+import fr.ird.observe.application.swing.ObserveOpenDataManager;
|
|
| 26 |
+import fr.ird.observe.application.swing.ui.ObserveMainUI;
|
|
| 27 |
+import fr.ird.observe.services.ObserveServicesProvider;
|
|
| 28 |
+import fr.ird.observe.services.dto.constants.GearType;
|
|
| 29 |
+ |
|
| 30 |
+/**
|
|
| 31 |
+ * @author Tony Chemit - dev@tchemit.fr
|
|
| 32 |
+ * @since 5.0
|
|
| 33 |
+ */
|
|
| 34 |
+public class MoveTripLonglineUIAction extends MoveTripUIAction {
|
|
| 35 |
+ |
|
| 36 |
+ private static final long serialVersionUID = 1L;
|
|
| 37 |
+ |
|
| 38 |
+ public static final String ACTION_NAME = "moveTripLongline";
|
|
| 39 |
+ |
|
| 40 |
+ public MoveTripLonglineUIAction(ObserveMainUI mainUI) {
|
|
| 41 |
+ super(mainUI, ACTION_NAME, GearType.longline);
|
|
| 42 |
+ }
|
|
| 43 |
+ |
|
| 44 |
+ @Override
|
|
| 45 |
+ int moveData(ObserveServicesProvider servicesProvider, ObserveOpenDataManager openDataManager, String oldParentId, String newParentId, String dataId) {
|
|
| 46 |
+ int position = servicesProvider.newTripLonglineService().moveTripLonglineToProgram(dataId, newParentId);
|
|
| 47 |
+ super.moveData(servicesProvider, openDataManager, oldParentId, newParentId, dataId);
|
|
| 48 |
+ return position;
|
|
| 49 |
+ }
|
|
| 50 |
+}
|
| ... | ... | @@ -22,18 +22,13 @@ package fr.ird.observe.application.swing.ui.actions.shared; |
| 22 | 22 |
* #L%
|
| 23 | 23 |
*/
|
| 24 | 24 |
|
| 25 |
-import fr.ird.observe.application.swing.ObserveSwingApplicationContext;
|
|
| 26 |
-import fr.ird.observe.services.dto.DataReference;
|
|
| 27 |
-import fr.ird.observe.services.dto.constants.GearType;
|
|
| 28 |
-import fr.ird.observe.services.dto.longline.TripLonglineDto;
|
|
| 29 |
-import fr.ird.observe.services.service.longline.TripLonglineService;
|
|
| 30 | 25 |
import fr.ird.observe.application.swing.ui.ObserveMainUI;
|
| 31 |
-import fr.ird.observe.application.swing.ui.content.ContentUI;
|
|
| 32 | 26 |
import fr.ird.observe.application.swing.ui.content.list.impl.longline.TripLonglinesUI;
|
| 33 | 27 |
import fr.ird.observe.application.swing.ui.content.list.impl.longline.TripLonglinesUIModel;
|
| 34 |
-import org.apache.commons.logging.Log;
|
|
| 35 |
-import org.apache.commons.logging.LogFactory;
|
|
| 36 |
- |
|
| 28 |
+import fr.ird.observe.services.ObserveServicesProvider;
|
|
| 29 |
+import fr.ird.observe.services.dto.DataReference;
|
|
| 30 |
+import fr.ird.observe.services.dto.constants.GearType;
|
|
| 31 |
+import fr.ird.observe.services.dto.longline.TripLonglineDto;
|
|
| 37 | 32 |
import java.util.ArrayList;
|
| 38 | 33 |
import java.util.List;
|
| 39 | 34 |
|
| ... | ... | @@ -41,43 +36,24 @@ import java.util.List; |
| 41 | 36 |
* @author Kevin Morin (Code Lutin)
|
| 42 | 37 |
* @since 5.0
|
| 43 | 38 |
*/
|
| 44 |
-public class MoveTripLonglinesUIAction extends MoveTripsUIAction<TripLonglineDto> {
|
|
| 39 |
+public class MoveTripLonglinesUIAction extends MoveTripsUIAction<TripLonglinesUI> {
|
|
| 45 | 40 |
|
| 46 | 41 |
private static final long serialVersionUID = 1L;
|
| 47 | 42 |
|
| 48 |
- /**
|
|
| 49 |
- * Logger.
|
|
| 50 |
- */
|
|
| 51 |
- private static final Log log = LogFactory.getLog(MoveTripLonglinesUIAction.class);
|
|
| 52 |
- |
|
| 53 | 43 |
public static final String ACTION_NAME = "moveTripLonglines";
|
| 54 | 44 |
|
| 55 | 45 |
public MoveTripLonglinesUIAction(ObserveMainUI mainUI) {
|
| 56 |
- super(mainUI, ACTION_NAME);
|
|
| 57 |
- }
|
|
| 58 |
- |
|
| 59 |
- @Override
|
|
| 60 |
- protected void checkUIClass(ContentUI<?> ui) throws IllegalStateException {
|
|
| 61 |
- if (!(ui instanceof TripLonglinesUI)) {
|
|
| 62 |
- throw new IllegalStateException("Can not come here!");
|
|
| 63 |
- }
|
|
| 64 |
- }
|
|
| 65 |
- |
|
| 66 |
- @Override
|
|
| 67 |
- protected GearType getGearType(ContentUI<?> ui) {
|
|
| 68 |
- return GearType.longline;
|
|
| 46 |
+ super(mainUI, ACTION_NAME, GearType.longline, TripLonglinesUI.class);
|
|
| 69 | 47 |
}
|
| 70 | 48 |
|
| 71 | 49 |
@Override
|
| 72 |
- protected List<Integer> getPositions(List<String> tripIds, String programId) {
|
|
| 73 |
- TripLonglineService service = ObserveSwingApplicationContext.get().getMainDataSourceServicesProvider().newTripLonglineService();
|
|
| 74 |
- return service.moveTripLonglinesToProgram(tripIds, programId);
|
|
| 50 |
+ List<Integer> moveData(List<String> dataIds, String newParentId, ObserveServicesProvider servicesProvider) {
|
|
| 51 |
+ return servicesProvider.newTripLonglineService().moveTripLonglinesToProgram(dataIds, newParentId);
|
|
| 75 | 52 |
}
|
| 76 | 53 |
|
| 77 | 54 |
@Override
|
| 78 |
- protected void updateModelData(ContentUI<?> ui) {
|
|
| 79 |
- TripLonglinesUI tripLonglinesUI = (TripLonglinesUI) ui;
|
|
| 80 |
- TripLonglinesUIModel model = tripLonglinesUI.getModel();
|
|
| 55 |
+ protected void updateModelData(TripLonglinesUI ui) {
|
|
| 56 |
+ TripLonglinesUIModel model = ui.getModel();
|
|
| 81 | 57 |
List<DataReference<TripLonglineDto>> data = new ArrayList<>(model.getData());
|
| 82 | 58 |
data.removeAll(model.getSelectedDatas());
|
| 83 | 59 |
model.setData(data);
|
| 1 |
+package fr.ird.observe.application.swing.ui.actions.shared;
|
|
| 2 |
+ |
|
| 3 |
+/*-
|
|
| 4 |
+ * #%L
|
|
| 5 |
+ * ObServe :: Application Swing
|
|
| 6 |
+ * %%
|
|
| 7 |
+ * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io
|
|
| 8 |
+ * %%
|
|
| 9 |
+ * This program is free software: you can redistribute it and/or modify
|
|
| 10 |
+ * it under the terms of the GNU General Public License as
|
|
| 11 |
+ * published by the Free Software Foundation, either version 3 of the
|
|
| 12 |
+ * License, or (at your option) any later version.
|
|
| 13 |
+ *
|
|
| 14 |
+ * This program is distributed in the hope that it will be useful,
|
|
| 15 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 |
+ * GNU General Public License for more details.
|
|
| 18 |
+ *
|
|
| 19 |
+ * You should have received a copy of the GNU General Public
|
|
| 20 |
+ * License along with this program. If not, see
|
|
| 21 |
+ * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 |
+ * #L%
|
|
| 23 |
+ */
|
|
| 24 |
+ |
|
| 25 |
+import fr.ird.observe.application.swing.ObserveOpenDataManager;
|
|
| 26 |
+import fr.ird.observe.application.swing.ui.ObserveMainUI;
|
|
| 27 |
+import fr.ird.observe.services.ObserveServicesProvider;
|
|
| 28 |
+import fr.ird.observe.services.dto.constants.GearType;
|
|
| 29 |
+ |
|
| 30 |
+/**
|
|
| 31 |
+ * @author Tony Chemit - dev@tchemit.fr
|
|
| 32 |
+ * @since 5.0
|
|
| 33 |
+ */
|
|
| 34 |
+public class MoveTripSeineUIAction extends MoveTripUIAction {
|
|
| 35 |
+ |
|
| 36 |
+ private static final long serialVersionUID = 1L;
|
|
| 37 |
+ |
|
| 38 |
+ public static final String ACTION_NAME = "moveTripSeine";
|
|
| 39 |
+ |
|
| 40 |
+ public MoveTripSeineUIAction(ObserveMainUI mainUI) {
|
|
| 41 |
+ super(mainUI, ACTION_NAME, GearType.seine);
|
|
| 42 |
+ }
|
|
| 43 |
+ |
|
| 44 |
+ @Override
|
|
| 45 |
+ int moveData(ObserveServicesProvider servicesProvider, ObserveOpenDataManager openDataManager, String oldParentId, String newParentId, String dataId) {
|
|
| 46 |
+ int position = servicesProvider.newTripSeineService().moveTripSeineToProgram(dataId, newParentId);
|
|
| 47 |
+ super.moveData(servicesProvider, openDataManager, oldParentId, newParentId, dataId);
|
|
| 48 |
+ return position;
|
|
| 49 |
+ }
|
|
| 50 |
+}
|
| ... | ... | @@ -23,17 +23,14 @@ package fr.ird.observe.application.swing.ui.actions.shared; |
| 23 | 23 |
*/
|
| 24 | 24 |
|
| 25 | 25 |
import fr.ird.observe.application.swing.ObserveSwingApplicationContext;
|
| 26 |
+import fr.ird.observe.application.swing.ui.ObserveMainUI;
|
|
| 27 |
+import fr.ird.observe.application.swing.ui.content.list.impl.seine.TripSeinesUI;
|
|
| 28 |
+import fr.ird.observe.application.swing.ui.content.list.impl.seine.TripSeinesUIModel;
|
|
| 29 |
+import fr.ird.observe.services.ObserveServicesProvider;
|
|
| 26 | 30 |
import fr.ird.observe.services.dto.DataReference;
|
| 27 | 31 |
import fr.ird.observe.services.dto.constants.GearType;
|
| 28 | 32 |
import fr.ird.observe.services.dto.seine.TripSeineDto;
|
| 29 | 33 |
import fr.ird.observe.services.service.seine.TripSeineService;
|
| 30 |
-import fr.ird.observe.application.swing.ui.ObserveMainUI;
|
|
| 31 |
-import fr.ird.observe.application.swing.ui.content.ContentUI;
|
|
| 32 |
-import fr.ird.observe.application.swing.ui.content.list.impl.seine.TripSeinesUI;
|
|
| 33 |
-import fr.ird.observe.application.swing.ui.content.list.impl.seine.TripSeinesUIModel;
|
|
| 34 |
-import org.apache.commons.logging.Log;
|
|
| 35 |
-import org.apache.commons.logging.LogFactory;
|
|
| 36 |
- |
|
| 37 | 34 |
import java.util.ArrayList;
|
| 38 | 35 |
import java.util.List;
|
| 39 | 36 |
|
| ... | ... | @@ -41,43 +38,24 @@ import java.util.List; |
| 41 | 38 |
* @author Kevin Morin (Code Lutin)
|
| 42 | 39 |
* @since 5.0
|
| 43 | 40 |
*/
|
| 44 |
-public class MoveTripSeinesUIAction extends MoveTripsUIAction<TripSeineDto> {
|
|
| 41 |
+public class MoveTripSeinesUIAction extends MoveTripsUIAction<TripSeinesUI> {
|
|
| 45 | 42 |
|
| 46 | 43 |
private static final long serialVersionUID = 1L;
|
| 47 | 44 |
|
| 48 |
- /**
|
|
| 49 |
- * Logger.
|
|
| 50 |
- */
|
|
| 51 |
- private static final Log log = LogFactory.getLog(MoveTripSeinesUIAction.class);
|
|
| 52 |
- |
|
| 53 | 45 |
public static final String ACTION_NAME = "moveTripSeines";
|
| 54 | 46 |
|
| 55 | 47 |
public MoveTripSeinesUIAction(ObserveMainUI mainUI) {
|
| 56 |
- super(mainUI, ACTION_NAME);
|
|
| 57 |
- }
|
|
| 58 |
- |
|
| 59 |
- @Override
|
|
| 60 |
- protected void checkUIClass(ContentUI<?> ui) throws IllegalStateException {
|
|
| 61 |
- if (!(ui instanceof TripSeinesUI)) {
|
|
| 62 |
- throw new IllegalStateException("Can not come here!");
|
|
| 63 |
- }
|
|
| 64 |
- }
|
|
| 65 |
- |
|
| 66 |
- @Override
|
|
| 67 |
- protected GearType getGearType(ContentUI<?> ui) {
|
|
| 68 |
- return GearType.seine;
|
|
| 48 |
+ super(mainUI, ACTION_NAME, GearType.seine, TripSeinesUI.class);
|
|
| 69 | 49 |
}
|
| 70 | 50 |
|
| 71 | 51 |
@Override
|
| 72 |
- protected List<Integer> getPositions(List<String> tripIds, String programId) {
|
|
| 73 |
- TripSeineService service = ObserveSwingApplicationContext.get().getMainDataSourceServicesProvider().newTripSeineService();
|
|
| 74 |
- return service.moveTripSeinesToProgram(tripIds, programId);
|
|
| 52 |
+ List<Integer> moveData(List<String> dataIds, String newParentId, ObserveServicesProvider servicesProvider) {
|
|
| 53 |
+ return servicesProvider.newTripSeineService().moveTripSeinesToProgram(dataIds, newParentId);
|
|
| 75 | 54 |
}
|
| 76 | 55 |
|
| 77 | 56 |
@Override
|
| 78 |
- protected void updateModelData(ContentUI<?> ui) {
|
|
| 79 |
- TripSeinesUI tripSeinesUI = (TripSeinesUI) ui;
|
|
| 80 |
- TripSeinesUIModel model = tripSeinesUI.getModel();
|
|
| 57 |
+ protected void updateModelData(TripSeinesUI ui) {
|
|
| 58 |
+ TripSeinesUIModel model = ui.getModel();
|
|
| 81 | 59 |
List<DataReference<TripSeineDto>> data = new ArrayList<>(model.getData());
|
| 82 | 60 |
data.removeAll(model.getSelectedDatas());
|
| 83 | 61 |
model.setData(data);
|
| 1 |
-package fr.ird.observe.application.swing.ui.tree.menu;
|
|
| 2 |
- |
|
| 3 |
-/*-
|
|
| 1 |
+/*
|
|
| 4 | 2 |
* #%L
|
| 5 | 3 |
* ObServe :: Application Swing
|
| 6 | 4 |
* %%
|
| ... | ... | @@ -8,7 +6,7 @@ package fr.ird.observe.application.swing.ui.tree.menu; |
| 8 | 6 |
* %%
|
| 9 | 7 |
* This program is free software: you can redistribute it and/or modify
|
| 10 | 8 |
* it under the terms of the GNU General Public License as
|
| 11 |
- * published by the Free Software Foundation, either version 3 of the
|
|
| 9 |
+ * published by the Free Software Foundation, either version 3 of the
|
|
| 12 | 10 |
* License, or (at your option) any later version.
|
| 13 | 11 |
*
|
| 14 | 12 |
* 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; |
| 16 | 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 17 | 15 |
* GNU General Public License for more details.
|
| 18 | 16 |
*
|
| 19 |
- * You should have received a copy of the GNU General Public
|
|
| 17 |
+ * You should have received a copy of the GNU General Public
|
|
| 20 | 18 |
* License along with this program. If not, see
|
| 21 | 19 |
* <http://www.gnu.org/licenses/gpl-3.0.html>.
|
| 22 | 20 |
* #L%
|
| 23 | 21 |
*/
|
| 22 |
+package fr.ird.observe.application.swing.ui.actions.shared;
|
|
| 24 | 23 |
|
| 24 |
+import fr.ird.observe.application.swing.ObserveOpenDataManager;
|
|
| 25 | 25 |
import fr.ird.observe.application.swing.ObserveSwingApplicationContext;
|
| 26 |
-import fr.ird.observe.application.swing.db.ObserveSwingDataSource;
|
|
| 27 |
-import fr.ird.observe.services.dto.IdHelper;
|
|
| 28 |
-import fr.ird.observe.services.dto.constants.GearType;
|
|
| 29 |
-import fr.ird.observe.services.dto.referential.ProgramDto;
|
|
| 30 |
-import fr.ird.observe.application.swing.ui.tree.node.ObserveNode;
|
|
| 26 |
+import fr.ird.observe.application.swing.decoration.decorators.ReferentialReferenceDecorator;
|
|
| 27 |
+import fr.ird.observe.application.swing.ui.ObserveMainUI;
|
|
| 31 | 28 |
import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper;
|
| 29 |
+import fr.ird.observe.application.swing.ui.tree.node.ObserveNode;
|
|
| 32 | 30 |
import fr.ird.observe.application.swing.ui.tree.node.ProgramLonglineNode;
|
| 33 | 31 |
import fr.ird.observe.application.swing.ui.tree.node.ProgramSeineNode;
|
| 34 |
-import fr.ird.observe.application.swing.ui.tree.actions.ChangeTripProgramActionListener;
|
|
| 35 |
-import fr.ird.observe.application.swing.ui.tree.actions.NodeChangeActionListener;
|
|
| 36 | 32 |
import fr.ird.observe.application.swing.ui.util.DecoratedNodeEntity;
|
| 37 |
-import fr.ird.observe.application.swing.decoration.decorators.ReferentialReferenceDecorator;
|
|
| 38 |
- |
|
| 33 |
+import fr.ird.observe.services.ObserveServicesProvider;
|
|
| 34 |
+import fr.ird.observe.services.dto.IdHelper;
|
|
| 35 |
+import fr.ird.observe.services.dto.constants.GearType;
|
|
| 36 |
+import fr.ird.observe.services.dto.referential.ProgramDto;
|
|
| 39 | 37 |
import java.util.ArrayList;
|
| 40 | 38 |
import java.util.List;
|
| 39 |
+import java.util.Optional;
|
|
| 40 |
+import javax.swing.JOptionPane;
|
|
| 41 |
+ |
|
| 42 |
+ |
|
| 43 |
+import static org.nuiton.i18n.I18n.n;
|
|
| 44 |
+import static org.nuiton.i18n.I18n.t;
|
|
| 41 | 45 |
|
| 42 | 46 |
/**
|
| 43 |
- * @author Kevin Morin (Code Lutin)
|
|
| 47 |
+ * Action pour changer le programme d'une ou plusieurs marée dans la liste.
|
|
| 48 |
+ *
|
|
| 49 |
+ * @author Tony Chemit - dev@tchemit.fr
|
|
| 44 | 50 |
* @since 5.0
|
| 45 | 51 |
*/
|
| 46 |
-public class MoveTripNodeMenuPopulator extends MoveNodeMenuPopulator {
|
|
| 52 |
+public abstract class MoveTripUIAction extends MoveSingleDataUIActionSupport {
|
|
| 53 |
+ |
|
| 54 |
+ private static final long serialVersionUID = 1L;
|
|
| 55 |
+ |
|
| 56 |
+ public static final String ACTION_NAME = "moveTrip";
|
|
| 57 |
+ |
|
| 58 |
+ private final GearType gearType;
|
|
| 59 |
+ |
|
| 60 |
+ MoveTripUIAction(ObserveMainUI mainUI, String actionName, GearType gearType) {
|
|
| 61 |
+ super(mainUI,
|
|
| 62 |
+ actionName,
|
|
| 63 |
+ n("observe.navigationMenu.move.trip"),
|
|
| 64 |
+ n("observe.navigationMenu.move.trip"),
|
|
| 65 |
+ "move-trips"
|
|
| 66 |
+ );
|
|
| 67 |
+ this.gearType = gearType;
|
|
| 68 |
+ }
|
|
| 47 | 69 |
|
| 48 | 70 |
@Override
|
| 49 |
- public NodeChangeActionListener createChangeActionListener(ObserveTreeHelper treeHelper,
|
|
| 50 |
- ObserveSwingDataSource dataSource,
|
|
| 51 |
- String id,
|
|
| 52 |
- String parentId) {
|
|
| 53 |
- return new ChangeTripProgramActionListener(treeHelper, dataSource, id, parentId);
|
|
| 71 |
+ Optional<String> getNewParentId(ObserveMainUI mainUI, ObserveNode oldParentNode) {
|
|
| 72 |
+ return chooseNewProgram(mainUI, gearType, oldParentNode.getId());
|
|
| 54 | 73 |
}
|
| 55 | 74 |
|
| 56 | 75 |
@Override
|
| 57 |
- public List<DecoratedNodeEntity> getPossibleParentNodes(ObserveNode tripNode, ObserveTreeHelper treeHelper) {
|
|
| 76 |
+ int moveData(ObserveServicesProvider servicesProvider, ObserveOpenDataManager openDataManager, String oldParentId, String newParentId, String dataId) {
|
|
| 58 | 77 |
|
| 59 |
- // noeud du programme parent
|
|
| 60 |
- ObserveNode parentNode = tripNode.getParent();
|
|
| 78 |
+ // Close old program and open new program
|
|
| 79 |
+ if (openDataManager.isOpen(dataId)) {
|
|
| 80 |
+ openDataManager.closeProgram(oldParentId);
|
|
| 81 |
+ openDataManager.openProgram(newParentId);
|
|
| 82 |
+ }
|
|
| 61 | 83 |
|
| 62 |
- // programmes du même type que le noeud de marée, sans le parent actuel
|
|
| 63 |
- List<DecoratedNodeEntity> possibleParents = new ArrayList<>();
|
|
| 84 |
+ // hum, we do NOT use this value (concrete classes define it)
|
|
| 85 |
+ return 0;
|
|
| 86 |
+ }
|
|
| 64 | 87 |
|
| 65 |
- // noeud longline ?
|
|
| 66 |
- GearType gearType = IdHelper.isLonglineId(tripNode.getId()) ? GearType.longline : GearType.seine;
|
|
| 88 |
+ @Override
|
|
| 89 |
+ void closeNode(ObserveOpenDataManager openDataManager, String dataId) {
|
|
| 90 |
+ // Don't do anything : trip should stay open when being transferred
|
|
| 91 |
+ }
|
|
| 67 | 92 |
|
| 68 |
- // racine
|
|
| 69 |
- ObserveNode rootNode = treeHelper.getRootNode();
|
|
| 93 |
+ @Override
|
|
| 94 |
+ ObserveNode getNewParentNode(ObserveTreeHelper treeHelper, ObserveNode grandParentNode, String newParentId) {
|
|
| 95 |
+ return treeHelper.getChild(grandParentNode, newParentId);
|
|
| 96 |
+ }
|
|
| 70 | 97 |
|
| 71 |
- createPossibleParents(parentNode.getId(), possibleParents, gearType, rootNode);
|
|
| 98 |
+ static Optional<String> chooseNewProgram(ObserveMainUI mainUI, GearType gearType, String oldProgramId) {
|
|
| 72 | 99 |
|
| 73 |
- return possibleParents;
|
|
| 74 |
- }
|
|
| 100 |
+ ObserveTreeHelper treeHelper = mainUI.getTreeHelper();
|
|
| 101 |
+ |
|
| 102 |
+ // racine
|
|
| 103 |
+ ObserveNode rootNode = treeHelper.getRootNode();
|
|
| 75 | 104 |
|
| 76 |
- public static void createPossibleParents(String oldProgramId, List<DecoratedNodeEntity> possibleParents, GearType gearType, ObserveNode rootNode) {
|
|
| 105 |
+ //on crée un tableau avec un programme en moins car on ne propose pas le programme actuel
|
|
| 106 |
+ List<DecoratedNodeEntity> decoratedProgramList = new ArrayList<>();
|
|
| 77 | 107 |
|
| 78 | 108 |
ReferentialReferenceDecorator<ProgramDto> programDecorator = ObserveSwingApplicationContext.get().getDecoratorService().getReferentialReferenceDecorator(ProgramDto.class);
|
| 79 | 109 |
|
| ... | ... | @@ -89,17 +119,30 @@ public class MoveTripNodeMenuPopulator extends MoveNodeMenuPopulator { |
| 89 | 119 |
if (programNode instanceof ProgramSeineNode && GearType.seine == gearType) {
|
| 90 | 120 |
|
| 91 | 121 |
ProgramSeineNode node = (ProgramSeineNode) programNode;
|
| 92 |
- possibleParents.add(DecoratedNodeEntity.newDecoratedNodeEntity(node, programDecorator));
|
|
| 122 |
+ decoratedProgramList.add(DecoratedNodeEntity.newDecoratedNodeEntity(node, programDecorator));
|
|
| 93 | 123 |
|
| 94 | 124 |
} else if (programNode instanceof ProgramLonglineNode && GearType.longline == gearType) {
|
| 95 | 125 |
|
| 96 | 126 |
ProgramLonglineNode node = (ProgramLonglineNode) programNode;
|
| 97 |
- possibleParents.add(DecoratedNodeEntity.newDecoratedNodeEntity(node, programDecorator));
|
|
| 127 |
+ decoratedProgramList.add(DecoratedNodeEntity.newDecoratedNodeEntity(node, programDecorator));
|
|
| 98 | 128 |
|
| 99 | 129 |
}
|
| 100 | 130 |
|
| 101 | 131 |
}
|
| 102 | 132 |
}
|
| 133 |
+ |
|
| 134 |
+ DecoratedNodeEntity[] decoratedPrograms =
|
|
| 135 |
+ decoratedProgramList.toArray(new DecoratedNodeEntity[decoratedProgramList.size()]);
|
|
| 136 |
+ |
|
| 137 |
+ DecoratedNodeEntity decoratedProgram = (DecoratedNodeEntity) JOptionPane.showInputDialog(mainUI,
|
|
| 138 |
+ t("observe.action.choose.program.message"),
|
|
| 139 |
+ t("observe.action.choose.program.title"),
|
|
| 140 |
+ JOptionPane.QUESTION_MESSAGE,
|
|
| 141 |
+ null,
|
|
| 142 |
+ decoratedPrograms,
|
|
| 143 |
+ null);
|
|
| 144 |
+ |
|
| 145 |
+ return Optional.ofNullable(decoratedProgram == null ? null : decoratedProgram.getId());
|
|
| 103 | 146 |
}
|
| 104 | 147 |
|
| 105 | 148 |
}
|
| ... | ... | @@ -23,29 +23,18 @@ package fr.ird.observe.application.swing.ui.actions.shared; |
| 23 | 23 |
|
| 24 | 24 |
import fr.ird.observe.application.swing.ObserveOpenDataManager;
|
| 25 | 25 |
import fr.ird.observe.application.swing.ObserveSwingApplicationContext;
|
| 26 |
-import fr.ird.observe.services.dto.DataDto;
|
|
| 27 |
-import fr.ird.observe.services.dto.DataReference;
|
|
| 28 |
-import fr.ird.observe.services.dto.constants.GearType;
|
|
| 29 | 26 |
import fr.ird.observe.application.swing.ui.ObserveMainUI;
|
| 30 |
-import fr.ird.observe.application.swing.ui.content.ContentUI;
|
|
| 31 |
-import fr.ird.observe.application.swing.ui.content.list.ContentListUIModel;
|
|
| 32 |
-import fr.ird.observe.application.swing.ui.tree.node.ObserveNode;
|
|
| 27 |
+import fr.ird.observe.application.swing.ui.content.list.ContentListUI;
|
|
| 33 | 28 |
import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper;
|
| 34 |
-import fr.ird.observe.application.swing.ui.tree.menu.MoveTripNodeMenuPopulator;
|
|
| 35 |
-import fr.ird.observe.application.swing.ui.util.DecoratedNodeEntity;
|
|
| 29 |
+import fr.ird.observe.application.swing.ui.tree.node.ObserveNode;
|
|
| 30 |
+import fr.ird.observe.services.dto.constants.GearType;
|
|
| 31 |
+import java.util.List;
|
|
| 32 |
+import java.util.Optional;
|
|
| 36 | 33 |
import org.apache.commons.logging.Log;
|
| 37 | 34 |
import org.apache.commons.logging.LogFactory;
|
| 38 | 35 |
|
| 39 |
-import javax.swing.JComponent;
|
|
| 40 |
-import javax.swing.JOptionPane;
|
|
| 41 |
-import javax.swing.SwingUtilities;
|
|
| 42 |
-import java.awt.event.ActionEvent;
|
|
| 43 |
-import java.util.ArrayList;
|
|
| 44 |
-import java.util.List;
|
|
| 45 |
-import java.util.stream.Collectors;
|
|
| 46 | 36 |
|
| 47 | 37 |
import static org.nuiton.i18n.I18n.n;
|
| 48 |
-import static org.nuiton.i18n.I18n.t;
|
|
| 49 | 38 |
|
| 50 | 39 |
/**
|
| 51 | 40 |
* 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; |
| 53 | 42 |
* @author Kevin Morin (Code Lutin)
|
| 54 | 43 |
* @since 5.0
|
| 55 | 44 |
*/
|
| 56 |
-public abstract class MoveTripsUIAction<T extends DataDto> extends AbstractUIAction {
|
|
| 45 |
+public abstract class MoveTripsUIAction<U extends ContentListUI<?, ?>> extends MoveMultipleDataUIActionSupport<U> {
|
|
| 57 | 46 |
|
| 58 | 47 |
private static final long serialVersionUID = 1L;
|
| 59 | 48 |
|
| 60 |
- /**
|
|
| 61 |
- * Logger.
|
|
| 62 |
- */
|
|
| 63 | 49 |
private static final Log log = LogFactory.getLog(MoveTripsUIAction.class);
|
| 64 | 50 |
|
| 65 | 51 |
public static final String ACTION_NAME = "moveTrips";
|
| 52 |
+ private final GearType gearType;
|
|
| 53 |
+ |
|
| 54 |
+ protected abstract void updateModelData(U ui);
|
|
| 66 | 55 |
|
| 67 |
- public MoveTripsUIAction(ObserveMainUI mainUI, String actionName) {
|
|
| 56 |
+ MoveTripsUIAction(ObserveMainUI mainUI, String actionName, GearType gearType, Class<U> uiType) {
|
|
| 68 | 57 |
super(mainUI,
|
| 69 | 58 |
actionName,
|
| 70 | 59 |
n("observe.content.action.move.trips"),
|
| 71 | 60 |
n("observe.content.action.move.trips.tip"),
|
| 72 |
- "move-trips"
|
|
| 61 |
+ "move-trips",
|
|
| 62 |
+ uiType
|
|
| 73 | 63 |
);
|
| 64 |
+ this.gearType = gearType;
|
|
| 74 | 65 |
}
|
| 75 | 66 |
|
| 76 | 67 |
@Override
|
| 77 |
- public void actionPerformed(final ActionEvent e) {
|
|
| 78 |
- |
|
| 79 |
- SwingUtilities.invokeLater(() -> {
|
|
| 80 |
- JComponent c = (JComponent) e.getSource();
|
|
| 81 |
- ContentUI<?> ui = (ContentUI<?>)
|
|
| 82 |
- c.getClientProperty("ui");
|
|
| 83 |
- if (ui == null) {
|
|
| 84 |
- throw new IllegalStateException(
|
|
| 85 |
- "could not find client property " +
|
|
| 86 |
- "ui on component" + c);
|
|
| 87 |
- }
|
|
| 88 |
- |
|
| 89 |
- checkUIClass(ui);
|
|
| 90 |
- |
|
| 91 |
- // get current program id
|
|
| 92 |
- ObserveTreeHelper treeHelper = getMainUI().getTreeHelper();
|
|
| 93 |
- ObserveNode oldProgramNode = treeHelper.getSelectedNode();
|
|
| 94 |
- String oldProgramId = oldProgramNode.getId();
|
|
| 95 |
- |
|
| 96 |
- // choose the new program
|
|
| 97 |
- String programId = chooseNewProgram(ui, oldProgramId);
|
|
| 98 |
- |
|
| 99 |
- if (programId != null) {
|
|
| 100 |
- |
|
| 101 |
- // change the program of the selected trips
|
|
| 102 |
- List<DataReference<T>> selectedDatas = ((ContentListUIModel) ui.getModel()).getSelectedDatas();
|
|
| 103 |
- List<String> tripIds = selectedDatas.stream().map(DataReference.ID_FUNCTION).collect(Collectors.toList());
|
|
| 104 |
- List<Integer> positions = getPositions(tripIds, programId);
|
|
| 105 |
- |
|
| 106 |
- // update the tree
|
|
| 107 |
- updateTree(ui, oldProgramNode, oldProgramId, programId, tripIds, positions);
|
|
| 108 |
- }
|
|
| 109 |
- |
|
| 110 |
- });
|
|
| 111 |
- |
|
| 68 |
+ Optional<String> getNewParentId(ObserveMainUI mainUI, ObserveNode oldParentNode) {
|
|
| 69 |
+ return MoveTripUIAction.chooseNewProgram(getMainUI(), gearType, oldParentNode.getId());
|
|
| 112 | 70 |
}
|
| 113 | 71 |
|
| 114 |
- protected String chooseNewProgram(ContentUI<?> ui, String oldProgramId) {
|
|
| 115 |
- |
|
| 116 |
- ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get();
|
|
| 117 |
- |
|
| 118 |
- ObserveTreeHelper treeHelper = getMainUI().getTreeHelper();
|
|
| 119 |
- |
|
| 120 |
- GearType geartype = getGearType(ui);
|
|
| 121 |
- |
|
| 122 |
- // racine
|
|
| 123 |
- ObserveNode rootNode = treeHelper.getRootNode();
|
|
| 124 |
- |
|
| 125 |
- //on crée un tableau avec un programme en moins car on ne propose pas le programme actuel
|
|
| 126 |
- List<DecoratedNodeEntity> decoratedProgramList = new ArrayList<>();
|
|
| 127 |
- |
|
| 128 |
- MoveTripNodeMenuPopulator.createPossibleParents(oldProgramId, decoratedProgramList, geartype, rootNode);
|
|
| 129 |
- |
|
| 130 |
- DecoratedNodeEntity[] decoratedPrograms =
|
|
| 131 |
- decoratedProgramList.toArray(new DecoratedNodeEntity[decoratedProgramList.size()]);
|
|
| 132 |
- |
|
| 133 |
- DecoratedNodeEntity decoratedProgram = (DecoratedNodeEntity) JOptionPane.showInputDialog(ui,
|
|
| 134 |
- t("observe.action.choose.program.message"),
|
|
| 135 |
- t("observe.action.choose.program.title"),
|
|
| 136 |
- JOptionPane.QUESTION_MESSAGE,
|
|
| 137 |
- null,
|
|
| 138 |
- decoratedPrograms,
|
|
| 139 |
- null);
|
|
| 140 |
- |
|
| 141 |
- return decoratedProgram == null ? null : decoratedProgram.getId();
|
|
| 142 |
- }
|
|
| 72 |
+ @Override
|
|
| 73 |
+ void updateUI(U ui, ObserveNode oldParentNode, String newParentId, List<String> dataIds, List<Integer> positions) {
|
|
| 143 | 74 |
|
| 144 |
- protected void updateTree(ContentUI<?> ui,
|
|
| 145 |
- ObserveNode oldProgramNode,
|
|
| 146 |
- String oldProgramId,
|
|
| 147 |
- String programId,
|
|
| 148 |
- List<String> tripIds,
|
|
| 149 |
- List<Integer> positions) {
|
|
| 75 |
+ String oldProgramId = oldParentNode.getId();
|
|
| 150 | 76 |
|
| 151 | 77 |
ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get();
|
| 152 | 78 |
ObserveOpenDataManager openDataManager = applicationContext.getOpenDataManager();
|
| 153 | 79 |
ObserveTreeHelper treeHelper = getMainUI().getTreeHelper();
|
| 154 | 80 |
|
| 155 | 81 |
ObserveNode rootNode = treeHelper.getRootNode();
|
| 156 |
- ObserveNode newProgramNode = treeHelper.getChild(rootNode, programId);
|
|
| 82 |
+ ObserveNode newProgramNode = treeHelper.getChild(rootNode, newParentId);
|
|
| 157 | 83 |
|
| 158 | 84 |
for (int i = 0, s = positions.size(); i < s; i++) {
|
| 159 | 85 |
|
| 160 |
- String tripId = tripIds.get(i);
|
|
| 161 |
- ObserveNode tripNode = treeHelper.getChild(oldProgramNode, tripId);
|
|
| 86 |
+ String tripId = dataIds.get(i);
|
|
| 87 |
+ ObserveNode tripNode = treeHelper.getChild(oldParentNode, tripId);
|
|
| 162 | 88 |
boolean wasOpen = tripNode.isOpen();
|
| 163 | 89 |
treeHelper.removeNode(tripNode);
|
| 164 | 90 |
|
| 165 | 91 |
if (wasOpen) {
|
| 166 | 92 |
openDataManager.closeProgram(oldProgramId);
|
| 167 |
- openDataManager.openProgram(programId);
|
|
| 93 |
+ openDataManager.openProgram(newParentId);
|
|
| 168 | 94 |
}
|
| 169 | 95 |
|
| 170 | 96 |
ObserveNode newTripNode = treeHelper.getChild(newProgramNode, tripId);
|
| ... | ... | @@ -181,17 +107,9 @@ public abstract class MoveTripsUIAction<T extends DataDto> extends AbstractUIAct |
| 181 | 107 |
|
| 182 | 108 |
updateModelData(ui);
|
| 183 | 109 |
|
| 184 |
- treeHelper.reloadNode(oldProgramNode, true);
|
|
| 110 |
+ treeHelper.reloadNode(oldParentNode, true);
|
|
| 185 | 111 |
treeHelper.reloadNode(newProgramNode, true);
|
| 186 | 112 |
treeHelper.selectNode(newProgramNode);
|
| 187 | 113 |
}
|
| 188 | 114 |
|
| 189 |
- protected abstract void checkUIClass(ContentUI<?> ui) throws IllegalStateException;
|
|
| 190 |
- |
|
| 191 |
- protected abstract GearType getGearType(ContentUI<?> ui);
|
|
| 192 |
- |
|
| 193 |
- protected abstract List<Integer> getPositions(List<String> tripIds, String programId);
|
|
| 194 |
- |
|
| 195 |
- protected abstract void updateModelData(ContentUI<?> ui);
|
|
| 196 |
- |
|
| 197 | 115 |
}
|
| ... | ... | @@ -23,24 +23,23 @@ package fr.ird.observe.application.swing.ui.tree; |
| 23 | 23 |
*/
|
| 24 | 24 |
|
| 25 | 25 |
import com.google.common.base.Preconditions;
|
| 26 |
-import com.google.common.collect.ImmutableMap;
|
|
| 27 | 26 |
import fr.ird.observe.application.swing.ObserveOpenDataManager;
|
| 28 | 27 |
import fr.ird.observe.application.swing.ObserveSwingApplicationContext;
|
| 29 | 28 |
import fr.ird.observe.application.swing.db.DataContext;
|
| 30 |
-import fr.ird.observe.application.swing.db.ObserveSwingDataSource;
|
|
| 29 |
+import fr.ird.observe.application.swing.ui.actions.shared.MoveActivityLonglineUIAction;
|
|
| 30 |
+import fr.ird.observe.application.swing.ui.actions.shared.MoveActivitySeineUIAction;
|
|
| 31 |
+import fr.ird.observe.application.swing.ui.actions.shared.MoveRouteUIAction;
|
|
| 32 |
+import fr.ird.observe.application.swing.ui.actions.shared.MoveTripLonglineUIAction;
|
|
| 33 |
+import fr.ird.observe.application.swing.ui.actions.shared.MoveTripSeineUIAction;
|
|
| 31 | 34 |
import fr.ird.observe.application.swing.ui.content.ContentUI;
|
| 32 | 35 |
import fr.ird.observe.application.swing.ui.content.open.ContentOpenableUI;
|
| 33 |
-import fr.ird.observe.application.swing.ui.tree.menu.MoveActivityLonglineNodeMenuPopulator;
|
|
| 34 |
-import fr.ird.observe.application.swing.ui.tree.menu.MoveActivitySeineNodeMenuPopulator;
|
|
| 35 |
-import fr.ird.observe.application.swing.ui.tree.menu.MoveNodeMenuPopulator;
|
|
| 36 |
-import fr.ird.observe.application.swing.ui.tree.menu.MoveRouteNodeMenuPopulator;
|
|
| 37 |
-import fr.ird.observe.application.swing.ui.tree.menu.MoveTripNodeMenuPopulator;
|
|
| 38 | 36 |
import fr.ird.observe.application.swing.ui.tree.node.ObserveNode;
|
| 39 |
-import fr.ird.observe.application.swing.ui.util.DecoratedNodeEntity;
|
|
| 40 |
-import jaxx.runtime.SwingUtil;
|
|
| 41 |
-import org.apache.commons.logging.Log;
|
|
| 42 |
-import org.apache.commons.logging.LogFactory;
|
|
| 43 |
- |
|
| 37 |
+import java.awt.Point;
|
|
| 38 |
+import java.awt.Rectangle;
|
|
| 39 |
+import java.awt.event.KeyAdapter;
|
|
| 40 |
+import java.awt.event.KeyEvent;
|
|
| 41 |
+import java.awt.event.MouseAdapter;
|
|
| 42 |
+import java.awt.event.MouseEvent;
|
|
| 44 | 43 |
import javax.swing.JButton;
|
| 45 | 44 |
import javax.swing.JMenuItem;
|
| 46 | 45 |
import javax.swing.JPopupMenu;
|
| ... | ... | @@ -49,16 +48,8 @@ import javax.swing.JTree; |
| 49 | 48 |
import javax.swing.MenuElement;
|
| 50 | 49 |
import javax.swing.SwingUtilities;
|
| 51 | 50 |
import javax.swing.tree.TreePath;
|
| 52 |
-import java.awt.Point;
|
|
| 53 |
-import java.awt.Rectangle;
|
|
| 54 |
-import java.awt.event.KeyAdapter;
|
|
| 55 |
-import java.awt.event.KeyEvent;
|
|
| 56 |
-import java.awt.event.MouseAdapter;
|
|
| 57 |
-import java.awt.event.MouseEvent;
|
|
| 58 |
-import java.util.List;
|
|
| 59 |
- |
|
| 60 |
-import static org.nuiton.i18n.I18n.n;
|
|
| 61 |
-import static org.nuiton.i18n.I18n.t;
|
|
| 51 |
+import org.apache.commons.logging.Log;
|
|
| 52 |
+import org.apache.commons.logging.LogFactory;
|
|
| 62 | 53 |
|
| 63 | 54 |
/**
|
| 64 | 55 |
* Created on 1/8/15.
|
| ... | ... | @@ -76,15 +67,6 @@ public class ObserveNavigationTreeShowPopupAction { |
| 76 | 67 |
private static final String ACTIVITY_SEINE_MENU_ITEMS = "activitySeine";
|
| 77 | 68 |
private static final String ACTIVITY_LONGLINE_MENU_ITEMS = "activityLongline";
|
| 78 | 69 |
|
| 79 |
- static {
|
|
| 80 |
- n("observe.navigationMenu.move.trip");
|
|
| 81 |
- n("observe.navigationMenu.move.route");
|
|
| 82 |
- n("observe.navigationMenu.move.activitySeine");
|
|
| 83 |
- n("observe.navigationMenu.move.activityLongline");
|
|
| 84 |
- }
|
|
| 85 |
- |
|
| 86 |
- private final ObserveTreeHelper treeHelper;
|
|
| 87 |
- |
|
| 88 | 70 |
private final JPopupMenu popup;
|
| 89 | 71 |
|
| 90 | 72 |
private final JTree tree;
|
| ... | ... | @@ -95,11 +77,8 @@ public class ObserveNavigationTreeShowPopupAction { |
| 95 | 77 |
private final JMenuItem moveAction;
|
| 96 | 78 |
private final JMenuItem deleteAction;
|
| 97 | 79 |
|
| 98 |
- private final ImmutableMap<String, MoveNodeMenuPopulator> moveNodeDataByNodeType;
|
|
| 99 |
- |
|
| 100 | 80 |
public ObserveNavigationTreeShowPopupAction(ObserveTreeHelper treeHelper, JScrollPane pane, JPopupMenu popup) {
|
| 101 | 81 |
|
| 102 |
- this.treeHelper = treeHelper;
|
|
| 103 | 82 |
this.popup = popup;
|
| 104 | 83 |
this.tree = treeHelper.getUI();
|
| 105 | 84 |
|
| ... | ... | @@ -135,11 +114,6 @@ public class ObserveNavigationTreeShowPopupAction { |
| 135 | 114 |
this.moveAction = moveComponent;
|
| 136 | 115 |
this.deleteAction = deleteActionComponent;
|
| 137 | 116 |
|
| 138 |
- moveNodeDataByNodeType = ImmutableMap.of(TRIP_MENU_ITEMS, new MoveTripNodeMenuPopulator(),
|
|
| 139 |
- ROUTE_MENU_ITEMS, new MoveRouteNodeMenuPopulator(),
|
|
| 140 |
- ACTIVITY_SEINE_MENU_ITEMS, new MoveActivitySeineNodeMenuPopulator(),
|
|
| 141 |
- ACTIVITY_LONGLINE_MENU_ITEMS, new MoveActivityLonglineNodeMenuPopulator());
|
|
| 142 |
- |
|
| 143 | 117 |
KeyAdapter keyAdapter = new KeyAdapter() {
|
| 144 | 118 |
@Override
|
| 145 | 119 |
public void keyPressed(KeyEvent e) {
|
| ... | ... | @@ -163,7 +137,7 @@ public class ObserveNavigationTreeShowPopupAction { |
| 163 | 137 |
pane.addMouseListener(mouseAdapter);
|
| 164 | 138 |
}
|
| 165 | 139 |
|
| 166 |
- protected void autoSelectNodeInTree(MouseEvent e) {
|
|
| 140 |
+ private void autoSelectNodeInTree(MouseEvent e) {
|
|
| 167 | 141 |
|
| 168 | 142 |
boolean rightClick = SwingUtilities.isRightMouseButton(e);
|
| 169 | 143 |
|
| ... | ... | @@ -204,7 +178,7 @@ public class ObserveNavigationTreeShowPopupAction { |
| 204 | 178 |
}
|
| 205 | 179 |
}
|
| 206 | 180 |
|
| 207 |
- public void openNodeMenu(KeyEvent e) {
|
|
| 181 |
+ private void openNodeMenu(KeyEvent e) {
|
|
| 208 | 182 |
|
| 209 | 183 |
if (e.getKeyCode() == KeyEvent.VK_CONTEXT_MENU && !tree.isSelectionEmpty()) {
|
| 210 | 184 |
|
| ... | ... | @@ -226,7 +200,7 @@ public class ObserveNavigationTreeShowPopupAction { |
| 226 | 200 |
}
|
| 227 | 201 |
}
|
| 228 | 202 |
|
| 229 |
- protected void showPopup(int row, Point p) {
|
|
| 203 |
+ private void showPopup(int row, Point p) {
|
|
| 230 | 204 |
|
| 231 | 205 |
if (log.isInfoEnabled()) {
|
| 232 | 206 |
log.info("Will show popup from row: " + row);
|
| ... | ... | @@ -244,7 +218,7 @@ public class ObserveNavigationTreeShowPopupAction { |
| 244 | 218 |
|
| 245 | 219 |
}
|
| 246 | 220 |
|
| 247 |
- protected void beforeOpenPopup(ObserveNode selectedNode) {
|
|
| 221 |
+ private void beforeOpenPopup(ObserveNode selectedNode) {
|
|
| 248 | 222 |
|
| 249 | 223 |
// clean popup
|
| 250 | 224 |
popup.removeAll();
|
| ... | ... | @@ -295,64 +269,47 @@ public class ObserveNavigationTreeShowPopupAction { |
| 295 | 269 |
}
|
| 296 | 270 |
}
|
| 297 | 271 |
|
| 298 |
- protected void beforeOpenMenu(ObserveNode selectedNode, String nodeType) {
|
|
| 272 |
+ private void beforeOpenMenu(ObserveNode selectedNode, String nodeType) {
|
|
| 299 | 273 |
if (log.isInfoEnabled()) {
|
| 300 | 274 |
log.info("Will load popup for " + nodeType + " node.");
|
| 301 | 275 |
}
|
| 302 | 276 |
|
| 303 |
- MoveNodeMenuPopulator moveNodeData = moveNodeDataByNodeType.get(nodeType);
|
|
| 304 |
- |
|
| 305 | 277 |
ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get();
|
| 306 | 278 |
|
| 279 |
+ ContentUI<?> selectedContentUI = applicationContext.getContentUIManager().getSelectedContentUI();
|
|
| 307 | 280 |
if (selectedNode.isOpen()) {
|
| 308 | 281 |
|
| 309 |
- closeAction.putClientProperty("ui", applicationContext.getContentUIManager().getSelectedContentUI());
|
|
| 282 |
+ closeAction.putClientProperty("ui", selectedContentUI);
|
|
| 310 | 283 |
popup.add(closeAction);
|
| 311 | 284 |
|
| 312 | 285 |
|
| 313 | 286 |
} else {
|
| 314 | 287 |
|
| 315 |
- openAction.putClientProperty("ui", applicationContext.getContentUIManager().getSelectedContentUI());
|
|
| 288 |
+ openAction.putClientProperty("ui", selectedContentUI);
|
|
| 316 | 289 |
popup.add(openAction);
|
| 317 | 290 |
|
| 318 | 291 |
}
|
| 319 | 292 |
|
| 320 |
- moveAction.setText(t("observe.navigationMenu.move." + nodeType));
|
|
| 321 |
- moveAction.setToolTipText(t("observe.navigationMenu.move." + nodeType));
|
|
| 322 |
- moveAction.setIcon(SwingUtil.getUIManagerActionIcon("move-" + nodeType));
|
|
| 323 |
- popup.add(moveAction);
|
|
| 324 |
- |
|
| 325 |
- moveAction.removeAll();
|
|
| 326 |
- |
|
| 327 |
- // get the available program for the trip
|
|
| 328 |
- |
|
| 329 |
- String id = selectedNode.getId();
|
|
| 330 |
- |
|
| 331 |
- ObserveSwingDataSource dataSource = treeHelper.getDataProvider().getDataSource();
|
|
| 332 |
- |
|
| 333 |
- List<DecoratedNodeEntity> possibleParentNodes = moveNodeData.getPossibleParentNodes(selectedNode, treeHelper);
|
|
| 334 |
- |
|
| 335 |
- for (DecoratedNodeEntity possibleParent : possibleParentNodes) {
|
|
| 336 |
- |
|
| 337 |
- String possibleParentId = possibleParent.getId();
|
|
| 338 |
- JMenuItem item = new JMenuItem(possibleParent.toString());
|
|
| 339 |
- item.setName(possibleParentId);
|
|
| 340 |
- |
|
| 341 |
- |
|
| 342 |
- item.addActionListener(moveNodeData.createChangeActionListener(treeHelper,
|
|
| 343 |
- dataSource,
|
|
| 344 |
- id,
|
|
| 345 |
- possibleParentId));
|
|
| 346 |
- |
|
| 347 |
- moveAction.add(item);
|
|
| 293 |
+ if (selectedNode.isTripSeineNode()) {
|
|
| 294 |
+ moveAction.setAction(new MoveTripSeineUIAction(applicationContext.getMainUI()));
|
|
| 295 |
+ } else if (selectedNode.isTripLonglineNode()) {
|
|
| 296 |
+ moveAction.setAction(new MoveTripLonglineUIAction(applicationContext.getMainUI()));
|
|
| 297 |
+ } else if (selectedNode.isRouteNode()) {
|
|
| 298 |
+ moveAction.setAction(new MoveRouteUIAction(applicationContext.getMainUI()));
|
|
| 299 |
+ } else if (selectedNode.isActivitySeineNode()) {
|
|
| 300 |
+ moveAction.setAction(new MoveActivitySeineUIAction(applicationContext.getMainUI()));
|
|
| 301 |
+ } else if (selectedNode.isActivityLonglineNode()) {
|
|
| 302 |
+ moveAction.setAction(new MoveActivityLonglineUIAction(applicationContext.getMainUI()));
|
|
| 348 | 303 |
}
|
| 349 | 304 |
|
| 350 |
- deleteAction.putClientProperty("ui", applicationContext.getContentUIManager().getSelectedContentUI());
|
|
| 305 |
+ popup.add(moveAction);
|
|
| 306 |
+ |
|
| 307 |
+ deleteAction.putClientProperty("ui", selectedContentUI);
|
|
| 351 | 308 |
deleteAction.setEnabled(selectedNode.isOpen());
|
| 352 | 309 |
popup.add(deleteAction);
|
| 353 | 310 |
}
|
| 354 | 311 |
|
| 355 |
- protected boolean isRowSelected(int requiredRow) {
|
|
| 312 |
+ private boolean isRowSelected(int requiredRow) {
|
|
| 356 | 313 |
|
| 357 | 314 |
boolean result = false;
|
| 358 | 315 |
|
| ... | ... | @@ -372,7 +329,7 @@ public class ObserveNavigationTreeShowPopupAction { |
| 372 | 329 |
|
| 373 | 330 |
}
|
| 374 | 331 |
|
| 375 |
- protected int getLowestSelectedRowCount() {
|
|
| 332 |
+ private int getLowestSelectedRowCount() {
|
|
| 376 | 333 |
|
| 377 | 334 |
Preconditions.checkState(!tree.isSelectionEmpty());
|
| 378 | 335 |
|
| 1 |
-package fr.ird.observe.application.swing.ui.tree.actions;
|
|
| 2 |
- |
|
| 3 |
-/*
|
|
| 4 |
- * #%L
|
|
| 5 |
- * ObServe :: Application Swing
|
|
| 6 |
- * %%
|
|
| 7 |
- * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io
|
|
| 8 |
- * %%
|
|
| 9 |
- * This program is free software: you can redistribute it and/or modify
|
|
| 10 |
- * it under the terms of the GNU General Public License as
|
|
| 11 |
- * published by the Free Software Foundation, either version 3 of the
|
|
| 12 |
- * License, or (at your option) any later version.
|
|
| 13 |
- *
|
|
| 14 |
- * This program is distributed in the hope that it will be useful,
|
|
| 15 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 |
- * GNU General Public License for more details.
|
|
| 18 |
- *
|
|
| 19 |
- * You should have received a copy of the GNU General Public
|
|
| 20 |
- * License along with this program. If not, see
|
|
| 21 |
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 |
- * #L%
|
|
| 23 |
- */
|
|
| 24 |
- |
|
| 25 |
- |
|
| 26 |
-import fr.ird.observe.application.swing.ObserveOpenDataManager;
|
|
| 27 |
-import fr.ird.observe.application.swing.ObserveSwingApplicationContext;
|
|
| 28 |
-import fr.ird.observe.application.swing.db.ObserveSwingDataSource;
|
|
| 29 |
-import fr.ird.observe.application.swing.decoration.ObserveI18nDecoratorHelper;
|
|
| 30 |
-import fr.ird.observe.application.swing.ui.tree.node.ObserveNode;
|
|
| 31 |
-import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper;
|
|
| 32 |
-import fr.ird.observe.services.dto.seine.ActivitySeineDto;
|
|
| 33 |
-import fr.ird.observe.services.service.seine.ActivitySeineService;
|
|
| 34 |
-import org.apache.commons.logging.Log;
|
|
| 35 |
-import org.apache.commons.logging.LogFactory;
|
|
| 36 |
- |
|
| 37 |
-/**
|
|
| 38 |
- * Created on 1/9/15.
|
|
| 39 |
- *
|
|
| 40 |
- * @author Tony Chemit - dev@tchemit.fr
|
|
| 41 |
- * @since 3.11
|
|
| 42 |
- */
|
|
| 43 |
-public class ChangeActivityRouteActionListener extends NodeChangeActionListener {
|
|
| 44 |
- |
|
| 45 |
- /** Logger. */
|
|
| 46 |
- private static final Log log = LogFactory.getLog(ChangeActivityRouteActionListener.class);
|
|
| 47 |
- |
|
| 48 |
- public ChangeActivityRouteActionListener(ObserveTreeHelper treeHelper,
|
|
| 49 |
- ObserveSwingDataSource dataSource,
|
|
| 50 |
- String activityId,
|
|
| 51 |
- String routeId) {
|
|
| 52 |
- super(treeHelper, activityId, routeId);
|
|
| 53 |
- }
|
|
| 54 |
- |
|
| 55 |
- @Override
|
|
| 56 |
- protected void closeNode(String activityId) {
|
|
| 57 |
- ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get();
|
|
| 58 |
- ObserveOpenDataManager openDataManager = applicationContext.getOpenDataManager();
|
|
| 59 |
- |
|
| 60 |
- if (openDataManager.isOpenActivitySeine(activityId)) {
|
|
| 61 |
- openDataManager.closeActivitySeine(activityId);
|
|
| 62 |
- }
|
|
| 63 |
- }
|
|
| 64 |
- |
|
| 65 |
- @Override
|
|
| 66 |
- protected ObserveNode getParentNode(ObserveNode node) {
|
|
| 67 |
- return node.getParent().getParent();
|
|
| 68 |
- }
|
|
| 69 |
- |
|
| 70 |
- @Override
|
|
| 71 |
- protected ObserveNode getNewParentNode(ObserveNode grandParentNode, String parentNodeId) {
|
|
| 72 |
- ObserveNode routeNode = getTreeHelper().getChild(grandParentNode, parentNodeId);
|
|
| 73 |
- String activitiesNodeId = ObserveI18nDecoratorHelper.getTypePluralI18nKey(ActivitySeineDto.class);
|
|
| 74 |
- return getTreeHelper().getChild(routeNode, activitiesNodeId);
|
|
| 75 |
- }
|
|
| 76 |
- |
|
| 77 |
- @Override
|
|
| 78 |
- protected int moveNodeToParent(String nodeId, String parentNodeId, String oldParentNodeId) {
|
|
| 79 |
- int position;
|
|
| 80 |
- |
|
| 81 |
- ActivitySeineService service = ObserveSwingApplicationContext.get().getMainDataSourceServicesProvider().newActivitySeineService();
|
|
| 82 |
- position = service.moveActivitySeineToRoute(nodeId, parentNodeId);
|
|
| 83 |
- |
|
| 84 |
- return position;
|
|
| 85 |
- }
|
|
| 86 |
- |
|
| 87 |
-}
|
| 1 |
-package fr.ird.observe.application.swing.ui.tree.actions;
|
|
| 2 |
- |
|
| 3 |
-/*
|
|
| 4 |
- * #%L
|
|
| 5 |
- * ObServe :: Application Swing
|
|
| 6 |
- * %%
|
|
| 7 |
- * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io
|
|
| 8 |
- * %%
|
|
| 9 |
- * This program is free software: you can redistribute it and/or modify
|
|
| 10 |
- * it under the terms of the GNU General Public License as
|
|
| 11 |
- * published by the Free Software Foundation, either version 3 of the
|
|
| 12 |
- * License, or (at your option) any later version.
|
|
| 13 |
- *
|
|
| 14 |
- * This program is distributed in the hope that it will be useful,
|
|
| 15 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 |
- * GNU General Public License for more details.
|
|
| 18 |
- *
|
|
| 19 |
- * You should have received a copy of the GNU General Public
|
|
| 20 |
- * License along with this program. If not, see
|
|
| 21 |
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 |
- * #L%
|
|
| 23 |
- */
|
|
| 24 |
- |
|
| 25 |
- |
|
| 26 |
-import fr.ird.observe.application.swing.ObserveOpenDataManager;
|
|
| 27 |
-import fr.ird.observe.application.swing.ObserveSwingApplicationContext;
|
|
| 28 |
-import fr.ird.observe.application.swing.db.ObserveSwingDataSource;
|
|
| 29 |
-import fr.ird.observe.application.swing.decoration.ObserveI18nDecoratorHelper;
|
|
| 30 |
-import fr.ird.observe.application.swing.ui.tree.node.ObserveNode;
|
|
| 31 |
-import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper;
|
|
| 32 |
-import fr.ird.observe.services.dto.longline.ActivityLonglineDto;
|
|
| 33 |
-import fr.ird.observe.services.service.longline.ActivityLonglineService;
|
|
| 34 |
-import org.apache.commons.logging.Log;
|
|
| 35 |
-import org.apache.commons.logging.LogFactory;
|
|
| 36 |
- |
|
| 37 |
-/**
|
|
| 38 |
- * Created on 1/9/15.
|
|
| 39 |
- *
|
|
| 40 |
- * @author Tony Chemit - dev@tchemit.fr
|
|
| 41 |
- * @since 3.11
|
|
| 42 |
- */
|
|
| 43 |
-public class ChangeActivityTripActionListener extends NodeChangeActionListener {
|
|
| 44 |
- |
|
| 45 |
- /** Logger. */
|
|
| 46 |
- private static final Log log = LogFactory.getLog(ChangeActivityTripActionListener.class);
|
|
| 47 |
- |
|
| 48 |
- public ChangeActivityTripActionListener(ObserveTreeHelper treeHelper,
|
|
| 49 |
- ObserveSwingDataSource dataSource,
|
|
| 50 |
- String activityId,
|
|
| 51 |
- String tripLonglineId) {
|
|
| 52 |
- super(treeHelper, activityId, tripLonglineId);
|
|
| 53 |
- }
|
|
| 54 |
- |
|
| 55 |
- @Override
|
|
| 56 |
- protected void closeNode(String activityId) {
|
|
| 57 |
- ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get();
|
|
| 58 |
- ObserveOpenDataManager openDataManager = applicationContext.getOpenDataManager();
|
|
| 59 |
- |
|
| 60 |
- if (openDataManager.isOpenActivityLongline(activityId)) {
|
|
| 61 |
- openDataManager.closeActivityLongline(activityId);
|
|
| 62 |
- }
|
|
| 63 |
- }
|
|
| 64 |
- |
|
| 65 |
- @Override
|
|
| 66 |
- protected ObserveNode getParentNode(ObserveNode node) {
|
|
| 67 |
- return node.getParent().getParent();
|
|
| 68 |
- }
|
|
| 69 |
- |
|
| 70 |
- @Override
|
|
| 71 |
- protected ObserveNode getNewParentNode(ObserveNode grandParentNode, String parentNodeId) {
|
|
| 72 |
- ObserveNode tripLonglineNode = getTreeHelper().getChild(grandParentNode, parentNodeId);
|
|
| 73 |
- String activitiesNodeId = ObserveI18nDecoratorHelper.getTypePluralI18nKey(ActivityLonglineDto.class);
|
|
| 74 |
- return getTreeHelper().getChild(tripLonglineNode, activitiesNodeId);
|
|
| 75 |
- }
|
|
| 76 |
- |
|
| 77 |
- @Override
|
|
| 78 |
- protected int moveNodeToParent(String nodeId, String parentNodeId, String oldParentNodeId) {
|
|
| 79 |
- int position;
|
|
| 80 |
- |
|
| 81 |
- ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get();
|
|
| 82 |
- |
|
| 83 |
- ActivityLonglineService service = applicationContext.getMainDataSourceServicesProvider().newActivityLonglineService();
|
|
| 84 |
- position = service.moveActivityLonglineToTripLongline(nodeId, parentNodeId);
|
|
| 85 |
- |
|
| 86 |
- return position;
|
|
| 87 |
- }
|
|
| 88 |
- |
|
| 89 |
-}
|
| 1 |
-package fr.ird.observe.application.swing.ui.tree.actions;
|
|
| 2 |
- |
|
| 3 |
-/*
|
|
| 4 |
- * #%L
|
|
| 5 |
- * ObServe :: Application Swing
|
|
| 6 |
- * %%
|
|
| 7 |
- * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io
|
|
| 8 |
- * %%
|
|
| 9 |
- * This program is free software: you can redistribute it and/or modify
|
|
| 10 |
- * it under the terms of the GNU General Public License as
|
|
| 11 |
- * published by the Free Software Foundation, either version 3 of the
|
|
| 12 |
- * License, or (at your option) any later version.
|
|
| 13 |
- *
|
|
| 14 |
- * This program is distributed in the hope that it will be useful,
|
|
| 15 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 |
- * GNU General Public License for more details.
|
|
| 18 |
- *
|
|
| 19 |
- * You should have received a copy of the GNU General Public
|
|
| 20 |
- * License along with this program. If not, see
|
|
| 21 |
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 |
- * #L%
|
|
| 23 |
- */
|
|
| 24 |
- |
|
| 25 |
- |
|
| 26 |
-import fr.ird.observe.application.swing.ObserveOpenDataManager;
|
|
| 27 |
-import fr.ird.observe.application.swing.ObserveSwingApplicationContext;
|
|
| 28 |
-import fr.ird.observe.application.swing.db.ObserveSwingDataSource;
|
|
| 29 |
-import fr.ird.observe.application.swing.decoration.ObserveI18nDecoratorHelper;
|
|
| 30 |
-import fr.ird.observe.application.swing.ui.tree.node.ObserveNode;
|
|
| 31 |
-import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper;
|
|
| 32 |
-import fr.ird.observe.services.dto.seine.RouteDto;
|
|
| 33 |
-import fr.ird.observe.services.service.seine.RouteService;
|
|
| 34 |
-import org.apache.commons.logging.Log;
|
|
| 35 |
-import org.apache.commons.logging.LogFactory;
|
|
| 36 |
- |
|
| 37 |
-/**
|
|
| 38 |
- * Created on 1/9/15.
|
|
| 39 |
- *
|
|
| 40 |
- * @author Tony Chemit - dev@tchemit.fr
|
|
| 41 |
- * @since 3.11
|
|
| 42 |
- */
|
|
| 43 |
-public class ChangeRouteTripActionListener extends NodeChangeActionListener {
|
|
| 44 |
- |
|
| 45 |
- /** Logger. */
|
|
| 46 |
- private static final Log log = LogFactory.getLog(ChangeRouteTripActionListener.class);
|
|
| 47 |
- |
|
| 48 |
- public ChangeRouteTripActionListener(ObserveTreeHelper treeHelper,
|
|
| 49 |
- ObserveSwingDataSource dataSource,
|
|
| 50 |
- String routeId,
|
|
| 51 |
- String tripId) {
|
|
| 52 |
- super(treeHelper, routeId, tripId);
|
|
| 53 |
- }
|
|
| 54 |
- |
|
| 55 |
- @Override
|
|
| 56 |
- protected void closeNode(String routeId) {
|
|
| 57 |
- ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get();
|
|
| 58 |
- ObserveOpenDataManager openDataManager = applicationContext.getOpenDataManager();
|
|
| 59 |
- |
|
| 60 |
- if (openDataManager.isOpenRoute(routeId)) {
|
|
| 61 |
- openDataManager.closeRoute(routeId);
|
|
| 62 |
- }
|
|
| 63 |
- }
|
|
| 64 |
- |
|
| 65 |
- @Override
|
|
| 66 |
- protected ObserveNode getParentNode(ObserveNode node) {
|
|
| 67 |
- return node.getParent().getParent();
|
|
| 68 |
- }
|
|
| 69 |
- |
|
| 70 |
- @Override
|
|
| 71 |
- protected ObserveNode getNewParentNode(ObserveNode grandParentNode, String parentNodeId) {
|
|
| 72 |
- ObserveNode tripNode = getTreeHelper().getChild(grandParentNode, parentNodeId);
|
|
| 73 |
- String routesNodeId = ObserveI18nDecoratorHelper.getTypePluralI18nKey(RouteDto.class);
|
|
| 74 |
- return getTreeHelper().getChild(tripNode, routesNodeId);
|
|
| 75 |
- }
|
|
| 76 |
- |
|
| 77 |
- @Override
|
|
| 78 |
- protected int moveNodeToParent(String nodeId, String parentNodeId, String oldParentNodeId) {
|
|
| 79 |
- int position;
|
|
| 80 |
- |
|
| 81 |
- RouteService service = ObserveSwingApplicationContext.get().getMainDataSourceServicesProvider().newRouteService();
|
|
| 82 |
- position = service.moveRouteToTripSeine(nodeId, parentNodeId);
|
|
| 83 |
- |
|
| 84 |
- return position;
|
|
| 85 |
- }
|
|
| 86 |
-}
|
| 1 |
-package fr.ird.observe.application.swing.ui.tree.actions;
|
|
| 2 |
- |
|
| 3 |
-/*
|
|
| 4 |
- * #%L
|
|
| 5 |
- * ObServe :: Application Swing
|
|
| 6 |
- * %%
|
|
| 7 |
- * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io
|
|
| 8 |
- * %%
|
|
| 9 |
- * This program is free software: you can redistribute it and/or modify
|
|
| 10 |
- * it under the terms of the GNU General Public License as
|
|
| 11 |
- * published by the Free Software Foundation, either version 3 of the
|
|
| 12 |
- * License, or (at your option) any later version.
|
|
| 13 |
- *
|
|
| 14 |
- * This program is distributed in the hope that it will be useful,
|
|
| 15 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 |
- * GNU General Public License for more details.
|
|
| 18 |
- *
|
|
| 19 |
- * You should have received a copy of the GNU General Public
|
|
| 20 |
- * License along with this program. If not, see
|
|
| 21 |
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 |
- * #L%
|
|
| 23 |
- */
|
|
| 24 |
- |
|
| 25 |
- |
|
| 26 |
-import fr.ird.observe.application.swing.ObserveOpenDataManager;
|
|
| 27 |
-import fr.ird.observe.application.swing.ObserveSwingApplicationContext;
|
|
| 28 |
-import fr.ird.observe.application.swing.db.ObserveSwingDataSource;
|
|
| 29 |
-import fr.ird.observe.services.ObserveServicesProvider;
|
|
| 30 |
-import fr.ird.observe.services.dto.IdHelper;
|
|
| 31 |
-import fr.ird.observe.services.service.longline.TripLonglineService;
|
|
| 32 |
-import fr.ird.observe.services.service.seine.TripSeineService;
|
|
| 33 |
-import fr.ird.observe.application.swing.ui.tree.node.ObserveNode;
|
|
| 34 |
-import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper;
|
|
| 35 |
-import org.apache.commons.logging.Log;
|
|
| 36 |
-import org.apache.commons.logging.LogFactory;
|
|
| 37 |
- |
|
| 38 |
-/**
|
|
| 39 |
- * Created on 1/9/15.
|
|
| 40 |
- *
|
|
| 41 |
- * @author Tony Chemit - dev@tchemit.fr
|
|
| 42 |
- * @since 3.11
|
|
| 43 |
- */
|
|
| 44 |
-public class ChangeTripProgramActionListener extends NodeChangeActionListener {
|
|
| 45 |
- |
|
| 46 |
- /** Logger. */
|
|
| 47 |
- private static final Log log = LogFactory.getLog(ChangeTripProgramActionListener.class);
|
|
| 48 |
- |
|
| 49 |
- public ChangeTripProgramActionListener(ObserveTreeHelper treeHelper,
|
|
| 50 |
- ObserveSwingDataSource dataSource,
|
|
| 51 |
- String tripId,
|
|
| 52 |
- String programId) {
|
|
| 53 |
- super(treeHelper, tripId, programId);
|
|
| 54 |
- }
|
|
| 55 |
- |
|
| 56 |
- @Override
|
|
| 57 |
- protected void closeNode(String tripId) {
|
|
| 58 |
- // Don't do anything : trip should stay open when being transferred
|
|
| 59 |
- }
|
|
| 60 |
- |
|
| 61 |
- @Override
|
|
| 62 |
- protected ObserveNode getParentNode(ObserveNode node) {
|
|
| 63 |
- return node.getParent();
|
|
| 64 |
- }
|
|
| 65 |
- |
|
| 66 |
- @Override
|
|
| 67 |
- protected ObserveNode getNewParentNode(ObserveNode grandParentNode, String parentNodeId) {
|
|
| 68 |
- return getTreeHelper().getChild(grandParentNode, parentNodeId);
|
|
| 69 |
- }
|
|
| 70 |
- |
|
| 71 |
- @Override
|
|
| 72 |
- protected int moveNodeToParent(String nodeId, String parentNodeId, String oldParentNodeId) {
|
|
| 73 |
- int position;
|
|
| 74 |
- |
|
| 75 |
- ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get();
|
|
| 76 |
- ObserveServicesProvider servicesProvider = applicationContext.getMainDataSourceServicesProvider();
|
|
| 77 |
- if (IdHelper.isTripLonglineId(nodeId)) {
|
|
| 78 |
- TripLonglineService service = servicesProvider.newTripLonglineService();
|
|
| 79 |
- position = service.moveTripLonglineToProgram(nodeId, parentNodeId);
|
|
| 80 |
- |
|
| 81 |
- } else {
|
|
| 82 |
- TripSeineService service = servicesProvider.newTripSeineService();
|
|
| 83 |
- position = service.moveTripSeineToProgram(nodeId, parentNodeId);
|
|
| 84 |
- }
|
|
| 85 |
- |
|
| 86 |
- // Close old program and open new program
|
|
| 87 |
- ObserveOpenDataManager openDataManager = applicationContext.getOpenDataManager();
|
|
| 88 |
- if (openDataManager.isOpen(nodeId)) {
|
|
| 89 |
- openDataManager.closeProgram(oldParentNodeId);
|
|
| 90 |
- openDataManager.openProgram(parentNodeId);
|
|
| 91 |
- }
|
|
| 92 |
- |
|
| 93 |
- return position;
|
|
| 94 |
- }
|
|
| 95 |
-}
|
| 1 |
-package fr.ird.observe.application.swing.ui.tree.actions;
|
|
| 2 |
- |
|
| 3 |
-/*
|
|
| 4 |
- * #%L
|
|
| 5 |
- * ObServe :: Application Swing
|
|
| 6 |
- * %%
|
|
| 7 |
- * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io
|
|
| 8 |
- * %%
|
|
| 9 |
- * This program is free software: you can redistribute it and/or modify
|
|
| 10 |
- * it under the terms of the GNU General Public License as
|
|
| 11 |
- * published by the Free Software Foundation, either version 3 of the
|
|
| 12 |
- * License, or (at your option) any later version.
|
|
| 13 |
- *
|
|
| 14 |
- * This program is distributed in the hope that it will be useful,
|
|
| 15 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 |
- * GNU General Public License for more details.
|
|
| 18 |
- *
|
|
| 19 |
- * You should have received a copy of the GNU General Public
|
|
| 20 |
- * License along with this program. If not, see
|
|
| 21 |
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 |
- * #L%
|
|
| 23 |
- */
|
|
| 24 |
- |
|
| 25 |
- |
|
| 26 |
-import fr.ird.observe.application.swing.ui.tree.node.ObserveNode;
|
|
| 27 |
-import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper;
|
|
| 28 |
-import org.apache.commons.logging.Log;
|
|
| 29 |
-import org.apache.commons.logging.LogFactory;
|
|
| 30 |
- |
|
| 31 |
-import java.awt.event.ActionEvent;
|
|
| 32 |
-import java.awt.event.ActionListener;
|
|
| 33 |
- |
|
| 34 |
-/**
|
|
| 35 |
- * Created on 1/9/15.
|
|
| 36 |
- *
|
|
| 37 |
- * @author Tony Chemit - dev@tchemit.fr
|
|
| 38 |
- * @since 3.11
|
|
| 39 |
- */
|
|
| 40 |
-public abstract class NodeChangeActionListener implements ActionListener {
|
|
| 41 |
- |
|
| 42 |
- /** Logger. */
|
|
| 43 |
- private static final Log log = LogFactory.getLog(NodeChangeActionListener.class);
|
|
| 44 |
- |
|
| 45 |
- private final String nodeId;
|
|
| 46 |
- |
|
| 47 |
- private final String parentNodeId;
|
|
| 48 |
- |
|
| 49 |
- private final ObserveTreeHelper treeHelper;
|
|
| 50 |
- |
|
| 51 |
- public NodeChangeActionListener(ObserveTreeHelper treeHelper,
|
|
| 52 |
- String nodeId,
|
|
| 53 |
- String parentNodeId) {
|
|
| 54 |
- this.nodeId = nodeId;
|
|
| 55 |
- this.parentNodeId = parentNodeId;
|
|
| 56 |
- this.treeHelper = treeHelper;
|
|
| 57 |
- }
|
|
| 58 |
- |
|
| 59 |
- @Override
|
|
| 60 |
- public void actionPerformed(ActionEvent event) {
|
|
| 61 |
- |
|
| 62 |
- ObserveNode node = treeHelper.getSelectedNode();
|
|
| 63 |
- ObserveNode oldParentNode = getParentNode(node);
|
|
| 64 |
- ObserveNode grandParentNode = oldParentNode.getParent();
|
|
| 65 |
- ObserveNode newParentNode = getNewParentNode(grandParentNode, parentNodeId);
|
|
| 66 |
- |
|
| 67 |
- closeNode(node.getId());
|
|
| 68 |
- |
|
| 69 |
- int position = moveNodeToParent(nodeId, parentNodeId, oldParentNode.getId());
|
|
| 70 |
- |
|
| 71 |
- treeHelper.selectNode(newParentNode);
|
|
| 72 |
- |
|
| 73 |
- treeHelper.removeNode(node);
|
|
| 74 |
- |
|
| 75 |
- ObserveNode newNode = treeHelper.getChild(newParentNode, nodeId);
|
|
| 76 |
- |
|
| 77 |
- if (newNode == null) {
|
|
| 78 |
- |
|
| 79 |
- // create it
|
|
| 80 |
- if (log.isInfoEnabled()) {
|
|
| 81 |
- log.info("Insert node: ");
|
|
| 82 |
- }
|
|
| 83 |
- treeHelper.insertNode(newParentNode, node, position);
|
|
| 84 |
- newNode = node;
|
|
| 85 |
- }
|
|
| 86 |
- |
|
| 87 |
- treeHelper.selectNode(newNode);
|
|
| 88 |
- |
|
| 89 |
- }
|
|
| 90 |
- |
|
| 91 |
- protected ObserveTreeHelper getTreeHelper() {
|
|
| 92 |
- return treeHelper;
|
|
| 93 |
- }
|
|
| 94 |
- |
|
| 95 |
- protected abstract void closeNode(String nodeId);
|
|
| 96 |
- |
|
| 97 |
- protected abstract ObserveNode getParentNode(ObserveNode node);
|
|
| 98 |
- |
|
| 99 |
- protected abstract ObserveNode getNewParentNode(ObserveNode grandParentNode, String parentNodeId);
|
|
| 100 |
- |
|
| 101 |
- protected abstract int moveNodeToParent(String nodeId, String parentNodeId, String oldParentNodeId);
|
|
| 102 |
-}
|
| 1 |
-package fr.ird.observe.application.swing.ui.tree.menu;
|
|
| 2 |
- |
|
| 3 |
-/*-
|
|
| 4 |
- * #%L
|
|
| 5 |
- * ObServe :: Application Swing
|
|
| 6 |
- * %%
|
|
| 7 |
- * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io
|
|
| 8 |
- * %%
|
|
| 9 |
- * This program is free software: you can redistribute it and/or modify
|
|
| 10 |
- * it under the terms of the GNU General Public License as
|
|
| 11 |
- * published by the Free Software Foundation, either version 3 of the
|
|
| 12 |
- * License, or (at your option) any later version.
|
|
| 13 |
- *
|
|
| 14 |
- * This program is distributed in the hope that it will be useful,
|
|
| 15 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 |
- * GNU General Public License for more details.
|
|
| 18 |
- *
|
|
| 19 |
- * You should have received a copy of the GNU General Public
|
|
| 20 |
- * License along with this program. If not, see
|
|
| 21 |
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 |
- * #L%
|
|
| 23 |
- */
|
|
| 24 |
- |
|
| 25 |
-import fr.ird.observe.application.swing.db.ObserveSwingDataSource;
|
|
| 26 |
-import fr.ird.observe.services.dto.IdHelper;
|
|
| 27 |
-import fr.ird.observe.services.dto.longline.TripLonglineDto;
|
|
| 28 |
-import fr.ird.observe.application.swing.decoration.DecoratorService;
|
|
| 29 |
-import fr.ird.observe.application.swing.ui.tree.node.ObserveNode;
|
|
| 30 |
-import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper;
|
|
| 31 |
-import fr.ird.observe.application.swing.ui.tree.node.TripLonglineNode;
|
|
| 32 |
-import fr.ird.observe.application.swing.ui.tree.actions.ChangeActivityTripActionListener;
|
|
| 33 |
-import fr.ird.observe.application.swing.ui.tree.actions.NodeChangeActionListener;
|
|
| 34 |
-import fr.ird.observe.application.swing.ui.util.DecoratedNodeEntity;
|
|
| 35 |
-import fr.ird.observe.application.swing.decoration.decorators.DataReferenceDecorator;
|
|
| 36 |
- |
|
| 37 |
-import java.util.ArrayList;
|
|
| 38 |
-import java.util.List;
|
|
| 39 |
- |
|
| 40 |
-/**
|
|
| 41 |
- * @author Kevin Morin (Code Lutin)
|
|
| 42 |
- * @since 5.0
|
|
| 43 |
- */
|
|
| 44 |
-public class MoveActivityLonglineNodeMenuPopulator extends MoveNodeMenuPopulator {
|
|
| 45 |
- |
|
| 46 |
- @Override
|
|
| 47 |
- public NodeChangeActionListener createChangeActionListener(ObserveTreeHelper treeHelper,
|
|
| 48 |
- ObserveSwingDataSource dataSource,
|
|
| 49 |
- String id,
|
|
| 50 |
- String parentId) {
|
|
| 51 |
- return new ChangeActivityTripActionListener(treeHelper, dataSource, id, parentId);
|
|
| 52 |
- }
|
|
| 53 |
- |
|
| 54 |
- @Override
|
|
| 55 |
- public List<DecoratedNodeEntity> getPossibleParentNodes(ObserveNode activityLonglineNode, ObserveTreeHelper treeHelper) {
|
|
| 56 |
- |
|
| 57 |
- // noeud de marée parent
|
|
| 58 |
- ObserveNode parentNode = activityLonglineNode.getParent().getParent();
|
|
| 59 |
- |
|
| 60 |
- // noeud de route de la marée sans le parent actuel
|
|
| 61 |
- List<DecoratedNodeEntity> possibleParents = new ArrayList<>();
|
|
| 62 |
- |
|
| 63 |
- // noeud du programme
|
|
| 64 |
- ObserveNode programNode = parentNode.getParent();
|
|
| 65 |
- |
|
| 66 |
- DecoratorService decoratorService = treeHelper.getTreeCellRenderer().getDecoratorService();
|
|
| 67 |
- DataReferenceDecorator<TripLonglineDto> tripDecorator = decoratorService.getDataReferenceDecorator(TripLonglineDto.class);
|
|
| 68 |
- |
|
| 69 |
- for (int i = 0, n = programNode.getChildCount(); i < n; i++) {
|
|
| 70 |
- |
|
| 71 |
- TripLonglineNode tripNode = (TripLonglineNode) programNode.getChildAt(i);
|
|
| 72 |
- String tripId = tripNode.getId();
|
|
| 73 |
- |
|
| 74 |
- // si le noeud de marée n'est pas le même que le parent actuel
|
|
| 75 |
- // si le noeud est bien un noeud de marée longline
|
|
| 76 |
- if (!parentNode.equals(tripNode) && IdHelper.isTripLonglineId(tripId)) {
|
|
| 77 |
- |
|
| 78 |
- possibleParents.add(DecoratedNodeEntity.newDecoratedNodeEntity(tripNode, tripDecorator));
|
|
| 79 |
- |
|
| 80 |
- }
|
|
| 81 |
- }
|
|
| 82 |
- |
|
| 83 |
- return possibleParents;
|
|
| 84 |
- }
|
|
| 85 |
-}
|
| 1 |
-package fr.ird.observe.application.swing.ui.tree.menu;
|
|
| 2 |
- |
|
| 3 |
-/*-
|
|
| 4 |
- * #%L
|
|
| 5 |
- * ObServe :: Application Swing
|
|
| 6 |
- * %%
|
|
| 7 |
- * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io
|
|
| 8 |
- * %%
|
|
| 9 |
- * This program is free software: you can redistribute it and/or modify
|
|
| 10 |
- * it under the terms of the GNU General Public License as
|
|
| 11 |
- * published by the Free Software Foundation, either version 3 of the
|
|
| 12 |
- * License, or (at your option) any later version.
|
|
| 13 |
- *
|
|
| 14 |
- * This program is distributed in the hope that it will be useful,
|
|
| 15 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 |
- * GNU General Public License for more details.
|
|
| 18 |
- *
|
|
| 19 |
- * You should have received a copy of the GNU General Public
|
|
| 20 |
- * License along with this program. If not, see
|
|
| 21 |
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 |
- * #L%
|
|
| 23 |
- */
|
|
| 24 |
- |
|
| 25 |
-import fr.ird.observe.application.swing.db.ObserveSwingDataSource;
|
|
| 26 |
-import fr.ird.observe.services.dto.IdHelper;
|
|
| 27 |
-import fr.ird.observe.services.dto.seine.RouteDto;
|
|
| 28 |
-import fr.ird.observe.application.swing.decoration.DecoratorService;
|
|
| 29 |
-import fr.ird.observe.application.swing.ui.tree.node.ObserveNode;
|
|
| 30 |
-import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper;
|
|
| 31 |
-import fr.ird.observe.application.swing.ui.tree.node.RouteSeineNode;
|
|
| 32 |
-import fr.ird.observe.application.swing.ui.tree.actions.ChangeActivityRouteActionListener;
|
|
| 33 |
-import fr.ird.observe.application.swing.ui.tree.actions.NodeChangeActionListener;
|
|
| 34 |
-import fr.ird.observe.application.swing.ui.util.DecoratedNodeEntity;
|
|
| 35 |
-import fr.ird.observe.application.swing.decoration.decorators.DataReferenceDecorator;
|
|
| 36 |
- |
|
| 37 |
-import java.util.ArrayList;
|
|
| 38 |
-import java.util.List;
|
|
| 39 |
- |
|
| 40 |
-/**
|
|
| 41 |
- * @author Kevin Morin (Code Lutin)
|
|
| 42 |
- * @since 5.0
|
|
| 43 |
- */
|
|
| 44 |
-public class MoveActivitySeineNodeMenuPopulator extends MoveNodeMenuPopulator {
|
|
| 45 |
- |
|
| 46 |
- @Override
|
|
| 47 |
- public NodeChangeActionListener createChangeActionListener(ObserveTreeHelper treeHelper,
|
|
| 48 |
- ObserveSwingDataSource dataSource,
|
|
| 49 |
- String id,
|
|
| 50 |
- String parentId) {
|
|
| 51 |
- return new ChangeActivityRouteActionListener(treeHelper, dataSource, id, parentId);
|
|
| 52 |
- }
|
|
| 53 |
- |
|
| 54 |
- @Override
|
|
| 55 |
- public List<DecoratedNodeEntity> getPossibleParentNodes(ObserveNode activitySeineNode, ObserveTreeHelper treeHelper) {
|
|
| 56 |
- |
|
| 57 |
- // noeud de route parent
|
|
| 58 |
- ObserveNode parentNode = activitySeineNode.getParent().getParent();
|
|
| 59 |
- |
|
| 60 |
- // noeud de route de la marée sans le parent actuel
|
|
| 61 |
- List<DecoratedNodeEntity> possibleParents = new ArrayList<>();
|
|
| 62 |
- |
|
| 63 |
- // noeud des routes de la marée
|
|
| 64 |
- ObserveNode routesNode = parentNode.getParent();
|
|
| 65 |
- |
|
| 66 |
- DecoratorService decoratorService = treeHelper.getTreeCellRenderer().getDecoratorService();
|
|
| 67 |
- DataReferenceDecorator<RouteDto> routeDecorator = decoratorService.getDataReferenceDecorator(RouteDto.class);
|
|
| 68 |
- |
|
| 69 |
- for (int i = 0, n = routesNode.getChildCount(); i < n; i++) {
|
|
| 70 |
- |
|
| 71 |
- RouteSeineNode routeNode = (RouteSeineNode) routesNode.getChildAt(i);
|
|
| 72 |
- String routeId = routeNode.getId();
|
|
| 73 |
- |
|
| 74 |
- // si le noeud de marée n'est pas le même que le parent actuel
|
|
| 75 |
- // si le noeud est bien un noeud de marée seine
|
|
| 76 |
- if (!parentNode.equals(routeNode) && IdHelper.isRouteId(routeId)) {
|
|
| 77 |
- |
|
| 78 |
- possibleParents.add(DecoratedNodeEntity.newDecoratedNodeEntity(routeNode, routeDecorator));
|
|
| 79 |
- |
|
| 80 |
- }
|
|
| 81 |
- }
|
|
| 82 |
- |
|
| 83 |
- return possibleParents;
|
|
| 84 |
- }
|
|
| 85 |
-}
|
| 1 |
-package fr.ird.observe.application.swing.ui.tree.menu;
|
|
| 2 |
- |
|
| 3 |
-/*-
|
|
| 4 |
- * #%L
|
|
| 5 |
- * ObServe :: Application Swing
|
|
| 6 |
- * %%
|
|
| 7 |
- * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io
|
|
| 8 |
- * %%
|
|
| 9 |
- * This program is free software: you can redistribute it and/or modify
|
|
| 10 |
- * it under the terms of the GNU General Public License as
|
|
| 11 |
- * published by the Free Software Foundation, either version 3 of the
|
|
| 12 |
- * License, or (at your option) any later version.
|
|
| 13 |
- *
|
|
| 14 |
- * This program is distributed in the hope that it will be useful,
|
|
| 15 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 |
- * GNU General Public License for more details.
|
|
| 18 |
- *
|
|
| 19 |
- * You should have received a copy of the GNU General Public
|
|
| 20 |
- * License along with this program. If not, see
|
|
| 21 |
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 |
- * #L%
|
|
| 23 |
- */
|
|
| 24 |
- |
|
| 25 |
-import fr.ird.observe.application.swing.db.ObserveSwingDataSource;
|
|
| 26 |
-import fr.ird.observe.application.swing.ui.tree.node.ObserveNode;
|
|
| 27 |
-import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper;
|
|
| 28 |
-import fr.ird.observe.application.swing.ui.tree.actions.NodeChangeActionListener;
|
|
| 29 |
-import fr.ird.observe.application.swing.ui.util.DecoratedNodeEntity;
|
|
| 30 |
- |
|
| 31 |
-import java.util.List;
|
|
| 32 |
- |
|
| 33 |
-/**
|
|
| 34 |
- * Objets pour créer les items du menu déplacer dans le menu contextuel de l'arbre
|
|
| 35 |
- *
|
|
| 36 |
- * @author Kevin Morin (Code Lutin)
|
|
| 37 |
- * @since 5.0
|
|
| 38 |
- */
|
|
| 39 |
-public abstract class MoveNodeMenuPopulator {
|
|
| 40 |
- |
|
| 41 |
- /**
|
|
| 42 |
- * Crée une action pour déplacer le noeud quand on sélectionne le menu du nouveau parent
|
|
| 43 |
- * @param treeHelper
|
|
| 44 |
- * @param dataSource
|
|
| 45 |
- * @param id
|
|
| 46 |
- * @param parentId
|
|
| 47 |
- * @return
|
|
| 48 |
- */
|
|
| 49 |
- public abstract NodeChangeActionListener createChangeActionListener(ObserveTreeHelper treeHelper,
|
|
| 50 |
- ObserveSwingDataSource dataSource,
|
|
| 51 |
- String id,
|
|
| 52 |
- String parentId);
|
|
| 53 |
- |
|
| 54 |
- /**
|
|
| 55 |
- * Récupère les parents dans lesquels on peut déplacer le noeud sélectionné
|
|
| 56 |
- * @param node le noeud sélectionné
|
|
| 57 |
- * @param treeHelper le treehelper
|
|
| 58 |
- * @return une liste contenant les ids et les libellés des noeuds
|
|
| 59 |
- */
|
|
| 60 |
- public abstract List<DecoratedNodeEntity> getPossibleParentNodes(ObserveNode node, ObserveTreeHelper treeHelper);
|
|
| 61 |
- |
|
| 62 |
-}
|
| 1 |
-package fr.ird.observe.application.swing.ui.tree.menu;
|
|
| 2 |
- |
|
| 3 |
-/*-
|
|
| 4 |
- * #%L
|
|
| 5 |
- * ObServe :: Application Swing
|
|
| 6 |
- * %%
|
|
| 7 |
- * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io
|
|
| 8 |
- * %%
|
|
| 9 |
- * This program is free software: you can redistribute it and/or modify
|
|
| 10 |
- * it under the terms of the GNU General Public License as
|
|
| 11 |
- * published by the Free Software Foundation, either version 3 of the
|
|
| 12 |
- * License, or (at your option) any later version.
|
|
| 13 |
- *
|
|
| 14 |
- * This program is distributed in the hope that it will be useful,
|
|
| 15 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 |
- * GNU General Public License for more details.
|
|
| 18 |
- *
|
|
| 19 |
- * You should have received a copy of the GNU General Public
|
|
| 20 |
- * License along with this program. If not, see
|
|
| 21 |
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 |
- * #L%
|
|
| 23 |
- */
|
|
| 24 |
- |
|
| 25 |
-import fr.ird.observe.application.swing.db.ObserveSwingDataSource;
|
|
| 26 |
-import fr.ird.observe.services.dto.IdHelper;
|
|
| 27 |
-import fr.ird.observe.services.dto.seine.TripSeineDto;
|
|
| 28 |
-import fr.ird.observe.application.swing.decoration.DecoratorService;
|
|
| 29 |
-import fr.ird.observe.application.swing.ui.tree.node.ObserveNode;
|
|
| 30 |
-import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper;
|
|
| 31 |
-import fr.ird.observe.application.swing.ui.tree.node.TripSeineNode;
|
|
| 32 |
-import fr.ird.observe.application.swing.ui.tree.actions.ChangeRouteTripActionListener;
|
|
| 33 |
-import fr.ird.observe.application.swing.ui.tree.actions.NodeChangeActionListener;
|
|
| 34 |
-import fr.ird.observe.application.swing.ui.util.DecoratedNodeEntity;
|
|
| 35 |
-import fr.ird.observe.application.swing.decoration.decorators.DataReferenceDecorator;
|
|
| 36 |
- |
|
| 37 |
-import java.util.ArrayList;
|
|
| 38 |
-import java.util.List;
|
|
| 39 |
- |
|
| 40 |
-/**
|
|
| 41 |
- * @author Kevin Morin (Code Lutin)
|
|
| 42 |
- * @since 5.0
|
|
| 43 |
- */
|
|
| 44 |
-public class MoveRouteNodeMenuPopulator extends MoveNodeMenuPopulator {
|
|
| 45 |
- |
|
| 46 |
- @Override
|
|
| 47 |
- public NodeChangeActionListener createChangeActionListener(ObserveTreeHelper treeHelper,
|
|
| 48 |
- ObserveSwingDataSource dataSource,
|
|
| 49 |
- String id,
|
|
| 50 |
- String parentId) {
|
|
| 51 |
- return new ChangeRouteTripActionListener(treeHelper, dataSource, id, parentId);
|
|
| 52 |
- }
|
|
| 53 |
- |
|
| 54 |
- @Override
|
|
| 55 |
- public List<DecoratedNodeEntity> getPossibleParentNodes(ObserveNode routeNode, ObserveTreeHelper treeHelper) {
|
|
| 56 |
- |
|
| 57 |
- // noeud de marée parent
|
|
| 58 |
- ObserveNode parentNode = routeNode.getParent().getParent();
|
|
| 59 |
- |
|
| 60 |
- // noeud de marée du programme sans le parent actuel
|
|
| 61 |
- List<DecoratedNodeEntity> possibleParents = new ArrayList<>();
|
|
| 62 |
- |
|
| 63 |
- // noeud du programme
|
|
| 64 |
- ObserveNode programNode = parentNode.getParent();
|
|
| 65 |
- |
|
| 66 |
- DecoratorService decoratorService = treeHelper.getTreeCellRenderer().getDecoratorService();
|
|
| 67 |
- DataReferenceDecorator<TripSeineDto> tripDecorator = decoratorService.getDataReferenceDecorator(TripSeineDto.class);
|
|
| 68 |
- |
|
| 69 |
- for (int i = 0, n = programNode.getChildCount(); i < n; i++) {
|
|
| 70 |
- |
|
| 71 |
- TripSeineNode tripNode = (TripSeineNode) programNode.getChildAt(i);
|
|
| 72 |
- String tripId = tripNode.getId();
|
|
| 73 |
- |
|
| 74 |
- // si le noeud de marée n'est pas le même que le parent actuel
|
|
| 75 |
- // si le noeud est bien un noeud de marée seine
|
|
| 76 |
- if (!parentNode.equals(tripNode) && IdHelper.isTripSeineId(tripId)) {
|
|
| 77 |
- |
|
| 78 |
- possibleParents.add(DecoratedNodeEntity.newDecoratedNodeEntity(tripNode, tripDecorator));
|
|
| 79 |
- |
|
| 80 |
- }
|
|
| 81 |
- }
|
|
| 82 |
- |
|
| 83 |
- return possibleParents;
|
|
| 84 |
- }
|
|
| 85 |
-}
|
| ... | ... | @@ -105,6 +105,14 @@ public class ObserveNode extends NavTreeNode<ObserveNode> { |
| 105 | 105 |
|| TripLonglineDto.class.isAssignableFrom(internalClass));
|
| 106 | 106 |
}
|
| 107 | 107 |
|
| 108 |
+ public boolean isTripSeineNode() {
|
|
| 109 |
+ return isDataNode() && TripSeineDto.class.isAssignableFrom(internalClass);
|
|
| 110 |
+ }
|
|
| 111 |
+ |
|
| 112 |
+ public boolean isTripLonglineNode() {
|
|
| 113 |
+ return isDataNode() && TripLonglineDto.class.isAssignableFrom(internalClass);
|
|
| 114 |
+ }
|
|
| 115 |
+ |
|
| 108 | 116 |
public boolean isRouteNode() {
|
| 109 | 117 |
return isDataNode() && RouteDto.class.isAssignableFrom(internalClass);
|
| 110 | 118 |
}
|