Author: tchemit Date: 2013-05-23 18:55:31 +0200 (Thu, 23 May 2013) New Revision: 999 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/999 Log: fixes #2503: [ERGO] etat du bouton ?\195?\169diter Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/SelectCruiseUIHandler.java Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/SelectCruiseUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/SelectCruiseUIHandler.java 2013-05-23 16:23:44 UTC (rev 998) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/SelectCruiseUIHandler.java 2013-05-23 16:55:31 UTC (rev 999) @@ -43,7 +43,9 @@ import javax.swing.JComboBox; import javax.swing.JComponent; import java.awt.event.ActionEvent; +import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.util.List; @@ -62,6 +64,14 @@ protected final PersistenceService persistenceService; + public static final MouseListener GRAB_FOCUS_ON_ENTER_LISTENER = new MouseAdapter() { + @Override + public void mouseEntered(MouseEvent e) { + JComponent source = (JComponent) e.getSource(); + source.grabFocus(); + } + }; + public SelectCruiseUIHandler(TuttiUI<?, ?> parentUI, SelectCruiseUI ui) { super(parentUI.getHandler().getContext(), ui); persistenceService = context.getPersistenceService(); @@ -164,10 +174,10 @@ Lists.newArrayList(model.getProtocols()), model.getProtocol()); - ui.getEditCruiseComboBox().putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE); - ui.getEditProgramComboBox().putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE); - ui.getEditProtocolComboBox().putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE); - ui.getNewProtocolComboBox().putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE); + initActionComboBox(ui.getEditProgramComboBox()); + initActionComboBox(ui.getEditCruiseComboBox()); + initActionComboBox(ui.getEditProtocolComboBox()); + initActionComboBox(ui.getNewProtocolComboBox()); model.addPropertyChangeListener(SelectCruiseUIModel.PROPERTY_PROTOCOLS, new PropertyChangeListener() { @Override @@ -250,10 +260,21 @@ protected boolean resetEditProtocolAction; + protected boolean resetNewProtocolAction; + protected boolean resetEditProgramAction; protected boolean resetEditCruiseAction; + public void resetNewProtolAction() { + resetNewProtocolAction = true; + try { + ui.getNewProtocolComboBox().setSelectedIndex(0); + } finally { + resetNewProtocolAction = false; + } + } + public void resetEditProtolAction() { resetEditProtocolAction = true; try { @@ -295,80 +316,34 @@ public void startEditProgramAction(MouseEvent event) { startComboFirstAction(event); -// JComboBox existingProgramCombo = (JComboBox) event.getSource(); -// TuttiActionHelper.runAction((AbstractButton) existingProgramCombo.getItemAt(0)); } public void startEditProgramAction(ActionEvent event) { startEditAction(!resetEditProgramAction, event); -// JComboBox existingProgramCombo = (JComboBox) event.getSource(); -// JButton selectedAction = (JButton) existingProgramCombo.getSelectedItem(); -// // hide popup before performing the action, otherwise, if the action -// // opens a popup, the user must click a first time to hide the combobox -// // popup to then interact with the popup opened by the action -// // (see http://forge.codelutin.com/issues/2032) -// existingProgramCombo.setSelectedIndex(0); -// existingProgramCombo.hidePopup(); -// TuttiActionHelper.runAction(selectedAction); } public void startEditCruiseAction(MouseEvent event) { startComboFirstAction(event); -// JComboBox existingCruiseCombo = (JComboBox) event.getSource(); -// TuttiActionHelper.runAction((AbstractButton) existingCruiseCombo.getItemAt(0)); } public void startEditCruiseAction(ActionEvent event) { startEditAction(!resetEditCruiseAction, event); -// JComboBox existingCruiseCombo = (JComboBox) event.getSource(); -// JButton selectedAction = (JButton) existingCruiseCombo.getSelectedItem(); -// // hide popup before performing the action, otherwise, if the action -// // opens a popup, the user must click a first time to hide the combobox -// // popup to then interact with the popup opened by the action -// // (see http://forge.codelutin.com/issues/2032) -// existingCruiseCombo.setSelectedIndex(0); -// existingCruiseCombo.hidePopup(); -// TuttiActionHelper.runAction(selectedAction); } public void startExistingProtocolAction(MouseEvent event) { startComboFirstAction(event); -// JComboBox existingProtocolCombo = (JComboBox) event.getSource(); -// TuttiActionHelper.runAction((AbstractButton) existingProtocolCombo.getItemAt(0)); } public void startExistingProtocolAction(ActionEvent event) { startEditAction(!resetEditProtocolAction, event); -// if (!resetEditProtocolAction) { -// JComboBox existingProtocolCombo = (JComboBox) event.getSource(); -// JButton selectedAction = (JButton) existingProtocolCombo.getSelectedItem(); -// // hide popup before performing the action, otherwise, if the action -// // opens a popup, the user must click a first time to hide the combobox -// // popup to then interact with the popup opened by the action -// // (see http://forge.codelutin.com/issues/2032) -// existingProtocolCombo.setSelectedIndex(0); -// existingProtocolCombo.hidePopup(); -// TuttiActionHelper.runAction(selectedAction); -// } } public void startNewProtocolAction(MouseEvent event) { startComboFirstAction(event); -// JComboBox newProtocolCombo = (JComboBox) event.getSource(); -// TuttiActionHelper.runAction((AbstractButton) newProtocolCombo.getItemAt(0)); } public void startNewProtocolAction(ActionEvent event) { - startEditAction(true, event); -// JComboBox newProtocolCombo = (JComboBox) event.getSource(); -// JButton selectedAction = (JButton) newProtocolCombo.getSelectedItem(); -// // hide popup before performing the action, otherwise, if the action -// // opens a popup, the user must click a first time to hide the combobox -// // popup to then interact with the popup opened by the action -// // (see http://forge.codelutin.com/issues/2032) -// newProtocolCombo.setSelectedIndex(0); -// newProtocolCombo.hidePopup(); -// TuttiActionHelper.runAction(selectedAction); + startEditAction(!resetNewProtocolAction, event); } protected void startComboFirstAction(MouseEvent event) { @@ -389,4 +364,9 @@ TuttiActionHelper.runAction(selectedAction); } } + + protected void initActionComboBox(JComboBox combo) { + combo.putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE); + combo.addMouseListener(GRAB_FOCUS_ON_ENTER_LISTENER); + } }