This is an automated email from the git hooks/post-receive script. New commit to branch feature/7622 in repository observe. See http://git.codelutin.com/observe.git commit e7d132e9f24b0498d0a84492cd347195be6a8dab Author: Kevin Morin <morin@codelutin.com> Date: Tue Nov 17 12:00:02 2015 +0100 ajout du bouton pour déplacer des routes depuis la liste (refs #7622) --- .../ui/actions/shared/MoveRoutesUIAction.java | 225 +++++++++++++++++++++ .../ui/content/list/impl/seine/RoutesUI.css | 7 + .../ui/content/list/impl/seine/RoutesUI.jaxx | 3 + 3 files changed, 235 insertions(+) diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/actions/shared/MoveRoutesUIAction.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/actions/shared/MoveRoutesUIAction.java new file mode 100644 index 0000000..5c23822 --- /dev/null +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/actions/shared/MoveRoutesUIAction.java @@ -0,0 +1,225 @@ +/* + * #%L + * ObServe :: Swing + * %% + * Copyright (C) 2008 - 2010 IRD, Codelutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +package fr.ird.observe.ui.actions.shared; + +import com.google.common.collect.Lists; +import fr.ird.observe.ObserveOpenDataManager; +import fr.ird.observe.ObserveSwingApplicationContext; +import fr.ird.observe.services.dto.ReferenceDto; +import fr.ird.observe.services.dto.ReferenceDtos; +import fr.ird.observe.services.dto.referential.ProgramDto; +import fr.ird.observe.services.dto.seine.TripSeineDto; +import fr.ird.observe.services.service.seine.RouteService; +import fr.ird.observe.services.service.seine.TripSeineService; +import fr.ird.observe.ui.DecoratorService; +import fr.ird.observe.ui.ObserveMainUI; +import fr.ird.observe.ui.content.ContentUI; +import fr.ird.observe.ui.content.list.ContentListUIModel; +import fr.ird.observe.ui.content.list.impl.seine.RoutesUI; +import fr.ird.observe.ui.tree.ObserveNode; +import fr.ird.observe.ui.tree.ObserveTreeHelper; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.decorator.Decorator; + +import javax.swing.JComponent; +import javax.swing.JOptionPane; +import javax.swing.SwingUtilities; +import java.awt.event.ActionEvent; +import java.util.ArrayList; +import java.util.LinkedHashSet; +import java.util.List; + +import static org.nuiton.i18n.I18n.n; +import static org.nuiton.i18n.I18n.t; + +/** + * Action pour changer le programme d'une ou plusieurs marée dans la liste. + * + * @author Kevin Morin (Code Lutin) + * @since 5.0 + */ +public class MoveRoutesUIAction extends AbstractUIAction { + + private static final long serialVersionUID = 1L; + + /** + * Logger. + */ + private static final Log log = LogFactory.getLog(MoveRoutesUIAction.class); + + public static final String ACTION_NAME = "moveRoutes"; + + public MoveRoutesUIAction(ObserveMainUI mainUI, String actionName) { + super(mainUI, + actionName, + n("observe.action.move.routes"), + n("observe.action.move.routes.tip"), + "move-trips" + ); + } + + @Override + public void actionPerformed(final ActionEvent e) { + + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + JComponent c = (JComponent) e.getSource(); + ContentUI<?> ui = (ContentUI<?>) + c.getClientProperty("ui"); + if (ui == null) { + throw new IllegalStateException( + "could not find client property " + + "ui on component" + c); + } + + if (!(ui instanceof RoutesUI)) { + throw new IllegalStateException("Can not come here!"); + } + + // get current program id + ObserveTreeHelper treeHelper = getMainUI().getTreeHelper(); + ObserveNode oldRoutesNode = treeHelper.getSelectedNode(); + String oldTripSeineId = oldRoutesNode.getParent().getId(); + + // choose the new program + String tripSeineId = chooseNewTripSeine(ui, oldTripSeineId); + + // change the program of the selected trips + List<ReferenceDto> selectedDatas = ((ContentListUIModel) ui.getModel()).getSelectedDatas(); + List<String> routeIds = Lists.transform(selectedDatas, ReferenceDtos.getIdFunction()); + RouteService service = ObserveSwingApplicationContext.get().newService(RouteService.class); + List<Integer> positions = service.moveRoutesToTripSeine(routeIds, tripSeineId); + + // update the tree + updateTree(ui, oldRoutesNode, oldTripSeineId, tripSeineId, routeIds, positions); + + } + }); + + } + + protected String chooseNewTripSeine(ContentUI<?> ui, String oldProgramId) { + ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get(); + + LinkedHashSet<ReferenceDto> allTripSeines = applicationContext.newService(TripSeineService.class) + .getAllTripSeine() + .getReference(); + + List<ReferenceDto<TripSeineDto>> tripSeines = new ArrayList<>(ReferenceDtos.castToCollectionOfReferenceDto(allTripSeines)); + + Decorator<ReferenceDto> decorator = applicationContext.getDecorator(ReferenceDto.class, + ProgramDto.class.getSimpleName()); + + //on crée un tableau avec un programme en moins car on ne propose pas le programme actuel + DecoratedTripSeine[] decoratedTripSeines = new DecoratedTripSeine[tripSeines.size() - 1]; + + int j = 0; + for (ReferenceDto tripSeine : tripSeines) { + if (!oldProgramId.equals(tripSeine.getId())) { + decoratedTripSeines[j++] = new DecoratedTripSeine(tripSeine.getId(), decorator.toString(tripSeine)); + } + } + + Object decoratedProgram = JOptionPane.showInputDialog(ui, + t("observe.action.choose.program.message"), + t("observe.action.choose.program.title"), + JOptionPane.QUESTION_MESSAGE, + null, + decoratedTripSeines, + null); + return ((DecoratedTripSeine) decoratedProgram).getId(); + } + + protected void updateTree(ContentUI<?> ui, + ObserveNode oldRoutesNode, + String oldTripSeineId, + String tripSeineId, + List<String> routeIds, + List<Integer> positions) { + + ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get(); + ObserveOpenDataManager openDataManager = applicationContext.getOpenDataManager(); + ObserveTreeHelper treeHelper = getMainUI().getTreeHelper(); + + ObserveNode oldTripSeineNode = oldRoutesNode.getParent(); + ObserveNode programNode = oldTripSeineNode.getParent(); + ObserveNode newTripSeineNode = treeHelper.getChild(programNode, tripSeineId); + String routesNodeId = DecoratorService.getPropertyLabel(ObserveTreeHelper.TREE_NODE_PREFIX, + TripSeineDto.PROPERTY_ROUTE); + ObserveNode newRoutesNode = treeHelper.getChild(newTripSeineNode, routesNodeId); + + for (int i = 0, s = positions.size(); i < s; i++) { + + String routeId = routeIds.get(i); + ObserveNode routeNode = treeHelper.getChild(oldRoutesNode, routeId); + boolean wasOpen = routeNode.isOpen(); + treeHelper.removeNode(routeNode); + + if (wasOpen) { + openDataManager.closeTripSeine(oldTripSeineId); + openDataManager.openTripSeine(programNode.getId(), tripSeineId); + } + + ObserveNode newRouteNode = treeHelper.getChild(newTripSeineNode, routeId); + + if (newRouteNode == null) { + + // create it + if (log.isInfoEnabled()) { + log.info("Insert route node: "); + } + //FIXME l'ordre n'est pas le bon + treeHelper.insertNode(newRoutesNode, newRouteNode, positions.get(i)); + } + } + ContentListUIModel model = (ContentListUIModel) ui.getModel(); + List<ReferenceDto> data = new ArrayList<>(model.getData()); + data.removeAll(model.getSelectedDatas()); + model.setData(data); + + treeHelper.reloadNode(programNode, true); + treeHelper.selectNode(newTripSeineNode); + } + + public static class DecoratedTripSeine { + + private final String id; + private final String label; + + public DecoratedTripSeine(String id, String label) { + this.id = id; + this.label = label; + } + + public String getId() { + return id; + } + + @Override + public String toString() { + return label; + } + } +} diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/RoutesUI.css b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/RoutesUI.css index 7e2c1a8..a545bd0 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/RoutesUI.css +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/RoutesUI.css @@ -34,3 +34,10 @@ toolTipText:"observe.action.create.route.tip"; } +#moveSelectedTrips { + text:"observe.action.move.routes"; + toolTipText:"observe.action.move.routes.tip"; + enabled:{model.getSelectedDatas() != null}; + _observeAction:{MoveRoutesUIAction.ACTION_NAME}; +} + diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/RoutesUI.jaxx b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/RoutesUI.jaxx index 2f9815e..76ae079 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/RoutesUI.jaxx +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/RoutesUI.jaxx @@ -29,6 +29,8 @@ fr.ird.observe.services.dto.seine.TripSeineDto fr.ird.observe.services.dto.seine.RouteDto fr.ird.observe.ui.actions.shared.SelectOpenNodeUIAction + fr.ird.observe.ui.actions.shared.MoveRoutesUIAction + static org.nuiton.i18n.I18n.n </import> @@ -49,6 +51,7 @@ <JButton id='gotoOpenChild' styleClass='gotoOpenRoute'/> <JButton id='gotoOpenChild2' styleClass='gotoOpenRoute2'/> <JButton id='createChild'/> + <JButton id='moveSelectedChildren'/> <!-- extra actions --> <Table id='extraActions' fill="both" weightx="1" insets='2'> -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.