branch develop updated (022a6c3 -> f8c4707)
This is an automated email from the git hooks/post-receive script. New change to branch develop in repository observe. See https://gitlab.nuiton.org/codelutin/observe.git from 022a6c3 Merge branch 'feature/6' into 'develop' new f8c4707 Rendre le dialogue de désactivation plus explicite (fixes #8879) (report version 6) The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit f8c470701b7fa9da77c111bc3adfbd4cc2a75f85 Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Dec 16 09:37:34 2016 +0100 Rendre le dialogue de désactivation plus explicite (fixes #8879) (report version 6) Summary of changes: .../ird/observe/application/swing/ui/UIHelper.java | 126 +++++++++++-- .../swing/ui/admin/export/ExportUIHandler.java | 5 +- .../ui/content/ref/ContentReferenceUIHandler.java | 57 +++--- .../ref/usage/UsageForDeleteUI.jaxx} | 56 +++--- .../content/ref/usage/UsageForDeleteUIHandler.java | 48 +++++ .../ref/usage/UsageForDesactivateUI.jaxx} | 58 +++--- .../ref/usage/UsageForDesactivateUIHandler.java | 49 +++++ .../ui/content/ref/usage/UsageForDisplayUI.jaxx | 62 +++++++ .../ref/usage/UsageForDisplayUIHandler.java | 31 ++++ .../content/ref/usage/UsageUIHandlerSupport.java | 171 ++++++++++++++++++ .../swing/ui/usage/UsagesUIHandler.java | 197 --------------------- .../i18n/application-swing_en_GB.properties | 1 + .../i18n/application-swing_es_ES.properties | 1 + .../i18n/application-swing_fr_FR.properties | 1 + 14 files changed, 563 insertions(+), 300 deletions(-) copy application-swing/src/main/java/fr/ird/observe/application/swing/ui/{usage/UsagesUI.jaxx => content/ref/usage/UsageForDeleteUI.jaxx} (54%) create mode 100644 application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ref/usage/UsageForDeleteUIHandler.java rename application-swing/src/main/java/fr/ird/observe/application/swing/ui/{usage/UsagesUI.jaxx => content/ref/usage/UsageForDesactivateUI.jaxx} (54%) create mode 100644 application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ref/usage/UsageForDesactivateUIHandler.java create mode 100644 application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ref/usage/UsageForDisplayUI.jaxx create mode 100644 application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ref/usage/UsageForDisplayUIHandler.java create mode 100644 application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ref/usage/UsageUIHandlerSupport.java delete mode 100644 application-swing/src/main/java/fr/ird/observe/application/swing/ui/usage/UsagesUIHandler.java -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository observe. See https://gitlab.nuiton.org/codelutin/observe.git commit f8c470701b7fa9da77c111bc3adfbd4cc2a75f85 Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Dec 16 09:37:34 2016 +0100 Rendre le dialogue de désactivation plus explicite (fixes #8879) (report version 6) --- .../ird/observe/application/swing/ui/UIHelper.java | 126 +++++++++++-- .../swing/ui/admin/export/ExportUIHandler.java | 5 +- .../ui/content/ref/ContentReferenceUIHandler.java | 57 +++--- .../ref/usage/UsageForDeleteUI.jaxx} | 56 +++--- .../content/ref/usage/UsageForDeleteUIHandler.java | 48 +++++ .../ref/usage/UsageForDesactivateUI.jaxx} | 58 +++--- .../ref/usage/UsageForDesactivateUIHandler.java | 49 +++++ .../ui/content/ref/usage/UsageForDisplayUI.jaxx | 62 +++++++ .../ref/usage/UsageForDisplayUIHandler.java | 31 ++++ .../content/ref/usage/UsageUIHandlerSupport.java | 171 ++++++++++++++++++ .../swing/ui/usage/UsagesUIHandler.java | 197 --------------------- .../i18n/application-swing_en_GB.properties | 1 + .../i18n/application-swing_es_ES.properties | 1 + .../i18n/application-swing_fr_FR.properties | 1 + 14 files changed, 563 insertions(+), 300 deletions(-) diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/UIHelper.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/UIHelper.java index df3edef..17406bb 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/UIHelper.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/UIHelper.java @@ -46,6 +46,7 @@ import org.nuiton.decorator.Decorator; import org.nuiton.jaxx.runtime.JaxxFileChooser; import javax.swing.JComponent; +import javax.swing.JDialog; import javax.swing.JOptionPane; import javax.swing.JScrollPane; import javax.swing.JTable; @@ -54,15 +55,25 @@ import javax.swing.SwingUtilities; import javax.swing.UIDefaults; import javax.swing.table.TableCellEditor; import javax.swing.table.TableCellRenderer; +import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; +import java.awt.Container; import java.awt.Toolkit; import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.StringSelection; +import java.awt.event.ComponentAdapter; +import java.awt.event.ComponentEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; import java.io.File; import java.io.IOException; import java.util.Arrays; +import static javax.swing.JOptionPane.CLOSED_OPTION; +import static javax.swing.JOptionPane.VALUE_PROPERTY; import static org.nuiton.i18n.I18n.t; /** @@ -166,25 +177,118 @@ public class UIHelper extends SwingUtil { } - public static int askUser(String title, String message, int typeMessage, Object[] options, int defaultOption) { - return askUser(null, title, message, typeMessage, options, defaultOption); + public static int askUser(String title, + String message, + int typeMessage, + Object[] options, + int defaultOption) { + return askUser( + null, + title, + message, + typeMessage, + options, + defaultOption + ); } - public static int askUser(Component parent, String title, Object message, int typeMessage, Object[] options, int defaultOption) { + public static int askUser(Component parent, + String title, + Object message, + int typeMessage, + Object[] options, + int defaultOption) { if (parent == null) { ObserveSwingApplicationContext tx = ObserveSwingApplicationContext.get(); if (tx != null) { parent = ObserveSwingApplicationContext.get().getMainUI(); } } - return JOptionPane.showOptionDialog(parent, - message, - title, - JOptionPane.DEFAULT_OPTION, - typeMessage, - null, - options, - options[defaultOption]); + return JOptionPane.showOptionDialog( + parent, + message, + title, + JOptionPane.DEFAULT_OPTION, + typeMessage, + null, + options, + options[defaultOption] + ); + } + + public static int askUser(JOptionPane pane, + String title, + Object[] options) { + + ObserveMainUI mainUI = ObserveSwingApplicationContext.get().getMainUI(); + JDialog dialog = new JDialog(mainUI, true); + dialog.setTitle(title); + + Container contentPane = dialog.getContentPane(); + + contentPane.setLayout(new BorderLayout()); + contentPane.add(pane, BorderLayout.CENTER); + dialog.setResizable(false); + + dialog.pack(); + dialog.setLocationRelativeTo(mainUI); + + final PropertyChangeListener listener = new PropertyChangeListener() { + public void propertyChange(PropertyChangeEvent event) { + // Let the defaultCloseOperation handle the closing + // if the user closed the window without selecting a button + // (newValue = null in that case). Otherwise, close the dialog. + if (dialog.isVisible() && event.getSource() == pane && + (event.getPropertyName().equals(VALUE_PROPERTY)) && + event.getNewValue() != null && + event.getNewValue() != JOptionPane.UNINITIALIZED_VALUE) { + dialog.setVisible(false); + } + } + }; + + WindowAdapter adapter = new WindowAdapter() { + private boolean gotFocus = false; + + public void windowClosing(WindowEvent we) { + pane.setValue(null); + } + + public void windowClosed(WindowEvent e) { + pane.removePropertyChangeListener(listener); + dialog.getContentPane().removeAll(); + } + + public void windowGainedFocus(WindowEvent we) { + // Once window gets focus, set initial focus + if (!gotFocus) { + pane.selectInitialValue(); + gotFocus = true; + } + } + }; + dialog.addWindowListener(adapter); + dialog.addWindowFocusListener(adapter); + dialog.addComponentListener(new ComponentAdapter() { + public void componentShown(ComponentEvent ce) { + // reset value to ensure closing works properly + pane.setValue(JOptionPane.UNINITIALIZED_VALUE); + } + }); + + pane.addPropertyChangeListener(listener); + + dialog.setVisible(true); + Object selectedValue = pane.getValue(); + + if (selectedValue == null) + return CLOSED_OPTION; + for (int counter = 0, maxCounter = options.length; + counter < maxCounter; counter++) { + if (options[counter].equals(selectedValue)) + return counter; + } + return CLOSED_OPTION; } /** diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/export/ExportUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/export/ExportUIHandler.java index 94564b7..fddfae2 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/export/ExportUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/export/ExportUIHandler.java @@ -33,8 +33,8 @@ import fr.ird.observe.application.swing.ui.UIHelper; import fr.ird.observe.application.swing.ui.admin.AdminStep; import fr.ird.observe.application.swing.ui.admin.AdminTabUIHandler; import fr.ird.observe.application.swing.ui.admin.config.ConfigUI; +import fr.ird.observe.application.swing.ui.content.ref.usage.UsageForDisplayUI; import fr.ird.observe.application.swing.ui.tree.selection.SelectionTreeModel; -import fr.ird.observe.application.swing.ui.usage.UsagesUI; import fr.ird.observe.application.swing.ui.util.ProgressModel; import fr.ird.observe.services.dto.AbstractReference; import fr.ird.observe.services.dto.DataReference; @@ -291,9 +291,8 @@ public class ExportUIHandler extends AdminTabUIHandler<ExportUI> implements UIHa String message = t("observe.message.show.usage.for.missingReferentials"); String message2 = t("observe.message.show.usage.for.missingReferentials2"); - UsagesUI usagesUI = new UsagesUI(ui); ReferenceMap usages = localDataSource.getReferentialMap(result.getMissingIds()); - usagesUI.init(message, message2, null, usages, null); + UsageForDisplayUI usagesUI = UsageForDisplayUI.build(message, usages); int reponse = UIHelper.askUser(null, t("observe.title.can.not.export.data"), diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ref/ContentReferenceUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ref/ContentReferenceUIHandler.java index 1c3e9c9..146d216 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ref/ContentReferenceUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ref/ContentReferenceUIHandler.java @@ -30,8 +30,10 @@ import fr.ird.observe.application.swing.decoration.decorators.ReferentialReferen import fr.ird.observe.application.swing.ui.UIHelper; import fr.ird.observe.application.swing.ui.content.ContentMode; import fr.ird.observe.application.swing.ui.content.ContentUIHandler; +import fr.ird.observe.application.swing.ui.content.ref.usage.UsageForDeleteUI; +import fr.ird.observe.application.swing.ui.content.ref.usage.UsageForDesactivateUI; +import fr.ird.observe.application.swing.ui.content.ref.usage.UsageForDisplayUI; import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTree; -import fr.ird.observe.application.swing.ui.usage.UsagesUI; import fr.ird.observe.application.swing.validation.ValidationContext; import fr.ird.observe.services.dto.Form; import fr.ird.observe.services.dto.ReferenceMap; @@ -152,20 +154,23 @@ public class ContentReferenceUIHandler<E extends ReferentialDto, U extends Conte String type = ObserveI18nDecoratorHelper.getTypeI18nKey(entity.getClass()); type = t(type); String message = t("observe.message.show.usage.for.delete", type, decorator.toString(entity)); - String message2 = t("observe.message.show.usage.for.delete2"); - String message3 = t("observe.message.show.usage.for.delete3"); - UsagesUI usagesUI = new UsagesUI(tx); - usagesUI.init(message, message2, message3, usages, (List) referenceList); + UsageForDeleteUI usagesUI = UsageForDeleteUI.build(message, usages, referenceList); - int reponse = UIHelper.askUser(null, + String replaceText = t("observe.choice.replace"); + Object[] options = { + replaceText, + t("observe.choice.cancel")}; + JOptionPane pane = new JOptionPane(usagesUI, JOptionPane.WARNING_MESSAGE, + JOptionPane.DEFAULT_OPTION, null, + options, options[0]); + + usagesUI.getHandler().attachToOptionPane(pane, replaceText); + + int reponse = UIHelper.askUser(pane, t("observe.title.can.not.delete.referentiel"), - usagesUI, - JOptionPane.WARNING_MESSAGE, - new Object[]{ - t("observe.choice.replace"), - t("observe.choice.cancel")}, - 0); + options + ); switch (reponse) { case 0: @@ -190,20 +195,23 @@ public class ContentReferenceUIHandler<E extends ReferentialDto, U extends Conte String type = ObserveI18nDecoratorHelper.getTypeI18nKey(entity.getClass()); type = t(type); String message = t("observe.message.show.usage.for.desactivated", type, decorator.toString(entity)); - String message2 = t("observe.message.show.usage.for.desactivated2"); - String message3 = t("observe.message.show.usage.for.desactivated3"); - UsagesUI usagesUI = new UsagesUI(tx); - usagesUI.init(message, message2, message3, usages, (List) referenceList); - int reponse = UIHelper.askUser(null, + UsageForDesactivateUI usagesUI = UsageForDesactivateUI.build(message, usages, referenceList); + + String replaceText = t("observe.choice.save"); + Object[] options = { + replaceText, + t("observe.choice.cancel")}; + JOptionPane pane = new JOptionPane(usagesUI, JOptionPane.WARNING_MESSAGE, + JOptionPane.DEFAULT_OPTION, null, + options, options[0]); + + usagesUI.getHandler().attachToOptionPane(pane, replaceText); + + int reponse = UIHelper.askUser(pane, t("observe.title.need.confirm.to.desactivate.referentiel"), - usagesUI, - JOptionPane.WARNING_MESSAGE, - new Object[]{ - t("observe.choice.save"), - t("observe.choice.cancel")}, - 0); + options); if (log.isDebugEnabled()) { log.debug("response : " + reponse); } @@ -381,8 +389,7 @@ public class ContentReferenceUIHandler<E extends ReferentialDto, U extends Conte ContentReferenceUI<E, U> ui = getUi(); - UsagesUI usagesUI = new UsagesUI(ui); - usagesUI.init(message, null, null, usages, null); + UsageForDisplayUI usagesUI = UsageForDisplayUI.build(message, usages); UIHelper.askUser(ui, t("observe.title.show.usage"), diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/usage/UsagesUI.jaxx b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ref/usage/UsageForDeleteUI.jaxx similarity index 54% copy from application-swing/src/main/java/fr/ird/observe/application/swing/ui/usage/UsagesUI.jaxx copy to application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ref/usage/UsageForDeleteUI.jaxx index a37abe4..cfa1d82 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/usage/UsagesUI.jaxx +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ref/usage/UsageForDeleteUI.jaxx @@ -2,19 +2,19 @@ #%L ObServe :: Application Swing %% - Copyright (C) 2008 - 2016 IRD, Code Lutin, Tony Chemit + Copyright (C) 2008 - 2016 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 + 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 + + 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% @@ -23,39 +23,32 @@ <!-- Interface graphique pour afficher la liste des usages d'une entitee donnee. --> -<JPanel id='usagePanel' layout='{new BorderLayout()}'> +<JPanel layout='{new BorderLayout()}'> <import> - fr.ird.observe.application.swing.ui.UIHelper - fr.ird.observe.services.dto.AbstractReference + fr.ird.observe.services.dto.AbstractReference fr.ird.observe.services.dto.ReferenceMap - + jaxx.runtime.context.JAXXInitialContext jaxx.runtime.swing.editor.bean.BeanComboBox - java.util.List + static org.nuiton.i18n.I18n.t </import> <script><![CDATA[ -public void init(String message, - String message2, - String message3, - ReferenceMap usages, - List<AbstractReference> referenceList) { - handler.initUI( message,message2, message3, usages, referenceList); -} - -public void clean() { - handler.cleanUI(); +public static UsageForDeleteUI build(String message, ReferenceMap usages, List references) { + return new UsageForDeleteUI(new JAXXInitialContext().add(message).add(usages).add(references)); } public <T> T getSelectedReplace() { return (T) replace.getSelectedItem(); } public void destroy() { log.info("destroy ui " + getName()); - UIHelper.destroy(this); + SwingUtil.destroy(this); + usages.removeAll(); + message.setText(null); } @Override @@ -66,21 +59,20 @@ protected void finalize() throws Throwable { ]]> </script> - <JPanel constraints="BorderLayout.NORTH" layout='{new BorderLayout()}'> - - <JPanel layout='{new BorderLayout()}' constraints="BorderLayout.CENTER"> - <JLabel id="message" constraints="BorderLayout.NORTH"/> - <JLabel id="message2" constraints="BorderLayout.CENTER"/> - <JLabel id="message3" constraints="BorderLayout.SOUTH"/> - </JPanel> - <JPanel id="replacePanel" border='{new TitledBorder(t("observe.usage.replaceTitle"))}' visible="false" - constraints="BorderLayout.SOUTH" layout="{new GridLayout(0, 1)}"> - <BeanComboBox id="replace"/> - </JPanel> + <Boolean id="canApply" javaBean="false"/> + + <JPanel layout="{new GridLayout(0, 1)}" constraints="BorderLayout.NORTH"> + <JLabel id="message"/> + <JLabel text="observe.message.show.usage.for.delete2"/> + <JLabel text="observe.message.show.usage.for.delete3"/> </JPanel> <JPanel id="usages" border='{new TitledBorder(t("observe.usage.usageTitle"))}' constraints="BorderLayout.CENTER" layout="{new GridLayout(0, 1)}"/> + <JPanel id="replacePanel" border='{new TitledBorder(t("observe.usage.replaceTitle"))}' + constraints="BorderLayout.SOUTH" layout="{new GridLayout(0, 1)}"> + <BeanComboBox id="replace"/> + </JPanel> </JPanel> diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ref/usage/UsageForDeleteUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ref/usage/UsageForDeleteUIHandler.java new file mode 100644 index 0000000..2c1c764 --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ref/usage/UsageForDeleteUIHandler.java @@ -0,0 +1,48 @@ +package fr.ird.observe.application.swing.ui.content.ref.usage; + +import jaxx.runtime.swing.editor.bean.BeanComboBox; + +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; + +/** + * Created on 16/12/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public class UsageForDeleteUIHandler extends UsageUIHandlerSupport<UsageForDeleteUI> { + + @Override + protected JLabel getMessage() { + return ui.getMessage(); + } + + @Override + protected JPanel getUsages() { + return ui.getUsages(); + } + + @Override + protected BeanComboBox<?> getReplace() { + return ui.getReplace(); + } + + @Override + public void afterInit(UsageForDeleteUI ui) { + super.afterInit(ui); + getReplace().addPropertyChangeListener(BeanComboBox.PROPERTY_SELECTED_ITEM, evt -> updateCanApply()); + } + + @Override + public void attachToOptionPane(JOptionPane pane, String message) { + super.attachToOptionPane(pane, message); + updateCanApply(); + } + + private void updateCanApply() { + boolean canApply = getReplace().getSelectedItem() != null; + ui.setCanApply(canApply); + } +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/usage/UsagesUI.jaxx b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ref/usage/UsageForDesactivateUI.jaxx similarity index 54% rename from application-swing/src/main/java/fr/ird/observe/application/swing/ui/usage/UsagesUI.jaxx rename to application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ref/usage/UsageForDesactivateUI.jaxx index a37abe4..ddc8439 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/usage/UsagesUI.jaxx +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ref/usage/UsageForDesactivateUI.jaxx @@ -2,19 +2,19 @@ #%L ObServe :: Application Swing %% - Copyright (C) 2008 - 2016 IRD, Code Lutin, Tony Chemit + Copyright (C) 2008 - 2016 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 + 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 + + 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% @@ -23,39 +23,32 @@ <!-- Interface graphique pour afficher la liste des usages d'une entitee donnee. --> -<JPanel id='usagePanel' layout='{new BorderLayout()}'> +<JPanel layout='{new BorderLayout()}'> <import> - fr.ird.observe.application.swing.ui.UIHelper - fr.ird.observe.services.dto.AbstractReference + fr.ird.observe.services.dto.AbstractReference fr.ird.observe.services.dto.ReferenceMap - + jaxx.runtime.context.JAXXInitialContext jaxx.runtime.swing.editor.bean.BeanComboBox - java.util.List + static org.nuiton.i18n.I18n.t </import> <script><![CDATA[ -public void init(String message, - String message2, - String message3, - ReferenceMap usages, - List<AbstractReference> referenceList) { - handler.initUI( message,message2, message3, usages, referenceList); -} - -public void clean() { - handler.cleanUI(); +public static UsageForDesactivateUI build(String message, ReferenceMap usages, List references) { + return new UsageForDesactivateUI(new JAXXInitialContext().add(message).add(usages).add(references)); } public <T> T getSelectedReplace() { return (T) replace.getSelectedItem(); } public void destroy() { log.info("destroy ui " + getName()); - UIHelper.destroy(this); + SwingUtil.destroy(this); + usages.removeAll(); + message.setText(null); } @Override @@ -66,21 +59,22 @@ protected void finalize() throws Throwable { ]]> </script> - <JPanel constraints="BorderLayout.NORTH" layout='{new BorderLayout()}'> - - <JPanel layout='{new BorderLayout()}' constraints="BorderLayout.CENTER"> - <JLabel id="message" constraints="BorderLayout.NORTH"/> - <JLabel id="message2" constraints="BorderLayout.CENTER"/> - <JLabel id="message3" constraints="BorderLayout.SOUTH"/> - </JPanel> - <JPanel id="replacePanel" border='{new TitledBorder(t("observe.usage.replaceTitle"))}' visible="false" - constraints="BorderLayout.SOUTH" layout="{new GridLayout(0, 1)}"> - <BeanComboBox id="replace"/> - </JPanel> + <Boolean id="canApply" javaBean="false"/> + + <JPanel layout="{new GridLayout(0, 1)}" constraints="BorderLayout.NORTH"> + <JLabel id="message"/> + <JLabel text="observe.message.show.usage.for.desactivated2"/> + <JLabel text="observe.message.show.usage.for.desactivated3"/> </JPanel> <JPanel id="usages" border='{new TitledBorder(t("observe.usage.usageTitle"))}' constraints="BorderLayout.CENTER" layout="{new GridLayout(0, 1)}"/> + <JPanel id="replacePanel" + constraints="BorderLayout.SOUTH" layout="{new BorderLayout()}"> + <JCheckBox id="shouldReplace" text="observe.usage.action.shouldReplace" constraints="BorderLayout.CENTER"/> + <BeanComboBox id="replace" border='{new TitledBorder(t("observe.usage.replaceTitle"))}' + enabled="{shouldReplace.isSelected()}" constraints="BorderLayout.SOUTH"/> + </JPanel> </JPanel> diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ref/usage/UsageForDesactivateUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ref/usage/UsageForDesactivateUIHandler.java new file mode 100644 index 0000000..359df0b --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ref/usage/UsageForDesactivateUIHandler.java @@ -0,0 +1,49 @@ +package fr.ird.observe.application.swing.ui.content.ref.usage; + +import jaxx.runtime.swing.editor.bean.BeanComboBox; + +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; + +/** + * Created on 16/12/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public class UsageForDesactivateUIHandler extends UsageUIHandlerSupport<UsageForDesactivateUI> { + + @Override + protected JLabel getMessage() { + return ui.getMessage(); + } + + @Override + protected JPanel getUsages() { + return ui.getUsages(); + } + + @Override + protected BeanComboBox<?> getReplace() { + return ui.getReplace(); + } + + @Override + public void afterInit(UsageForDesactivateUI ui) { + super.afterInit(ui); + getReplace().addPropertyChangeListener(BeanComboBox.PROPERTY_SELECTED_ITEM, evt -> updateCanApply()); + ui.getShouldReplace().addItemListener(evt -> updateCanApply()); + } + + @Override + public void attachToOptionPane(JOptionPane pane, String message) { + super.attachToOptionPane(pane, message); + updateCanApply(); + } + + private void updateCanApply() { + boolean canApply = !ui.getShouldReplace().isSelected() || getReplace().getSelectedItem() != null; + ui.setCanApply(canApply); + } +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ref/usage/UsageForDisplayUI.jaxx b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ref/usage/UsageForDisplayUI.jaxx new file mode 100644 index 0000000..f54b85f --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ref/usage/UsageForDisplayUI.jaxx @@ -0,0 +1,62 @@ +<!-- + #%L + ObServe :: Application Swing + %% + Copyright (C) 2008 - 2016 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% + --> + +<!-- +Interface graphique pour afficher la liste des usages d'une entitee donnee. +--> +<JPanel id='usagePanel' layout='{new BorderLayout()}'> + + <import> + + fr.ird.observe.services.dto.ReferenceMap + jaxx.runtime.context.JAXXInitialContext + + static org.nuiton.i18n.I18n.t + </import> + + <script><![CDATA[ + +public static UsageForDisplayUI build(String message, ReferenceMap usages) { + return new UsageForDisplayUI(new JAXXInitialContext().add(message).add(usages)); +} + +public void destroy() { + log.info("destroy ui " + getName()); + SwingUtil.destroy(this); + usages.removeAll(); + message.setText(null); +} + +@Override +protected void finalize() throws Throwable { + super.finalize(); + destroy(); +} +]]> + </script> + + <JLabel id="message" constraints="BorderLayout.NORTH"/> + + <JPanel id="usages" border='{new TitledBorder(t("observe.usage.usageTitle"))}' constraints="BorderLayout.CENTER" + layout="{new GridLayout(0, 1)}"/> + +</JPanel> diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ref/usage/UsageForDisplayUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ref/usage/UsageForDisplayUIHandler.java new file mode 100644 index 0000000..ca51f10 --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ref/usage/UsageForDisplayUIHandler.java @@ -0,0 +1,31 @@ +package fr.ird.observe.application.swing.ui.content.ref.usage; + +import jaxx.runtime.swing.editor.bean.BeanComboBox; + +import javax.swing.JLabel; +import javax.swing.JPanel; + +/** + * Created on 16/12/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public class UsageForDisplayUIHandler extends UsageUIHandlerSupport<UsageForDisplayUI> { + + @Override + protected JLabel getMessage() { + return ui.getMessage(); + } + + @Override + protected JPanel getUsages() { + return ui.getUsages(); + } + + @Override + protected BeanComboBox<?> getReplace() { + return null; + } + +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ref/usage/UsageUIHandlerSupport.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ref/usage/UsageUIHandlerSupport.java new file mode 100644 index 0000000..44df932 --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ref/usage/UsageUIHandlerSupport.java @@ -0,0 +1,171 @@ +package fr.ird.observe.application.swing.ui.content.ref.usage; + +import fr.ird.observe.application.swing.ObserveSwingApplicationContext; +import fr.ird.observe.application.swing.decoration.DecoratorService; +import fr.ird.observe.application.swing.decoration.ObserveI18nDecoratorHelper; +import fr.ird.observe.services.dto.AbstractReference; +import fr.ird.observe.services.dto.DataDto; +import fr.ird.observe.services.dto.DataReference; +import fr.ird.observe.services.dto.IdDto; +import fr.ird.observe.services.dto.ReferenceMap; +import fr.ird.observe.services.dto.referential.ReferentialDto; +import fr.ird.observe.services.dto.referential.ReferentialReference; +import jaxx.runtime.JAXXObject; +import jaxx.runtime.spi.UIHandler; +import jaxx.runtime.swing.editor.bean.BeanComboBox; +import org.apache.commons.lang3.BooleanUtils; +import org.nuiton.decorator.Decorator; +import org.nuiton.decorator.JXPathDecorator; + +import javax.swing.JButton; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import java.awt.Component; +import java.awt.Container; +import java.awt.Dimension; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.stream.Collectors; + +import static org.nuiton.i18n.I18n.n; +import static org.nuiton.i18n.I18n.t; + +/** + * Created on 16/12/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public abstract class UsageUIHandlerSupport<U extends JAXXObject> implements UIHandler<U> { + + U ui; + + protected abstract JLabel getMessage(); + + protected abstract JPanel getUsages(); + + protected abstract BeanComboBox<?> getReplace(); + + @Override + public void beforeInit(U ui) { + this.ui = ui; + } + + @Override + public void afterInit(U ui) { + + String message = ui.getContextValue(String.class); + getMessage().setText(message); + ReferenceMap usages = ui.getContextValue(ReferenceMap.class); + if (usages.isEmpty()) { + getUsages().add(new JLabel(t("observe.message.no.usage.for.entity"))); + } else { + + for (Map.Entry<Class<? extends IdDto>, Set<? extends AbstractReference>> entry : usages.entrySet()) { + Class dtoType = entry.getKey(); + Set references = entry.getValue(); + String typeTitle = t(ObserveI18nDecoratorHelper.getTypeI18nKey(dtoType)); + if (DataDto.class.isAssignableFrom(dtoType)) { + addDataReferenceUsages(dtoType, references, typeTitle); + } else { + addReferentialReferenceUsages(dtoType, references, typeTitle); + } + + } + + } + + BeanComboBox<?> comboBox = getReplace(); + if (comboBox != null) { + List<AbstractReference> references = ui.getContextValue(List.class); + AbstractReference reference = references.get(0); + Class type = reference.getType(); + comboBox.setBeanType(type); + comboBox.setI18nPrefix("observe.common."); + DecoratorService decoratorService = ObserveSwingApplicationContext.get().getDecoratorService(); + Decorator referenceDecorator = decoratorService.getReferenceDecorator(type); + + comboBox.init((JXPathDecorator) referenceDecorator, (List) references); + } + } + + public void attachToOptionPane(JOptionPane pane, String message) { + JButton jButton = findButton(pane, message); + Objects.requireNonNull(jButton); + jButton.setEnabled(false); + ui.addPropertyChangeListener("canApply", evt -> { + Boolean newValue = (Boolean) evt.getNewValue(); + jButton.setEnabled(BooleanUtils.isTrue(newValue)); + }); + } + + protected <D extends DataDto> void addDataReferenceUsages(Class<D> dtoType, + Set<DataReference<D>> references, + String typeTitle) { + + String typetitle = n("observe.content.label.usage.data.title"); + typetitle = t(typetitle, typeTitle, references.size()); + + Decorator<?> decorator = ObserveSwingApplicationContext.get().getDecoratorService().getDataReferenceDecorator(dtoType); + Objects.requireNonNull(decorator, "could not find decorator for type " + dtoType); + + buildUsagePanel(decorator, references, typetitle); + } + + + protected <D extends ReferentialDto> void addReferentialReferenceUsages(Class<D> dtoType, + Set<ReferentialReference<D>> references, + String typeTitle) { + + String typetitle = n("observe.content.label.usage.referentiel.title"); + typetitle = t(typetitle, typeTitle, references.size()); + + Decorator<?> decorator = ObserveSwingApplicationContext.get().getDecoratorService().getReferentialReferenceDecorator(dtoType); + Objects.requireNonNull(decorator, "could not find decorator for type " + dtoType); + + buildUsagePanel(decorator, references, typetitle); + } + + protected <D extends IdDto, R extends AbstractReference<D>> void buildUsagePanel(Decorator<?> decorator, Set<R> references, String typetitle) { + + List<String> data = new ArrayList<>(references.size()); + data.addAll(references.stream().map(decorator::toString).collect(Collectors.toList())); + + JList<? super String> l = new JList<>(data.toArray()); + + JScrollPane pane = new JScrollPane(); + pane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); + pane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); + pane.setMinimumSize(new Dimension(300, 30)); + pane.setColumnHeaderView(new JLabel(typetitle)); + pane.setViewportView(l); + getUsages().add(pane); + } + + + protected JButton findButton(Container c, String text) { + + for (Component component : c.getComponents()) { + if (component instanceof JButton) { + if (text.equals(((JButton) component).getText())) { + return (JButton) component; + } + continue; + } + if (component instanceof Container) { + JButton button = findButton((Container) component, text); + if (button != null) { + return button; + } + } + } + return null; + } + +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/usage/UsagesUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/usage/UsagesUIHandler.java deleted file mode 100644 index 69136e5..0000000 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/usage/UsagesUIHandler.java +++ /dev/null @@ -1,197 +0,0 @@ -/* - * #%L - * ObServe :: Application Swing - * %% - * Copyright (C) 2008 - 2016 IRD, Code Lutin, 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.application.swing.ui.usage; - -import fr.ird.observe.application.swing.ObserveSwingApplicationContext; -import fr.ird.observe.application.swing.decoration.DecoratorService; -import fr.ird.observe.application.swing.decoration.ObserveI18nDecoratorHelper; -import fr.ird.observe.services.dto.AbstractReference; -import fr.ird.observe.services.dto.DataDto; -import fr.ird.observe.services.dto.DataReference; -import fr.ird.observe.services.dto.IdDto; -import fr.ird.observe.services.dto.ReferenceMap; -import fr.ird.observe.services.dto.referential.ReferentialDto; -import fr.ird.observe.services.dto.referential.ReferentialReference; -import jaxx.runtime.spi.UIHandler; -import jaxx.runtime.swing.editor.bean.BeanComboBox; -import org.apache.commons.collections4.CollectionUtils; -import org.nuiton.decorator.Decorator; -import org.nuiton.decorator.JXPathDecorator; - -import javax.swing.JLabel; -import javax.swing.JList; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import java.awt.Dimension; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Set; -import java.util.stream.Collectors; - -import static org.nuiton.i18n.I18n.n; -import static org.nuiton.i18n.I18n.t; - -/** - * @author Tony Chemit - chemit@codelutin.com - * @since 1.2 - */ -public class UsagesUIHandler implements UIHandler<UsagesUI> { - - private UsagesUI ui; - - @Override - public void beforeInit(UsagesUI ui) { - this.ui = ui; - } - - @Override - public void afterInit(UsagesUI ui) { - - } - - /** - * Afficher les usages d'une entite donnee. - * - * @param message le message a afficher en haut - * @param message2 message supplementaire a afficher en haut - * @param message3 message supplementaire a afficher en haut - * @param usages les utilisations de l'entite donnee - * @param referenceList la liste optionnel des références possibles de remplacement - */ - public void initUI(String message, - String message2, - String message3, - ReferenceMap usages, - List<AbstractReference> referenceList) { - // toujours nettoyer l'ui avant tout - cleanUI(); - - ui.getMessage().setText(t(message)); - if (message2 != null) { - ui.getMessage2().setVisible(true); - ui.getMessage2().setText(message2); - } - if (message3 != null) { - ui.getMessage3().setVisible(true); - ui.getMessage3().setText(message3); - } - if (usages.isEmpty()) { - ui.getUsages().add(new JLabel(t("observe.message.no.usage.for.entity"))); - } else { - - for (Map.Entry<Class<? extends IdDto>, Set<? extends AbstractReference>> entry : usages.entrySet()) { - Class dtoType = entry.getKey(); - Set references = entry.getValue(); - String typeTitle = t(ObserveI18nDecoratorHelper.getTypeI18nKey(dtoType)); - if (DataDto.class.isAssignableFrom(dtoType)) { - addDataReferenceUsages(dtoType, references, typeTitle); - } else { - addReferentialReferenceUsages(dtoType, references, typeTitle); - } - - } - - JPanel panel = ui.getReplacePanel(); - - if (CollectionUtils.isNotEmpty(referenceList)) { - - panel.setVisible(true); - AbstractReference reference = referenceList.get(0); - Class type = reference.getType(); - BeanComboBox<?> comboBox = ui.getReplace(); - comboBox.setBeanType(type); - comboBox.setI18nPrefix("observe.common."); - DecoratorService decoratorService = ObserveSwingApplicationContext.get().getDecoratorService(); - Decorator referenceDecorator = decoratorService.getReferenceDecorator(type); - - comboBox.init((JXPathDecorator) referenceDecorator, (List) referenceList); - - } else { - panel.setVisible(false); - } - } - } - - public void cleanUI() { - ui.getUsages().removeAll(); - ui.getMessage().setText(null); - ui.getMessage2().setText(null); - ui.getMessage2().setVisible(false); - ui.getMessage3().setText(null); - ui.getMessage3().setVisible(false); - } - - - protected <D extends DataDto> void addDataReferenceUsages(Class<D> dtoType, - Set<DataReference<D>> references, - String typeTitle) { - - int size = references.size(); - String typetitle = n("observe.content.label.usage.data.title"); - typetitle = t(typetitle, typeTitle, size); - - Decorator<?> decorator = ObserveSwingApplicationContext.get().getDecoratorService().getDataReferenceDecorator(dtoType); - Objects.requireNonNull(decorator, "could not find decorator for type " + dtoType); - - List<String> data = new ArrayList<>(size); - data.addAll(references.stream().map(decorator::toString).collect(Collectors.toList())); - - JList<? super String> l = new JList<>(data.toArray()); - - JScrollPane pane = new JScrollPane(); - pane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); - pane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); - pane.setMinimumSize(new Dimension(300, 30)); -// pane.setMaximumSize(new Dimension(300, 100)); - pane.setColumnHeaderView(new JLabel(typetitle)); - pane.setViewportView(l); - ui.getUsages().add(pane); - } - - protected <D extends ReferentialDto> void addReferentialReferenceUsages(Class<D> dtoType, - Set<ReferentialReference<D>> references, - String typeTitle) { - - int size = references.size(); - String typetitle = n("observe.content.label.usage.referentiel.title"); - typetitle = t(typetitle, typeTitle, size); - - Decorator<?> decorator = ObserveSwingApplicationContext.get().getDecoratorService().getReferentialReferenceDecorator(dtoType); - Objects.requireNonNull(decorator, "could not find decorator for type " + dtoType); - - List<String> data = new ArrayList<>(size); - data.addAll(references.stream().map(decorator::toString).collect(Collectors.toList())); - - JList<? super String> l = new JList<>(data.toArray()); - - JScrollPane pane = new JScrollPane(); - pane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); - pane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); - pane.setMinimumSize(new Dimension(300, 30)); -// pane.setMaximumSize(new Dimension(300, 100)); - pane.setColumnHeaderView(new JLabel(typetitle)); - pane.setViewportView(l); - ui.getUsages().add(pane); - } -} diff --git a/application-swing/src/main/resources/i18n/application-swing_en_GB.properties b/application-swing/src/main/resources/i18n/application-swing_en_GB.properties index 150da67..98d41f7 100644 --- a/application-swing/src/main/resources/i18n/application-swing_en_GB.properties +++ b/application-swing/src/main/resources/i18n/application-swing_en_GB.properties @@ -1742,6 +1742,7 @@ observe.type.setLongline.unsaved=New fishing operation observe.type.setSeine.unsaved=New set observe.type.tripLongline.unsaved=New trip observe.type.tripSeine.unsaved=New trip +observe.usage.action.shouldReplace=Remplace desactivated referential ? observe.usage.replaceTitle=Replacement object observe.usage.usageTitle=Founded references observe.validator.field.tip=Property '%1$s' diff --git a/application-swing/src/main/resources/i18n/application-swing_es_ES.properties b/application-swing/src/main/resources/i18n/application-swing_es_ES.properties index 8b266c6..9819163 100644 --- a/application-swing/src/main/resources/i18n/application-swing_es_ES.properties +++ b/application-swing/src/main/resources/i18n/application-swing_es_ES.properties @@ -1742,6 +1742,7 @@ observe.type.setLongline.unsaved=Nuevo lance observe.type.setSeine.unsaved=Nuevo lance observe.type.tripLongline.unsaved=Nueva marea observe.type.tripSeine.unsaved=Nueva marea +observe.usage.action.shouldReplace=Remplacer le référentiel désactivé ? \#TODO observe.usage.replaceTitle=Objet de remplacement \#TODO observe.usage.usageTitle=Références trouvées \#TODO observe.validator.field.tip=Propriedad '%1$s' diff --git a/application-swing/src/main/resources/i18n/application-swing_fr_FR.properties b/application-swing/src/main/resources/i18n/application-swing_fr_FR.properties index 4e8fff6..74d5063 100644 --- a/application-swing/src/main/resources/i18n/application-swing_fr_FR.properties +++ b/application-swing/src/main/resources/i18n/application-swing_fr_FR.properties @@ -1742,6 +1742,7 @@ observe.type.setLongline.unsaved=Nouvelle opération de pêche observe.type.setSeine.unsaved=Nouvelle calée observe.type.tripLongline.unsaved=Nouvelle marée observe.type.tripSeine.unsaved=Nouvelle marée +observe.usage.action.shouldReplace=Remplacer le référentiel désactivé ? observe.usage.replaceTitle=Objet de remplacement observe.usage.usageTitle=Références trouvées observe.validator.field.tip=Propriété '%1$s' -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
participants (1)
-
codelutin.com scm