Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe Commits: a72cf7a2 by Tony CHEMIT at 2017-08-04T21:43:04+02:00 Raccourcis sur assistant de connexion (See #822) - - - - - 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: ===================================== client/src/main/java/fr/ird/observe/client/ui/storage/StorageUI.jaxx ===================================== --- a/client/src/main/java/fr/ird/observe/client/ui/storage/StorageUI.jaxx +++ b/client/src/main/java/fr/ird/observe/client/ui/storage/StorageUI.jaxx @@ -44,7 +44,7 @@ <StorageUIModel id='model' javaBean='getContextValue(StorageUIModel.class)'/> <!-- le bloqueur d'ui lorsqu'une action est en cours ou annulée --> - <BlockingLayerUI id='busyBlockLayerUI'/> + <StorageUIBlockingLayerUI id='busyBlockLayerUI' constructorParams='this'/> <CardLayout> <!-- les differents contenu d'onglets --> ===================================== client/src/main/java/fr/ird/observe/client/ui/storage/StorageUIBlockingLayerUI.java ===================================== --- /dev/null +++ b/client/src/main/java/fr/ird/observe/client/ui/storage/StorageUIBlockingLayerUI.java @@ -0,0 +1,170 @@ +package fr.ird.observe.client.ui.storage; + +/*- + * #%L + * ObServe :: Client + * %% + * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import com.google.common.collect.ImmutableSet; +import fr.ird.observe.client.ObserveSwingApplicationContext; +import fr.ird.observe.client.ui.actions.AbstractUIAction; +import fr.ird.observe.client.ui.content.ContentUI; +import java.awt.event.ActionEvent; +import java.awt.event.KeyEvent; +import java.awt.event.MouseEvent; +import java.util.Set; +import javax.swing.Action; +import javax.swing.ActionMap; +import javax.swing.InputMap; +import javax.swing.JComponent; +import javax.swing.KeyStroke; +import javax.swing.SwingUtilities; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.jdesktop.jxlayer.JXLayer; +import org.nuiton.jaxx.runtime.swing.BlockingLayerUI; + +/** + * Created on 09/11/16. + * + * @author Tony Chemit - dev@tchemit.fr + * @since 6.0 + */ +public class StorageUIBlockingLayerUI extends BlockingLayerUI { + + /** Logger */ + private static final Log log = LogFactory.getLog(StorageUIBlockingLayerUI.class); + + private static final Set<Integer> GLOBAL_KEY_CODES = ImmutableSet.of( + KeyEvent.VK_F1, + KeyEvent.VK_F2, + KeyEvent.VK_F3, + KeyEvent.VK_F4, + KeyEvent.VK_F5, + KeyEvent.VK_F6, + KeyEvent.VK_F7, + KeyEvent.VK_F8, + KeyEvent.VK_F9, + KeyEvent.VK_F10, + KeyEvent.VK_F11, + KeyEvent.VK_F12 + ); + + private final StorageUI ui; + + StorageUIBlockingLayerUI(StorageUI ui) { + this.ui = ui; + } + + @Override + protected void processMouseEvent(MouseEvent e, JXLayer<? extends JComponent> l) { + + switch (e.getID()) { + case MouseEvent.MOUSE_ENTERED: + if (log.isDebugEnabled()) { + log.debug("Enter in formula zone: " + e); + } + ObserveSwingApplicationContext.get().getMainUI().getModel().setFocusOnNavigation(false); + } + super.processMouseEvent(e, l); + } + + @Override + protected void processKeyEvent(KeyEvent e, JXLayer<? extends JComponent> l) { + + if (block) { + return; + } + + InputMap inputMap = ui.getTabs().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); + ActionMap actionMap = ui.getTabs().getActionMap(); + + boolean consumed = e.isConsumed(); + + if (!consumed && e.isControlDown() && e.getKeyChar() != '\uFFFF') { + + KeyStroke keyStroke = KeyStroke.getKeyStroke("ctrl pressed " + (char) e.getKeyCode()); + + if (keyStroke == null) { + super.processKeyEvent(e, l); + return; + } + consumed = doAction(keyStroke, inputMap, actionMap); + } + + if (!consumed && e.getID() == KeyEvent.KEY_RELEASED && !e.isAltDown() && !e.isAltGraphDown() + && !e.isMetaDown() && GLOBAL_KEY_CODES.contains(e.getKeyCode())) { + + if (!e.isShiftDown()) { + + KeyStroke keyStroke = KeyStroke.getKeyStroke(e.getKeyCode(), e.isControlDown() ? KeyEvent.CTRL_DOWN_MASK : 0); + if (keyStroke == null) { + super.processKeyEvent(e, l); + return; + } + + consumed = doAction(keyStroke, inputMap, actionMap); + + } else if (e.isControlDown()) { + + KeyStroke keyStroke = KeyStroke.getKeyStroke(e.getKeyCode(), KeyEvent.CTRL_DOWN_MASK + KeyEvent.SHIFT_DOWN_MASK); + if (keyStroke == null) { + super.processKeyEvent(e, l); + return; + } + + consumed = doAction(keyStroke, inputMap, actionMap); + } + + } + + if (consumed) { + e.consume(); + } else { + super.processKeyEvent(e, l); + } + + } + + protected boolean doAction(KeyStroke keyStroke, InputMap inputMap, ActionMap actionMap) { + + String actionName = (String) inputMap.get(keyStroke); + if (actionName != null) { + + Action action = actionMap.get(actionName); + + JComponent editor = (JComponent) action.getValue(AbstractUIAction.EDITOR); + if (editor == null || (editor.isVisible() && editor.isEnabled())) { + + if (log.isInfoEnabled()) { + log.info("Found action: " + action.getValue(Action.NAME) + " for keyStroke: " + keyStroke); + } + SwingUtilities.invokeLater(() -> action.actionPerformed(new ActionEvent(ui, 0, (String) action.getValue(Action.NAME)))); + } else { + if (log.isInfoEnabled()) { + log.info("Found disabled action: " + action.getValue(Action.NAME) + " for keyStroke: " + keyStroke); + } + } + // We found the action, it is now consumed whatever we have done with it. + return true; + } + return false; + } +} ===================================== client/src/main/java/fr/ird/observe/client/ui/storage/StorageUIHandler.java ===================================== --- a/client/src/main/java/fr/ird/observe/client/ui/storage/StorageUIHandler.java +++ b/client/src/main/java/fr/ird/observe/client/ui/storage/StorageUIHandler.java @@ -36,6 +36,8 @@ import fr.ird.observe.client.db.constants.ConnexionStatus; import fr.ird.observe.client.ui.ObserveKeyStrokes; import fr.ird.observe.client.ui.ObserveMainUI; import fr.ird.observe.client.ui.UIHelper; +import fr.ird.observe.client.ui.actions.AbstractUIAction; +import fr.ird.observe.client.ui.storage.tabs.ChooseDbModeUI; import fr.ird.observe.client.ui.storage.tabs.ConfigUI; import fr.ird.observe.client.ui.storage.tabs.RolesTableModel; import fr.ird.observe.client.ui.storage.tabs.SecurityModel; @@ -60,18 +62,22 @@ import java.awt.event.ActionEvent; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +import java.util.Enumeration; import java.util.Objects; import java.util.Set; import javax.swing.AbstractAction; +import javax.swing.AbstractButton; import javax.swing.ActionMap; import javax.swing.InputMap; import javax.swing.JComponent; import javax.swing.JTabbedPane; +import javax.swing.KeyStroke; import javax.swing.SwingUtilities; import org.apache.commons.io.FileUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.jaxx.runtime.spi.UIHandler; +import org.nuiton.jaxx.runtime.swing.JAXXButtonGroup; import org.nuiton.jaxx.runtime.swing.wizard.WizardUILancher; @@ -755,6 +761,45 @@ public class StorageUIHandler implements UIHandler<StorageUI> { // chargement du modèle model.init(ui, dataSourceConfiguration); + + ChooseDbModeUI tabUi = ui.getCHOOSE_DB_MODE(); + + addGroupMnemonic(tabUi.getDbMode(), "pressed F"); + addGroupMnemonic(tabUi.getCreationMode(), "ctrl F"); + + } + + private void addGroupMnemonic(JAXXButtonGroup buttonGroup, String keystrokePrefix) { + Enumeration<AbstractButton> elements = buttonGroup.getElements(); + int index = 1; + + InputMap inputMap = ui.getTabs().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); + ActionMap actionMap = ui.getTabs().getActionMap(); + while (elements.hasMoreElements()) { + AbstractButton abstractButton = elements.nextElement(); + KeyStroke k = KeyStroke.getKeyStroke(keystrokePrefix + (index++)); + String actionName = abstractButton.getName(); + inputMap.put(k, actionName); + AbstractAction action = new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + abstractButton.doClick(); + Boolean changeStep = (Boolean) abstractButton.getClientProperty("changeStep"); + if (changeStep != null && changeStep) { + SwingUtilities.invokeLater(ui.getNextAction()::doClick); + return; + } + Boolean apply = (Boolean) abstractButton.getClientProperty("apply"); + if (apply != null && apply) { + SwingUtilities.invokeLater(ui.getNextAction()::doClick); + SwingUtilities.invokeLater(ui.getApplyAction()::doClick); + } + } + }; + action.putValue(AbstractUIAction.EDITOR, abstractButton); + actionMap.put(actionName, action); + ObserveKeyStrokes.addKeyStroke(abstractButton, k); + } } private void initSelectData(StorageUI ui) { ===================================== client/src/main/java/fr/ird/observe/client/ui/storage/tabs/ChooseDbModeUIHandler.java ===================================== --- a/client/src/main/java/fr/ird/observe/client/ui/storage/tabs/ChooseDbModeUIHandler.java +++ b/client/src/main/java/fr/ird/observe/client/ui/storage/tabs/ChooseDbModeUIHandler.java @@ -26,27 +26,15 @@ import fr.ird.observe.client.I18nEnumHelper; import fr.ird.observe.client.ObserveSwingApplicationContext; import fr.ird.observe.client.ObserveTextGenerator; import fr.ird.observe.client.configuration.constants.CreationMode; -import fr.ird.observe.client.ui.ObserveKeyStrokes; import fr.ird.observe.client.ui.storage.StorageStep; -import fr.ird.observe.client.ui.storage.StorageUI; import fr.ird.observe.client.ui.storage.StorageUIModel; import java.awt.Component; -import java.awt.event.ActionEvent; import java.beans.PropertyChangeListener; import java.io.File; import java.util.Date; -import java.util.Enumeration; -import javax.swing.AbstractAction; -import javax.swing.AbstractButton; -import javax.swing.ActionMap; -import javax.swing.InputMap; -import javax.swing.JComponent; import javax.swing.JPanel; import javax.swing.JRadioButton; -import javax.swing.KeyStroke; -import javax.swing.SwingUtilities; import org.nuiton.jaxx.runtime.spi.UIHandler; -import org.nuiton.jaxx.runtime.swing.JAXXButtonGroup; import static org.nuiton.i18n.I18n.t; @@ -73,42 +61,6 @@ public class ChooseDbModeUIHandler extends StorageTabUIHandler<ChooseDbModeUI> i model.addPropertyChangeListener(StorageUIModel.DB_MODE_PROPERTY_NAME, listener); model.addPropertyChangeListener(StorageUIModel.CREATION_MODE_PROPERTY_NAME, listener); ui.setDescriptionText(t(StorageStep.CHOOSE_DB_MODE.getDescription())); - - addGroupMnemonic(ui.getDbMode(), "pressed F"); - addGroupMnemonic(ui.getCreationMode(), "ctrl F"); - - } - - private void addGroupMnemonic(JAXXButtonGroup buttonGroup, String keystrokePrefix) { - Enumeration<AbstractButton> elements = buttonGroup.getElements(); - int index = 1; - InputMap inputMap = ui.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); - ActionMap actionMap = ui.getActionMap(); - while (elements.hasMoreElements()) { - AbstractButton abstractButton = elements.nextElement(); - KeyStroke k = KeyStroke.getKeyStroke(keystrokePrefix + (index++)); - String actionName = abstractButton.getName(); - inputMap.put(k, actionName); - actionMap.put(actionName, new AbstractAction() { - @Override - public void actionPerformed(ActionEvent e) { - abstractButton.doClick(); - Boolean changeStep = (Boolean) abstractButton.getClientProperty("changeStep"); - if (changeStep != null && changeStep) { - StorageUI parentContainer = ui.getParentContainer(StorageUI.class); - SwingUtilities.invokeLater(parentContainer.getNextAction()::doClick); - return; - } - Boolean apply = (Boolean) abstractButton.getClientProperty("apply"); - if (apply != null && apply) { - StorageUI parentContainer = ui.getParentContainer(StorageUI.class); - SwingUtilities.invokeLater(parentContainer.getNextAction()::doClick); - SwingUtilities.invokeLater(parentContainer.getApplyAction()::doClick); - } - } - }); - ObserveKeyStrokes.addKeyStroke(abstractButton, k); - } } protected String updateInternalDumpModeLabel(@SuppressWarnings("unused") boolean dumpExist) { View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/commit/a72cf7a2f08de9f405f37a8012f0... --- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/commit/a72cf7a2f08de9f405f37a8012f0... You're receiving this email because of your account on gitlab.com.