- don't prompt save ignored
- auto focus to error field
- messagebox should always be modal
This commit is contained in:
Heng Sin Low 2009-05-19 09:01:35 +00:00
parent a8793b1fad
commit 30e7e53baa
5 changed files with 177 additions and 143 deletions

View File

@ -27,6 +27,7 @@ import org.compiere.model.GridTable;
import org.compiere.model.MSysConfig; import org.compiere.model.MSysConfig;
import org.compiere.util.DisplayType; import org.compiere.util.DisplayType;
import org.compiere.util.Env; import org.compiere.util.Env;
import org.zkoss.zk.au.out.AuFocus;
import org.zkoss.zk.au.out.AuScript; import org.zkoss.zk.au.out.AuScript;
import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.Event;
@ -49,7 +50,7 @@ import org.zkoss.zul.event.ZulEvents;
public class GridPanel extends Borderlayout implements EventListener public class GridPanel extends Borderlayout implements EventListener
{ {
/** /**
* *
*/ */
private static final long serialVersionUID = 860960136170704359L; private static final long serialVersionUID = 860960136170704359L;
@ -58,18 +59,18 @@ public class GridPanel extends Borderlayout implements EventListener
private static final int MAX_COLUMN_WIDTH = 300; private static final int MAX_COLUMN_WIDTH = 300;
private Grid listbox = null; private Grid listbox = null;
private int pageSize = 100; private int pageSize = 100;
private GridField[] gridField; private GridField[] gridField;
private AbstractTableModel tableModel; private AbstractTableModel tableModel;
private int numColumns = 5; private int numColumns = 5;
private int windowNo; private int windowNo;
private GridTab gridTab; private GridTab gridTab;
private boolean init; private boolean init;
private GridTableListModel listModel; private GridTableListModel listModel;
@ -83,14 +84,14 @@ public class GridPanel extends Borderlayout implements EventListener
private boolean modeless; private boolean modeless;
public static final String PAGE_SIZE_KEY = "ZK_PAGING_SIZE"; public static final String PAGE_SIZE_KEY = "ZK_PAGING_SIZE";
public static final String MODE_LESS_KEY = "ZK_GRID_EDIT_MODELESS"; public static final String MODE_LESS_KEY = "ZK_GRID_EDIT_MODELESS";
public GridPanel() public GridPanel()
{ {
this(0); this(0);
} }
/** /**
* @param windowNo * @param windowNo
*/ */
@ -100,55 +101,55 @@ public class GridPanel extends Borderlayout implements EventListener
listbox = new Grid(); listbox = new Grid();
south = new South(); south = new South();
this.appendChild(south); this.appendChild(south);
//default paging size //default paging size
pageSize = MSysConfig.getIntValue(PAGE_SIZE_KEY, 100); pageSize = MSysConfig.getIntValue(PAGE_SIZE_KEY, 100);
//default true for backward compatibility //default true for backward compatibility
modeless = MSysConfig.getBooleanValue(MODE_LESS_KEY, true); modeless = MSysConfig.getBooleanValue(MODE_LESS_KEY, true);
} }
/** /**
* *
* @param gridTab * @param gridTab
*/ */
public void init(GridTab gridTab) public void init(GridTab gridTab)
{ {
if (init) return; if (init) return;
this.gridTab = gridTab; this.gridTab = gridTab;
tableModel = gridTab.getTableModel(); tableModel = gridTab.getTableModel();
numColumns = tableModel.getColumnCount(); numColumns = tableModel.getColumnCount();
gridField = ((GridTable)tableModel).getFields(); gridField = ((GridTable)tableModel).getFields();
setupColumns(); setupColumns();
render(); render();
updateListIndex(); updateListIndex();
this.init = true; this.init = true;
} }
/** /**
* *
* @return boolean * @return boolean
*/ */
public boolean isInit() { public boolean isInit() {
return init; return init;
} }
/** /**
* call when tab is activated * call when tab is activated
* @param gridTab * @param gridTab
*/ */
public void activate(GridTab gridTab) { public void activate(GridTab gridTab) {
if (!isInit()) { if (!isInit()) {
init(gridTab); init(gridTab);
} }
} }
/** /**
* refresh after switching from form view * refresh after switching from form view
* @param gridTab * @param gridTab
@ -171,9 +172,9 @@ public class GridPanel extends Borderlayout implements EventListener
*/ */
public void updateListIndex() { public void updateListIndex() {
if (gridTab == null || !gridTab.isOpen()) return; if (gridTab == null || !gridTab.isOpen()) return;
int rowIndex = gridTab.getCurrentRow(); int rowIndex = gridTab.getCurrentRow();
if (pageSize > 0) { if (pageSize > 0) {
if (paging.getTotalSize() != gridTab.getRowCount()) if (paging.getTotalSize() != gridTab.getRowCount())
paging.setTotalSize(gridTab.getRowCount()); paging.setTotalSize(gridTab.getRowCount());
int pgIndex = rowIndex >= 0 ? rowIndex % pageSize : 0; int pgIndex = rowIndex >= 0 ? rowIndex % pageSize : 0;
@ -186,18 +187,18 @@ public class GridPanel extends Borderlayout implements EventListener
} else if (rowIndex == renderer.getCurrentRowIndex()){ } else if (rowIndex == renderer.getCurrentRowIndex()){
if (modeless && !renderer.isEditing()) if (modeless && !renderer.isEditing())
Events.echoEvent("onPostSelectedRowChanged", this, null); Events.echoEvent("onPostSelectedRowChanged", this, null);
return; return;
} else { } else {
if (renderer.isEditing()) { if (renderer.isEditing()) {
renderer.stopEditing(false); renderer.stopEditing(false);
if (((renderer.getCurrentRowIndex() - pgIndex) / pageSize) == pgNo) { if (((renderer.getCurrentRowIndex() - pgIndex) / pageSize) == pgNo) {
listModel.updateComponent(renderer.getCurrentRowIndex() % pageSize); listModel.updateComponent(renderer.getCurrentRowIndex() % pageSize);
} }
} }
} }
if (paging.getActivePage() != pgNo) { if (paging.getActivePage() != pgNo) {
paging.setActivePage(pgNo); paging.setActivePage(pgNo);
} }
if (rowIndex >= 0 && pgIndex >= 0) { if (rowIndex >= 0 && pgIndex >= 0) {
Events.echoEvent("onPostSelectedRowChanged", this, null); Events.echoEvent("onPostSelectedRowChanged", this, null);
} }
@ -216,12 +217,12 @@ public class GridPanel extends Borderlayout implements EventListener
{ {
this.pageSize = pageSize; this.pageSize = pageSize;
} }
public void clear() public void clear()
{ {
this.getChildren().clear(); this.getChildren().clear();
} }
/** /**
* toggle visibility * toggle visibility
* @param bool * @param bool
@ -233,17 +234,17 @@ public class GridPanel extends Borderlayout implements EventListener
else else
this.setVisible(false); this.setVisible(false);
} }
private void setupColumns() private void setupColumns()
{ {
if (init) return; if (init) return;
Columns columns = new Columns(); Columns columns = new Columns();
listbox.appendChild(columns); listbox.appendChild(columns);
columns.setSizable(true); columns.setSizable(true);
columns.setMenupopup("auto"); columns.setMenupopup("auto");
columns.setColumnsgroup(false); columns.setColumnsgroup(false);
Map<Integer, String> colnames = new HashMap<Integer, String>(); Map<Integer, String> colnames = new HashMap<Integer, String>();
int index = 0; int index = 0;
for (int i = 0; i < numColumns; i++) for (int i = 0; i < numColumns; i++)
@ -256,35 +257,35 @@ public class GridPanel extends Borderlayout implements EventListener
column.setSortAscending(new SortComparator(i, true, Env.getLanguage(Env.getCtx()))); column.setSortAscending(new SortComparator(i, true, Env.getLanguage(Env.getCtx())));
column.setSortDescending(new SortComparator(i, false, Env.getLanguage(Env.getCtx()))); column.setSortDescending(new SortComparator(i, false, Env.getLanguage(Env.getCtx())));
column.setLabel(gridField[i].getHeader()); column.setLabel(gridField[i].getHeader());
int l = DisplayType.isNumeric(gridField[i].getDisplayType()) int l = DisplayType.isNumeric(gridField[i].getDisplayType())
? 120 : gridField[i].getDisplayLength() * 9; ? 120 : gridField[i].getDisplayLength() * 9;
if (gridField[i].getHeader().length() * 9 > l) if (gridField[i].getHeader().length() * 9 > l)
l = gridField[i].getHeader().length() * 9; l = gridField[i].getHeader().length() * 9;
if (l > MAX_COLUMN_WIDTH) if (l > MAX_COLUMN_WIDTH)
l = MAX_COLUMN_WIDTH; l = MAX_COLUMN_WIDTH;
else if ( l < MIN_COLUMN_WIDTH) else if ( l < MIN_COLUMN_WIDTH)
l = MIN_COLUMN_WIDTH; l = MIN_COLUMN_WIDTH;
column.setWidth(Integer.toString(l) + "px"); column.setWidth(Integer.toString(l) + "px");
columns.appendChild(column); columns.appendChild(column);
} }
} }
} }
private void render() private void render()
{ {
LayoutUtils.addSclass("adtab-grid-panel", this); LayoutUtils.addSclass("adtab-grid-panel", this);
listbox.setVflex(true); listbox.setVflex(true);
listbox.setFixedLayout(true); listbox.setFixedLayout(true);
listbox.addEventListener(Events.ON_CLICK, this); listbox.addEventListener(Events.ON_CLICK, this);
updateModel(); updateModel();
Center center = new Center(); Center center = new Center();
center.appendChild(listbox); center.appendChild(listbox);
this.appendChild(center); this.appendChild(center);
if (pageSize > 0) if (pageSize > 0)
{ {
paging = new Paging(); paging = new Paging();
paging.setPageSize(pageSize); paging.setPageSize(pageSize);
@ -298,21 +299,21 @@ public class GridPanel extends Borderlayout implements EventListener
{ {
south.setVisible(false); south.setVisible(false);
} }
} }
private void updateModel() { private void updateModel() {
listModel = new GridTableListModel((GridTable)tableModel, windowNo); listModel = new GridTableListModel((GridTable)tableModel, windowNo);
listModel.setPageSize(pageSize); listModel.setPageSize(pageSize);
if (renderer != null && renderer.isEditing()) if (renderer != null && renderer.isEditing())
renderer.stopEditing(false); renderer.stopEditing(false);
renderer = new GridTabRowRenderer(gridTab, windowNo); renderer = new GridTabRowRenderer(gridTab, windowNo);
renderer.setGridPanel(this); renderer.setGridPanel(this);
listbox.setRowRenderer(renderer); listbox.setRowRenderer(renderer);
listbox.setModel(listModel); listbox.setModel(listModel);
} }
/** /**
* deactivate panel * deactivate panel
*/ */
@ -322,9 +323,9 @@ public class GridPanel extends Borderlayout implements EventListener
} }
public void onEvent(Event event) throws Exception public void onEvent(Event event) throws Exception
{ {
if (event == null) if (event == null)
return; return;
else if (event.getTarget() == listbox && Events.ON_CLICK.equals(event.getName())) else if (event.getTarget() == listbox && Events.ON_CLICK.equals(event.getName()))
{ {
Object data = event.getData(); Object data = event.getData();
@ -342,7 +343,7 @@ public class GridPanel extends Borderlayout implements EventListener
else else
{ {
int index = listbox.getRows().getChildren().indexOf(data); int index = listbox.getRows().getChildren().indexOf(data);
if (index >= 0 ) { if (index >= 0 ) {
onSelectedRowChange(index); onSelectedRowChange(index);
} }
} }
@ -362,24 +363,24 @@ public class GridPanel extends Borderlayout implements EventListener
private void onSelectedRowChange(int index) { private void onSelectedRowChange(int index) {
if (updateModelIndex(index)) { if (updateModelIndex(index)) {
updateListIndex(); updateListIndex();
} }
} }
/** /**
* Event after the current selected row change * Event after the current selected row change
*/ */
public void onPostSelectedRowChanged() { public void onPostSelectedRowChanged() {
if (listbox.getRows().getChildren().isEmpty()) if (listbox.getRows().getChildren().isEmpty())
return; return;
int rowIndex = gridTab.isOpen() ? gridTab.getCurrentRow() : -1; int rowIndex = gridTab.isOpen() ? gridTab.getCurrentRow() : -1;
if (rowIndex >= 0 && pageSize > 0) { if (rowIndex >= 0 && pageSize > 0) {
int pgIndex = rowIndex >= 0 ? rowIndex % pageSize : 0; int pgIndex = rowIndex >= 0 ? rowIndex % pageSize : 0;
org.zkoss.zul.Row row = (org.zkoss.zul.Row) listbox.getRows().getChildren().get(pgIndex); org.zkoss.zul.Row row = (org.zkoss.zul.Row) listbox.getRows().getChildren().get(pgIndex);
if (!isRowRendered(row, pgIndex)) { if (!isRowRendered(row, pgIndex)) {
listbox.renderRow(row); listbox.renderRow(row);
} else { } else {
renderer.setCurrentRow(row); renderer.setCurrentRow(row);
} }
if (modeless && !renderer.isEditing()) { if (modeless && !renderer.isEditing()) {
renderer.editCurrentRow(); renderer.editCurrentRow();
@ -392,7 +393,7 @@ public class GridPanel extends Borderlayout implements EventListener
if (!isRowRendered(row, rowIndex)) { if (!isRowRendered(row, rowIndex)) {
listbox.renderRow(row); listbox.renderRow(row);
} else { } else {
renderer.setCurrentRow(row); renderer.setCurrentRow(row);
} }
if (modeless && !renderer.isEditing()) { if (modeless && !renderer.isEditing()) {
renderer.editCurrentRow(); renderer.editCurrentRow();
@ -409,7 +410,7 @@ public class GridPanel extends Borderlayout implements EventListener
} }
private boolean isRowRendered(org.zkoss.zul.Row row, int index) { private boolean isRowRendered(org.zkoss.zul.Row row, int index) {
if (row.getChildren().size() == 0) { if (row.getChildren().size() == 0) {
return false; return false;
} else if (row.getChildren().size() == 1) { } else if (row.getChildren().size() == 1) {
if (!(row.getChildren().get(0) instanceof Div)) { if (!(row.getChildren().get(0) instanceof Div)) {
@ -418,20 +419,20 @@ public class GridPanel extends Borderlayout implements EventListener
} }
return true; return true;
} }
private boolean updateModelIndex(int rowIndex) { private boolean updateModelIndex(int rowIndex) {
if (pageSize > 0) { if (pageSize > 0) {
int start = listModel.getPage() * listModel.getPageSize(); int start = listModel.getPage() * listModel.getPageSize();
rowIndex = start + rowIndex; rowIndex = start + rowIndex;
} }
if (gridTab.getCurrentRow() != rowIndex) { if (gridTab.getCurrentRow() != rowIndex) {
gridTab.navigate(rowIndex); gridTab.navigate(rowIndex);
return true; return true;
} }
return false; return false;
} }
/** /**
* @return Grid * @return Grid
*/ */
@ -448,7 +449,7 @@ public class GridPanel extends Borderlayout implements EventListener
{ {
return; return;
} }
// Selective // Selective
if (col > 0) if (col > 0)
return; return;
@ -475,7 +476,7 @@ public class GridPanel extends Borderlayout implements EventListener
} }
/** /**
* *
* @param windowNo * @param windowNo
*/ */
public void setWindowNo(int windowNo) { public void setWindowNo(int windowNo) {
@ -498,4 +499,17 @@ public class GridPanel extends Borderlayout implements EventListener
renderer.setFocusToEditor(); renderer.setFocusToEditor();
} }
} }
public void setFocusToField(String columnName) {
boolean found = false;
for (WEditor editor : renderer.getEditors()) {
if (found)
editor.setHasFocus(false);
else if (columnName.equals(editor.getColumnName())) {
editor.setHasFocus(true);
Clients.response(new AuFocus(editor.getComponent()));
found = true;
}
}
}
} }

View File

@ -42,15 +42,15 @@ import org.zkoss.zul.Separator;
public class Messagebox extends Window implements EventListener public class Messagebox extends Window implements EventListener
{ {
/** /**
* *
*/ */
private static final long serialVersionUID = -4957498533838144942L; private static final long serialVersionUID = -4957498533838144942L;
private String msg = new String(""); private String msg = new String("");
private String imgSrc = new String(""); private String imgSrc = new String("");
// private Label lblMsg = new Label(); // private Label lblMsg = new Label();
private Text lblMsg = new Text(); private Text lblMsg = new Text();
private Button btnOk = new Button(); private Button btnOk = new Button();
private Button btnCancel = new Button(); private Button btnCancel = new Button();
private Button btnYes = new Button(); private Button btnYes = new Button();
@ -58,62 +58,62 @@ public class Messagebox extends Window implements EventListener
private Button btnAbort = new Button(); private Button btnAbort = new Button();
private Button btnRetry = new Button(); private Button btnRetry = new Button();
private Button btnIgnore = new Button(); private Button btnIgnore = new Button();
private Image img = new Image(); private Image img = new Image();
private int returnValue; private int returnValue;
/** A OK button. */ /** A OK button. */
public static final int OK = 0x0001; public static final int OK = 0x0001;
/** A Cancel button. */ /** A Cancel button. */
public static final int CANCEL = 0x0002; public static final int CANCEL = 0x0002;
/** A Yes button. */ /** A Yes button. */
public static final int YES = 0x0010; public static final int YES = 0x0010;
/** A No button. */ /** A No button. */
public static final int NO = 0x0020; public static final int NO = 0x0020;
/** A Abort button. */ /** A Abort button. */
public static final int ABORT = 0x0100; public static final int ABORT = 0x0100;
/** A Retry button. */ /** A Retry button. */
public static final int RETRY = 0x0200; public static final int RETRY = 0x0200;
/** A IGNORE button. */ /** A IGNORE button. */
public static final int IGNORE = 0x0400; public static final int IGNORE = 0x0400;
/** A symbol consisting of a question mark in a circle. */ /** A symbol consisting of a question mark in a circle. */
public static final String QUESTION = "~./zul/img/msgbox/question.gif"; public static final String QUESTION = "~./zul/img/msgbox/question.gif";
/** A symbol consisting of an exclamation point in a triangle with a yellow background. */ /** A symbol consisting of an exclamation point in a triangle with a yellow background. */
public static final String EXCLAMATION = "~./zul/img/msgbox/exclamation.gif"; public static final String EXCLAMATION = "~./zul/img/msgbox/exclamation.gif";
/** A symbol of a lowercase letter i in a circle. */ /** A symbol of a lowercase letter i in a circle. */
public static final String INFORMATION = "~./zul/img/msgbox/information.gif"; public static final String INFORMATION = "~./zul/img/msgbox/information.gif";
/** A symbol consisting of a white X in a circle with a red background. */ /** A symbol consisting of a white X in a circle with a red background. */
public static final String ERROR = "~./zul/img/msgbox/error.gif"; public static final String ERROR = "~./zul/img/msgbox/error.gif";
/** Contains no symbols. */ /** Contains no symbols. */
public static final String NONE = null; public static final String NONE = null;
public Messagebox() public Messagebox()
{ {
super(); super();
} }
private void init() private void init()
{ {
Properties ctx = Env.getCtx(); Properties ctx = Env.getCtx();
lblMsg.setValue(msg); lblMsg.setValue(msg);
btnOk.setLabel(Util.cleanAmp(Msg.getMsg(ctx, "OK"))); btnOk.setLabel(Util.cleanAmp(Msg.getMsg(ctx, "OK")));
btnOk.setImage("/images/Ok16.png"); btnOk.setImage("/images/Ok16.png");
btnOk.addEventListener(Events.ON_CLICK, this); btnOk.addEventListener(Events.ON_CLICK, this);
LayoutUtils.addSclass("action-text-button", btnOk); LayoutUtils.addSclass("action-text-button", btnOk);
btnCancel.setLabel(Util.cleanAmp(Msg.getMsg(ctx, "Cancel"))); btnCancel.setLabel(Util.cleanAmp(Msg.getMsg(ctx, "Cancel")));
btnCancel.setImage("/images/Cancel16.png"); btnCancel.setImage("/images/Cancel16.png");
btnCancel.addEventListener(Events.ON_CLICK, this); btnCancel.addEventListener(Events.ON_CLICK, this);
@ -123,47 +123,47 @@ public class Messagebox extends Window implements EventListener
btnYes.setImage("/images/Ok16.png"); btnYes.setImage("/images/Ok16.png");
btnYes.addEventListener(Events.ON_CLICK, this); btnYes.addEventListener(Events.ON_CLICK, this);
LayoutUtils.addSclass("action-text-button", btnYes); LayoutUtils.addSclass("action-text-button", btnYes);
btnNo.setLabel(Util.cleanAmp(Msg.getMsg(ctx, "No"))); btnNo.setLabel(Util.cleanAmp(Msg.getMsg(ctx, "No")));
btnNo.setImage("/images/Cancel16.png"); btnNo.setImage("/images/Cancel16.png");
btnNo.addEventListener(Events.ON_CLICK, this); btnNo.addEventListener(Events.ON_CLICK, this);
LayoutUtils.addSclass("action-text-button", btnNo); LayoutUtils.addSclass("action-text-button", btnNo);
btnAbort.setLabel("Abort"); btnAbort.setLabel("Abort");
//btnAbort.setImage("/images/"); //btnAbort.setImage("/images/");
btnAbort.addEventListener(Events.ON_CLICK, this); btnAbort.addEventListener(Events.ON_CLICK, this);
LayoutUtils.addSclass("action-text-button", btnAbort); LayoutUtils.addSclass("action-text-button", btnAbort);
btnRetry.setLabel("Retry"); btnRetry.setLabel("Retry");
//btnRetry.setImage("/images/"); //btnRetry.setImage("/images/");
btnRetry.addEventListener(Events.ON_CLICK, this); btnRetry.addEventListener(Events.ON_CLICK, this);
LayoutUtils.addSclass("action-text-button", btnRetry); LayoutUtils.addSclass("action-text-button", btnRetry);
btnIgnore.setLabel("Ignore"); btnIgnore.setLabel("Ignore");
btnIgnore.setImage("/images/Ignore16.png"); btnIgnore.setImage("/images/Ignore16.png");
btnIgnore.addEventListener(Events.ON_CLICK, this); btnIgnore.addEventListener(Events.ON_CLICK, this);
LayoutUtils.addSclass("action-text-button", btnIgnore); LayoutUtils.addSclass("action-text-button", btnIgnore);
Panel pnlMessage = new Panel(); Panel pnlMessage = new Panel();
pnlMessage.setWidth("100%"); pnlMessage.setWidth("100%");
pnlMessage.setStyle("text-align:left"); pnlMessage.setStyle("text-align:left");
pnlMessage.appendChild(lblMsg); pnlMessage.appendChild(lblMsg);
Panel pnlImage = new Panel(); Panel pnlImage = new Panel();
img.setSrc(imgSrc); img.setSrc(imgSrc);
pnlImage.setWidth("100%"); pnlImage.setWidth("100%");
pnlImage.setStyle("text-align:center"); pnlImage.setStyle("text-align:center");
pnlImage.appendChild(img); pnlImage.appendChild(img);
Hbox hbox = new Hbox(); Hbox hbox = new Hbox();
hbox.setWidth("100%"); hbox.setWidth("100%");
hbox.setWidths("10%, 90%"); hbox.setWidths("10%, 90%");
hbox.appendChild(pnlImage); hbox.appendChild(pnlImage);
hbox.appendChild(pnlMessage); hbox.appendChild(pnlMessage);
Hbox pnlButtons = new Hbox(); Hbox pnlButtons = new Hbox();
pnlButtons.setWidth("100%"); pnlButtons.setWidth("100%");
pnlButtons.setStyle("text-align:center"); pnlButtons.setStyle("text-align:center");
@ -174,27 +174,27 @@ public class Messagebox extends Window implements EventListener
pnlButtons.appendChild(btnAbort); pnlButtons.appendChild(btnAbort);
pnlButtons.appendChild(btnRetry); pnlButtons.appendChild(btnRetry);
pnlButtons.appendChild(btnIgnore); pnlButtons.appendChild(btnIgnore);
this.setWidth("100%"); this.setWidth("100%");
this.setBorder("normal"); this.setBorder("normal");
this.setContentStyle("background-color:#ffffff"); this.setContentStyle("background-color:#ffffff");
this.setPosition("left, top"); this.setPosition("left, top");
Separator blank = new Separator(); Separator blank = new Separator();
blank.setOrient("vertical"); blank.setOrient("vertical");
blank.setHeight("5px"); blank.setHeight("5px");
hbox.appendChild(blank); hbox.appendChild(blank);
hbox.appendChild(pnlButtons); hbox.appendChild(pnlButtons);
this.appendChild(hbox); this.appendChild(hbox);
} }
public int show(String message, String title, int buttons, String icon) public int show(String message, String title, int buttons, String icon)
{ {
this.msg = message; this.msg = message;
this.imgSrc = icon; this.imgSrc = icon;
btnOk.setVisible(false); btnOk.setVisible(false);
btnCancel.setVisible(false); btnCancel.setVisible(false);
btnYes.setVisible(false); btnYes.setVisible(false);
@ -202,66 +202,55 @@ public class Messagebox extends Window implements EventListener
btnRetry.setVisible(false); btnRetry.setVisible(false);
btnAbort.setVisible(false); btnAbort.setVisible(false);
btnIgnore.setVisible(false); btnIgnore.setVisible(false);
if ((buttons & OK) != 0) if ((buttons & OK) != 0)
btnOk.setVisible(true); btnOk.setVisible(true);
if ((buttons & CANCEL) != 0) if ((buttons & CANCEL) != 0)
btnCancel.setVisible(true); btnCancel.setVisible(true);
if ((buttons & YES) != 0) if ((buttons & YES) != 0)
btnYes.setVisible(true); btnYes.setVisible(true);
if ((buttons & NO) != 0) if ((buttons & NO) != 0)
btnNo.setVisible(true); btnNo.setVisible(true);
if ((buttons & RETRY) != 0) if ((buttons & RETRY) != 0)
btnRetry.setVisible(true); btnRetry.setVisible(true);
if ((buttons & ABORT) != 0) if ((buttons & ABORT) != 0)
btnAbort.setVisible(true); btnAbort.setVisible(true);
if ((buttons & IGNORE) != 0) if ((buttons & IGNORE) != 0)
btnIgnore.setVisible(true); btnIgnore.setVisible(true);
init(); init();
if (icon.equals(QUESTION)) this.setTitle(title);
{ this.setWidth("500px");
this.setTitle(title); this.setPosition("center");
this.setWidth("500px"); this.setClosable(true);
this.setPosition("center"); this.setAttribute(Window.MODE_KEY, Window.MODE_MODAL);
this.setClosable(true); this.setSizable(true);
this.setAttribute(Window.MODE_KEY, Window.MODE_MODAL);
this.setSizable(true);
}
else
{
this.setTitle(title);
this.setAttribute(Window.MODE_KEY, Window.MODE_OVERLAPPED);
this.setWidth("500px");
this.setClosable(true);
this.setSizable(true);
}
this.setVisible(true); this.setVisible(true);
AEnv.showCenterScreen(this); AEnv.showCenterScreen(this);
return returnValue; return returnValue;
} }
public static int showDialog(String message, String title, int buttons, String icon) throws InterruptedException public static int showDialog(String message, String title, int buttons, String icon) throws InterruptedException
{ {
Messagebox msg = new Messagebox(); Messagebox msg = new Messagebox();
return msg.show(message, title, buttons, icon); return msg.show(message, title, buttons, icon);
} }
public void onEvent(Event event) throws Exception public void onEvent(Event event) throws Exception
{ {
if (event == null) if (event == null)
return; return;
if (event.getTarget() == btnOk) if (event.getTarget() == btnOk)
{ {
returnValue = OK; returnValue = OK;
@ -290,7 +279,7 @@ public class Messagebox extends Window implements EventListener
{ {
returnValue = IGNORE; returnValue = IGNORE;
} }
this.detach(); this.detach();
} }
} }

View File

@ -478,4 +478,8 @@ public abstract class WEditor implements EventListener, PropertyChangeListener
public boolean isHasFocus() { public boolean isHasFocus() {
return hasFocus; return hasFocus;
} }
public void setHasFocus(boolean b) {
hasFocus = b;
}
} }

View File

@ -1062,6 +1062,23 @@ DataStatusListener, IADTabpanel, VetoableChangeListener
listPanel.focus(); listPanel.focus();
} }
public void setFocusToField(String columnName) {
if (formComponent.isVisible()) {
boolean found = false;
for (WEditor editor : editors) {
if (found)
editor.setHasFocus(false);
else if (columnName.equals(editor.getColumnName())) {
editor.setHasFocus(true);
Clients.response(new AuFocus(editor.getComponent()));
found = true;
}
}
} else {
listPanel.setFocusToField(columnName);
}
}
/** /**
* @see IADTabpanel#onEnterKey() * @see IADTabpanel#onEnterKey()
*/ */

View File

@ -928,6 +928,17 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To
// Confirm Error // Confirm Error
if (e.isError() && !e.isConfirmed()) if (e.isError() && !e.isConfirmed())
{ {
//focus to error field
ADTabpanel tabPanel = (ADTabpanel) getADTab().getSelectedTabpanel();
GridField[] fields = curTab.getFields();
for (GridField field : fields)
{
if (field.isError())
{
tabPanel.setFocusToField(field.getColumnName());
break;
}
}
FDialog.error(curWindowNo, null, e.getAD_Message(), e.getInfo()); FDialog.error(curWindowNo, null, e.getAD_Message(), e.getInfo());
e.setConfirmed(true); // show just once - if MTable.setCurrentRow is involved the status event is re-issued e.setConfirmed(true); // show just once - if MTable.setCurrentRow is involved the status event is re-issued
} }
@ -1244,8 +1255,7 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To
String msg = CLogger.retrieveErrorString(null); String msg = CLogger.retrieveErrorString(null);
if (msg != null) if (msg != null)
FDialog.error(curWindowNo, parent, null, msg); FDialog.error(curWindowNo, parent, null, msg);
else
FDialog.error(curWindowNo, parent, "SaveIgnored");
//actual error will prompt in the dataStatusChanged event //actual error will prompt in the dataStatusChanged event
statusBar.setStatusLine(Msg.getMsg(Env.getCtx(), "SaveIgnored"), true); statusBar.setStatusLine(Msg.getMsg(Env.getCtx(), "SaveIgnored"), true);
} }