Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe
Commits:
-
a72cf7a2
by Tony CHEMIT at 2017-08-04T21:43:04+02:00
4 changed files:
- client/src/main/java/fr/ird/observe/client/ui/storage/StorageUI.jaxx
- + client/src/main/java/fr/ird/observe/client/ui/storage/StorageUIBlockingLayerUI.java
- client/src/main/java/fr/ird/observe/client/ui/storage/StorageUIHandler.java
- client/src/main/java/fr/ird/observe/client/ui/storage/tabs/ChooseDbModeUIHandler.java
Changes:
| ... | ... | @@ -44,7 +44,7 @@ |
| 44 | 44 |
<StorageUIModel id='model' javaBean='getContextValue(StorageUIModel.class)'/>
|
| 45 | 45 |
|
| 46 | 46 |
<!-- le bloqueur d'ui lorsqu'une action est en cours ou annulée -->
|
| 47 |
- <BlockingLayerUI id='busyBlockLayerUI'/>
|
|
| 47 |
+ <StorageUIBlockingLayerUI id='busyBlockLayerUI' constructorParams='this'/>
|
|
| 48 | 48 |
|
| 49 | 49 |
<CardLayout>
|
| 50 | 50 |
<!-- les differents contenu d'onglets -->
|
| 1 |
+package fr.ird.observe.client.ui.storage;
|
|
| 2 |
+ |
|
| 3 |
+/*-
|
|
| 4 |
+ * #%L
|
|
| 5 |
+ * ObServe :: Client
|
|
| 6 |
+ * %%
|
|
| 7 |
+ * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io
|
|
| 8 |
+ * %%
|
|
| 9 |
+ * This program is free software: you can redistribute it and/or modify
|
|
| 10 |
+ * it under the terms of the GNU General Public License as
|
|
| 11 |
+ * published by the Free Software Foundation, either version 3 of the
|
|
| 12 |
+ * License, or (at your option) any later version.
|
|
| 13 |
+ *
|
|
| 14 |
+ * This program is distributed in the hope that it will be useful,
|
|
| 15 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 |
+ * GNU General Public License for more details.
|
|
| 18 |
+ *
|
|
| 19 |
+ * You should have received a copy of the GNU General Public
|
|
| 20 |
+ * License along with this program. If not, see
|
|
| 21 |
+ * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 |
+ * #L%
|
|
| 23 |
+ */
|
|
| 24 |
+ |
|
| 25 |
+import com.google.common.collect.ImmutableSet;
|
|
| 26 |
+import fr.ird.observe.client.ObserveSwingApplicationContext;
|
|
| 27 |
+import fr.ird.observe.client.ui.actions.AbstractUIAction;
|
|
| 28 |
+import fr.ird.observe.client.ui.content.ContentUI;
|
|
| 29 |
+import java.awt.event.ActionEvent;
|
|
| 30 |
+import java.awt.event.KeyEvent;
|
|
| 31 |
+import java.awt.event.MouseEvent;
|
|
| 32 |
+import java.util.Set;
|
|
| 33 |
+import javax.swing.Action;
|
|
| 34 |
+import javax.swing.ActionMap;
|
|
| 35 |
+import javax.swing.InputMap;
|
|
| 36 |
+import javax.swing.JComponent;
|
|
| 37 |
+import javax.swing.KeyStroke;
|
|
| 38 |
+import javax.swing.SwingUtilities;
|
|
| 39 |
+import org.apache.commons.logging.Log;
|
|
| 40 |
+import org.apache.commons.logging.LogFactory;
|
|
| 41 |
+import org.jdesktop.jxlayer.JXLayer;
|
|
| 42 |
+import org.nuiton.jaxx.runtime.swing.BlockingLayerUI;
|
|
| 43 |
+ |
|
| 44 |
+/**
|
|
| 45 |
+ * Created on 09/11/16.
|
|
| 46 |
+ *
|
|
| 47 |
+ * @author Tony Chemit - dev@tchemit.fr
|
|
| 48 |
+ * @since 6.0
|
|
| 49 |
+ */
|
|
| 50 |
+public class StorageUIBlockingLayerUI extends BlockingLayerUI {
|
|
| 51 |
+ |
|
| 52 |
+ /** Logger */
|
|
| 53 |
+ private static final Log log = LogFactory.getLog(StorageUIBlockingLayerUI.class);
|
|
| 54 |
+ |
|
| 55 |
+ private static final Set<Integer> GLOBAL_KEY_CODES = ImmutableSet.of(
|
|
| 56 |
+ KeyEvent.VK_F1,
|
|
| 57 |
+ KeyEvent.VK_F2,
|
|
| 58 |
+ KeyEvent.VK_F3,
|
|
| 59 |
+ KeyEvent.VK_F4,
|
|
| 60 |
+ KeyEvent.VK_F5,
|
|
| 61 |
+ KeyEvent.VK_F6,
|
|
| 62 |
+ KeyEvent.VK_F7,
|
|
| 63 |
+ KeyEvent.VK_F8,
|
|
| 64 |
+ KeyEvent.VK_F9,
|
|
| 65 |
+ KeyEvent.VK_F10,
|
|
| 66 |
+ KeyEvent.VK_F11,
|
|
| 67 |
+ KeyEvent.VK_F12
|
|
| 68 |
+ );
|
|
| 69 |
+ |
|
| 70 |
+ private final StorageUI ui;
|
|
| 71 |
+ |
|
| 72 |
+ StorageUIBlockingLayerUI(StorageUI ui) {
|
|
| 73 |
+ this.ui = ui;
|
|
| 74 |
+ }
|
|
| 75 |
+ |
|
| 76 |
+ @Override
|
|
| 77 |
+ protected void processMouseEvent(MouseEvent e, JXLayer<? extends JComponent> l) {
|
|
| 78 |
+ |
|
| 79 |
+ switch (e.getID()) {
|
|
| 80 |
+ case MouseEvent.MOUSE_ENTERED:
|
|
| 81 |
+ if (log.isDebugEnabled()) {
|
|
| 82 |
+ log.debug("Enter in formula zone: " + e);
|
|
| 83 |
+ }
|
|
| 84 |
+ ObserveSwingApplicationContext.get().getMainUI().getModel().setFocusOnNavigation(false);
|
|
| 85 |
+ }
|
|
| 86 |
+ super.processMouseEvent(e, l);
|
|
| 87 |
+ }
|
|
| 88 |
+ |
|
| 89 |
+ @Override
|
|
| 90 |
+ protected void processKeyEvent(KeyEvent e, JXLayer<? extends JComponent> l) {
|
|
| 91 |
+ |
|
| 92 |
+ if (block) {
|
|
| 93 |
+ return;
|
|
| 94 |
+ }
|
|
| 95 |
+ |
|
| 96 |
+ InputMap inputMap = ui.getTabs().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
|
|
| 97 |
+ ActionMap actionMap = ui.getTabs().getActionMap();
|
|
| 98 |
+ |
|
| 99 |
+ boolean consumed = e.isConsumed();
|
|
| 100 |
+ |
|
| 101 |
+ if (!consumed && e.isControlDown() && e.getKeyChar() != '\uFFFF') {
|
|
| 102 |
+ |
|
| 103 |
+ KeyStroke keyStroke = KeyStroke.getKeyStroke("ctrl pressed " + (char) e.getKeyCode());
|
|
| 104 |
+ |
|
| 105 |
+ if (keyStroke == null) {
|
|
| 106 |
+ super.processKeyEvent(e, l);
|
|
| 107 |
+ return;
|
|
| 108 |
+ }
|
|
| 109 |
+ consumed = doAction(keyStroke, inputMap, actionMap);
|
|
| 110 |
+ }
|
|
| 111 |
+ |
|
| 112 |
+ if (!consumed && e.getID() == KeyEvent.KEY_RELEASED && !e.isAltDown() && !e.isAltGraphDown()
|
|
| 113 |
+ && !e.isMetaDown() && GLOBAL_KEY_CODES.contains(e.getKeyCode())) {
|
|
| 114 |
+ |
|
| 115 |
+ if (!e.isShiftDown()) {
|
|
| 116 |
+ |
|
| 117 |
+ KeyStroke keyStroke = KeyStroke.getKeyStroke(e.getKeyCode(), e.isControlDown() ? KeyEvent.CTRL_DOWN_MASK : 0);
|
|
| 118 |
+ if (keyStroke == null) {
|
|
| 119 |
+ super.processKeyEvent(e, l);
|
|
| 120 |
+ return;
|
|
| 121 |
+ }
|
|
| 122 |
+ |
|
| 123 |
+ consumed = doAction(keyStroke, inputMap, actionMap);
|
|
| 124 |
+ |
|
| 125 |
+ } else if (e.isControlDown()) {
|
|
| 126 |
+ |
|
| 127 |
+ KeyStroke keyStroke = KeyStroke.getKeyStroke(e.getKeyCode(), KeyEvent.CTRL_DOWN_MASK + KeyEvent.SHIFT_DOWN_MASK);
|
|
| 128 |
+ if (keyStroke == null) {
|
|
| 129 |
+ super.processKeyEvent(e, l);
|
|
| 130 |
+ return;
|
|
| 131 |
+ }
|
|
| 132 |
+ |
|
| 133 |
+ consumed = doAction(keyStroke, inputMap, actionMap);
|
|
| 134 |
+ }
|
|
| 135 |
+ |
|
| 136 |
+ }
|
|
| 137 |
+ |
|
| 138 |
+ if (consumed) {
|
|
| 139 |
+ e.consume();
|
|
| 140 |
+ } else {
|
|
| 141 |
+ super.processKeyEvent(e, l);
|
|
| 142 |
+ }
|
|
| 143 |
+ |
|
| 144 |
+ }
|
|
| 145 |
+ |
|
| 146 |
+ protected boolean doAction(KeyStroke keyStroke, InputMap inputMap, ActionMap actionMap) {
|
|
| 147 |
+ |
|
| 148 |
+ String actionName = (String) inputMap.get(keyStroke);
|
|
| 149 |
+ if (actionName != null) {
|
|
| 150 |
+ |
|
| 151 |
+ Action action = actionMap.get(actionName);
|
|
| 152 |
+ |
|
| 153 |
+ JComponent editor = (JComponent) action.getValue(AbstractUIAction.EDITOR);
|
|
| 154 |
+ if (editor == null || (editor.isVisible() && editor.isEnabled())) {
|
|
| 155 |
+ |
|
| 156 |
+ if (log.isInfoEnabled()) {
|
|
| 157 |
+ log.info("Found action: " + action.getValue(Action.NAME) + " for keyStroke: " + keyStroke);
|
|
| 158 |
+ }
|
|
| 159 |
+ SwingUtilities.invokeLater(() -> action.actionPerformed(new ActionEvent(ui, 0, (String) action.getValue(Action.NAME))));
|
|
| 160 |
+ } else {
|
|
| 161 |
+ if (log.isInfoEnabled()) {
|
|
| 162 |
+ log.info("Found disabled action: " + action.getValue(Action.NAME) + " for keyStroke: " + keyStroke);
|
|
| 163 |
+ }
|
|
| 164 |
+ }
|
|
| 165 |
+ // We found the action, it is now consumed whatever we have done with it.
|
|
| 166 |
+ return true;
|
|
| 167 |
+ }
|
|
| 168 |
+ return false;
|
|
| 169 |
+ }
|
|
| 170 |
+}
|
| ... | ... | @@ -36,6 +36,8 @@ import fr.ird.observe.client.db.constants.ConnexionStatus; |
| 36 | 36 |
import fr.ird.observe.client.ui.ObserveKeyStrokes;
|
| 37 | 37 |
import fr.ird.observe.client.ui.ObserveMainUI;
|
| 38 | 38 |
import fr.ird.observe.client.ui.UIHelper;
|
| 39 |
+import fr.ird.observe.client.ui.actions.AbstractUIAction;
|
|
| 40 |
+import fr.ird.observe.client.ui.storage.tabs.ChooseDbModeUI;
|
|
| 39 | 41 |
import fr.ird.observe.client.ui.storage.tabs.ConfigUI;
|
| 40 | 42 |
import fr.ird.observe.client.ui.storage.tabs.RolesTableModel;
|
| 41 | 43 |
import fr.ird.observe.client.ui.storage.tabs.SecurityModel;
|
| ... | ... | @@ -60,18 +62,22 @@ import java.awt.event.ActionEvent; |
| 60 | 62 |
import java.io.File;
|
| 61 | 63 |
import java.io.FileOutputStream;
|
| 62 | 64 |
import java.io.IOException;
|
| 65 |
+import java.util.Enumeration;
|
|
| 63 | 66 |
import java.util.Objects;
|
| 64 | 67 |
import java.util.Set;
|
| 65 | 68 |
import javax.swing.AbstractAction;
|
| 69 |
+import javax.swing.AbstractButton;
|
|
| 66 | 70 |
import javax.swing.ActionMap;
|
| 67 | 71 |
import javax.swing.InputMap;
|
| 68 | 72 |
import javax.swing.JComponent;
|
| 69 | 73 |
import javax.swing.JTabbedPane;
|
| 74 |
+import javax.swing.KeyStroke;
|
|
| 70 | 75 |
import javax.swing.SwingUtilities;
|
| 71 | 76 |
import org.apache.commons.io.FileUtils;
|
| 72 | 77 |
import org.apache.commons.logging.Log;
|
| 73 | 78 |
import org.apache.commons.logging.LogFactory;
|
| 74 | 79 |
import org.nuiton.jaxx.runtime.spi.UIHandler;
|
| 80 |
+import org.nuiton.jaxx.runtime.swing.JAXXButtonGroup;
|
|
| 75 | 81 |
import org.nuiton.jaxx.runtime.swing.wizard.WizardUILancher;
|
| 76 | 82 |
|
| 77 | 83 |
|
| ... | ... | @@ -755,6 +761,45 @@ public class StorageUIHandler implements UIHandler<StorageUI> { |
| 755 | 761 |
|
| 756 | 762 |
// chargement du modèle
|
| 757 | 763 |
model.init(ui, dataSourceConfiguration);
|
| 764 |
+ |
|
| 765 |
+ ChooseDbModeUI tabUi = ui.getCHOOSE_DB_MODE();
|
|
| 766 |
+ |
|
| 767 |
+ addGroupMnemonic(tabUi.getDbMode(), "pressed F");
|
|
| 768 |
+ addGroupMnemonic(tabUi.getCreationMode(), "ctrl F");
|
|
| 769 |
+ |
|
| 770 |
+ }
|
|
| 771 |
+ |
|
| 772 |
+ private void addGroupMnemonic(JAXXButtonGroup buttonGroup, String keystrokePrefix) {
|
|
| 773 |
+ Enumeration<AbstractButton> elements = buttonGroup.getElements();
|
|
| 774 |
+ int index = 1;
|
|
| 775 |
+ |
|
| 776 |
+ InputMap inputMap = ui.getTabs().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
|
|
| 777 |
+ ActionMap actionMap = ui.getTabs().getActionMap();
|
|
| 778 |
+ while (elements.hasMoreElements()) {
|
|
| 779 |
+ AbstractButton abstractButton = elements.nextElement();
|
|
| 780 |
+ KeyStroke k = KeyStroke.getKeyStroke(keystrokePrefix + (index++));
|
|
| 781 |
+ String actionName = abstractButton.getName();
|
|
| 782 |
+ inputMap.put(k, actionName);
|
|
| 783 |
+ AbstractAction action = new AbstractAction() {
|
|
| 784 |
+ @Override
|
|
| 785 |
+ public void actionPerformed(ActionEvent e) {
|
|
| 786 |
+ abstractButton.doClick();
|
|
| 787 |
+ Boolean changeStep = (Boolean) abstractButton.getClientProperty("changeStep");
|
|
| 788 |
+ if (changeStep != null && changeStep) {
|
|
| 789 |
+ SwingUtilities.invokeLater(ui.getNextAction()::doClick);
|
|
| 790 |
+ return;
|
|
| 791 |
+ }
|
|
| 792 |
+ Boolean apply = (Boolean) abstractButton.getClientProperty("apply");
|
|
| 793 |
+ if (apply != null && apply) {
|
|
| 794 |
+ SwingUtilities.invokeLater(ui.getNextAction()::doClick);
|
|
| 795 |
+ SwingUtilities.invokeLater(ui.getApplyAction()::doClick);
|
|
| 796 |
+ }
|
|
| 797 |
+ }
|
|
| 798 |
+ };
|
|
| 799 |
+ action.putValue(AbstractUIAction.EDITOR, abstractButton);
|
|
| 800 |
+ actionMap.put(actionName, action);
|
|
| 801 |
+ ObserveKeyStrokes.addKeyStroke(abstractButton, k);
|
|
| 802 |
+ }
|
|
| 758 | 803 |
}
|
| 759 | 804 |
|
| 760 | 805 |
private void initSelectData(StorageUI ui) {
|
| ... | ... | @@ -26,27 +26,15 @@ import fr.ird.observe.client.I18nEnumHelper; |
| 26 | 26 |
import fr.ird.observe.client.ObserveSwingApplicationContext;
|
| 27 | 27 |
import fr.ird.observe.client.ObserveTextGenerator;
|
| 28 | 28 |
import fr.ird.observe.client.configuration.constants.CreationMode;
|
| 29 |
-import fr.ird.observe.client.ui.ObserveKeyStrokes;
|
|
| 30 | 29 |
import fr.ird.observe.client.ui.storage.StorageStep;
|
| 31 |
-import fr.ird.observe.client.ui.storage.StorageUI;
|
|
| 32 | 30 |
import fr.ird.observe.client.ui.storage.StorageUIModel;
|
| 33 | 31 |
import java.awt.Component;
|
| 34 |
-import java.awt.event.ActionEvent;
|
|
| 35 | 32 |
import java.beans.PropertyChangeListener;
|
| 36 | 33 |
import java.io.File;
|
| 37 | 34 |
import java.util.Date;
|
| 38 |
-import java.util.Enumeration;
|
|
| 39 |
-import javax.swing.AbstractAction;
|
|
| 40 |
-import javax.swing.AbstractButton;
|
|
| 41 |
-import javax.swing.ActionMap;
|
|
| 42 |
-import javax.swing.InputMap;
|
|
| 43 |
-import javax.swing.JComponent;
|
|
| 44 | 35 |
import javax.swing.JPanel;
|
| 45 | 36 |
import javax.swing.JRadioButton;
|
| 46 |
-import javax.swing.KeyStroke;
|
|
| 47 |
-import javax.swing.SwingUtilities;
|
|
| 48 | 37 |
import org.nuiton.jaxx.runtime.spi.UIHandler;
|
| 49 |
-import org.nuiton.jaxx.runtime.swing.JAXXButtonGroup;
|
|
| 50 | 38 |
|
| 51 | 39 |
|
| 52 | 40 |
import static org.nuiton.i18n.I18n.t;
|
| ... | ... | @@ -73,42 +61,6 @@ public class ChooseDbModeUIHandler extends StorageTabUIHandler<ChooseDbModeUI> i |
| 73 | 61 |
model.addPropertyChangeListener(StorageUIModel.DB_MODE_PROPERTY_NAME, listener);
|
| 74 | 62 |
model.addPropertyChangeListener(StorageUIModel.CREATION_MODE_PROPERTY_NAME, listener);
|
| 75 | 63 |
ui.setDescriptionText(t(StorageStep.CHOOSE_DB_MODE.getDescription()));
|
| 76 |
- |
|
| 77 |
- addGroupMnemonic(ui.getDbMode(), "pressed F");
|
|
| 78 |
- addGroupMnemonic(ui.getCreationMode(), "ctrl F");
|
|
| 79 |
- |
|
| 80 |
- }
|
|
| 81 |
- |
|
| 82 |
- private void addGroupMnemonic(JAXXButtonGroup buttonGroup, String keystrokePrefix) {
|
|
| 83 |
- Enumeration<AbstractButton> elements = buttonGroup.getElements();
|
|
| 84 |
- int index = 1;
|
|
| 85 |
- InputMap inputMap = ui.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
|
|
| 86 |
- ActionMap actionMap = ui.getActionMap();
|
|
| 87 |
- while (elements.hasMoreElements()) {
|
|
| 88 |
- AbstractButton abstractButton = elements.nextElement();
|
|
| 89 |
- KeyStroke k = KeyStroke.getKeyStroke(keystrokePrefix + (index++));
|
|
| 90 |
- String actionName = abstractButton.getName();
|
|
| 91 |
- inputMap.put(k, actionName);
|
|
| 92 |
- actionMap.put(actionName, new AbstractAction() {
|
|
| 93 |
- @Override
|
|
| 94 |
- public void actionPerformed(ActionEvent e) {
|
|
| 95 |
- abstractButton.doClick();
|
|
| 96 |
- Boolean changeStep = (Boolean) abstractButton.getClientProperty("changeStep");
|
|
| 97 |
- if (changeStep != null && changeStep) {
|
|
| 98 |
- StorageUI parentContainer = ui.getParentContainer(StorageUI.class);
|
|
| 99 |
- SwingUtilities.invokeLater(parentContainer.getNextAction()::doClick);
|
|
| 100 |
- return;
|
|
| 101 |
- }
|
|
| 102 |
- Boolean apply = (Boolean) abstractButton.getClientProperty("apply");
|
|
| 103 |
- if (apply != null && apply) {
|
|
| 104 |
- StorageUI parentContainer = ui.getParentContainer(StorageUI.class);
|
|
| 105 |
- SwingUtilities.invokeLater(parentContainer.getNextAction()::doClick);
|
|
| 106 |
- SwingUtilities.invokeLater(parentContainer.getApplyAction()::doClick);
|
|
| 107 |
- }
|
|
| 108 |
- }
|
|
| 109 |
- });
|
|
| 110 |
- ObserveKeyStrokes.addKeyStroke(abstractButton, k);
|
|
| 111 |
- }
|
|
| 112 | 64 |
}
|
| 113 | 65 |
|
| 114 | 66 |
protected String updateInternalDumpModeLabel(@SuppressWarnings("unused") boolean dumpExist) {
|