[ 1646152 ] Shortcut Alt-Down not saving pending numeric field changes

- enhance support for editor that do commit on focus lost instead of every keystroke.
This commit is contained in:
Heng Sin Low 2008-02-27 18:44:22 +00:00
parent 27208593d6
commit be7aa6cab3
4 changed files with 96 additions and 9 deletions

View File

@ -1313,6 +1313,7 @@ public final class APanel extends CPanel
if (tabPane.isEnabledAt(index)) if (tabPane.isEnabledAt(index))
{ {
m_curGC.getTable().removeEditor(); m_curGC.getTable().removeEditor();
m_curGC.acceptEditorChanges();
tabPane.setSelectedIndex(index); tabPane.setSelectedIndex(index);
break; break;
} }
@ -1323,6 +1324,7 @@ public final class APanel extends CPanel
else else
{ {
m_curGC.getTable().removeEditor(); m_curGC.getTable().removeEditor();
m_curGC.acceptEditorChanges();
m_curWinTab.setSelectedIndex(index+1); m_curWinTab.setSelectedIndex(index+1);
} }
@ -1346,6 +1348,7 @@ public final class APanel extends CPanel
if (tabPane.isEnabledAt(index)) if (tabPane.isEnabledAt(index))
{ {
m_curGC.getTable().removeEditor(); m_curGC.getTable().removeEditor();
m_curGC.acceptEditorChanges();
tabPane.setSelectedIndex(index); tabPane.setSelectedIndex(index);
break; break;
} }
@ -1356,6 +1359,7 @@ public final class APanel extends CPanel
else else
{ {
m_curGC.getTable().removeEditor(); m_curGC.getTable().removeEditor();
m_curGC.acceptEditorChanges();
m_curWinTab.setSelectedIndex(index-1); m_curWinTab.setSelectedIndex(index-1);
} }
} // navigateParent } // navigateParent
@ -1444,6 +1448,7 @@ public final class APanel extends CPanel
else if (cmd.equals(aFirst.getName())) else if (cmd.equals(aFirst.getName()))
{ /*cmd_save(false);*/ { /*cmd_save(false);*/
m_curGC.getTable().removeEditor(); m_curGC.getTable().removeEditor();
m_curGC.acceptEditorChanges();
m_curTab.navigate(0); m_curTab.navigate(0);
} }
else if (cmd.equals(aSwitchLinesUpAction.getName())) else if (cmd.equals(aSwitchLinesUpAction.getName()))
@ -1457,6 +1462,7 @@ public final class APanel extends CPanel
{ /* cmd_save(false); */ { /* cmd_save(false); */
//up-image + shift //up-image + shift
m_curGC.getTable().removeEditor(); m_curGC.getTable().removeEditor();
m_curGC.acceptEditorChanges();
if ((e.getModifiers() & ActionEvent.SHIFT_MASK) != 0) { if ((e.getModifiers() & ActionEvent.SHIFT_MASK) != 0) {
m_curTab.switchRows(m_curTab.getCurrentRow(), m_curTab.getCurrentRow() - 1, m_curGC.getTable().getSortColumn(), m_curGC.getTable().isSortAscending()); m_curTab.switchRows(m_curTab.getCurrentRow(), m_curTab.getCurrentRow() - 1, m_curGC.getTable().getSortColumn(), m_curGC.getTable().isSortAscending());
} else { } else {
@ -1474,6 +1480,7 @@ public final class APanel extends CPanel
{ /* cmd_save(false); */ { /* cmd_save(false); */
//down-image + shift //down-image + shift
m_curGC.getTable().removeEditor(); m_curGC.getTable().removeEditor();
m_curGC.acceptEditorChanges();
if ((e.getModifiers() & ActionEvent.SHIFT_MASK) != 0) { if ((e.getModifiers() & ActionEvent.SHIFT_MASK) != 0) {
m_curTab.switchRows(m_curTab.getCurrentRow(), m_curTab.getCurrentRow() + 1, m_curGC.getTable().getSortColumn(), m_curGC.getTable().isSortAscending()); m_curTab.switchRows(m_curTab.getCurrentRow(), m_curTab.getCurrentRow() + 1, m_curGC.getTable().getSortColumn(), m_curGC.getTable().isSortAscending());
} else { } else {
@ -1483,6 +1490,7 @@ public final class APanel extends CPanel
else if (cmd.equals(aLast.getName())) else if (cmd.equals(aLast.getName()))
{ /*cmd_save(false);*/ { /*cmd_save(false);*/
m_curGC.getTable().removeEditor(); m_curGC.getTable().removeEditor();
m_curGC.acceptEditorChanges();
m_curTab.navigate(m_curTab.getRowCount()-1); m_curTab.navigate(m_curTab.getRowCount()-1);
} }
else if (cmd.equals(aParent.getName())) else if (cmd.equals(aParent.getName()))
@ -1687,6 +1695,7 @@ public final class APanel extends CPanel
log.config("Manual=" + manualCmd); log.config("Manual=" + manualCmd);
m_errorDisplayed = false; m_errorDisplayed = false;
m_curGC.stopEditor(true); m_curGC.stopEditor(true);
m_curGC.acceptEditorChanges();
if (m_curAPanelTab != null) if (m_curAPanelTab != null)
{ {

View File

@ -1239,8 +1239,32 @@ public class GridController extends CPanel
} }
//FR [ 1757088 ] //FR [ 1757088 ]
public VPanel getvPanel() public VPanel getvPanel()
{ {
return vPanel; return vPanel;
} }
/**
* Accept pending editor changes.
*/
public void acceptEditorChanges()
{
if (isSingleRow())
{
Component c = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
if (c != null && this.isAncestorOf(c))
{
Component t = c;
while (t != null && t != this)
{
if (t instanceof VManagedEditor)
{
((VManagedEditor)t).commitChanges();
return;
}
t = t.getParent();
}
}
}
}
} // GridController } // GridController

View File

@ -0,0 +1,37 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 2008 Low Heng Sin All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. 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, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
*****************************************************************************/
package org.compiere.grid.ed;
/**
* Interface for editor with a commit and rollback lifecycle.
* @author Low Heng Sin
*
*/
public interface VManagedEditor {
/**
* Commit pending changes
*/
public void commitChanges();
/**
* Rollback pending changes
*/
public void rollbackChanges();
/**
* Are there any pending changes
* @return boolean
*/
public boolean isDirty();
}

View File

@ -40,7 +40,7 @@ import org.compiere.util.*;
* <li>BF [ 1834393 ] VNumber.setFocusable not working * <li>BF [ 1834393 ] VNumber.setFocusable not working
*/ */
public final class VNumber extends JComponent public final class VNumber extends JComponent
implements VEditor, ActionListener, KeyListener, FocusListener implements VEditor, ActionListener, KeyListener, FocusListener, VManagedEditor
{ {
/** Number of Columns (12) */ /** Number of Columns (12) */
public final static int SIZE = 12; public final static int SIZE = 12;
@ -524,8 +524,11 @@ public final class VNumber extends JComponent
fireVetoableChange (m_columnName, m_oldText, getValue()); fireVetoableChange (m_columnName, m_oldText, getValue());
fireActionPerformed(); fireActionPerformed();
} }
else // indicate change else
fireVetoableChange (m_columnName, m_oldText, getValue()); {
// indicate change
fireVetoableChange (m_columnName, m_oldText, null);
}
} }
catch (PropertyVetoException pve) {} catch (PropertyVetoException pve) {}
m_setting = false; m_setting = false;
@ -555,7 +558,10 @@ public final class VNumber extends JComponent
m_text.setText(m_initialText); m_text.setText(m_initialText);
return; return;
}*/ }*/
commitChanges();
} // focusLost
public void commitChanges() {
Object oo = getValue(); Object oo = getValue();
if (m_rangeSet) if (m_rangeSet)
{ {
@ -598,7 +604,7 @@ public final class VNumber extends JComponent
} }
catch (PropertyVetoException pve) catch (PropertyVetoException pve)
{} {}
} // focusLost }
/** /**
* Invalid Entry - Start Calculator * Invalid Entry - Start Calculator
@ -710,4 +716,15 @@ public final class VNumber extends JComponent
} }
} // fireActionPerformed } // fireActionPerformed
/**/ /**/
public boolean isDirty() {
return m_modified;
}
public void rollbackChanges() {
m_text.setText (m_oldText);
m_initialText = m_oldText;
m_modified = false;
}
} // VNumber } // VNumber