branch develop-5.x updated (35273c5 -> 07dc206)
This is an automated email from the git hooks/post-receive script. New change to branch develop-5.x in repository observe. See https://gitlab.nuiton.org/codelutin/observe.git from 35273c5 Mise à jour des libraries (Fixes #8891) new 07dc206 Rendre le dialogue de désactivation plus explicite (fixes #8879) 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 07dc206cbe7801eb2d4fc1d31b0b941266a1889e 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) Summary of changes: .../ird/observe/application/swing/ui/UIHelper.java | 86 ++++++++++ .../ui/content/ref/ContentReferenceUIHandler.java | 73 ++++---- .../ref/usage/UsageForDeleteUI.jaxx} | 64 +++---- .../content/ref/usage/UsageForDeleteUIHandler.java | 48 ++++++ .../ref/usage/UsageForDesactivateUI.jaxx} | 66 +++---- .../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 | 189 --------------------- .../i18n/application-swing_en_GB.properties | 1 + .../i18n/application-swing_es_ES.properties | 1 + .../i18n/application-swing_fr_FR.properties | 1 + 13 files changed, 530 insertions(+), 312 deletions(-) copy application-swing/src/main/java/fr/ird/observe/application/swing/ui/{usage/UsagesUI.jaxx => content/ref/usage/UsageForDeleteUI.jaxx} (53%) 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} (53%) 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-5.x in repository observe. See https://gitlab.nuiton.org/codelutin/observe.git commit 07dc206cbe7801eb2d4fc1d31b0b941266a1889e 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) --- .../ird/observe/application/swing/ui/UIHelper.java | 86 ++++++++++ .../ui/content/ref/ContentReferenceUIHandler.java | 73 ++++---- .../ref/usage/UsageForDeleteUI.jaxx} | 64 +++---- .../content/ref/usage/UsageForDeleteUIHandler.java | 48 ++++++ .../ref/usage/UsageForDesactivateUI.jaxx} | 66 +++---- .../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 | 189 --------------------- .../i18n/application-swing_en_GB.properties | 1 + .../i18n/application-swing_es_ES.properties | 1 + .../i18n/application-swing_fr_FR.properties | 1 + 13 files changed, 530 insertions(+), 312 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 a9ab74e..3b5e971 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 @@ -43,6 +43,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; @@ -52,12 +53,20 @@ import javax.swing.UIDefaults; import javax.swing.event.HyperlinkEvent; 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.Desktop; 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.net.URISyntaxException; @@ -65,6 +74,8 @@ import java.net.URL; import java.util.Arrays; import java.util.List; +import static javax.swing.JOptionPane.CLOSED_OPTION; +import static javax.swing.JOptionPane.VALUE_PROPERTY; import static org.nuiton.i18n.I18n.t; /** @@ -207,6 +218,81 @@ public class UIHelper extends SwingUtil { ); } + 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; + } + /** * Choisir un fichier via un sélecteur graphique de fichiers. * 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 5121fa2..419682b 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.UsageForDisplayUI; +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.tree.ObserveTreeHelper; -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; @@ -135,20 +137,23 @@ public class ContentReferenceUIHandler<E extends ReferentialDto> extends Content 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: @@ -173,20 +178,23 @@ public class ContentReferenceUIHandler<E extends ReferentialDto> extends Content 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); } @@ -369,8 +377,7 @@ public class ContentReferenceUIHandler<E extends ReferentialDto> extends Content ContentReferenceUI<E> 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"), @@ -394,8 +401,6 @@ public class ContentReferenceUIHandler<E extends ReferentialDto> extends Content ui.getViewLayout().addPropertyChangeListener(CardLayout2Ext.SELECTED_PROPERTY_NAME, evt -> SwingUtilities.invokeLater(revalidate)); - -// UIHelper.getLayer(ui.getEditKeyTable()).setUI(ui.getEditKeyTableLayerUI()); } @Override @@ -458,7 +463,6 @@ public class ContentReferenceUIHandler<E extends ReferentialDto> extends Content ContentReferenceUI<E> ui = getUi(); JToolBar toolBar = ui.getTitleRightToolBar(); toolBar.add(ui.getShowUniqueKeys(), 2); -// toolBar.add(ui.getShowTechnicalInformations(), 2); toolBar.add(ui.getShowUsages(), 2); } @@ -521,14 +525,6 @@ public class ContentReferenceUIHandler<E extends ReferentialDto> extends Content } } - protected void reloadReferentialReferenceSetsInModel(Form<E> form) { - - loadReferentialReferenceSetsInModel(form); - - updateReferentialBeanListHeader(getModel().getBeanType(), getUi().getReferentialListHeader()); - - } - @Override protected void prepareValidationContext() { super.prepareValidationContext(); @@ -542,11 +538,6 @@ public class ContentReferenceUIHandler<E extends ReferentialDto> extends Content validationContext.setEditingReferentielList(data); } -// @Override -// public boolean closeUI() throws Exception { -// return super.closeUI(); -// } - void createUI() { ContentReferenceUI<E> ui = getUi(); 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 53% 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 ab1cfd2..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 @@ -6,15 +6,15 @@ %% 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,49 +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[ -private UsagesUIHandler handler = new UsagesUIHandler(); - -public void init(String message, - String message2, - String message3, - ReferenceMap usages, - List<AbstractReference> referenceList) { - getHandler().initUI(this, message,message2, message3, usages, referenceList); -} - -public void clean() { - getHandler().cleanUI(this); +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(); } -protected UsagesUIHandler getHandler() { - return handler; -} - -void $afterCompleteSetup() { - -} - public void destroy() { log.info("destroy ui " + getName()); - UIHelper.destroy(this); + SwingUtil.destroy(this); + usages.removeAll(); + message.setText(null); } @Override @@ -76,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 53% 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 ab1cfd2..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 @@ -6,15 +6,15 @@ %% 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,49 +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[ -private UsagesUIHandler handler = new UsagesUIHandler(); - -public void init(String message, - String message2, - String message3, - ReferenceMap usages, - List<AbstractReference> referenceList) { - getHandler().initUI(this, message,message2, message3, usages, referenceList); -} - -public void clean() { - getHandler().cleanUI(this); +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(); } -protected UsagesUIHandler getHandler() { - return handler; -} - -void $afterCompleteSetup() { - -} - public void destroy() { log.info("destroy ui " + getName()); - UIHelper.destroy(this); + SwingUtil.destroy(this); + usages.removeAll(); + message.setText(null); } @Override @@ -76,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 40990f5..0000000 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/usage/UsagesUIHandler.java +++ /dev/null @@ -1,189 +0,0 @@ -/* - * #%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% - */ -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.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 { - - /** - * Afficher les usages d'une entite donnee. - * - * @param ui l'ui - * @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(UsagesUI ui, - String message, - String message2, - String message3, - ReferenceMap usages, - List<AbstractReference> referenceList) { - // toujours nettoyer l'ui avant tout - cleanUI(ui); - - 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(ui, dtoType, references, typeTitle); - } else { - addReferentialReferenceUsages(ui, 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(UsagesUI ui) { - 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(UsagesUI ui, - 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(UsagesUI ui, - 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 36e3454..7fc4542 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 @@ -1699,6 +1699,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 1f3c1e3..b352c92 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 @@ -1699,6 +1699,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 a688252..67a7e72 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 @@ -1699,6 +1699,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