IDEMPIERE-1149 Implements SetFocus on field - handle the default focus in edit mode for grid view

This commit is contained in:
Elaine Tan 2013-08-05 17:05:02 +08:00
parent 4277e7395e
commit beaaf3e8e3
1 changed files with 23 additions and 7 deletions

View File

@ -27,6 +27,7 @@ import org.adempiere.webui.component.Urlbox;
import org.adempiere.webui.editor.WButtonEditor;
import org.adempiere.webui.editor.WEditor;
import org.adempiere.webui.editor.WEditorPopupMenu;
import org.adempiere.webui.editor.WImageEditor;
import org.adempiere.webui.editor.WebEditorFactory;
import org.adempiere.webui.event.ActionEvent;
import org.adempiere.webui.event.ActionListener;
@ -89,6 +90,9 @@ public class GridTabRowRenderer implements RowRenderer<Object[]>, RowRendererExt
private int currentRowIndex = -1;
private AbstractADWindowContent m_windowPanel;
private ActionListener buttonListener;
/** DefaultFocusField */
private WEditor defaultFocusField = null;
/**
*
@ -384,6 +388,10 @@ public class GridTabRowRenderer implements RowRenderer<Object[]>, RowRendererExt
editor.getComponent().setWidgetOverride("fieldHelp", HelpController.escapeJavascriptContent(gridPanelFields[i].getHelp()));
editor.getComponent().setWidgetListener("onFocus", "zWatch.fire('onFieldTooltip', this, null, this.fieldHeader(), this.fieldDescription(), this.fieldHelp());");
editor.getComponent().setWidgetListener("onBlur", "zWatch.fire('onFieldTooltip', this);");
// Default Focus
if (defaultFocusField == null && gridPanelFields[i].isDefaultFocus())
defaultFocusField = editor;
}
if (!gridPanelFields[i].isDisplayedGrid() || gridPanelFields[i].isToolbarButton()) {
@ -585,14 +593,22 @@ public class GridTabRowRenderer implements RowRenderer<Object[]>, RowRendererExt
if (currentRow != null && currentRow.getParent() != null) {
WEditor toFocus = null;
WEditor firstEditor = null;
for (WEditor editor : getEditors()) {
if (editor.isVisible() && editor.getComponent().getParent() != null) {
if (editor.isReadWrite()) {
toFocus = editor;
break;
if (defaultFocusField != null
&& defaultFocusField.isVisible() && defaultFocusField.isReadWrite() && defaultFocusField.getComponent().getParent() != null
&& !(defaultFocusField instanceof WImageEditor)) {
toFocus = defaultFocusField;
}
else
{
for (WEditor editor : getEditors()) {
if (editor.isVisible() && editor.getComponent().getParent() != null) {
if (editor.isReadWrite()) {
toFocus = editor;
break;
}
if (firstEditor == null)
firstEditor = editor;
}
if (firstEditor == null)
firstEditor = editor;
}
}
if (toFocus != null) {