Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe Commits: 8ee80278 by Tony CHEMIT at 2018-09-21T12:08:11Z start to improve navigation popup - - - - - 49c9586a by Tony CHEMIT at 2018-09-21T12:20:37Z Fix some validation messages - - - - - 23 changed files: - client/src/main/java/fr/ird/observe/client/ui/ObserveCommon.jcss - client/src/main/java/fr/ird/observe/client/ui/ObserveKeyStrokes.java - client/src/main/java/fr/ird/observe/client/ui/actions/UIActionSupport.java - + client/src/main/java/fr/ird/observe/client/ui/actions/content/ShowTechnicalInformationsAction.java - client/src/main/java/fr/ird/observe/client/ui/content/ContentUI.jaxx - client/src/main/java/fr/ird/observe/client/ui/content/ContentUI.jcss - client/src/main/java/fr/ird/observe/client/ui/content/ContentUIHandler.java - client/src/main/java/fr/ird/observe/client/ui/content/data/longline/TripLonglineUI.jaxx - client/src/main/java/fr/ird/observe/client/ui/content/data/longline/TripLonglineUI.jcss - client/src/main/java/fr/ird/observe/client/ui/content/data/longline/logbook/ActivityLonglineLogbookUI.jaxx - client/src/main/java/fr/ird/observe/client/ui/content/data/longline/logbook/ActivityLonglineLogbookUI.jcss - client/src/main/java/fr/ird/observe/client/ui/content/data/longline/obs/ActivityLonglineObsUI.jaxx - client/src/main/java/fr/ird/observe/client/ui/content/data/longline/obs/ActivityLonglineObsUI.jcss - client/src/main/java/fr/ird/observe/client/ui/content/data/seine/ActivitySeineUI.jaxx - client/src/main/java/fr/ird/observe/client/ui/content/data/seine/ActivitySeineUI.jcss - client/src/main/java/fr/ird/observe/client/ui/content/data/seine/RouteUI.jaxx - client/src/main/java/fr/ird/observe/client/ui/content/data/seine/RouteUI.jcss - client/src/main/java/fr/ird/observe/client/ui/content/data/seine/TripSeineUI.jaxx - client/src/main/java/fr/ird/observe/client/ui/content/data/seine/TripSeineUI.jcss - client/src/main/java/fr/ird/observe/client/ui/content/ref/ContentReferenceUIHandler.java - client/src/main/java/fr/ird/observe/client/ui/tree/ObserveNavigationTreeShowPopupAction.java - validation/src/main/resources/fr/ird/observe/dto/data/seine/ActivitySeineDto-create-error-validation.xml - validation/src/main/resources/fr/ird/observe/dto/data/seine/ActivitySeineDto-update-error-validation.xml Changes: ===================================== client/src/main/java/fr/ird/observe/client/ui/ObserveCommon.jcss ===================================== @@ -24,6 +24,10 @@ computeI18n:"skip" } +.forceNavigation { + _forceNavigation: true; +} + JToolBar { borderPainted:false; floatable:false; ===================================== client/src/main/java/fr/ird/observe/client/ui/ObserveKeyStrokes.java ===================================== @@ -85,6 +85,7 @@ public abstract class ObserveKeyStrokes { public static final KeyStroke KEY_STROKE_CHANGE_FOCUS = KeyStroke.getKeyStroke("pressed F1"); public static final KeyStroke KEY_STROKE_SAVE = KeyStroke.getKeyStroke("ctrl pressed S"); public static final KeyStroke KEY_STROKE_SHIFT_ALT_ENTER = KeyStroke.getKeyStroke("alt shift pressed ENTER"); + public static final KeyStroke KEY_STROKE_SHOW_TECHNICAL_INFORMATIONS = KeyStroke.getKeyStroke("shift pressed F1"); public static final KeyStroke KEY_STROKE_GO_DOWN = KeyStroke.getKeyStroke("alt pressed D"); public static final KeyStroke KEY_STROKE_ADD_DCP = KeyStroke.getKeyStroke("ctrl pressed P"); public static final KeyStroke KEY_STROKE_ADD_SET_LONGLINE = KeyStroke.getKeyStroke("ctrl pressed L"); ===================================== client/src/main/java/fr/ird/observe/client/ui/actions/UIActionSupport.java ===================================== @@ -82,6 +82,19 @@ public abstract class UIActionSupport extends AbstractAction { } } + + public String getText() { + return (String) getValue(SHORT_DESCRIPTION); + } + + public String getToolTipText() { + return (String) getValue(LONG_DESCRIPTION); + } + + public Icon getIcon() { + return (Icon) getValue(SMALL_ICON); + } + public static void register(Action action, InputMap inputMap, ActionMap actionMap, KeyStroke keyStroke, String actionCommandKey) { if (keyStroke != null) { inputMap.put(keyStroke, actionCommandKey); ===================================== client/src/main/java/fr/ird/observe/client/ui/actions/content/ShowTechnicalInformationsAction.java ===================================== @@ -0,0 +1,162 @@ +package fr.ird.observe.client.ui.actions.content; + +/*- + * #%L + * ObServe :: Client + * %% + * Copyright (C) 2008 - 2018 IRD, Code Lutin, Ultreia.io + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ird.observe.client.ObserveSwingApplicationContext; +import fr.ird.observe.client.ui.ObserveKeyStrokes; +import fr.ird.observe.client.ui.ObserveMainUI; +import fr.ird.observe.client.ui.content.ContentUI; +import fr.ird.observe.client.ui.content.ContentUIModel; +import fr.ird.observe.client.ui.util.SpringUtilities; +import fr.ird.observe.dto.IdDto; +import fr.ird.observe.dto.referential.ReferentialDto; +import org.apache.commons.lang3.time.FastDateFormat; +import org.nuiton.decorator.Decorator; + +import javax.swing.JButton; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JPopupMenu; +import javax.swing.JTextField; +import javax.swing.SpringLayout; +import javax.swing.border.TitledBorder; +import java.awt.Dimension; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; +import java.util.Locale; +import java.util.Objects; + +import static org.nuiton.i18n.I18n.n; +import static org.nuiton.i18n.I18n.t; + +/** + * Created by tchemit on 21/09/2018. + * + * @author Tony Chemit - dev@tchemit.fr + */ +public class ShowTechnicalInformationsAction extends AbstractContentUIAction { + + public static final String ACTION_NAME = ShowTechnicalInformationsAction.class.getName(); + private static final long serialVersionUID = 1L; + + private final FastDateFormat dateFormat; + + public ShowTechnicalInformationsAction(ObserveMainUI mainUI) { + super(mainUI, + ACTION_NAME, + null, + n("observe.action.show.technical.informations.tip"), + "show-informations", + ObserveKeyStrokes.KEY_STROKE_SHOW_TECHNICAL_INFORMATIONS); + putValue(NAME, null); + Locale locale = ObserveSwingApplicationContext.get().getConfig().getLocale(); + if (Locale.ENGLISH.equals(locale)) { + dateFormat = FastDateFormat.getInstance("yyyy-MM-ddZZ hh:mm:ss"); + } else { + dateFormat = FastDateFormat.getInstance("dd/MM/yyyy hh:mm:ss"); + } + } + + @Override + protected void actionPerformed(ContentUI<?, ?> contentUI) { + + JButton button = contentUI.getShowTechnicalInformations(); + + ContentUIModel<?> model = contentUI.getModel(); + IdDto bean = model.isEditing() ? model.getBean() : contentUI.getHandler().getSelectedBean(); + + if (bean.getLastUpdateDate() == null) { + return; + } + + JPanel content = new JPanel(new SpringLayout()); + + FocusListener l = new FocusListener() { + @Override + public void focusGained(FocusEvent e) { + JTextField source = (JTextField) e.getSource(); + source.setSelectionStart(0); + source.setSelectionEnd(source.getText().length()); + } + + @Override + public void focusLost(FocusEvent e) { + + } + }; + + { + content.add(new JLabel(t("observe.common.Dto.topiaId"))); + JTextField comp = new JTextField(bean.getId()); + comp.setEditable(false); + comp.addFocusListener(l); + content.add(comp); + } + + Class<?> beanType = model.getBeanType(); + boolean isReferential = ReferentialDto.class.isAssignableFrom(beanType); + if (isReferential) { + content.add(new JLabel(t("observe.common.Dto.topiaCreateDate"))); + JTextField comp = new JTextField(dateFormat.format(bean.getCreateDate())); + comp.setEditable(false); + comp.addFocusListener(l); + content.add(comp); + } + + { + content.add(new JLabel(t("observe.common.Dto.lastUpdateDate"))); + JTextField comp = new JTextField(dateFormat.format(bean.getLastUpdateDate())); + comp.setEditable(false); + comp.addFocusListener(l); + content.add(comp); + } + + if (isReferential) { + content.add(new JLabel(t("observe.common.Dto.topiaVersion"))); + JTextField comp = new JTextField(String.valueOf(bean.getVersion())); + comp.setEditable(false); + comp.addFocusListener(l); + content.add(comp); + } + + SpringUtilities.makeCompactGrid(content, isReferential ? 4 : 2, 2, 5, 5, 5, 5); + + Decorator<?> decorator = ObserveSwingApplicationContext.get().getDecoratorService().getDecoratorByType(beanType); + Objects.requireNonNull(decorator, "Cant find decorator of type " + beanType); + String title = t("observe.common.Dto.technicalInformations", "\n" + decorator.toString(bean)); + + content.setBorder(new TitledBorder(title)); + + JPopupMenu popup = new JPopupMenu(); + popup.setBorderPainted(true); + popup.add(content); + popup.pack(); + + Dimension dim = popup.getPreferredSize(); + int x = (int) (button.getPreferredSize().getWidth() - dim.getWidth()); + int y = button.getHeight(); + popup.show(button, x, y); + + } + +} ===================================== client/src/main/java/fr/ird/observe/client/ui/content/ContentUI.jaxx ===================================== @@ -36,6 +36,7 @@ fr.ird.observe.client.configuration.ClientConfig fr.ird.observe.client.ui.actions.content.GoUpUIAction fr.ird.observe.client.ui.actions.content.GoDownUIAction + fr.ird.observe.client.ui.actions.content.ShowTechnicalInformationsAction fr.ird.observe.client.ui.content.ContentUIHandler fr.ird.observe.dto.IdDto @@ -47,6 +48,9 @@ javax.swing.JComboBox javax.swing.JList javax.swing.UIManager + javax.swing.AbstractButton + + static org.nuiton.i18n.I18n.t </import> <ClientConfig id='config' initializer='ObserveSwingApplicationContext.get().getConfig()'/> @@ -73,6 +77,8 @@ public abstract ContentUIHandler<E,U> getHandler(); + public List<AbstractButton> getNavigationPopupActions() { return getHandler().getNavigationPopupActions(); } + public Object getSelectedBean(JComboBox combo) { return combo.getSelectedItem(); } @@ -140,8 +146,7 @@ public void createData() { <JButton id='actionDown'/> </JXLayer> - <JButton id='showTechnicalInformations' - onActionPerformed='getHandler().showTechnicalInformations((JButton) event.getSource());'/> + <JButton id='showTechnicalInformations'/> <JLabel id='titleRight'/> </JToolBar> @@ -160,6 +165,9 @@ public void createData() { <JPanel id="invisible" visible='false'> + <JPanel id="navigationActions"> + <!--Place here all actions you want to see in navigation popup but not in the form--> + </JPanel> </JPanel> </org.jdesktop.swingx.JXTitledPanel> ===================================== client/src/main/java/fr/ird/observe/client/ui/content/ContentUI.jcss ===================================== @@ -37,6 +37,7 @@ #actionDown { _observeAction:{GoDownUIAction.ACTION_NAME}; _protectFocus:true; + _skipNavigation:true; } #actionUpPane { @@ -46,6 +47,7 @@ #actionUp { _observeAction:{GoUpUIAction.ACTION_NAME}; _protectFocus:true; + _skipNavigation:true; } @@ -59,8 +61,7 @@ #showTechnicalInformations { _original:true; - toolTipText:"observe.action.show.technical.informations.tip"; - actionIcon:"show-informations"; + _observeAction:{ShowTechnicalInformationsAction.ACTION_NAME}; enabled:{!model.isCreatingMode() && (model.getBean() != null)}; focusPainted:false; borderPainted:false; ===================================== client/src/main/java/fr/ird/observe/client/ui/content/ContentUIHandler.java ===================================== @@ -106,6 +106,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.nuiton.decorator.Decorator; import org.nuiton.decorator.DecoratorUtil; +import org.nuiton.jaxx.runtime.JAXXObject; import org.nuiton.jaxx.runtime.context.DefaultJAXXContext; import org.nuiton.jaxx.validator.swing.SwingValidatorMessageTableModel; import org.nuiton.jaxx.validator.swing.SwingValidatorUtil; @@ -1179,7 +1180,7 @@ public abstract class ContentUIHandler<E extends IdDto, U extends ContentUI<E, U } - protected E getSelectedBean() { + public E getSelectedBean() { return getModel().getBean(); } @@ -1603,4 +1604,55 @@ public abstract class ContentUIHandler<E extends IdDto, U extends ContentUI<E, U List<R> filter(List<R> incomingReferences); } + /** + * @return actions usable in the navigation popup. + */ + public List<AbstractButton> getNavigationPopupActions() { + List<AbstractButton> result = new LinkedList<>(); + collectNavigationPopupActions(result, ui, "actions", "extraActions", "navigationActions", "titleRightToolBar"); + for (Object object : ui.get$objectMap().values()) { + if (object != ui && object instanceof ContentUI) { + collectNavigationPopupActions(result, (JAXXObject) object, "actions", "extraActions", "navigationActions"); + } + } + return result; + } + + protected void collectNavigationPopupActions(List<AbstractButton> result, JAXXObject jaxxObject, String... containers) { + for (Object object : jaxxObject.get$objectMap().values()) { + if (object instanceof AbstractButton) { + AbstractButton button = (AbstractButton) object; + boolean force = Objects.equals(true, button.getClientProperty("forceNavigation")); + if (!force) { + if (!button.isEnabled()) { + log.info("Reject (disabled) action: " + button.getName() + " - " + button.getText()); + continue; + } + if (!button.isShowing()) { + log.info("Reject (hidden) action: " + button.getName() + " - " + button.getText()); + continue; + } + if (Objects.equals(true, button.getClientProperty("skipNavigation"))) { + log.info("Reject (skip) action: " + button.getName() + " - " + button.getText()); + continue; + } + + boolean found = false; + for (String container : containers) { + found = SwingUtilities.getAncestorNamed(container, button) != null; + if (found) { + break; + } + } + if (!found) { + log.info("Reject (out of zone) action: " + button.getName() + " - " + button.getText()); + continue; + } + } + log.info("Keep action: " + button.getName() + " - " + button.getText()); + result.add(button); + } + } + + } } ===================================== client/src/main/java/fr/ird/observe/client/ui/content/data/longline/TripLonglineUI.jaxx ===================================== @@ -40,6 +40,7 @@ fr.ird.observe.dto.referential.longline.ObservationTripTypeReference fr.ird.observe.dto.referential.longline.LogbookTripTypeReference fr.ird.observe.client.ui.actions.content.DeleteDataUIAction + fr.ird.observe.client.ui.actions.content.MoveTripLonglineUIAction fr.ird.observe.client.ui.actions.main.global.DeleteDataGlobalUIAction fr.ird.observe.client.ui.actions.main.global.NewNextDataGlobalUIAction fr.ird.observe.client.ui.util.JComment @@ -355,4 +356,7 @@ protected boolean canEditOcean(java.util.LinkedHashSet<TripLonglineActivityObsDt <JButton id='closeAndCreate'/> <JButton id='actionDown'/> + <JPanel id="forceNavigation"> + <JButton id='move' styleClass="forceNavigation"/> + </JPanel> </fr.ird.observe.client.ui.content.open.ContentOpenableUI> ===================================== client/src/main/java/fr/ird/observe/client/ui/content/data/longline/TripLonglineUI.jcss ===================================== @@ -216,3 +216,7 @@ BigTextEditor { #logbookComment { property:{TripLonglineDto.PROPERTY_LOGBOOK_COMMENT}; } + +#move { + _observeAction:{MoveTripLonglineUIAction.ACTION_NAME}; +} ===================================== client/src/main/java/fr/ird/observe/client/ui/content/data/longline/logbook/ActivityLonglineLogbookUI.jaxx ===================================== @@ -38,6 +38,7 @@ fr.ird.observe.client.ui.actions.content.AddActivityLonglineLogbookSetUIAction fr.ird.observe.client.ui.actions.content.DeleteDataUIAction + fr.ird.observe.client.ui.actions.content.MoveActivityLonglineLogbookUIAction fr.ird.observe.client.ui.actions.main.global.DeleteDataGlobalUIAction fr.ird.observe.client.ui.actions.main.global.OpenDataGlobalUIAction fr.ird.observe.client.ui.actions.main.global.CloseDataGlobalUIAction ===================================== client/src/main/java/fr/ird/observe/client/ui/content/data/longline/logbook/ActivityLonglineLogbookUI.jcss ===================================== @@ -100,3 +100,7 @@ enabled:{!model.isModified() && model.isValid() && model.isSetOperation() && ! bean.isHasSetLongline()}; _observeAction:{AddActivityLonglineLogbookSetUIAction.ACTION_NAME}; } + +#move { + _observeAction:{MoveActivityLonglineLogbookUIAction.ACTION_NAME}; +} \ No newline at end of file ===================================== client/src/main/java/fr/ird/observe/client/ui/content/data/longline/obs/ActivityLonglineObsUI.jaxx ===================================== @@ -35,6 +35,7 @@ fr.ird.observe.client.ui.actions.content.AddActivityLonglineObsSetUIAction fr.ird.observe.client.ui.actions.content.DeleteDataUIAction + fr.ird.observe.client.ui.actions.content.MoveActivityLonglineObsUIAction fr.ird.observe.client.ui.actions.main.global.DeleteDataGlobalUIAction fr.ird.observe.client.ui.actions.main.global.OpenDataGlobalUIAction fr.ird.observe.client.ui.actions.main.global.CloseDataGlobalUIAction @@ -155,5 +156,7 @@ </cell> </row> </Table> - + <JPanel id="forceNavigation"> + <JButton id='move' styleClass="forceNavigation"/> + </JPanel> </fr.ird.observe.client.ui.content.open.ContentOpenableUI> ===================================== client/src/main/java/fr/ird/observe/client/ui/content/data/longline/obs/ActivityLonglineObsUI.jcss ===================================== @@ -97,3 +97,7 @@ _observeAction:{AddActivityLonglineObsSetUIAction.ACTION_NAME}; } + +#move { + _observeAction:{MoveActivityLonglineObsUIAction.ACTION_NAME}; +} ===================================== client/src/main/java/fr/ird/observe/client/ui/content/data/seine/ActivitySeineUI.jaxx ===================================== @@ -44,9 +44,10 @@ org.nuiton.jaxx.widgets.temperature.TemperatureEditor org.nuiton.jaxx.widgets.temperature.TemperatureEditorConfig - fr.ird.observe.client.ui.actions.content.DeleteDataUIAction fr.ird.observe.client.ui.actions.content.AddActivitySeineSetUIAction fr.ird.observe.client.ui.actions.content.AddActivitySeineFloatingObjectUIAction + fr.ird.observe.client.ui.actions.content.DeleteDataUIAction + fr.ird.observe.client.ui.actions.content.MoveActivitySeineUIAction fr.ird.observe.client.ui.util.JComment org.nuiton.jaxx.widgets.number.NumberEditor @@ -303,5 +304,7 @@ </cell> </row> </Table> - + <JPanel id="forceNavigation"> + <JButton id='move' styleClass="forceNavigation"/> + </JPanel> </fr.ird.observe.client.ui.content.open.ContentOpenableUI> ===================================== client/src/main/java/fr/ird/observe/client/ui/content/data/seine/ActivitySeineUI.jcss ===================================== @@ -181,3 +181,6 @@ visible:{bean.isDcpOperation()}; _observeAction:{AddActivitySeineFloatingObjectUIAction.ACTION_NAME}; } +#move { + _observeAction:{MoveActivitySeineUIAction.ACTION_NAME}; +} \ No newline at end of file ===================================== client/src/main/java/fr/ird/observe/client/ui/content/data/seine/RouteUI.jaxx ===================================== @@ -30,6 +30,7 @@ <import> fr.ird.observe.dto.data.seine.RouteDto fr.ird.observe.client.ui.actions.content.DeleteDataUIAction + fr.ird.observe.client.ui.actions.content.MoveRouteUIAction fr.ird.observe.client.ui.util.JComment org.jdesktop.swingx.JXDatePicker @@ -95,5 +96,7 @@ <JButton id='close'/> <JButton id='closeAndCreate'/> <JButton id='actionDown'/> - + <JPanel id="forceNavigation"> + <JButton id='move' styleClass="forceNavigation"/> + </JPanel> </fr.ird.observe.client.ui.content.open.ContentOpenableUI> ===================================== client/src/main/java/fr/ird/observe/client/ui/content/data/seine/RouteUI.jcss ===================================== @@ -66,3 +66,6 @@ NumberEditor { #delete { _toolTipText:{t("observe.common.RouteDto.action.delete.tip")}; } +#move { + _observeAction:{MoveRouteUIAction.ACTION_NAME}; +} \ No newline at end of file ===================================== client/src/main/java/fr/ird/observe/client/ui/content/data/seine/TripSeineUI.jaxx ===================================== @@ -41,6 +41,7 @@ fr.ird.observe.dto.referential.DataQualityReference fr.ird.observe.client.ui.actions.content.DeleteDataUIAction + fr.ird.observe.client.ui.actions.content.MoveTripSeineUIAction fr.ird.observe.client.ui.util.JComment fr.ird.observe.client.ui.util.tripMap.TripMapUI @@ -262,5 +263,7 @@ protected boolean canEditOcean(java.util.LinkedHashSet<RouteStubDto> routes) { <JButton id='close'/> <JButton id='closeAndCreate'/> <JButton id='actionDown'/> - + <JPanel id="forceNavigation"> + <JButton id='move' styleClass="forceNavigation"/> + </JPanel> </fr.ird.observe.client.ui.content.open.ContentOpenableUI> ===================================== client/src/main/java/fr/ird/observe/client/ui/content/data/seine/TripSeineUI.jcss ===================================== @@ -153,3 +153,6 @@ NumberEditor { #delete { _toolTipText:{t("observe.common.TripDto.action.delete.tip")}; } +#move { + _observeAction:{MoveTripSeineUIAction.ACTION_NAME}; +} \ No newline at end of file ===================================== client/src/main/java/fr/ird/observe/client/ui/content/ref/ContentReferenceUIHandler.java ===================================== @@ -414,7 +414,7 @@ public class ContentReferenceUIHandler<D extends ReferentialDto, R extends Refer } @Override - protected D getSelectedBean() { + public D getSelectedBean() { return getModel().getSelectedBean(); } ===================================== client/src/main/java/fr/ird/observe/client/ui/tree/ObserveNavigationTreeShowPopupAction.java ===================================== @@ -10,12 +10,12 @@ package fr.ird.observe.client.ui.tree; * 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>. @@ -24,40 +24,35 @@ package fr.ird.observe.client.ui.tree; import com.google.common.base.Preconditions; import fr.ird.observe.client.ObserveSwingApplicationContext; -import fr.ird.observe.client.ui.actions.content.MoveActivityLonglineLogbookUIAction; -import fr.ird.observe.client.ui.actions.content.MoveActivityLonglineObsUIAction; -import fr.ird.observe.client.ui.actions.content.MoveActivitySeineUIAction; -import fr.ird.observe.client.ui.actions.content.MoveRouteUIAction; -import fr.ird.observe.client.ui.actions.content.MoveTripLonglineUIAction; -import fr.ird.observe.client.ui.actions.content.MoveTripSeineUIAction; +import fr.ird.observe.client.ui.ObserveKeyStrokes; import fr.ird.observe.client.ui.content.ContentUI; -import fr.ird.observe.client.ui.content.open.ContentOpenableUI; import fr.ird.observe.client.ui.tree.navigation.NavigationTree; import fr.ird.observe.client.ui.tree.navigation.nodes.NavigationTreeNodeSupport; -import fr.ird.observe.client.ui.tree.navigation.nodes.ReferenceNavigationTreeNodeSupport; -import fr.ird.observe.dto.data.longline.ActivityLonglineLogbookReference; -import fr.ird.observe.dto.data.longline.ActivityLonglineObsReference; -import fr.ird.observe.dto.data.longline.TripLonglineReference; -import fr.ird.observe.dto.data.seine.ActivitySeineReference; -import fr.ird.observe.dto.data.seine.RouteReference; -import fr.ird.observe.dto.data.seine.TripSeineReference; -import fr.ird.observe.dto.navigation.ObserveNavigationNode; -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.jetbrains.annotations.NotNull; -import javax.swing.JButton; +import javax.swing.AbstractAction; +import javax.swing.AbstractButton; +import javax.swing.Action; import javax.swing.JMenuItem; import javax.swing.JPopupMenu; import javax.swing.JScrollPane; +import javax.swing.KeyStroke; import javax.swing.MenuElement; import javax.swing.SwingUtilities; import javax.swing.tree.TreePath; import java.awt.Point; import java.awt.Rectangle; +import java.awt.event.ActionEvent; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.TreeMap; /** * Created on 1/8/15. @@ -70,21 +65,21 @@ public class ObserveNavigationTreeShowPopupAction { /** Logger. */ private static final Logger log = LogManager.getLogger(ObserveNavigationTreeShowPopupAction.class); - private static final String TRIP_SEINE_MENU_ITEMS = "tripSeine"; - private static final String TRIP_LONGLINE_MENU_ITEMS = "tripLongline"; - private static final String ROUTE_MENU_ITEMS = "route"; - private static final String ACTIVITY_SEINE_MENU_ITEMS = "activitySeine"; - private static final String ACTIVITY_LONGLINE_MENU_ITEMS = "activityLongline"; +// private static final String TRIP_SEINE_MENU_ITEMS = "tripSeine"; +// private static final String TRIP_LONGLINE_MENU_ITEMS = "tripLongline"; +// private static final String ROUTE_MENU_ITEMS = "route"; +// private static final String ACTIVITY_SEINE_MENU_ITEMS = "activitySeine"; +// private static final String ACTIVITY_LONGLINE_MENU_ITEMS = "activityLongline"; private final JPopupMenu popup; private final NavigationTree tree; private final JMenuItem noAction; - private final JMenuItem openAction; - private final JMenuItem closeAction; - private final JMenuItem moveAction; - private final JMenuItem deleteAction; +// private final JMenuItem openAction; +// private final JMenuItem closeAction; +// private final JMenuItem moveAction; +// private final JMenuItem deleteAction; public ObserveNavigationTreeShowPopupAction(NavigationTree tree, JScrollPane pane, JPopupMenu popup) { @@ -92,36 +87,35 @@ public class ObserveNavigationTreeShowPopupAction { this.tree = tree; JMenuItem noActionComponent = null; - // trip menus - JMenuItem moveComponent = null; - JMenuItem openActionComponent = null; - JMenuItem closeActionComponent = null; - JMenuItem deleteActionComponent = null; +// JMenuItem moveComponent = null; +// JMenuItem openActionComponent = null; +// JMenuItem closeActionComponent = null; +// JMenuItem deleteActionComponent = null; for (MenuElement menuElement : popup.getSubElements()) { if (menuElement.getComponent().getName().equals("navigationNoAction")) { noActionComponent = (JMenuItem) menuElement.getComponent(); } - if (menuElement.getComponent().getName().equals("navigationMoveAction")) { - moveComponent = (JMenuItem) menuElement.getComponent(); - } - if (menuElement.getComponent().getName().equals("navigationOpenAction")) { - openActionComponent = (JMenuItem) menuElement.getComponent(); - } - if (menuElement.getComponent().getName().equals("navigationCloseAction")) { - closeActionComponent = (JMenuItem) menuElement.getComponent(); - } - if (menuElement.getComponent().getName().equals("navigationDeleteAction")) { - deleteActionComponent = (JMenuItem) menuElement.getComponent(); - } +// if (menuElement.getComponent().getName().equals("navigationMoveAction")) { +// moveComponent = (JMenuItem) menuElement.getComponent(); +// } +// if (menuElement.getComponent().getName().equals("navigationOpenAction")) { +// openActionComponent = (JMenuItem) menuElement.getComponent(); +// } +// if (menuElement.getComponent().getName().equals("navigationCloseAction")) { +// closeActionComponent = (JMenuItem) menuElement.getComponent(); +// } +// if (menuElement.getComponent().getName().equals("navigationDeleteAction")) { +// deleteActionComponent = (JMenuItem) menuElement.getComponent(); +// } } this.noAction = noActionComponent; - this.openAction = openActionComponent; - this.closeAction = closeActionComponent; - this.moveAction = moveComponent; - this.deleteAction = deleteActionComponent; +// this.openAction = openActionComponent; +// this.closeAction = closeActionComponent; +// this.moveAction = moveComponent; +// this.deleteAction = deleteActionComponent; KeyAdapter keyAdapter = new KeyAdapter() { @Override @@ -146,124 +140,115 @@ public class ObserveNavigationTreeShowPopupAction { pane.addMouseListener(mouseAdapter); } + @NotNull + private static String removeKeyStroke(String text) { + int lastIndex = text.lastIndexOf('('); + if (lastIndex > -1) { + text = text.substring(0, lastIndex - 1).trim(); + } + return text; + } + private void autoSelectNodeInTree(MouseEvent e) { + boolean rightClick = SwingUtilities.isRightMouseButton(e); + if (rightClick) { + // get the coordinates of the mouse click Point p = e.getPoint(); + int closestRowForLocation = tree.getClosestRowForLocation(e.getX(), e.getY()); + int rowToSelect = -1; + if (isRowSelected(closestRowForLocation)) { + rowToSelect = closestRowForLocation; } + if (rowToSelect == -1) { + // try to change selection + TreePath pathForRow = tree.getPathForRow(closestRowForLocation); tree.setSelectionPath(pathForRow); + if (isRowSelected(closestRowForLocation)) { + rowToSelect = closestRowForLocation; } + } + if (rowToSelect != -1) { + showPopup(rowToSelect, p); + } + } } private void openNodeMenu(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_CONTEXT_MENU && !tree.isSelectionEmpty()) { + // get the lowest selected row int lowestRow = getLowestSelectedRowCount(); + // get the selected column Rectangle r = tree.getRowBounds(lowestRow); + // get the point in the middle lower of the cell Point p = new Point(r.x + r.width / 2, r.y + r.height); - log.debug("Row " + lowestRow + " found t point [" + p + "]"); + + if (log.isDebugEnabled()) { + log.debug("Row " + lowestRow + " found t point [" + p + "]"); + } + showPopup(lowestRow, p); + } } private void showPopup(int row, Point p) { + log.info("Will show popup from row: " + row); + NavigationTreeNodeSupport selectedNode = (NavigationTreeNodeSupport) tree.getPathForRow(row).getLastPathComponent(); + log.info("Found selected node: " + selectedNode); - beforeOpenPopup(selectedNode); - popup.show(tree, p.x, p.y); + + SwingUtilities.invokeLater(() -> { + beforeOpenPopup(selectedNode); + popup.show(tree, p.x, p.y); + }); + } - //FIXME private void beforeOpenPopup(NavigationTreeNodeSupport selectedNode) { + + // clean popup popup.removeAll(); + popup.setLabel(selectedNode.getText()); ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get(); -// ClientDataContext dataContext = applicationContext.getDataContext(); ContentUI<?, ?> selectedContentUI = applicationContext.getContentUIManager().getSelectedContentUI(); - ObserveNavigationNode<?> selectedNodeId = selectedContentUI.getHandler().getSelectedNode(); - String selectedId = selectedNodeId.getId(); - ObserveNavigationNode<?> editNode = selectedContentUI.getHandler().getEditNode(); -// ObserveOpenDataManager openDataManager = applicationContext.getOpenDataManager(); - boolean closeActionEnabled = false; - if (selectedContentUI instanceof ContentOpenableUI) { - JButton closeButton = ((ContentOpenableUI) selectedContentUI).getClose(); - closeActionEnabled = closeButton.isEnabled(); + List<AbstractButton> actions = selectedContentUI.getNavigationPopupActions(); + if (actions.isEmpty()) { + popup.add(noAction); + } else { + Map<String, AbstractButton> actionMap = new TreeMap<>(); + actions.forEach(a -> actionMap.put(getActionText(a), a)); + actionMap.forEach(this::addAction); } -// Class dataType = selectedNode.getDataType(); -// if (TripSeineReference.class.equals(dataType)) { -// beforeOpenMenu((ReferenceNavigationTreeNodeSupport) selectedNode, TRIP_SEINE_MENU_ITEMS); -// openAction.setEnabled(editNode.isDisabled()); -// closeAction.setEnabled(closeActionEnabled); -// } else if (TripLonglineReference.class.equals(dataType)) { -// beforeOpenMenu((ReferenceNavigationTreeNodeSupport) selectedNode, TRIP_LONGLINE_MENU_ITEMS); -// openAction.setEnabled(editNode.isDisabled()); -// closeAction.setEnabled(closeActionEnabled); -// } else if (RouteReference.class.equals(dataType)) { -// beforeOpenMenu((ReferenceNavigationTreeNodeSupport) selectedNode, ROUTE_MENU_ITEMS); -// openAction.setEnabled(openDataManager.canOpenRoute(dataContext.getSelectedTripSeineId())); -// closeAction.setEnabled(closeActionEnabled); -// } else if (ActivitySeineReference.class.equals(dataType)) { -// beforeOpenMenu((ReferenceNavigationTreeNodeSupport) selectedNode, ACTIVITY_SEINE_MENU_ITEMS); -// openAction.setEnabled(openDataManager.canOpenActivitySeine(dataContext.getSelectedRouteId())); -// closeAction.setEnabled(closeActionEnabled); -// } else if (ActivityLonglineObsReference.class.equals(dataType)) { -// beforeOpenMenu((ReferenceNavigationTreeNodeSupport) selectedNode, ACTIVITY_LONGLINE_MENU_ITEMS); -// openAction.setEnabled(openDataManager.canOpenActivityLonglineObs(dataContext.getSelectedTripLonglineId())); -// closeAction.setEnabled(closeActionEnabled); -// } else if (ActivityLonglineLogbookReference.class.equals(dataType)) { -// beforeOpenMenu((ReferenceNavigationTreeNodeSupport) selectedNode, ACTIVITY_LONGLINE_MENU_ITEMS); -// openAction.setEnabled(openDataManager.canOpenActivityLonglineLogbook(dataContext.getSelectedTripLonglineId())); -// closeAction.setEnabled(closeActionEnabled); -// } else { -// popup.add(noAction); -// } } - private void beforeOpenMenu(ReferenceNavigationTreeNodeSupport selectedNode, String nodeType) { - log.info("Will load popup for " + nodeType + " node."); - ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get(); - if (selectedNode.isOpen()) { - closeAction.putClientProperty("ui", applicationContext.getContentUIManager().getSelectedContentUI()); - popup.add(closeAction); - } else { - openAction.putClientProperty("ui", applicationContext.getContentUIManager().getSelectedContentUI()); - popup.add(openAction); - } - Class dataType = selectedNode.getDataType(); - if (TripSeineReference.class.equals(dataType)) { - moveAction.setAction(new MoveTripSeineUIAction(applicationContext.getMainUI())); - } else if (TripLonglineReference.class.equals(dataType)) { - moveAction.setAction(new MoveTripLonglineUIAction(applicationContext.getMainUI())); - } else if (RouteReference.class.equals(dataType)) { - moveAction.setAction(new MoveRouteUIAction(applicationContext.getMainUI())); - } else if (ActivitySeineReference.class.equals(dataType)) { - moveAction.setAction(new MoveActivitySeineUIAction(applicationContext.getMainUI())); - } else if (ActivityLonglineObsReference.class.equals(dataType)) { - moveAction.setAction(new MoveActivityLonglineObsUIAction(applicationContext.getMainUI())); - } else if (ActivityLonglineLogbookReference.class.equals(dataType)) { - moveAction.setAction(new MoveActivityLonglineLogbookUIAction(applicationContext.getMainUI())); - } - popup.add(moveAction); - deleteAction.putClientProperty("ui", applicationContext.getContentUIManager().getSelectedContentUI()); - deleteAction.setEnabled(selectedNode.isOpen()); - popup.add(deleteAction); + private void addAction(String text, AbstractButton abstractButton) { + JMenuItem menuItem = new JMenuItem(); + MenuAction menuAction = new MenuAction(abstractButton, text, popup.getComponentCount()); + menuItem.setAction(menuAction); + popup.add(menuItem); } private boolean isRowSelected(int requiredRow) { @@ -272,6 +257,7 @@ public class ObserveNavigationTreeShowPopupAction { if (selectedRows != null) { for (int selectedRow : selectedRows) { if (requiredRow == selectedRow) { + // match result = true; break; @@ -293,4 +279,41 @@ public class ObserveNavigationTreeShowPopupAction { return lowestRow; } + private String getActionText(AbstractButton abstractButton) { + String text = abstractButton.getText(); + if (text == null || text.equals(abstractButton.getName())) { + text = abstractButton.getToolTipText(); + } + Objects.requireNonNull(text, "Button with no text, nor tip, kind of strange, don't you think?"); + return text; + } + + private static class MenuAction extends AbstractAction { + + private final Action action; + + MenuAction(AbstractButton abstractButton, String text, int pos) { + super(removeKeyStroke(text), abstractButton.getIcon()); + int a = 'A' + pos; + KeyStroke keyStroke = KeyStroke.getKeyStroke("ctrl pressed " + (char) a); + putValue(ACCELERATOR_KEY, keyStroke); + String toolTipText = abstractButton.getToolTipText(); + if (toolTipText != null) { + toolTipText = removeKeyStroke(toolTipText); + toolTipText = ObserveKeyStrokes.suffixTextWithKeyStroke(toolTipText, keyStroke); + putValue(SHORT_DESCRIPTION, toolTipText); + } + this.action = new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + abstractButton.doClick(); + } + }; + } + + @Override + public void actionPerformed(ActionEvent e) { + action.actionPerformed(e); + } + } } ===================================== validation/src/main/resources/fr/ird/observe/dto/data/seine/ActivitySeineDto-create-error-validation.xml ===================================== @@ -179,7 +179,7 @@ <field-validator type="quadrantDto" short-circuit="true"> <param name="ocean">currentTripSeine.ocean</param> <message> - observe.validation.activity.invalid.quadrant##${currentTripSeine.ocean.libelle} + observe.validation.activity.invalid.quadrant##${currentTripSeine.ocean.label} </message> </field-validator> ===================================== validation/src/main/resources/fr/ird/observe/dto/data/seine/ActivitySeineDto-update-error-validation.xml ===================================== @@ -37,7 +37,7 @@ <field-validator type="quadrantDto" short-circuit="true"> <param name="ocean">currentTripSeine.ocean</param> <message> - observe.validation.activity.invalid.quadrant##${currentTripSeine.ocean.libelle} + observe.validation.activity.invalid.quadrant##${currentTripSeine.ocean.label} </message> </field-validator> View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/compare/3071f6df9ed75c7aa631dc9efd0... -- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/compare/3071f6df9ed75c7aa631dc9efd0... You're receiving this email because of your account on gitlab.com.
participants (1)
-
Tony CHEMIT