diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/component/GridPanel.java b/zkwebui/WEB-INF/src/org/adempiere/webui/component/GridPanel.java index 576a014482..395d84fd04 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/component/GridPanel.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/component/GridPanel.java @@ -27,9 +27,11 @@ import org.adempiere.webui.LayoutUtils; import org.compiere.model.GridField; import org.compiere.model.GridTab; import org.compiere.model.GridTable; +import org.zkoss.zk.au.out.AuEcho; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.EventListener; import org.zkoss.zk.ui.event.Events; +import org.zkoss.zk.ui.util.Clients; import org.zkoss.zkex.zul.Borderlayout; import org.zkoss.zkex.zul.Center; import org.zkoss.zkex.zul.South; @@ -68,6 +70,8 @@ public class GridPanel extends Borderlayout implements EventListener private GridTableListModel listModel; private Paging paging; + + private GridTabListItemRenderer renderer; public GridPanel() { @@ -136,11 +140,19 @@ public class GridPanel extends Borderlayout implements EventListener } if (paging.getActivePage() != pgNo) paging.setActivePage(pgNo); - if (listbox.getSelectedIndex() != pgIndex) - listbox.setSelectedIndex(pgIndex); + if (listbox.getSelectedIndex() != pgIndex) { + renderer.stopEditing(false); + listModel.updateComponent(listbox.getSelectedIndex()); + listModel.updateComponent(pgIndex); + listbox.setSelectedIndex(pgIndex); + } } else { - if (listbox.getSelectedIndex() != rowIndex) - listbox.setSelectedIndex(rowIndex); + if (listbox.getSelectedIndex() != rowIndex) { + renderer.stopEditing(false); + listModel.updateComponent(listbox.getSelectedIndex()); + listModel.updateComponent(rowIndex); + listbox.setSelectedIndex(rowIndex); + } } } @@ -207,7 +219,8 @@ public class GridPanel extends Borderlayout implements EventListener center.appendChild(listbox); this.appendChild(center); - if (pageSize > 0) { + if (pageSize > 0) + { paging = new Paging(); paging.setPageSize(pageSize); paging.setTotalSize(tableModel.getRowCount()); @@ -216,13 +229,25 @@ public class GridPanel extends Borderlayout implements EventListener south.appendChild(paging); this.appendChild(south); paging.addEventListener(ZulEvents.ON_PAGING, this); - } + //workaround for layout problem + this.setVisible(false); + Clients.response(new AuEcho(this, "postRender", null)); + } + } + + public void postRender() + { + this.setVisible(true); + this.getParent().invalidate(); } private void updateModel() { listModel = new GridTableListModel((GridTable)tableModel, windowNo); listModel.setPageSize(pageSize); - listbox.setItemRenderer(listModel); + if (renderer != null) + renderer.stopEditing(false); + renderer = new GridTabListItemRenderer(gridTab, windowNo); + listbox.setItemRenderer(renderer); listbox.setModel(listModel); } @@ -239,7 +264,8 @@ public class GridPanel extends Borderlayout implements EventListener return; else if (event.getTarget() == listbox) { - updateModelIndex(); + int index = listbox.getSelectedIndex(); + onSelectedRowChange(index); } else if (event.getTarget() == paging) { @@ -249,20 +275,34 @@ public class GridPanel extends Borderlayout implements EventListener listbox.clearSelection(); listModel.setPage(pgNo); listbox.setSelectedIndex(0); - updateModelIndex(); + onSelectedRowChange(0); } } } - private void updateModelIndex() { + private void onSelectedRowChange(int index) { + if (updateModelIndex()) { + listModel.updateComponent(index); + listbox.setSelectedIndex(index); + } else if (!renderer.isInitialize()) { + listModel.updateComponent(index); + listbox.setSelectedIndex(index); + } + } + + private boolean updateModelIndex() { int rowIndex = listbox.getSelectedIndex(); if (pageSize > 0) { int start = listModel.getPage() * listModel.getPageSize(); rowIndex = start + rowIndex; } - if (gridTab.getCurrentRow() != rowIndex) + if (gridTab.getCurrentRow() != rowIndex) { + renderer.stopEditing(true); gridTab.navigate(rowIndex); + return true; + } + return false; } public Listbox getListbox() { diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/component/GridTabListItemRenderer.java b/zkwebui/WEB-INF/src/org/adempiere/webui/component/GridTabListItemRenderer.java new file mode 100644 index 0000000000..94e2a19086 --- /dev/null +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/component/GridTabListItemRenderer.java @@ -0,0 +1,258 @@ +/****************************************************************************** + * Copyright (C) 2008 Low Heng Sin * + * 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.adempiere.webui.component; + +import java.sql.Timestamp; +import java.text.SimpleDateFormat; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +import org.adempiere.webui.editor.WEditor; +import org.adempiere.webui.editor.WEditorPopupMenu; +import org.adempiere.webui.editor.WebEditorFactory; +import org.adempiere.webui.event.ContextMenuListener; +import org.adempiere.webui.util.GridTabDataBinder; +import org.compiere.model.GridField; +import org.compiere.model.GridTab; +import org.compiere.model.MAccountLookup; +import org.compiere.model.MLookup; +import org.compiere.model.MLookupFactory; +import org.compiere.util.DisplayType; +import org.compiere.util.Env; +import org.compiere.util.NamePair; +import org.zkoss.zk.ui.event.Event; +import org.zkoss.zk.ui.event.EventListener; +import org.zkoss.zk.ui.event.Events; +import org.zkoss.zul.Listbox; +import org.zkoss.zul.Listcell; +import org.zkoss.zul.Listitem; +import org.zkoss.zul.ListitemRenderer; +import org.zkoss.zul.ListitemRendererExt; + +/** + * ListItem renderer for GridTab list box. + * @author hengsin + * + */ +public class GridTabListItemRenderer implements ListitemRenderer, ListitemRendererExt { + + private GridTab gridTab; + private int windowNo; + private GridTabDataBinder dataBinder; + private Map editors = new HashMap(); + + /** + * + * @param gridTab + * @param windowNo + */ + public GridTabListItemRenderer(GridTab gridTab, int windowNo) { + this.gridTab = gridTab; + this.windowNo = windowNo; + this.dataBinder = new GridTabDataBinder(gridTab); + } + + /** + * @param listitem + * @param data + * @see ListitemRenderer#render(Listitem, Object) + */ + public void render(Listitem listitem, Object data) throws Exception { + Object[] values = (Object[])data; + int columnCount = gridTab.getTableModel().getColumnCount(); + GridField[] gridField = gridTab.getFields(); + for (int i = 0; i < columnCount; i++) { + if (!gridField[i].isDisplayed()) { + continue; + } + if (editors.get(gridField[i]) == null) + editors.put(gridField[i], WebEditorFactory.getEditor(gridField[i], true)); + + int rowIndex = listitem.getIndex(); + Listcell cell = null; + if (rowIndex == gridTab.getCurrentRow() && gridField[i].isEditable(true)) { + cell = getEditorCell(gridField[i], values[i], i); + cell.setParent(listitem); + } else { + if (gridField[i].getDisplayType() == DisplayType.YesNo) { + cell = new Listcell("", null); + cell.setParent(listitem); + cell.setStyle("text-align:center"); + createReadonlyCheckbox(values[i], cell); + } else { + cell = new Listcell(getDisplayText(values[i], i), null); + cell.setParent(listitem); + } + } + CellListener listener = new CellListener((Listbox) listitem.getParent()); + cell.addEventListener(Events.ON_DOUBLE_CLICK, listener); + } + } + + private void createReadonlyCheckbox(Object value, Listcell cell) { + Checkbox checkBox = new Checkbox(); + if (value != null && "true".equalsIgnoreCase(value.toString())) + checkBox.setChecked(true); + else + checkBox.setChecked(false); + checkBox.setDisabled(true); + checkBox.setParent(cell); + } + + private Listcell getEditorCell(GridField gridField, Object object, int i) { + Listcell cell = new Listcell("", null); + WEditor editor = editors.get(gridField); + if (editor != null) { + editor.addValueChangeListener(dataBinder); + cell.appendChild(editor.getComponent()); + gridField.addPropertyChangeListener(editor); + editor.setValue(gridField.getValue()); + WEditorPopupMenu popupMenu = editor.getPopupMenu(); + + if (popupMenu != null) + { + popupMenu.addMenuListener((ContextMenuListener)editor); + cell.appendChild(popupMenu); + } + } + + return cell; + } + + /** + * Detach all editor and optionally set the current value of the editor as cell label. + * @param updateCellLabel + */ + public void stopEditing(boolean updateCellLabel) { + for (Entry entry : editors.entrySet()) { + if (entry.getValue().getComponent().getParent() != null) { + if (updateCellLabel) { + Listcell cell = (Listcell) entry.getValue().getComponent().getParent(); + if (entry.getKey().getDisplayType() == DisplayType.YesNo) { + cell.setLabel(""); + createReadonlyCheckbox(entry.getValue().getValue(), cell); + } else { + cell.setLabel(getDisplayText(entry.getValue().getValue(), getColumnIndex(entry.getKey()))); + } + } + entry.getValue().getComponent().detach(); + entry.getKey().removePropertyChangeListener(entry.getValue()); + entry.getValue().removeValuechangeListener(dataBinder); + } + } + } + + private int getColumnIndex(GridField field) { + GridField[] fields = gridTab.getFields(); + for(int i = 0; i < fields.length; i++) { + if (fields[i] == field) + return i; + } + return 0; + } + + /** + * @see ListitemRendererExt#getControls() + */ + public int getControls() { + return DETACH_ON_RENDER; + } + + /** + * @param item + * @see ListitemRendererExt#newListcell(Listitem) + */ + public Listcell newListcell(Listitem item) { + ListCell listCell = new ListCell(); + listCell.applyProperties(); + listCell.setParent(item); + return listCell; + } + + /** + * @param listbox + * @see ListitemRendererExt#newListitem(Listbox) + */ + public Listitem newListitem(Listbox listbox) { + ListItem item = new ListItem(); + item.applyProperties(); + return item; + } + + private String getDisplayText(Object value, int columnIndex) + { + if (value == null) + return ""; + + GridField[] gridField = gridTab.getFields(); + if (gridTab.getTableModel().getColumnClass(columnIndex).equals(Integer.class)) + { + if (gridField[columnIndex].isLookup()) + { + NamePair namepair = null; + if (gridField[columnIndex].getDisplayType() == DisplayType.Account) + { + MAccountLookup lookup = new MAccountLookup(Env.getCtx(), windowNo); + namepair = lookup.get(value); + } + else + { + MLookup lookup = MLookupFactory.get( + Env.getCtx(), windowNo, 0, gridField[columnIndex].getAD_Column_ID(), + gridField[columnIndex].getDisplayType()); + + namepair = lookup.get(value); + } + if (namepair != null) + return namepair.getName(); + else + return ""; + } + else + return value.toString(); + } + else if (gridTab.getTableModel().getColumnClass(columnIndex).equals(Timestamp.class)) + { + SimpleDateFormat dateFormat = DisplayType.getDateFormat(DisplayType.Date); + return dateFormat.format((Timestamp)value); + } + else + return value.toString(); + } + + class CellListener implements EventListener { + + private Listbox _listbox; + + public CellListener(Listbox listbox) { + _listbox = listbox; + } + + public void onEvent(Event event) throws Exception { + if (Events.ON_DOUBLE_CLICK.equals(event.getName())) { + Event evt = new Event(Events.ON_DOUBLE_CLICK, _listbox); + Events.sendEvent(_listbox, evt); + } + } + + } + + /** + * Is renderer initialize + * @return boolean + */ + public boolean isInitialize() { + return !editors.isEmpty(); + } +} diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/component/GridTableListModel.java b/zkwebui/WEB-INF/src/org/adempiere/webui/component/GridTableListModel.java index 089fa3c1a5..5252560100 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/component/GridTableListModel.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/component/GridTableListModel.java @@ -12,33 +12,17 @@ *****************************************************************************/ package org.adempiere.webui.component; -import java.sql.Timestamp; -import java.text.SimpleDateFormat; import java.util.Comparator; import org.compiere.model.DataStatusEvent; import org.compiere.model.DataStatusListener; import org.compiere.model.GridField; import org.compiere.model.GridTable; -import org.compiere.model.MAccountLookup; -import org.compiere.model.MLookup; -import org.compiere.model.MLookupFactory; -import org.compiere.util.DisplayType; -import org.compiere.util.Env; -import org.compiere.util.NamePair; import org.zkoss.zk.ui.Executions; -import org.zkoss.zk.ui.event.Event; -import org.zkoss.zk.ui.event.EventListener; -import org.zkoss.zk.ui.event.Events; import org.zkoss.zul.AbstractListModel; import org.zkoss.zul.ListModel; import org.zkoss.zul.ListModelExt; -import org.zkoss.zul.Listbox; -import org.zkoss.zul.Listcell; -import org.zkoss.zul.Listitem; import org.zkoss.zul.ListitemComparator; -import org.zkoss.zul.ListitemRenderer; -import org.zkoss.zul.ListitemRendererExt; import org.zkoss.zul.event.ListDataEvent; /** @@ -46,8 +30,7 @@ import org.zkoss.zul.event.ListDataEvent; * @author Low Heng Sin * */ -public class GridTableListModel extends AbstractListModel implements ListitemRenderer, -ListitemRendererExt, DataStatusListener, ListModelExt { +public class GridTableListModel extends AbstractListModel implements DataStatusListener, ListModelExt { private GridTable tableModel; private GridField[] gridField; @@ -147,125 +130,7 @@ ListitemRendererExt, DataStatusListener, ListModelExt { return pageSize; } } - - /** - * @param listitem - * @param data - * @see ListitemRenderer#render(Listitem, Object) - */ - public void render(Listitem listitem, Object data) throws Exception { - Object[] values = (Object[])data; - int columnCount = tableModel.getColumnCount(); - for (int i = 0; i < columnCount; i++) { - if (!gridField[i].isDisplayed()) { - continue; - } - Listcell cell = null; - if (gridField[i].getDisplayType() == DisplayType.YesNo) { - cell = new Listcell("", null); - cell.setParent(listitem); - cell.setStyle("text-align:center"); - Checkbox checkBox = new Checkbox(); - if (values[i] != null && "true".equalsIgnoreCase(values[i].toString())) - checkBox.setChecked(true); - else - checkBox.setChecked(false); - checkBox.setDisabled(true); - checkBox.setParent(cell); - } else { - cell = new Listcell(getCell(values[i], i), null); - cell.setParent(listitem); - } - CellListener listener = new CellListener((Listbox) listitem.getParent()); - cell.addEventListener(Events.ON_DOUBLE_CLICK, listener); - } - } - class CellListener implements EventListener { - - private Listbox _listbox; - - public CellListener(Listbox listbox) { - _listbox = listbox; - } - - public void onEvent(Event event) throws Exception { - if (Events.ON_DOUBLE_CLICK.equals(event.getName())) { - Event evt = new Event(Events.ON_DOUBLE_CLICK, _listbox); - Events.sendEvent(_listbox, evt); - } - } - - } - - private String getCell(Object obj, int columnIndex) - { - if (obj == null) - return ""; - - if (tableModel.getColumnClass(columnIndex).equals(Integer.class)) - { - if (gridField[columnIndex].isLookup()) - { - NamePair namepair = null; - if (gridField[columnIndex].getDisplayType() == DisplayType.Account) - { - MAccountLookup lookup = new MAccountLookup(Env.getCtx(), windowNo); - namepair = lookup.get(obj); - } - else - { - MLookup lookup = MLookupFactory.get( - Env.getCtx(), windowNo, 0, gridField[columnIndex].getAD_Column_ID(), - gridField[columnIndex].getDisplayType()); - - namepair = lookup.get(obj); - } - if (namepair != null) - return namepair.getName(); - else - return ""; - } - else - return obj.toString(); - } - else if (tableModel.getColumnClass(columnIndex).equals(Timestamp.class)) - { - SimpleDateFormat dateFormat = DisplayType.getDateFormat(DisplayType.Date); - return dateFormat.format((Timestamp)obj); - } - else - return obj.toString(); - } - - /** - * @see ListitemRendererExt#getControls() - */ - public int getControls() { - return DETACH_ON_RENDER; - } - - /** - * @param item - * @see ListitemRendererExt#newListcell(Listitem) - */ - public Listcell newListcell(Listitem item) { - ListCell listCell = new ListCell(); - listCell.applyProperties(); - listCell.setParent(item); - return listCell; - } - - /** - * @param listbox - * @see ListitemRendererExt#newListitem(Listbox) - */ - public Listitem newListitem(Listbox listbox) { - ListItem item = new ListItem(); - item.applyProperties(); - return item; - } - /** * @param e * @see DataStatusListener#dataStatusChanged(DataStatusEvent) @@ -276,6 +141,26 @@ ListitemRendererExt, DataStatusListener, ListModelExt { } } + + /** + * Request components that attached to this model to re-render a row. + * @param row + */ + public void updateComponent(int row) { + updateComponent(row, row); + } + + /** + * Request components that attached to this model to re-render a range of row. + * @param fromRow + * @param toRow + */ + public void updateComponent(int fromRow, int toRow) { + //must run from the UI thread + if (Executions.getCurrent() != null) { + fireEvent(ListDataEvent.CONTENTS_CHANGED, fromRow, toRow); + } + } /** * @param cmpr diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/component/ListModelTable.java b/zkwebui/WEB-INF/src/org/adempiere/webui/component/ListModelTable.java index 95582c129f..53831fb0b4 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/component/ListModelTable.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/component/ListModelTable.java @@ -27,8 +27,10 @@ import java.util.Vector; import org.adempiere.webui.event.WTableModelEvent; import org.adempiere.webui.event.WTableModelListener; +import org.zkoss.zk.ui.Executions; import org.zkoss.zul.ListModelExt; import org.zkoss.zul.ListModelList; +import org.zkoss.zul.event.ListDataEvent; /** * This is a ListModel to be used with Listbox. @@ -362,4 +364,24 @@ public class ListModelTable extends ListModelList implements ListModelExt public int getRowCount() { return getSize(); } + + /** + * Request components that attached to this model to re-render a row. + * @param row + */ + public void updateComponent(int row) { + updateComponent(row, row); + } + + /** + * Request components that attached to this model to re-render a range of row. + * @param fromRow + * @param toRow + */ + public void updateComponent(int fromRow, int toRow) { + //must run from the UI thread + if (Executions.getCurrent() != null) { + fireEvent(ListDataEvent.CONTENTS_CHANGED, fromRow, toRow); + } + } } diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/component/NumberBox.java b/zkwebui/WEB-INF/src/org/adempiere/webui/component/NumberBox.java index 12d18f37fa..930e1ed966 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/component/NumberBox.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/component/NumberBox.java @@ -23,6 +23,9 @@ import java.text.ParseException; import org.adempiere.webui.LayoutUtils; import org.adempiere.webui.apps.AEnv; +import org.zkoss.zhtml.Table; +import org.zkoss.zhtml.Td; +import org.zkoss.zhtml.Tr; import org.zkoss.zk.ui.event.EventListener; import org.zkoss.zk.ui.event.Events; import org.zkoss.zul.Decimalbox; @@ -67,20 +70,40 @@ public class NumberBox extends Div private void init() { - decimalBox = new Decimalbox(); + Table grid = new Table(); + appendChild(grid); + grid.setStyle("border: none; padding: 0px; margin: 0px;"); + grid.setDynamicProperty("border", "0"); + grid.setDynamicProperty("cellpadding", "0"); + grid.setDynamicProperty("cellspacing", "0"); + + Tr tr = new Tr(); + grid.appendChild(tr); + tr.setStyle("border: none; padding: 0px; margin: 0px; white-space:nowrap; "); + + Td td = new Td(); + tr.appendChild(td); + td.setStyle("border: none; padding: 0px; margin: 0px;"); + decimalBox = new Decimalbox(); if (integral) decimalBox.setScale(0); decimalBox.setStyle("display: inline;"); - - btn = new Button(); + td.appendChild(decimalBox); + + Td btnColumn = new Td(); + tr.appendChild(btnColumn); + btnColumn.setStyle("border: none; padding: 0px; margin: 0px;"); + btnColumn.setSclass("editor-button"); + btn = new Button(); btn.setImage("/images/Calculator10.png"); + btn.setTabindex(-1); + LayoutUtils.addSclass("editor-button", btn); + btnColumn.appendChild(btn); popup = getCalculatorPopup(); LayoutUtils.addSclass("editor-button", btn); btn.setPopup(popup); btn.setStyle("text-align: center;"); - appendChild(decimalBox); - appendChild(btn); appendChild(popup); String style = AEnv.isFirefox2() ? "display: inline" : "display: inline-block"; diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/component/WListbox.java b/zkwebui/WEB-INF/src/org/adempiere/webui/component/WListbox.java index 1143aa9281..235beee4c2 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/component/WListbox.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/component/WListbox.java @@ -89,7 +89,7 @@ public class WListbox extends Listbox implements TableValueChangeListener, WTabl rowRenderer.addTableValueChangeListener(this); setItemRenderer(rowRenderer); - setModel(new ListModelTable()); + setModel(new ListModelTable()); } /** @@ -936,18 +936,21 @@ public class WListbox extends Listbox implements TableValueChangeListener, WTabl // if the event was caused by an ID Column and the value is a boolean // then set the IDColumn's select field - if (this.getValueAt(row, col) instanceof IDColumn - && event.getNewValue() instanceof Boolean) + if (col >= 0 && row >=0) { - newBoolean = ((Boolean)event.getNewValue()).booleanValue(); - idColumn = (IDColumn)this.getValueAt(row, col); - idColumn.setSelected(newBoolean); - this.setValueAt(idColumn, row, col); - } - // othewise just set the value in the model to the new value - else - { - this.setValueAt(event.getNewValue(), row, col); + if (this.getValueAt(row, col) instanceof IDColumn + && event.getNewValue() instanceof Boolean) + { + newBoolean = ((Boolean)event.getNewValue()).booleanValue(); + idColumn = (IDColumn)this.getValueAt(row, col); + idColumn.setSelected(newBoolean); + this.setValueAt(idColumn, row, col); + } + // othewise just set the value in the model to the new value + else + { + this.setValueAt(event.getNewValue(), row, col); + } } return; @@ -964,7 +967,7 @@ public class WListbox extends Listbox implements TableValueChangeListener, WTabl // this causes re-rendering of the Listbox this.setModel(this.getModel()); - + return; } @@ -1008,14 +1011,25 @@ public class WListbox extends Listbox implements TableValueChangeListener, WTabl { this.repaint(); } - else + else if ((event.getType() == WTableModelEvent.CONTENTS_CHANGED) + && event.getFirstRow() != WTableModelEvent.ALL_ROWS + && !m_readWriteColumn.isEmpty()) { - this.setModel(this.getModel()); + int[] indices = this.getSelectedIndices(); + ListModelTable model = this.getModel(); + if (event.getLastRow() > event.getFirstRow()) + model.updateComponent(event.getFirstRow(), event.getLastRow()); + else + model.updateComponent(event.getFirstRow()); + if (indices != null && indices.length > 0) + { + this.setSelectedIndices(indices); + } } return; } - + /** * no op, to ease porting of swing form */ diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WAccountEditor.java b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WAccountEditor.java index eb501b5767..44a03da5bb 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WAccountEditor.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WAccountEditor.java @@ -36,7 +36,7 @@ import org.zkoss.zk.ui.event.Events; */ public class WAccountEditor extends WEditor { - private static final String[] LISTENER_EVENTS = {Events.ON_CLICK, Events.ON_CHANGE}; + private static final String[] LISTENER_EVENTS = {Events.ON_CLICK, Events.ON_CHANGE, Events.ON_FOCUS}; private MAccountLookup m_mAccount; @@ -173,6 +173,10 @@ public class WAccountEditor extends WEditor { cmd_button(); } + else if (Events.ON_FOCUS.equalsIgnoreCase(event.getName()) && gridField != null) + { + this.setReadWrite(gridField.isEditable(true)); + } } public String[] getEvents() diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WAssignmentEditor.java b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WAssignmentEditor.java index 28b4a3b622..4ff2f5daad 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WAssignmentEditor.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WAssignmentEditor.java @@ -22,6 +22,8 @@ import org.zkoss.zk.ui.event.Events; public class WAssignmentEditor extends WEditor { private final static CLogger log = CLogger.getCLogger(WAssignmentEditor.class); + + private static final String[] LISTENER_EVENTS = {Events.ON_CLICK, Events.ON_FOCUS}; private boolean m_readWrite; private Object m_value; @@ -39,9 +41,14 @@ public class WAssignmentEditor extends WEditor { private void initComponents() { getComponent().getTextbox().setReadonly(true); getComponent().setButtonImage("images/Assignment10.png"); - getComponent().addEventListener(Events.ON_CLICK, this); } + + + @Override + public String[] getEvents() { + return LISTENER_EVENTS; + } @Override public EditorBox getComponent() { @@ -119,30 +126,37 @@ public class WAssignmentEditor extends WEditor { public void onEvent(Event event) throws Exception { // - Integer oldValue = (Integer)getValue(); - int S_ResourceAssignment_ID = oldValue == null ? 0 : oldValue.intValue(); - MResourceAssignment ma = new MResourceAssignment(Env.getCtx(), S_ResourceAssignment_ID, null); - - // Start VAssignment Dialog - if (S_ResourceAssignment_ID != 0) + if (Events.ON_CLICK.equalsIgnoreCase(event.getName())) { - WAssignmentDialog vad = new WAssignmentDialog (ma, true, true); - ma = vad.getMResourceAssignment(); - } - // Start InfoSchedule directly - else - { - InfoSchedule is = new InfoSchedule(ma, true); - ma = is.getMResourceAssignment(); - } - - // Set Value - if (ma != null && ma.getS_ResourceAssignment_ID() != 0) - { - setValue(new Integer(ma.getS_ResourceAssignment_ID())); - ValueChangeEvent vce = new ValueChangeEvent(this, gridField.getColumnName(), oldValue, getValue()); - fireValueChange(vce); + Integer oldValue = (Integer)getValue(); + int S_ResourceAssignment_ID = oldValue == null ? 0 : oldValue.intValue(); + MResourceAssignment ma = new MResourceAssignment(Env.getCtx(), S_ResourceAssignment_ID, null); + + // Start VAssignment Dialog + if (S_ResourceAssignment_ID != 0) + { + WAssignmentDialog vad = new WAssignmentDialog (ma, true, true); + ma = vad.getMResourceAssignment(); + } + // Start InfoSchedule directly + else + { + InfoSchedule is = new InfoSchedule(ma, true); + ma = is.getMResourceAssignment(); + } + + // Set Value + if (ma != null && ma.getS_ResourceAssignment_ID() != 0) + { + setValue(new Integer(ma.getS_ResourceAssignment_ID())); + ValueChangeEvent vce = new ValueChangeEvent(this, gridField.getColumnName(), oldValue, getValue()); + fireValueChange(vce); + } } + else if (Events.ON_FOCUS.equalsIgnoreCase(event.getName()) && gridField != null) + { + this.setReadWrite(gridField.isEditable(true)); + } } } diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WBinaryEditor.java b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WBinaryEditor.java index e65ddc83cf..d2a048aebd 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WBinaryEditor.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WBinaryEditor.java @@ -26,7 +26,7 @@ import org.zkoss.zk.ui.event.Events; */ public class WBinaryEditor extends WEditor { - private static final String[] LISTENER_EVENTS = {}; + private static final String[] LISTENER_EVENTS = {Events.ON_CLICK, Events.ON_FOCUS}; /** Logger */ private static CLogger log = CLogger.getCLogger(WBinaryEditor.class); @@ -45,8 +45,6 @@ public class WBinaryEditor extends WEditor label.setValue(" "); getComponent().setLabel("-"); getComponent().setTooltiptext(gridField.getDescription()); - getComponent().addEventListener(Events.ON_CLICK, this); - } @Override @@ -129,5 +127,9 @@ public class WBinaryEditor extends WEditor if (!dialog.isCancel() && dialog.isChange()) m_data = dialog.getData(); } + else if (Events.ON_FOCUS.equalsIgnoreCase(event.getName()) && gridField != null) + { + this.setReadWrite(gridField.isEditable(true)); + } } } diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WButtonEditor.java b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WButtonEditor.java index 395374cb10..5f313ecaab 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WButtonEditor.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WButtonEditor.java @@ -48,7 +48,7 @@ import org.zkoss.zk.ui.event.Events; */ public class WButtonEditor extends WEditor { - private static final String[] LISTENER_EVENTS = {}; + private static final String[] LISTENER_EVENTS = {Events.ON_CLICK, Events.ON_FOCUS}; private static final CLogger logger; @@ -100,7 +100,6 @@ public class WButtonEditor extends WEditor label.setValue(" "); getComponent().setLabel(gridField.getHeader()); getComponent().setTooltiptext(gridField.getDescription()); - getComponent().addEventListener(Events.ON_CLICK, this); String columnName = super.getColumnName(); if (columnName.equals("PaymentRule")) @@ -275,5 +274,9 @@ public class WButtonEditor extends WEditor evtListener.actionPerformed(actionEvent); } } + else if (Events.ON_FOCUS.equalsIgnoreCase(event.getName()) && gridField != null) + { + this.setReadWrite(gridField.isEditable(true)); + } } } diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WDateEditor.java b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WDateEditor.java index 4e7339f514..64737def19 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WDateEditor.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WDateEditor.java @@ -37,7 +37,7 @@ import org.zkoss.zk.ui.event.Events; */ public class WDateEditor extends WEditor { - private static final String[] LISTENER_EVENTS = {Events.ON_CHANGE}; + private static final String[] LISTENER_EVENTS = {Events.ON_CHANGE, Events.ON_FOCUS}; private static final CLogger logger; static @@ -105,17 +105,24 @@ public class WDateEditor extends WEditor public void onEvent(Event event) { - Date date = getComponent().getValue(); - Timestamp newValue = null; - - if (date != null) - { - newValue = new Timestamp(date.getTime()); - } - - ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), oldValue, newValue); - super.fireValueChange(changeEvent); - oldValue = newValue; + if (Events.ON_CHANGE.equalsIgnoreCase(event.getName())) + { + Date date = getComponent().getValue(); + Timestamp newValue = null; + + if (date != null) + { + newValue = new Timestamp(date.getTime()); + } + + ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), oldValue, newValue); + super.fireValueChange(changeEvent); + oldValue = newValue; + } + else if (Events.ON_FOCUS.equalsIgnoreCase(event.getName()) && gridField != null) + { + this.setReadWrite(gridField.isEditable(true)); + } } @Override diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WDatetimeEditor.java b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WDatetimeEditor.java index 38ea8c59ab..4a71ac6288 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WDatetimeEditor.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WDatetimeEditor.java @@ -29,7 +29,7 @@ import org.zkoss.zk.ui.event.Events; */ public class WDatetimeEditor extends WEditor { - private static final String[] LISTENER_EVENTS = {Events.ON_CHANGE}; + private static final String[] LISTENER_EVENTS = {Events.ON_CHANGE, Events.ON_FOCUS}; private static final CLogger logger; static @@ -98,17 +98,24 @@ public class WDatetimeEditor extends WEditor public void onEvent(Event event) { - Date date = getComponent().getValue(); - Timestamp newValue = null; - - if (date != null) - { - newValue = new Timestamp(date.getTime()); - } - - ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), oldValue, newValue); - super.fireValueChange(changeEvent); - oldValue = newValue; + if (Events.ON_CHANGE.equalsIgnoreCase(event.getName())) + { + Date date = getComponent().getValue(); + Timestamp newValue = null; + + if (date != null) + { + newValue = new Timestamp(date.getTime()); + } + + ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), oldValue, newValue); + super.fireValueChange(changeEvent); + oldValue = newValue; + } + else if (Events.ON_FOCUS.equalsIgnoreCase(event.getName()) && gridField != null) + { + this.setReadWrite(gridField.isEditable(true)); + } } @Override diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WEditor.java b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WEditor.java index f14dbcd0bb..ffca6a6754 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WEditor.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WEditor.java @@ -292,6 +292,11 @@ public abstract class WEditor implements EventListener, PropertyChangeListener listeners.add(listener); } + public boolean removeValuechangeListener(ValueChangeListener listener) + { + return listeners.remove(listener); + } + protected void fireValueChange(ValueChangeEvent event) { for (ValueChangeListener listener : listeners) diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WFilenameEditor.java b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WFilenameEditor.java index 71a14d8979..73f89bcfaf 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WFilenameEditor.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WFilenameEditor.java @@ -35,7 +35,7 @@ import org.zkoss.zul.Fileupload; */ public class WFilenameEditor extends WEditor { - private static final String[] LISTENER_EVENTS = {Events.ON_CLICK, Events.ON_CHANGE}; + private static final String[] LISTENER_EVENTS = {Events.ON_CLICK, Events.ON_CHANGE, Events.ON_FOCUS}; private static final CLogger log = CLogger.getCLogger(WFilenameEditor.class); @@ -98,6 +98,10 @@ public class WFilenameEditor extends WEditor { cmd_file(); } + else if (Events.ON_FOCUS.equalsIgnoreCase(event.getName()) && gridField != null) + { + this.setReadWrite(gridField.isEditable(true)); + } } /** diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WImageEditor.java b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WImageEditor.java index ef468d68ed..6b81aada19 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WImageEditor.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WImageEditor.java @@ -33,7 +33,7 @@ import org.zkoss.zk.ui.event.Events; */ public class WImageEditor extends WEditor { - private static final String[] LISTENER_EVENTS = {}; + private static final String[] LISTENER_EVENTS = {Events.ON_CLICK, Events.ON_FOCUS}; private static final CLogger logger; @@ -66,7 +66,6 @@ public class WImageEditor extends WEditor private void init() { getComponent().setLabel("-"); - getComponent().addEventListener(Events.ON_CLICK, this); } @Override @@ -151,5 +150,9 @@ public class WImageEditor extends WEditor ValueChangeEvent vce = new ValueChangeEvent(this, gridField.getColumnName(), oldValue, newValue); fireValueChange(vce); } + else if (Events.ON_FOCUS.equalsIgnoreCase(event.getName()) && gridField != null) + { + this.setReadWrite(gridField.isEditable(true)); + } } } diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WLocationEditor.java b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WLocationEditor.java index 7e7083c7e8..18dd0c72ef 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WLocationEditor.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WLocationEditor.java @@ -40,7 +40,7 @@ import org.zkoss.zk.ui.event.Events; **/ public class WLocationEditor extends WEditor implements EventListener, PropertyChangeListener { - private static final String[] LISTENER_EVENTS = {Events.ON_CLICK}; + private static final String[] LISTENER_EVENTS = {Events.ON_CLICK, Events.ON_FOCUS}; private static CLogger log = CLogger.getCLogger(WLocationEditor.class); private static final long serialVersionUID = 1L; @@ -163,6 +163,10 @@ public class WLocationEditor extends WEditor implements EventListener, PropertyC } setValue(ii); } + else if (Events.ON_FOCUS.equalsIgnoreCase(event.getName()) && gridField != null) + { + this.setReadWrite(gridField.isEditable(true)); + } } /** diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WLocatorEditor.java b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WLocatorEditor.java index 81faf88f0a..38bbf0c514 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WLocatorEditor.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WLocatorEditor.java @@ -49,7 +49,7 @@ import org.zkoss.zk.ui.event.Events; public class WLocatorEditor extends WEditor implements EventListener, PropertyChangeListener { - private static final String[] LISTENER_EVENTS = {Events.ON_CLICK}; + private static final String[] LISTENER_EVENTS = {Events.ON_CLICK, Events.ON_FOCUS}; private String m_columnName; private MLocatorLookup m_mLocator; @@ -178,42 +178,48 @@ public class WLocatorEditor extends WEditor implements EventListener, PropertyCh public void onEvent(Event event) throws Exception { - // Warehouse/Product - - int only_Warehouse_ID = getOnly_Warehouse_ID(); - int only_Product_ID = getOnly_Product_ID(); - - log.config("Only Warehouse_ID=" + only_Warehouse_ID + ", Product_ID=" + only_Product_ID); - - // Text Entry ok - - if (event.getTarget() == getComponent() && actionText(only_Warehouse_ID, only_Product_ID)) - return; - - // Button - Start Dialog - - int M_Locator_ID = 0; - - if (m_value instanceof Integer) - M_Locator_ID = ((Integer)m_value).intValue(); - - m_mLocator.setOnly_Warehouse_ID(only_Warehouse_ID); - m_mLocator.setOnly_Product_ID(getOnly_Product_ID()); - - WLocatorDialog ld = new WLocatorDialog(Msg.translate(Env.getCtx(), m_columnName), - m_mLocator, M_Locator_ID, isMandatory(), only_Warehouse_ID, this.m_WindowNo); - - // display - ld.setVisible(true); - AEnv.showWindow(ld); - - m_mLocator.setOnly_Warehouse_ID(0); - - // redisplay - - if (!ld.isChanged()) - return; - setValue (ld.getValue(), true); + if (Events.ON_CLICK.equalsIgnoreCase(event.getName())) + { + // Warehouse/Product + int only_Warehouse_ID = getOnly_Warehouse_ID(); + int only_Product_ID = getOnly_Product_ID(); + + log.config("Only Warehouse_ID=" + only_Warehouse_ID + ", Product_ID=" + only_Product_ID); + + // Text Entry ok + + if (event.getTarget() == getComponent() && actionText(only_Warehouse_ID, only_Product_ID)) + return; + + // Button - Start Dialog + + int M_Locator_ID = 0; + + if (m_value instanceof Integer) + M_Locator_ID = ((Integer)m_value).intValue(); + + m_mLocator.setOnly_Warehouse_ID(only_Warehouse_ID); + m_mLocator.setOnly_Product_ID(getOnly_Product_ID()); + + WLocatorDialog ld = new WLocatorDialog(Msg.translate(Env.getCtx(), m_columnName), + m_mLocator, M_Locator_ID, isMandatory(), only_Warehouse_ID, this.m_WindowNo); + + // display + ld.setVisible(true); + AEnv.showWindow(ld); + + m_mLocator.setOnly_Warehouse_ID(0); + + // redisplay + + if (!ld.isChanged()) + return; + setValue (ld.getValue(), true); + } + else if (Events.ON_FOCUS.equalsIgnoreCase(event.getName()) && gridField != null) + { + this.setReadWrite(gridField.isEditable(true)); + } } /** diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WNumberEditor.java b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WNumberEditor.java index 30a653db6d..0814bbd3d9 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WNumberEditor.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WNumberEditor.java @@ -39,7 +39,7 @@ import org.zkoss.zk.ui.event.Events; */ public class WNumberEditor extends WEditor { - public static final String[] LISTENER_EVENTS = {Events.ON_CHANGE}; + public static final String[] LISTENER_EVENTS = {Events.ON_CHANGE, Events.ON_FOCUS}; public static final int MAX_DISPLAY_LENGTH = 20; @@ -105,10 +105,17 @@ public class WNumberEditor extends WEditor */ public void onEvent(Event event) { - BigDecimal newValue = getComponent().getValue(); - ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), oldValue, newValue); - super.fireValueChange(changeEvent); - oldValue = newValue; + if (Events.ON_CHANGE.equalsIgnoreCase(event.getName())) + { + BigDecimal newValue = getComponent().getValue(); + ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), oldValue, newValue); + super.fireValueChange(changeEvent); + oldValue = newValue; + } + else if (Events.ON_FOCUS.equalsIgnoreCase(event.getName()) && gridField != null) + { + this.setReadWrite(gridField.isEditable(true)); + } } @Override diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WPAttributeEditor.java b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WPAttributeEditor.java index 31d5ccb48d..2157fea9ff 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WPAttributeEditor.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WPAttributeEditor.java @@ -38,7 +38,7 @@ import org.zkoss.zk.ui.event.Events; */ public class WPAttributeEditor extends WEditor implements ContextMenuListener { - private static final String[] LISTENER_EVENTS = {Events.ON_CLICK, Events.ON_CHANGE}; + private static final String[] LISTENER_EVENTS = {Events.ON_CLICK, Events.ON_CHANGE, Events.ON_FOCUS}; private static final CLogger log = CLogger.getCLogger(WPAttributeEditor.class); @@ -130,6 +130,10 @@ public class WPAttributeEditor extends WEditor implements ContextMenuListener { cmd_dialog(); } + else if (Events.ON_FOCUS.equalsIgnoreCase(event.getName()) && gridField != null) + { + this.setReadWrite(gridField.isEditable(true)); + } } /** diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WSearchEditor.java b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WSearchEditor.java index 9e6b3976e1..eb35e92fdc 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WSearchEditor.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WSearchEditor.java @@ -56,7 +56,7 @@ import org.zkoss.zk.ui.event.Events; */ public class WSearchEditor extends WEditor implements ContextMenuListener, ValueChangeListener, IZoomableEditor { - private static final String[] LISTENER_EVENTS = {Events.ON_CLICK, Events.ON_CHANGE, Events.ON_OK}; + private static final String[] LISTENER_EVENTS = {Events.ON_CLICK, Events.ON_CHANGE, Events.ON_OK, Events.ON_FOCUS}; private Lookup lookup; private String m_tableName = null; private String m_keyColumnName = null; @@ -216,8 +216,17 @@ public class WSearchEditor extends WEditor implements ContextMenuListener, Value } else if (Events.ON_CLICK.equals(e.getName())) { + if (infoPanel != null) + { + infoPanel.detach(); + infoPanel = null; + } actionButton(""); } + else if (Events.ON_FOCUS.equalsIgnoreCase(e.getName()) && gridField != null) + { + this.setReadWrite(gridField.isEditable(true)); + } } @@ -433,7 +442,7 @@ public class WSearchEditor extends WEditor implements ContextMenuListener, Value { if (lookup == null) return; // leave button disabled - + /** * Three return options: * - Value Selected & OK pressed => store result => result has value diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WStringEditor.java b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WStringEditor.java index 0866dd9c39..59048c9c7e 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WStringEditor.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WStringEditor.java @@ -44,12 +44,14 @@ public class WStringEditor extends WEditor implements ContextMenuListener { private static final String EDITOR_EVENT = "EDITOR"; - private static final String[] LISTENER_EVENTS = {Events.ON_CHANGE}; + private static final String[] LISTENER_EVENTS = {Events.ON_CHANGE, Events.ON_FOCUS}; private String oldText; private WEditorPopupMenu popupMenu; + private boolean tableEditor = false; + /** * to ease porting of swing form */ @@ -58,10 +60,14 @@ public class WStringEditor extends WEditor implements ContextMenuListener this("String", false, false, true, 30, 30, "", null); } - public WStringEditor(GridField gridField) + public WStringEditor(GridField gridField) { + this(gridField, false); + } + + public WStringEditor(GridField gridField, boolean tableEditor) { super(new Textbox(), gridField); - + this.tableEditor = tableEditor; init(gridField.getObscureType()); } @@ -111,20 +117,23 @@ public class WStringEditor extends WEditor implements ContextMenuListener } getComponent().setCols(displayLength); - if (gridField.getDisplayType() == DisplayType.Text) + if (!tableEditor) { - getComponent().setMultiline(true); - getComponent().setRows(3); - } - else if (gridField.getDisplayType() == DisplayType.TextLong) - { - getComponent().setMultiline(true); - getComponent().setRows(5); - } - else if (gridField.getDisplayType() == DisplayType.Memo) - { - getComponent().setMultiline(true); - getComponent().setRows(8); + if (gridField.getDisplayType() == DisplayType.Text) + { + getComponent().setMultiline(true); + getComponent().setRows(3); + } + else if (gridField.getDisplayType() == DisplayType.TextLong) + { + getComponent().setMultiline(true); + getComponent().setRows(5); + } + else if (gridField.getDisplayType() == DisplayType.Memo) + { + getComponent().setMultiline(true); + getComponent().setRows(8); + } } getComponent().setObscureType(obscureType); @@ -147,6 +156,10 @@ public class WStringEditor extends WEditor implements ContextMenuListener ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), oldText, newText); super.fireValueChange(changeEvent); oldText = newText; + } + else if (Events.ON_FOCUS.equalsIgnoreCase(event.getName()) && gridField != null) + { + this.setReadWrite(gridField.isEditable(true)); } } diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WTableDirEditor.java b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WTableDirEditor.java index 80dc4f8fc1..1cf8249eb1 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WTableDirEditor.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WTableDirEditor.java @@ -50,7 +50,7 @@ import org.zkoss.zk.ui.event.Events; public class WTableDirEditor extends WEditor implements ListDataListener, ContextMenuListener, IZoomableEditor { - public final static String[] LISTENER_EVENTS = {Events.ON_SELECT}; + public final static String[] LISTENER_EVENTS = {Events.ON_SELECT, Events.ON_FOCUS}; private static final CLogger logger; @@ -259,10 +259,17 @@ ContextMenuListener, IZoomableEditor public void onEvent(Event event) { - Object newValue = getValue(); - ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), oldValue, newValue); - super.fireValueChange(changeEvent); - oldValue = newValue; + if (Events.ON_SELECT.equalsIgnoreCase(event.getName())) + { + Object newValue = getValue(); + ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), oldValue, newValue); + super.fireValueChange(changeEvent); + oldValue = newValue; + } + else if (Events.ON_FOCUS.equalsIgnoreCase(event.getName()) && gridField != null) + { + this.setReadWrite(gridField.isEditable(true)); + } } public String[] getEvents() diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WTimeEditor.java b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WTimeEditor.java index a9cd98be4e..083aff4747 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WTimeEditor.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WTimeEditor.java @@ -30,7 +30,7 @@ import org.zkoss.zul.Timebox; */ public class WTimeEditor extends WEditor { - private static final String[] LISTENER_EVENTS = {Events.ON_CHANGE}; + private static final String[] LISTENER_EVENTS = {Events.ON_CHANGE, Events.ON_FOCUS}; private static final CLogger logger; static @@ -90,17 +90,24 @@ public class WTimeEditor extends WEditor public void onEvent(Event event) { - Date date = getComponent().getValue(); - Timestamp newValue = null; - - if (date != null) - { - newValue = new Timestamp(date.getTime()); - } - - ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), oldValue, newValue); - super.fireValueChange(changeEvent); - oldValue = newValue; + if (Events.ON_CHANGE.equalsIgnoreCase(event.getName())) + { + Date date = getComponent().getValue(); + Timestamp newValue = null; + + if (date != null) + { + newValue = new Timestamp(date.getTime()); + } + + ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), oldValue, newValue); + super.fireValueChange(changeEvent); + oldValue = newValue; + } + else if (Events.ON_FOCUS.equalsIgnoreCase(event.getName()) && gridField != null) + { + this.setReadWrite(gridField.isEditable(true)); + } } @Override diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WUrlEditor.java b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WUrlEditor.java index 2236a34cb0..b51e762d7c 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WUrlEditor.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WUrlEditor.java @@ -29,7 +29,7 @@ import org.zkoss.zk.ui.event.Events; public class WUrlEditor extends WEditor { - private static final String[] LISTENER_EVENTS = {Events.ON_CLICK, Events.ON_CHANGE}; + private static final String[] LISTENER_EVENTS = {Events.ON_CLICK, Events.ON_CHANGE, Events.ON_FOCUS}; public WUrlEditor(GridField gridField) { @@ -108,6 +108,10 @@ public class WUrlEditor extends WEditor FDialog.warn(0, this.getComponent(), "URLnotValid", message); } + else if (Events.ON_FOCUS.equalsIgnoreCase(event.getName()) && gridField != null) + { + this.setReadWrite(gridField.isEditable(true)); + } } public String[] getEvents() diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WYesNoEditor.java b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WYesNoEditor.java index 550c1fca8b..1aa6eb29c6 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WYesNoEditor.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WYesNoEditor.java @@ -37,7 +37,7 @@ import org.zkoss.zk.ui.event.Events; */ public class WYesNoEditor extends WEditor { - public static final String[] LISTENER_EVENTS = {Events.ON_CHECK}; + public static final String[] LISTENER_EVENTS = {Events.ON_CHECK, Events.ON_FOCUS}; private static final CLogger logger; static @@ -62,10 +62,17 @@ public class WYesNoEditor extends WEditor public void onEvent(Event event) { - Boolean newValue = (Boolean)getValue(); - ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), oldValue, newValue); - super.fireValueChange(changeEvent); - oldValue = newValue; + if (Events.ON_CHECK.equalsIgnoreCase(event.getName())) + { + Boolean newValue = (Boolean)getValue(); + ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), oldValue, newValue); + super.fireValueChange(changeEvent); + oldValue = newValue; + } + else if (Events.ON_FOCUS.equalsIgnoreCase(event.getName()) && gridField != null) + { + this.setReadWrite(gridField.isEditable(true)); + } } public void propertyChange(PropertyChangeEvent evt) diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WebEditorFactory.java b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WebEditorFactory.java index bdbfee0f74..3865792e3b 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WebEditorFactory.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WebEditorFactory.java @@ -76,7 +76,7 @@ public class WebEditorFactory } else { - editor = new WStringEditor(gridField); + editor = new WStringEditor(gridField, tableEditor); } } /** File */ diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/panel/ADTabpanel.java b/zkwebui/WEB-INF/src/org/adempiere/webui/panel/ADTabpanel.java index ff38f37e45..10b415de67 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/panel/ADTabpanel.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/panel/ADTabpanel.java @@ -45,14 +45,12 @@ import org.adempiere.webui.editor.WEditor; import org.adempiere.webui.editor.WEditorPopupMenu; import org.adempiere.webui.editor.WebEditorFactory; import org.adempiere.webui.event.ContextMenuListener; -import org.adempiere.webui.event.ValueChangeEvent; -import org.adempiere.webui.event.ValueChangeListener; +import org.adempiere.webui.util.GridTabDataBinder; import org.adempiere.webui.window.FDialog; import org.compiere.model.DataStatusEvent; import org.compiere.model.DataStatusListener; import org.compiere.model.GridField; import org.compiere.model.GridTab; -import org.compiere.model.GridTable; import org.compiere.model.GridWindow; import org.compiere.model.MLookup; import org.compiere.model.MTree; @@ -94,7 +92,7 @@ import org.zkoss.zul.Treeitem; * @author Low Heng Sin */ public class ADTabpanel extends Div implements Evaluatee, EventListener, -DataStatusListener, ValueChangeListener, IADTabpanel +DataStatusListener, IADTabpanel { private static final CLogger logger; @@ -134,6 +132,8 @@ DataStatusListener, ValueChangeListener, IADTabpanel private Tree tree = null; + private GridTabDataBinder dataBinder; + public ADTabpanel() { init(); @@ -169,6 +169,7 @@ DataStatusListener, ValueChangeListener, IADTabpanel this.gridTab = gridTab; this.windowPanel = winPanel; gridTab.addDataStatusListener(this); + this.dataBinder = new GridTabDataBinder(gridTab); this.getChildren().clear(); @@ -373,7 +374,7 @@ DataStatusListener, ValueChangeListener, IADTabpanel } else { - editor.addValueChangeListener(this); + editor.addValueChangeListener(dataBinder); } if (editor.getComponent() instanceof HtmlBasedComponent) { @@ -835,57 +836,6 @@ DataStatusListener, ValueChangeListener, IADTabpanel } } - public void valueChange(ValueChangeEvent e) - { - if (gridTab.isProcessed()) // only active records - { - Object source = e.getSource(); - if (source instanceof WEditor) - { - if (!((WEditor)source).isReadWrite()) - { - logger.config("(" + gridTab.toString() + ") " + e.getPropertyName()); - return; - } - } - else - { - logger.config("(" + gridTab.toString() + ") " + e.getPropertyName()); - return; - } - } // processed - logger.config("(" + gridTab.toString() + ") " - + e.getPropertyName() + "=" + e.getNewValue() + " (" + e.getOldValue() + ") " - + (e.getOldValue() == null ? "" : e.getOldValue().getClass().getName())); - - - // Get Row/Col Info - GridTable mTable = gridTab.getTableModel(); - int row = gridTab.getCurrentRow(); - int col = mTable.findColumn(e.getPropertyName()); - // - if (e.getNewValue() == null && e.getOldValue() != null - && e.getOldValue().toString().length() > 0) // some editors return "" instead of null -// this is the original code from GridController, don't know what it does there but it breaks ignore button for web ui -// mTable.setChanged (true); - mTable.setValueAt (e.getNewValue(), row, col); - else - { - // mTable.setValueAt (e.getNewValue(), row, col, true); - mTable.setValueAt (e.getNewValue(), row, col); // -> dataStatusChanged -> dynamicDisplay - // Force Callout - if ( e.getPropertyName().equals("S_ResourceAssignment_ID") ) - { - GridField mField = gridTab.getField(col); - if (mField != null && mField.getCallout().length() > 0) - { - gridTab.processFieldChange(mField); // Dependencies & Callout - } - } - } - - } // ValueChange - public void switchRowPresentation() { if (formComponent.isVisible()) { formComponent.setVisible(false); diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/util/GridTabDataBinder.java b/zkwebui/WEB-INF/src/org/adempiere/webui/util/GridTabDataBinder.java new file mode 100644 index 0000000000..a37f540970 --- /dev/null +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/util/GridTabDataBinder.java @@ -0,0 +1,95 @@ +/****************************************************************************** + * Copyright (C) 2008 Low Heng Sin * + * 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.adempiere.webui.util; + +import org.adempiere.webui.editor.WEditor; +import org.adempiere.webui.event.ValueChangeEvent; +import org.adempiere.webui.event.ValueChangeListener; +import org.compiere.model.GridField; +import org.compiere.model.GridTab; +import org.compiere.model.GridTable; +import org.compiere.util.CLogger; + +/** + * Transfer data from editor to GridTab + * @author hengsin + * + */ +public class GridTabDataBinder implements ValueChangeListener { + + private final static CLogger logger = CLogger.getCLogger(GridTabDataBinder.class); + + private GridTab gridTab; + + /** + * + * @param gridTab + */ + public GridTabDataBinder(GridTab gridTab) { + this.gridTab = gridTab; + } + + /** + * @param e + */ + public void valueChange(ValueChangeEvent e) + { + if (gridTab.isProcessed()) // only active records + { + Object source = e.getSource(); + if (source instanceof WEditor) + { + if (!((WEditor)source).isReadWrite()) + { + logger.config("(" + gridTab.toString() + ") " + e.getPropertyName()); + return; + } + } + else + { + logger.config("(" + gridTab.toString() + ") " + e.getPropertyName()); + return; + } + } // processed + logger.config("(" + gridTab.toString() + ") " + + e.getPropertyName() + "=" + e.getNewValue() + " (" + e.getOldValue() + ") " + + (e.getOldValue() == null ? "" : e.getOldValue().getClass().getName())); + + + // Get Row/Col Info + GridTable mTable = gridTab.getTableModel(); + int row = gridTab.getCurrentRow(); + int col = mTable.findColumn(e.getPropertyName()); + // + if (e.getNewValue() == null && e.getOldValue() != null + && e.getOldValue().toString().length() > 0) // some editors return "" instead of null +// this is the original code from GridController, don't know what it does there but it breaks ignore button for web ui +// mTable.setChanged (true); + mTable.setValueAt (e.getNewValue(), row, col); + else + { + // mTable.setValueAt (e.getNewValue(), row, col, true); + mTable.setValueAt (e.getNewValue(), row, col); // -> dataStatusChanged -> dynamicDisplay + // Force Callout + if ( e.getPropertyName().equals("S_ResourceAssignment_ID") ) + { + GridField mField = gridTab.getField(col); + if (mField != null && mField.getCallout().length() > 0) + { + gridTab.processFieldChange(mField); // Dependencies & Callout + } + } + } + + } // ValueChange +}