Tony CHEMIT pushed to branch develop-9 at ultreiaio / ird-observe
Commits:
-
2fb68110
by Tony Chemit at 2021-04-20T09:04:35+02:00
7 changed files:
- client/datasource/editor/api/src/main/i18n/getters/java.getter
- + client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/actions/CopyAuthenticationToken.java
- client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/menu/actions/ShowStorageInfoAction.java
- client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/navigation/actions/ToggleInformation.java
- client/i18n/src/main/i18n/translations/observe_en_GB.properties
- client/i18n/src/main/i18n/translations/observe_es_ES.properties
- client/i18n/src/main/i18n/translations/observe_fr_FR.properties
Changes:
| ... | ... | @@ -180,12 +180,14 @@ observe.ui.choice.confirm.delete |
| 180 | 180 |
observe.ui.choice.confirm.move
|
| 181 | 181 |
observe.ui.choice.confirm.replace
|
| 182 | 182 |
observe.ui.choice.continue
|
| 183 |
+observe.ui.choice.copy.token
|
|
| 183 | 184 |
observe.ui.choice.doNotSave
|
| 184 | 185 |
observe.ui.choice.quit
|
| 185 | 186 |
observe.ui.choice.replace
|
| 186 | 187 |
observe.ui.choice.save
|
| 187 | 188 |
observe.ui.content.action.configure.tip
|
| 188 | 189 |
observe.ui.content.action.insert.tip
|
| 190 |
+observe.ui.copy.authentication.token.done
|
|
| 189 | 191 |
observe.ui.datasource.actions.config.data.source.requires.read.data
|
| 190 | 192 |
observe.ui.datasource.actions.config.data.source.requires.read.referential
|
| 191 | 193 |
observe.ui.datasource.actions.config.data.source.requires.write.data
|
| 1 |
+package fr.ird.observe.client.datasource.editor.api.actions;
|
|
| 2 |
+ |
|
| 3 |
+import fr.ird.observe.client.WithClientUIContext;
|
|
| 4 |
+import fr.ird.observe.client.datasource.api.ObserveSwingDataSource;
|
|
| 5 |
+import fr.ird.observe.client.util.UIHelper;
|
|
| 6 |
+ |
|
| 7 |
+import javax.swing.AbstractAction;
|
|
| 8 |
+import javax.swing.JComponent;
|
|
| 9 |
+import javax.swing.JDialog;
|
|
| 10 |
+import javax.swing.JOptionPane;
|
|
| 11 |
+import javax.swing.SwingUtilities;
|
|
| 12 |
+import javax.swing.UIManager;
|
|
| 13 |
+import java.awt.event.ActionEvent;
|
|
| 14 |
+import java.util.Objects;
|
|
| 15 |
+ |
|
| 16 |
+import static io.ultreia.java4all.i18n.I18n.t;
|
|
| 17 |
+ |
|
| 18 |
+/**
|
|
| 19 |
+ * Created on 20/04/2021.
|
|
| 20 |
+ *
|
|
| 21 |
+ * @author Tony Chemit - dev@tchemit.fr
|
|
| 22 |
+ * @since 9.0.0
|
|
| 23 |
+ */
|
|
| 24 |
+public class CopyAuthenticationToken extends AbstractAction implements WithClientUIContext {
|
|
| 25 |
+ private final ObserveSwingDataSource source;
|
|
| 26 |
+ private final JComponent popup;
|
|
| 27 |
+ |
|
| 28 |
+ public CopyAuthenticationToken(ObserveSwingDataSource source, JComponent popup) {
|
|
| 29 |
+ this.source = Objects.requireNonNull(source);
|
|
| 30 |
+ this.popup = popup;
|
|
| 31 |
+ putValue(SMALL_ICON, UIManager.getIcon("action.report-copy"));
|
|
| 32 |
+ putValue(NAME, t("observe.ui.choice.copy.token"));
|
|
| 33 |
+ putValue(SHORT_DESCRIPTION, t("observe.ui.choice.copy.token"));
|
|
| 34 |
+ }
|
|
| 35 |
+ |
|
| 36 |
+ @Override
|
|
| 37 |
+ public void actionPerformed(ActionEvent e) {
|
|
| 38 |
+ UIHelper.copyToClipBoard(source.getConnection().getAuthenticationToken());
|
|
| 39 |
+ getClientUIContext().setUiStatus(t("observe.ui.copy.authentication.token.done"));
|
|
| 40 |
+ if (popup != null) {
|
|
| 41 |
+ if (popup instanceof JOptionPane) {
|
|
| 42 |
+ JOptionPane optionPane = (JOptionPane) popup;
|
|
| 43 |
+ JDialog dialog = (JDialog) SwingUtilities.getAncestorOfClass(JDialog.class, optionPane);
|
|
| 44 |
+ dialog.setVisible(false);
|
|
| 45 |
+ } else {
|
|
| 46 |
+ |
|
| 47 |
+ popup.setVisible(false);
|
|
| 48 |
+ }
|
|
| 49 |
+ }
|
|
| 50 |
+ }
|
|
| 51 |
+}
|
| ... | ... | @@ -24,11 +24,22 @@ package fr.ird.observe.client.datasource.editor.api.menu.actions; |
| 24 | 24 |
|
| 25 | 25 |
import fr.ird.observe.client.datasource.api.ObserveSwingDataSource;
|
| 26 | 26 |
import fr.ird.observe.client.datasource.api.ObserveSwingDataSourceTemplate;
|
| 27 |
+import fr.ird.observe.client.datasource.editor.api.actions.CopyAuthenticationToken;
|
|
| 28 |
+import fr.ird.observe.client.datasource.editor.api.content.referential.usage.UsageUIHandlerSupport;
|
|
| 27 | 29 |
import fr.ird.observe.client.datasource.editor.api.menu.DataSourceEditorMenu;
|
| 30 |
+import fr.ird.observe.client.util.UIHelper;
|
|
| 28 | 31 |
|
| 32 |
+import javax.swing.Action;
|
|
| 33 |
+import javax.swing.JButton;
|
|
| 29 | 34 |
import javax.swing.JLabel;
|
| 30 | 35 |
import javax.swing.JOptionPane;
|
| 36 |
+import javax.swing.JPanel;
|
|
| 37 |
+import javax.swing.SwingUtilities;
|
|
| 38 |
+import java.awt.BorderLayout;
|
|
| 31 | 39 |
import java.awt.event.ActionEvent;
|
| 40 |
+import java.awt.event.ComponentAdapter;
|
|
| 41 |
+import java.awt.event.ComponentEvent;
|
|
| 42 |
+import java.util.Objects;
|
|
| 32 | 43 |
|
| 33 | 44 |
import static io.ultreia.java4all.i18n.I18n.t;
|
| 34 | 45 |
|
| ... | ... | @@ -48,14 +59,38 @@ public class ShowStorageInfoAction extends DataSourceEditorMenuActionSupport { |
| 48 | 59 |
protected void doActionPerformed(ActionEvent event, DataSourceEditorMenu ui) {
|
| 49 | 60 |
|
| 50 | 61 |
ObserveSwingDataSource source = getObserveDataSourcesManager().getOptionalMainDataSource().orElse(null);
|
| 51 |
- |
|
| 52 | 62 |
String text = ObserveSwingDataSourceTemplate.generate(source);
|
| 53 |
- JOptionPane.showMessageDialog(
|
|
| 54 |
- getClientUIContext().getMainUI(),
|
|
| 55 |
- new JLabel(text),
|
|
| 56 |
- t("observe.ui.title.storage.info"),
|
|
| 57 |
- JOptionPane.INFORMATION_MESSAGE);
|
|
| 63 |
+ JPanel content = new JPanel(new BorderLayout());
|
|
| 64 |
+ content.add(new JLabel(text), BorderLayout.CENTER);
|
|
| 65 |
+ boolean withTokenOption = source != null && source.isServer();
|
|
| 66 |
+ Object[] options;
|
|
| 67 |
+ if (withTokenOption) {
|
|
| 68 |
+ CopyAuthenticationToken dummyAction = new CopyAuthenticationToken(source, null);
|
|
| 69 |
+ options = new Object[]{dummyAction.getValue(Action.NAME), t("observe.ui.choice.quit")};
|
|
| 70 |
+ } else {
|
|
| 71 |
+ options = new Object[]{t("observe.ui.choice.quit")};
|
|
| 72 |
+ }
|
|
| 73 |
+ |
|
| 74 |
+ JOptionPane optionPane = new JOptionPane(new JLabel(text), JOptionPane.INFORMATION_MESSAGE, JOptionPane.DEFAULT_OPTION, null, options, options[0]);
|
|
| 75 |
+ |
|
| 76 |
+ if (withTokenOption) {
|
|
| 77 |
+ CopyAuthenticationToken action = new CopyAuthenticationToken(source, optionPane);
|
|
| 78 |
+ |
|
| 79 |
+ JButton jButton = UsageUIHandlerSupport.findButton(optionPane, (String) options[0]);
|
|
| 80 |
+ Objects.requireNonNull(jButton).setAction(action);
|
|
| 81 |
+ optionPane.addComponentListener(new ComponentAdapter() {
|
|
| 82 |
+ @Override
|
|
| 83 |
+ public void componentShown(ComponentEvent e) {
|
|
| 84 |
+ SwingUtilities.invokeLater(jButton::grabFocus);
|
|
| 85 |
+ }
|
|
| 86 |
+ });
|
|
| 87 |
+ }
|
|
| 58 | 88 |
|
| 89 |
+ int response = UIHelper.askUser(getClientUIContext().getMainUI(), optionPane, t("observe.ui.title.storage.info"), options);
|
|
| 90 |
+ if (withTokenOption && response == 0) {
|
|
| 91 |
+ UIHelper.copyToClipBoard(source.getConnection().getAuthenticationToken());
|
|
| 92 |
+ getClientUIContext().setUiStatus(t("observe.ui.copy.authentication.token.done"));
|
|
| 93 |
+ }
|
|
| 59 | 94 |
}
|
| 60 | 95 |
|
| 61 | 96 |
}
|
| ... | ... | @@ -26,12 +26,15 @@ import fr.ird.observe.client.WithClientUIContext; |
| 26 | 26 |
import fr.ird.observe.client.datasource.api.ObserveSwingDataSource;
|
| 27 | 27 |
import fr.ird.observe.client.datasource.api.ObserveSwingDataSourceTemplate;
|
| 28 | 28 |
import fr.ird.observe.client.datasource.editor.api.ObserveKeyStrokesEditorApi;
|
| 29 |
+import fr.ird.observe.client.datasource.editor.api.actions.CopyAuthenticationToken;
|
|
| 29 | 30 |
import fr.ird.observe.client.datasource.editor.api.menu.DataSourceEditorMenuModel;
|
| 30 | 31 |
import fr.ird.observe.client.datasource.editor.api.navigation.NavigationUI;
|
| 31 | 32 |
|
| 33 |
+import javax.swing.JButton;
|
|
| 32 | 34 |
import javax.swing.JLabel;
|
| 33 | 35 |
import javax.swing.JPanel;
|
| 34 | 36 |
import javax.swing.JPopupMenu;
|
| 37 |
+import javax.swing.SwingUtilities;
|
|
| 35 | 38 |
import javax.swing.border.TitledBorder;
|
| 36 | 39 |
import javax.swing.event.PopupMenuEvent;
|
| 37 | 40 |
import javax.swing.event.PopupMenuListener;
|
| ... | ... | @@ -81,9 +84,32 @@ public class ToggleInformation extends NavigationConfigUIActionSupport implement |
| 81 | 84 |
String text = ObserveSwingDataSourceTemplate.generate(source);
|
| 82 | 85 |
JPanel content = new JPanel(new BorderLayout());
|
| 83 | 86 |
content.add(new JLabel(text), BorderLayout.CENTER);
|
| 87 |
+ boolean withTokenOption = source != null && source.isServer();
|
|
| 88 |
+ JPopupMenu popup = ui.getInformationPopup();
|
|
| 89 |
+ if (withTokenOption) {
|
|
| 90 |
+ CopyAuthenticationToken action = new CopyAuthenticationToken(source, popup);
|
|
| 91 |
+ JButton copyToken = new JButton(action);
|
|
| 92 |
+ JPanel actions = new JPanel();
|
|
| 93 |
+ actions.add(copyToken, BorderLayout.CENTER);
|
|
| 94 |
+ content.add(actions, BorderLayout.SOUTH);
|
|
| 95 |
+ popup.addPopupMenuListener(new PopupMenuListener() {
|
|
| 96 |
+ @Override
|
|
| 97 |
+ public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
|
|
| 98 |
+ SwingUtilities.invokeLater(copyToken::grabFocus);
|
|
| 99 |
+ }
|
|
| 100 |
+ |
|
| 101 |
+ @Override
|
|
| 102 |
+ public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
|
|
| 103 |
+ |
|
| 104 |
+ }
|
|
| 105 |
+ |
|
| 106 |
+ @Override
|
|
| 107 |
+ public void popupMenuCanceled(PopupMenuEvent e) {
|
|
| 108 |
+ }
|
|
| 109 |
+ });
|
|
| 110 |
+ }
|
|
| 84 | 111 |
String title = t("observe.ui.title.storage.info");
|
| 85 | 112 |
content.setBorder(new TitledBorder(title + " "));
|
| 86 |
- JPopupMenu popup = ui.getInformationPopup();
|
|
| 87 | 113 |
popup.removeAll();
|
| 88 | 114 |
popup.add(content);
|
| 89 | 115 |
adaptPopupSize(ui, popup, content);
|
| ... | ... | @@ -1360,6 +1360,7 @@ observe.ui.choice.confirm.insert=Confirm to insert |
| 1360 | 1360 |
observe.ui.choice.confirm.move=Move
|
| 1361 | 1361 |
observe.ui.choice.confirm.replace=Replace
|
| 1362 | 1362 |
observe.ui.choice.continue=Continue
|
| 1363 |
+observe.ui.choice.copy.token=Copy authentication token
|
|
| 1363 | 1364 |
observe.ui.choice.dcp.default=Other opérations or objects (FOB)
|
| 1364 | 1365 |
observe.ui.choice.doNotSave=Do not save
|
| 1365 | 1366 |
observe.ui.choice.generate.feedback=Generate
|
| ... | ... | @@ -1368,6 +1369,7 @@ observe.ui.choice.replace=Replace |
| 1368 | 1369 |
observe.ui.choice.save=Save
|
| 1369 | 1370 |
observe.ui.content.action.configure.tip=Actions
|
| 1370 | 1371 |
observe.ui.content.action.insert.tip=Create
|
| 1372 |
+observe.ui.copy.authentication.token.done=Authentication token was copied to clipboard
|
|
| 1371 | 1373 |
observe.ui.datasource.actions.config.data.source.requires.read.data=Requires read permission on referential
|
| 1372 | 1374 |
observe.ui.datasource.actions.config.data.source.requires.read.referential=Requires read permission on data
|
| 1373 | 1375 |
observe.ui.datasource.actions.config.data.source.requires.write.data=Requires write permission on data
|
| ... | ... | @@ -1360,6 +1360,7 @@ observe.ui.choice.confirm.insert=Confirmer l'insertion \#TODO |
| 1360 | 1360 |
observe.ui.choice.confirm.move=Cambiar
|
| 1361 | 1361 |
observe.ui.choice.confirm.replace=Reemplazar
|
| 1362 | 1362 |
observe.ui.choice.continue=Continuar
|
| 1363 |
+observe.ui.choice.copy.token=Copy authentication token \#TODO
|
|
| 1363 | 1364 |
observe.ui.choice.dcp.default=Other opérations or objects (FOB) \#TODO
|
| 1364 | 1365 |
observe.ui.choice.doNotSave=No grabar
|
| 1365 | 1366 |
observe.ui.choice.generate.feedback=Generate \#TODO
|
| ... | ... | @@ -1368,6 +1369,7 @@ observe.ui.choice.replace=Reemplazar |
| 1368 | 1369 |
observe.ui.choice.save=Grabar
|
| 1369 | 1370 |
observe.ui.content.action.configure.tip=Actions \#TODO
|
| 1370 | 1371 |
observe.ui.content.action.insert.tip=Create \#TODO
|
| 1372 |
+observe.ui.copy.authentication.token.done=Authentication token was copied to clipboard \#TODO
|
|
| 1371 | 1373 |
observe.ui.datasource.actions.config.data.source.requires.read.data=Requires read permission on referential \#TODO
|
| 1372 | 1374 |
observe.ui.datasource.actions.config.data.source.requires.read.referential=Requires read permission on data \#TODO
|
| 1373 | 1375 |
observe.ui.datasource.actions.config.data.source.requires.write.data=Requires write permission on data \#TODO
|
| ... | ... | @@ -1360,6 +1360,7 @@ observe.ui.choice.confirm.insert=Confirmer l'insertion |
| 1360 | 1360 |
observe.ui.choice.confirm.move=Déplacer
|
| 1361 | 1361 |
observe.ui.choice.confirm.replace=Remplacer
|
| 1362 | 1362 |
observe.ui.choice.continue=Continuer
|
| 1363 |
+observe.ui.choice.copy.token=Copier le jeton d'authentification
|
|
| 1363 | 1364 |
observe.ui.choice.dcp.default=Autre opérations et types d'objets (FOB)
|
| 1364 | 1365 |
observe.ui.choice.doNotSave=Ne pas enregistrer
|
| 1365 | 1366 |
observe.ui.choice.generate.feedback=Générer
|
| ... | ... | @@ -1368,6 +1369,7 @@ observe.ui.choice.replace=Remplacer |
| 1368 | 1369 |
observe.ui.choice.save=Enregistrer
|
| 1369 | 1370 |
observe.ui.content.action.configure.tip=Actions
|
| 1370 | 1371 |
observe.ui.content.action.insert.tip=Créer
|
| 1372 |
+observe.ui.copy.authentication.token.done=Le jeton d'authentification a été copié dans le presse-papier
|
|
| 1371 | 1373 |
observe.ui.datasource.actions.config.data.source.requires.read.data=La lecture sur les données n'est pas autorisée
|
| 1372 | 1374 |
observe.ui.datasource.actions.config.data.source.requires.read.referential=La lecture sur les référentiels n'est pas autorisée
|
| 1373 | 1375 |
observe.ui.datasource.actions.config.data.source.requires.write.data=L'écriture sur les données n'est pas autorisée
|