IDEMPIERE-5567 Support of UUID as Key (FHCA-4195) (#1837)

* IDEMPIERE-5567 Support of UUID as Key (FHCA-4195)

- Fix Record UUID editor

* - Separate WRecordEditor and WRecordUUIDEditor for ID and UUID

* IDEMPIERE-5567 Support of UUID as Key (FHCA-4195)

- integrate patch from Heng Sin

---------

Co-authored-by: hengsin <hengsin@gmail.com>
This commit is contained in:
Carlos Ruiz 2023-05-21 13:39:08 +02:00 committed by GitHub
parent 7c41f997b2
commit 4a1dcb265b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 730 additions and 487 deletions

View File

@ -66,7 +66,7 @@ public class MTable extends X_AD_Table implements ImmutablePOSupport
/**
*
*/
private static final long serialVersionUID = -4206879140460545905L;
private static final long serialVersionUID = 6308179531110429747L;
public final static int MAX_OFFICIAL_ID = 999999;
@ -521,6 +521,17 @@ public class MTable extends X_AD_Table implements ImmutablePOSupport
return (getKeyColumns() != null && getKeyColumns().length == 1 && getKeyColumns()[0].equals(uuColName));
}
/**
* @return true if table has a UUID key
*/
public boolean hasUUIDKey()
{
String uuColName = PO.getUUIDColumnName(getTableName());
if (m_columns == null)
getColumns(false);
return m_columnNameMap.get(uuColName.toUpperCase()) != null;
}
/**
* Get Identifier Columns of Table
* @return Identifier columns

View File

@ -188,9 +188,10 @@ public final class AEnv
if (AD_Window_ID == 0)
return;
MTable table = MTable.get(Env.getCtx(), AD_Table_ID);
MQuery query = MQuery.getEqualQuery(PO.getUUIDColumnName(table.getTableName()), Record_UU);
String uuColName = PO.getUUIDColumnName(table.getTableName());
MQuery query = MQuery.getEqualQuery(uuColName, Record_UU);
query.setZoomTableName(table.getTableName());
query.setZoomColumnName(table.getUUIDColumnName());
query.setZoomColumnName(uuColName);
query.setZoomValue(Record_UU);
zoom(AD_Window_ID, query);
} // zoom

View File

@ -0,0 +1,476 @@
/**********************************************************************
* This file is part of iDempiere ERP Open Source *
* http://www.idempiere.org *
* *
* Copyright (C) Contributors *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* *
* 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., 51 Franklin Street, Fifth Floor, Boston, *
* MA 02110-1301, USA. *
* *
* Contributors: *
* - Igor Pojzl, Cloudempiere *
* - Peter Takacs, Cloudempiere *
**********************************************************************/
package org.adempiere.webui.editor;
import org.adempiere.util.GridRowCtx;
import org.adempiere.webui.ValuePreference;
import org.adempiere.webui.component.Textbox;
import org.adempiere.webui.component.ToolBarButton;
import org.adempiere.webui.event.ContextMenuEvent;
import org.adempiere.webui.event.ContextMenuListener;
import org.adempiere.webui.event.ValueChangeEvent;
import org.adempiere.webui.theme.ThemeManager;
import org.adempiere.webui.window.Dialog;
import org.adempiere.webui.window.FindWindow;
import org.adempiere.webui.window.WFieldRecordInfo;
import org.adempiere.webui.window.WRecordIDDialog;
import org.compiere.model.GridField;
import org.compiere.model.Lookup;
import org.compiere.model.MColumn;
import org.compiere.model.MLookup;
import org.compiere.model.MLookupFactory;
import org.compiere.model.MLookupInfo;
import org.compiere.model.MTable;
import org.compiere.util.DisplayType;
import org.compiere.util.Env;
import org.compiere.util.Msg;
import org.compiere.util.Util;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zk.ui.sys.ComponentCtrl;
import org.zkoss.zul.Div;
/**
* Default editor for {@link DisplayType#RecordID} and {@link DisplayType#RecordUU}.<br/>
* Implemented with composite component of {@link Textbox} and {@link ToolBarButton}.<br/>
* The editor uses {@link WRecordIDDialog} for edit or viewing.
* @author Peter Takacs, Cloudempiere
*
*/
public abstract class WRecordEditor<T> extends WEditor implements ContextMenuListener, IZoomableEditor {
/** Is Read/Write enabled on the editor */
private boolean m_ReadWrite;
/** Record_ID or Record_UU value */
protected Object recordIDValue;
/** AD_Table_ID value */
protected Object tableIDValue;
/** Current tab's AD_Table_ID GridField */
protected GridField tableIDGridField;
// UI components
protected Textbox recordTextBox;
protected ToolBarButton editButton;
protected ToolBarButton zoomButton;
// image url for toolbar button
private static final String IMAGES_CONTEXT_ZOOM_PNG = "images/Zoom16.png";
private static final String IMAGES_CONTEXT_EDIT_RECORD_PNG = "images/EditRecord16.png";
/**
* Constructor
* @param div
* @param gridField
* @param tableEditor
* @param editorConfiguration
*/
public WRecordEditor(GridField gridField, boolean tableEditor, IEditorConfiguration editorConfiguration) {
super(new Div(), gridField, tableEditor, editorConfiguration);
getComponent().setSclass("recordid-editor");
getComponent().addEventListener(Events.ON_RIGHT_CLICK, this);
init();
}
/**
* Init component and context menu
*/
protected void init() {
if(gridTab != null) {
tableIDGridField = gridTab.getField("AD_Table_ID");
if(tableIDGridField == null) {
throw new RuntimeException("AD_Table_ID field not found");
}
tableIDGridField.addPropertyChangeListener(evt -> {
if (GridField.PROPERTY.equals(evt.getPropertyName())) {
tableIDValue = evt.getNewValue();
}
});
} else {
String tableIdTxt = Env.getContext(gridField.getVO().ctx, gridField.getWindowNo(), FindWindow.TABNO, "AD_Table_ID", true);
if (!Util.isEmpty(tableIdTxt, true)) {
tableIDValue = Integer.parseInt(tableIdTxt);
}
getComponent().addCallback(ComponentCtrl.AFTER_PAGE_ATTACHED, t -> afterPageAttached(t));
}
recordTextBox = new Textbox();
recordTextBox.setParent(getComponent());
recordTextBox.setWidth("100%");
recordTextBox.setReadonly(true);
editButton = new ToolBarButton();
editButton.setStyle("right: 21px;");
if (ThemeManager.isUseFontIconForImage())
editButton.setIconSclass("z-icon-Edit");
else
editButton.setImage(ThemeManager.getThemeResource(IMAGES_CONTEXT_EDIT_RECORD_PNG));
editButton.setParent(getComponent());
editButton.addEventListener(Events.ON_CLICK, this);
editButton.setTooltiptext(Msg.getMsg(Env.getCtx(), "Edit"));
zoomButton = new ToolBarButton();
if (ThemeManager.isUseFontIconForImage())
zoomButton.setIconSclass("z-icon-Zoom");
else
zoomButton.setImage(ThemeManager.getThemeResource(IMAGES_CONTEXT_ZOOM_PNG));
zoomButton.setParent(getComponent());
zoomButton.addEventListener(Events.ON_CLICK, this);
zoomButton.setTooltiptext(Msg.getMsg(Env.getCtx(), "Zoom"));
if (gridField != null)
{
popupMenu = new WEditorPopupMenu(true, true, isShowPreference());
popupMenu.addMenuListener(this);
addChangeLogMenu(popupMenu);
}
}
/**
* Handle AFTER_PAGE_ATTACHED callback to get AD_Table_ID grid field from find window
* @param t
*/
private void afterPageAttached(Object t) {
if (t instanceof Component) {
Component component = (Component) t;
Component parent = component.getParent();
while (parent != null) {
if (parent instanceof FindWindow)
break;
parent = parent.getParent();
}
if (parent != null && parent instanceof FindWindow) {
FindWindow fw = (FindWindow) parent;
GridField field = fw.getTargetMField("AD_Table_ID");
if (field != null) {
//search field initialisation code duplicated from FindWindow
field = field.clone(gridField.getVO().ctx);
field.loadLookupNoValidate();
Lookup lookup = field.getLookup();
if (lookup != null && lookup instanceof MLookup)
{
MLookup mLookup = (MLookup) lookup;
mLookup.getLookupInfo().tabNo = FindWindow.TABNO;
if (field.getVO().ValidationCodeLookup != null && !field.getVO().ValidationCodeLookup.isEmpty())
{
mLookup.getLookupInfo().ValidationCode = field.getVO().ValidationCodeLookup;
mLookup.getLookupInfo().IsValidated = false;
}
}
tableIDGridField = field;
if (tableIDValue != null)
tableIDGridField.setValue(tableIDValue, false);
}
}
}
}
/**
* Refresh text box display text
*/
private void actionRefresh()
{
recordTextBox.setValue(getDisplay());
}
@Override
public void onMenu(ContextMenuEvent evt)
{
if (WEditorPopupMenu.REQUERY_EVENT.equals(evt.getContextEvent()))
{
actionRefresh();
}
else if (WEditorPopupMenu.ZOOM_EVENT.equals(evt.getContextEvent()))
{
actionZoom();
}
else if (WEditorPopupMenu.CHANGE_LOG_EVENT.equals(evt.getContextEvent()))
{
WFieldRecordInfo.start(gridField);
}
else if (WEditorPopupMenu.PREFERENCE_EVENT.equals(evt.getContextEvent()))
{
if (isShowPreference())
ValuePreference.start (getComponent(), gridField, getValue());
}
}
@Override
public void setReadWrite(boolean readWrite) {
m_ReadWrite = readWrite;
if(editButton != null)
editButton.setDisabled(!readWrite);
}
@Override
public boolean isReadWrite() {
return m_ReadWrite;
}
@Override
public void setValue(Object value) {
setValue(value, true);
}
/**
* Set Value
* @param value new value
* @param fire true to fire value change event
*/
protected void setValue (Object value, boolean fire) {
if (value == null || Util.isEmpty(value.toString(), true)) {
recordTextBox.setValue("");
value = null;
} else {
recordTextBox.setValue(value.toString());
//get initial ad_table_id value
if (tableIDValue == null && tableIDGridField != null) {
tableIDValue = tableIDGridField.getValue();
}
if(value != null && tableIDValue != null) {
int tableID = Integer.parseInt(String.valueOf(tableIDValue));
if (tableID > 0) {
Object recordID = toKeyValue(value);
if(recordID != null && tableID > 0)
recordTextBox.setValue(getIdentifier(tableID, recordID));
}
}
}
if (fire
&&
( (value == null && recordIDValue != null)
|| (value != null && recordIDValue == null)
|| (value != null && !value.equals(recordIDValue))
)) {
// Record_ID
ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), recordIDValue, value);
super.fireValueChange(changeEvent);
}
recordIDValue = value;
}
@Override
public Object getValue() {
return recordIDValue;
}
@Override
public String getDisplay() {
if (recordIDValue == null)
return "";
if((tableIDValue != null) && (recordIDValue != null)) {
int tableID;
Object recordID;
try {
tableID = Integer.parseInt(String.valueOf(tableIDValue));
recordID = toKeyValue(recordIDValue);
} catch (NumberFormatException e) {
return recordIDValue.toString();
}
return getIdentifier(tableID, recordID);
}
else {
return recordIDValue.toString();
}
}
@Override
public String getDisplayTextForGridView(GridRowCtx gridRowCtx, Object value) {
if (value == null)
return "";
if (gridTab != null) {
String key = gridTab.getWindowNo() + "|AD_Table_ID";
Object rowTableIdValue = gridRowCtx.get(key);
int rowTableID;
Object rowRecordID;
try {
rowTableID = Integer.parseInt(String.valueOf(rowTableIdValue));
rowRecordID = toKeyValue(value);
} catch (NumberFormatException e) {
return value.toString();
}
return getIdentifier(rowTableID, rowRecordID);
} else {
return value.toString();
}
}
@Override
public void onEvent(Event event) throws Exception {
if(event.getName().equalsIgnoreCase(Events.ON_CLICK)) {
if(event.getTarget().equals(zoomButton)) {
actionZoom();
}
else if(event.getTarget().equals(editButton)) {
if (tableIDGridField != null) {
//for find window context
if (gridTab == null) {
String tableIdTxt = Env.getContext(gridField.getVO().ctx, gridField.getWindowNo(), FindWindow.TABNO, "AD_Table_ID", true);
if (!Util.isEmpty(tableIdTxt, true)) {
tableIDValue = Integer.parseInt(tableIdTxt);
}
}
if (tableIDValue != null && tableIDValue instanceof Integer) {
String error = validateTableIdValue((int) tableIDValue);
if (!Util.isEmpty(error)) {
Dialog.error(tableIDGridField.getWindowNo(), error);
return;
}
}
new WRecordIDDialog(recordTextBox.getPage(), this, tableIDGridField);
}
}
}
else if(event.getName().equalsIgnoreCase(Events.ON_RIGHT_CLICK)) {
if(event.getTarget().equals(getComponent())) {
popupMenu.open(getComponent());
}
}
}
/**
* Get Lookup
* @param tableID
* @return null if tableID <= 0 or the table doesn't have any key column, else {@link MLookup}
*/
public MLookup getRecordsLookup(int tableID) {
return getRecordsLookup(tableID, false);
}
/**
* Get Lookup
* @param tableID
* @param tableBased - if the lookup checks for the UUID Key Column based on the table (true), or on the columnName (false)
* @return null if tableID <= 0 or the table doesn't have any key column, else {@link MLookup}
*/
private MLookup getRecordsLookup(int tableID, boolean tableBased) {
if(tableID <= 0)
return null;
MTable mTable = MTable.get(Env.getCtx(), tableID, null);
String keyColumn = "";
if (tableBased) {
String[] keyColumns = mTable.getKeyColumns();
keyColumn = keyColumns != null && keyColumns.length > 0 ? keyColumns[0] : null;
} else {
keyColumn = getKeyColumn(mTable);
}
if (Util.isEmpty(keyColumn))
return null;
MColumn mColumn = MColumn.get(Env.getCtx(), mTable.getTableName(), keyColumn);
int tabNo = gridTab != null ? gridTab.getTabNo() : FindWindow.TABNO;
int windowNo = gridTab != null ? gridTab.getWindowNo() : gridField.getWindowNo();
MLookupInfo lookupInfo = MLookupFactory.getLookupInfo (Env.getCtx(), windowNo, tabNo, mColumn.getAD_Column_ID(), DisplayType.Search);
return new MLookup(lookupInfo, tabNo);
}
/**
* Get Identifier String from AD_Table_ID and Record_ID
* @param tableID
* @param recordID
* @return String
*/
public String getIdentifier(int tableID, Object recordID) {
MLookup lookup = getRecordsLookup(tableID);
return lookup != null ? lookup.getDisplay(recordID) : "";
}
/**
* Get Parent Identifier String from AD_Table_ID and Record_ID
* @param tableID
* @param recordID
* @return String
*/
public String getParentIdentifier(int tableID, Object recordID) {
MLookup lookup = getRecordsLookup(tableID, true);
return lookup != null ? lookup.getDisplay(recordID) : "";
}
/**
* Get AD_Table_ID
* @return AD_Table_ID value
*/
public Object getAD_Table_ID() {
return tableIDValue;
}
/**
* Set AD_Table_ID
* @param tableID
*/
public void setAD_Table_ID(Object tableID){
// Data Binding
// AD_Table_ID
if (gridTab != null) {
Object oldValue = gridTab.getValue("AD_Table_ID");
gridTab.setValue(tableIDGridField, tableID);
ValueChangeEvent changeEvent = new ValueChangeEvent(this, "AD_Table_ID", oldValue, tableID);
super.fireValueChange(changeEvent);
} else {
ValueChangeEvent changeEvent = new ValueChangeEvent(this, "AD_Table_ID", tableIDValue, tableID);
super.fireValueChange(changeEvent);
}
tableIDValue = tableID;
}
@Override
public Div getComponent() {
return (Div) super.getComponent();
}
/**
* @param mTable Reference table
* @return Key column name
*/
protected abstract String getKeyColumn(MTable mTable);
/**
* Convert value to key value type
* @param value
* @return key value
*/
public abstract T toKeyValue(Object value);
/**
* Validate selected table id value
* @param tableIDEditor
* @param tableId
* @return error message or null
*/
public abstract String validateTableIdValue(int tableId);
}

View File

@ -29,64 +29,25 @@ import java.beans.PropertyChangeEvent;
import java.util.Objects;
import org.adempiere.exceptions.AdempiereException;
import org.adempiere.util.GridRowCtx;
import org.adempiere.webui.ValuePreference;
import org.adempiere.webui.apps.AEnv;
import org.adempiere.webui.component.Textbox;
import org.adempiere.webui.component.ToolBarButton;
import org.adempiere.webui.event.ContextMenuEvent;
import org.adempiere.webui.event.ContextMenuListener;
import org.adempiere.webui.event.ValueChangeEvent;
import org.adempiere.webui.theme.ThemeManager;
import org.adempiere.webui.window.Dialog;
import org.adempiere.webui.window.FindWindow;
import org.adempiere.webui.window.WFieldRecordInfo;
import org.adempiere.webui.window.WRecordIDDialog;
import org.compiere.model.GridField;
import org.compiere.model.Lookup;
import org.compiere.model.MColumn;
import org.compiere.model.MLookup;
import org.compiere.model.MLookupFactory;
import org.compiere.model.MLookupInfo;
import org.compiere.model.MRole;
import org.compiere.model.MTable;
import org.compiere.util.DisplayType;
import org.compiere.util.Env;
import org.compiere.util.Msg;
import org.compiere.util.Util;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zk.ui.sys.ComponentCtrl;
import org.zkoss.zul.Div;
/**
* Default editor for {@link DisplayType#RecordID} and {@link DisplayType#RecordUU}.<br/>
* Default editor for {@link DisplayType#RecordID}.<br/>
* Implemented with composite component of {@link Textbox} and {@link ToolBarButton}.<br/>
* The editor uses {@link WRecordIDDialog} for edit or viewing.
* @author Peter Takacs, Cloudempiere
*
*/
public class WRecordIDEditor extends WEditor implements ContextMenuListener, IZoomableEditor {
/** Is Read/Write enabled on the editor */
private boolean m_ReadWrite;
/** Record_ID or Record_UU value */
private Object recordIDValue;
/** AD_Table_ID value */
private Object tableIDValue;
/** Current tab's AD_Table_ID GridField */
private GridField tableIDGridField;
// UI components
private Textbox recordTextBox;
private ToolBarButton editButton;
private ToolBarButton zoomButton;
// image url for toolbar button
private static final String IMAGES_CONTEXT_ZOOM_PNG = "images/Zoom16.png";
private static final String IMAGES_CONTEXT_EDIT_RECORD_PNG = "images/EditRecord16.png";
public class WRecordIDEditor extends WRecordEditor<Integer> {
/**
* Constructor
@ -95,177 +56,21 @@ public class WRecordIDEditor extends WEditor implements ContextMenuListener, IZo
* @param editorConfiguration
*/
public WRecordIDEditor(GridField gridField, boolean tableEditor, IEditorConfiguration editorConfiguration) {
super(new Div(), gridField, tableEditor, editorConfiguration);
getComponent().setSclass("recordid-editor");
getComponent().addEventListener(Events.ON_RIGHT_CLICK, this);
init();
super(gridField, tableEditor, editorConfiguration);
}
/**
* Init component and context menu
*/
private void init() {
if(gridTab != null) {
tableIDGridField = gridTab.getField("AD_Table_ID");
if(tableIDGridField == null) {
throw new RuntimeException("AD_Table_ID field not found");
}
tableIDGridField.addPropertyChangeListener(evt -> {
if (GridField.PROPERTY.equals(evt.getPropertyName())) {
tableIDValue = evt.getNewValue();
}
});
} else {
String tableIdTxt = Env.getContext(gridField.getVO().ctx, gridField.getWindowNo(), FindWindow.TABNO, "AD_Table_ID", true);
if (!Util.isEmpty(tableIdTxt, true)) {
tableIDValue = Integer.parseInt(tableIdTxt);
}
getComponent().addCallback(ComponentCtrl.AFTER_PAGE_ATTACHED, t -> afterPageAttached(t));
}
recordTextBox = new Textbox();
recordTextBox.setParent(getComponent());
recordTextBox.setWidth("100%");
recordTextBox.setReadonly(true);
editButton = new ToolBarButton();
editButton.setStyle("right: 21px;");
if (ThemeManager.isUseFontIconForImage())
editButton.setIconSclass("z-icon-Edit");
else
editButton.setImage(ThemeManager.getThemeResource(IMAGES_CONTEXT_EDIT_RECORD_PNG));
editButton.setParent(getComponent());
editButton.addEventListener(Events.ON_CLICK, this);
editButton.setTooltiptext(Msg.getMsg(Env.getCtx(), "Edit"));
zoomButton = new ToolBarButton();
if (ThemeManager.isUseFontIconForImage())
zoomButton.setIconSclass("z-icon-Zoom");
else
zoomButton.setImage(ThemeManager.getThemeResource(IMAGES_CONTEXT_ZOOM_PNG));
zoomButton.setParent(getComponent());
zoomButton.addEventListener(Events.ON_CLICK, this);
zoomButton.setTooltiptext(Msg.getMsg(Env.getCtx(), "Zoom"));
if (gridField != null)
{
popupMenu = new WEditorPopupMenu(true, true, isShowPreference());
popupMenu.addMenuListener(this);
addChangeLogMenu(popupMenu);
}
}
/**
* Handle AFTER_PAGE_ATTACHED callback to get AD_Table_ID grid field from find window
* @param t
*/
private void afterPageAttached(Object t) {
if (t instanceof Component) {
Component component = (Component) t;
Component parent = component.getParent();
while (parent != null) {
if (parent instanceof FindWindow)
break;
parent = parent.getParent();
}
if (parent != null && parent instanceof FindWindow) {
FindWindow fw = (FindWindow) parent;
GridField field = fw.getTargetMField("AD_Table_ID");
if (field != null) {
//search field initialisation code duplicated from FindWindow
field = field.clone(gridField.getVO().ctx);
field.loadLookupNoValidate();
Lookup lookup = field.getLookup();
if (lookup != null && lookup instanceof MLookup)
{
MLookup mLookup = (MLookup) lookup;
mLookup.getLookupInfo().tabNo = FindWindow.TABNO;
if (field.getVO().ValidationCodeLookup != null && !field.getVO().ValidationCodeLookup.isEmpty())
{
mLookup.getLookupInfo().ValidationCode = field.getVO().ValidationCodeLookup;
mLookup.getLookupInfo().IsValidated = false;
}
}
tableIDGridField = field;
if (tableIDValue != null)
tableIDGridField.setValue(tableIDValue, false);
}
}
}
}
/**
* Refresh text box display text
*/
private void actionRefresh()
{
recordTextBox.setValue(getDisplay());
}
@Override
public void actionZoom()
{
String s = tableIDValue != null ? String.valueOf(tableIDValue) : "";
int tableID = s.length() > 0 ? Integer.parseInt(s) : 0;
MTable table = MTable.get(tableID);
if (table.isUUIDKeyTable()) {
String recordUU = recordIDValue != null ? recordIDValue.toString() : "";
if(tableID <= 0)
return;
if (!MRole.getDefault().isTableAccess(tableID, false))
throw new AdempiereException(Msg.getMsg(Env.getCtx(), "AccessTableNoView"));
AEnv.zoomUU(tableID, recordUU);
} else {
s = recordIDValue != null ? String.valueOf(recordIDValue) : "";
int recordID = s.length() > 0 ? Integer.parseInt(s) : 0;
if(tableID <= 0 || recordID < 0)
return;
if (!MRole.getDefault().isTableAccess(tableID, false))
throw new AdempiereException(Msg.getMsg(Env.getCtx(), "AccessTableNoView"));
AEnv.zoom(tableID, recordID);
}
}
@Override
public void onMenu(ContextMenuEvent evt)
{
if (WEditorPopupMenu.REQUERY_EVENT.equals(evt.getContextEvent()))
{
actionRefresh();
}
else if (WEditorPopupMenu.ZOOM_EVENT.equals(evt.getContextEvent()))
{
actionZoom();
}
else if (WEditorPopupMenu.CHANGE_LOG_EVENT.equals(evt.getContextEvent()))
{
WFieldRecordInfo.start(gridField);
}
else if (WEditorPopupMenu.PREFERENCE_EVENT.equals(evt.getContextEvent()))
{
if (isShowPreference())
ValuePreference.start (getComponent(), gridField, getValue());
}
}
@Override
public void setReadWrite(boolean readWrite) {
m_ReadWrite = readWrite;
if(editButton != null)
editButton.setDisabled(!readWrite);
}
@Override
public boolean isReadWrite() {
return m_ReadWrite;
s = recordIDValue != null ? String.valueOf(recordIDValue) : "";
int recordID = s.length() > 0 ? Integer.parseInt(s) : 0;
if(tableID <= 0 || recordID < 0)
return;
if (!MRole.getDefault().isTableAccess(tableID, false))
throw new AdempiereException(Msg.getMsg(Env.getCtx(), "AccessTableNoView"));
AEnv.zoom(tableID, recordID);
}
@Override
@ -276,222 +81,32 @@ public class WRecordIDEditor extends WEditor implements ContextMenuListener, IZo
int tableID = tableIDValue != null ? Integer.parseInt(String.valueOf(tableIDValue)) : 0;
if (tableID > 0) {
MTable table = MTable.get(tableID);
if (table.isUUIDKeyTable()) {
String recordUU = Objects.toString(evt.getNewValue(), "");
if (tableID > 0 && recordUU.length() > 0)
table.getPOByUU(recordUU, null); // calls po.checkCrossTenant() method
} else {
int recordID = Integer.parseInt(Objects.toString(evt.getNewValue(), "-1"));
if (tableID > 0 && recordID >= 0)
table.getPO(recordID, null); // calls po.checkCrossTenant() method
}
int recordID = Integer.parseInt(Objects.toString(evt.getNewValue(), "-1"));
if (tableID > 0 && recordID >= 0)
table.getPO(recordID, null); // calls po.checkCrossTenant() method
}
setValue(evt.getNewValue(), false);
}
}
@Override
public void setValue(Object value) {
setValue(value, true);
}
/**
* Set Value
* @param value new value
* @param fire true to fire value change event
*/
private void setValue (Object value, boolean fire) {
if (value == null || Util.isEmpty(value.toString(), true)) {
recordTextBox.setValue("");
value = null;
} else {
recordTextBox.setValue(value.toString());
//get initial ad_table_id value
if (tableIDValue == null && tableIDGridField != null) {
tableIDValue = tableIDGridField.getValue();
}
if(value != null && tableIDValue != null) {
int tableID = Integer.parseInt(String.valueOf(tableIDValue));
if (tableID > 0) {
MTable table = MTable.get(tableID);
Object recordID;
if (table.isUUIDKeyTable())
recordID = value.toString();
else
recordID = Integer.parseInt(String.valueOf(value));
if(recordID != null && tableID > 0)
recordTextBox.setValue(getIdentifier(tableID, recordID));
}
}
}
if (fire
&&
( (value == null && recordIDValue != null)
|| (value != null && recordIDValue == null)
|| (value != null && !value.equals(recordIDValue))
)) {
// Record_ID
ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), recordIDValue, value);
super.fireValueChange(changeEvent);
}
recordIDValue = value;
@Override
public Integer toKeyValue(Object value) {
return value != null ? Integer.parseInt(String.valueOf(value)) : null;
}
@Override
public Object getValue() {
return recordIDValue;
}
@Override
public String getDisplay() {
if (recordIDValue == null)
return "";
if((tableIDValue != null) && (recordIDValue != null)) {
int tableID;
Object recordID;
try {
tableID = Integer.parseInt(String.valueOf(tableIDValue));
MTable table = MTable.get(tableID);
if (table.isUUIDKeyTable())
recordID = recordIDValue.toString();
else
recordID = Integer.parseInt(String.valueOf(recordIDValue));
} catch (NumberFormatException e) {
return recordIDValue.toString();
}
return getIdentifier(tableID, recordID);
}
else {
return recordIDValue.toString();
}
}
@Override
public String getDisplayTextForGridView(GridRowCtx gridRowCtx, Object value) {
if (value == null)
return "";
if (gridTab != null) {
String key = gridTab.getWindowNo() + "|AD_Table_ID";
Object rowTableIdValue = gridRowCtx.get(key);
int rowTableID;
Object rowRecordID;
try {
rowTableID = Integer.parseInt(String.valueOf(rowTableIdValue));
MTable table = MTable.get(rowTableID);
if (table.isUUIDKeyTable())
rowRecordID = value.toString();
else
rowRecordID = Integer.parseInt(String.valueOf(value));
} catch (NumberFormatException e) {
return value.toString();
}
return getIdentifier(rowTableID, rowRecordID);
} else {
return value.toString();
}
}
@Override
public void onEvent(Event event) throws Exception {
if(event.getName().equalsIgnoreCase(Events.ON_CLICK)) {
if(event.getTarget().equals(zoomButton)) {
actionZoom();
}
else if(event.getTarget().equals(editButton)) {
if (tableIDGridField != null) {
//for find window context
if (gridTab == null) {
String tableIdTxt = Env.getContext(gridField.getVO().ctx, gridField.getWindowNo(), FindWindow.TABNO, "AD_Table_ID", true);
if (!Util.isEmpty(tableIdTxt, true)) {
tableIDValue = Integer.parseInt(tableIdTxt);
}
}
if (tableIDValue != null && tableIDValue instanceof Integer) {
MTable table = MTable.get((Integer)tableIDValue);
if (table.isUUIDKeyTable()) {
if (! getColumnName().endsWith("_UU")) {
Dialog.error(tableIDGridField.getWindowNo(), "UUTableNotCompatibleWithRecordID");
return;
}
}
}
new WRecordIDDialog(recordTextBox.getPage(), this, tableIDGridField);
}
}
}
else if(event.getName().equalsIgnoreCase(Events.ON_RIGHT_CLICK)) {
if(event.getTarget().equals(getComponent())) {
popupMenu.open(getComponent());
}
}
}
/**
* Get Lookup
* @param tableID
* @return null if tableID <= 0 or the table doesn't have any key column, else {@link MLookup}
*/
public MLookup getRecordsLookup(int tableID) {
if(tableID <= 0)
return null;
MTable mTable = MTable.get(Env.getCtx(), tableID, null);
protected String getKeyColumn(MTable mTable) {
String[] keyColumns = mTable.getKeyColumns();
String keyColumn = "";
if(keyColumns.length > 0)
keyColumn = keyColumns[0];
else
return null;
MColumn mColumn = MColumn.get(Env.getCtx(), mTable.getTableName(), keyColumn);
int tabNo = gridTab != null ? gridTab.getTabNo() : FindWindow.TABNO;
int windowNo = gridTab != null ? gridTab.getWindowNo() : gridField.getWindowNo();
MLookupInfo lookupInfo = MLookupFactory.getLookupInfo (Env.getCtx(), windowNo, tabNo, mColumn.getAD_Column_ID(), DisplayType.Search);
return new MLookup(lookupInfo, tabNo);
}
/**
* Get Identifier String from AD_Table_ID and Record_ID
* @param tableID
* @param recordID
* @return String
*/
public String getIdentifier(int tableID, Object recordID) {
MLookup lookup = getRecordsLookup(tableID);
return lookup != null ? lookup.getDisplay(recordID) : "";
}
/**
* Get AD_Table_ID
* @return AD_Table_ID value
*/
public Object getAD_Table_ID() {
return tableIDValue;
}
/**
* Set AD_Table_ID
* @param tableID
*/
public void setAD_Table_ID(Object tableID){
// Data Binding
// AD_Table_ID
if (gridTab != null) {
Object oldValue = gridTab.getValue("AD_Table_ID");
gridTab.setValue(tableIDGridField, tableID);
ValueChangeEvent changeEvent = new ValueChangeEvent(this, "AD_Table_ID", oldValue, tableID);
super.fireValueChange(changeEvent);
} else {
ValueChangeEvent changeEvent = new ValueChangeEvent(this, "AD_Table_ID", tableIDValue, tableID);
super.fireValueChange(changeEvent);
}
tableIDValue = tableID;
return keyColumns != null && keyColumns.length > 0 ? keyColumns[0] : null;
}
@Override
public Div getComponent() {
return (Div) super.getComponent();
public String validateTableIdValue(int tableId) {
MTable table = MTable.get(tableId);
if (table.isUUIDKeyTable())
return "UUTableNotCompatibleWithRecordID";
if (! table.isIDKeyTable())
return "TableHasNoKeyColumn";
return null;
}
}

View File

@ -0,0 +1,110 @@
/**********************************************************************
* This file is part of iDempiere ERP Open Source *
* http://www.idempiere.org *
* *
* Copyright (C) Contributors *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* *
* 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., 51 Franklin Street, Fifth Floor, Boston, *
* MA 02110-1301, USA. *
* *
* Contributors: *
* - Igor Pojzl, Cloudempiere *
* - Peter Takacs, Cloudempiere *
**********************************************************************/
package org.adempiere.webui.editor;
import java.beans.PropertyChangeEvent;
import java.util.Objects;
import org.adempiere.exceptions.AdempiereException;
import org.adempiere.webui.apps.AEnv;
import org.adempiere.webui.component.Textbox;
import org.adempiere.webui.component.ToolBarButton;
import org.adempiere.webui.window.WRecordIDDialog;
import org.compiere.model.GridField;
import org.compiere.model.MRole;
import org.compiere.model.MTable;
import org.compiere.model.PO;
import org.compiere.util.DisplayType;
import org.compiere.util.Env;
import org.compiere.util.Msg;
/**
* Default editor for {@link DisplayType#RecordUU}.<br/>
* Implemented with composite component of {@link Textbox} and {@link ToolBarButton}.<br/>
* The editor uses {@link WRecordIDDialog} for edit or viewing.
* @author Peter Takacs, Cloudempiere
*
*/
public class WRecordUUIDEditor extends WRecordEditor<String> {
/**
* Constructor
* @param gridField
* @param tableEditor
* @param editorConfiguration
*/
public WRecordUUIDEditor(GridField gridField, boolean tableEditor, IEditorConfiguration editorConfiguration) {
super(gridField, tableEditor, editorConfiguration);
}
@Override
public void actionZoom()
{
String s = tableIDValue != null ? String.valueOf(tableIDValue) : "";
int tableID = s.length() > 0 ? Integer.parseInt(s) : 0;
String recordUU = recordIDValue != null ? recordIDValue.toString() : "";
if(tableID <= 0)
return;
if (!MRole.getDefault().isTableAccess(tableID, false))
throw new AdempiereException(Msg.getMsg(Env.getCtx(), "AccessTableNoView"));
AEnv.zoomUU(tableID, recordUU);
}
@Override
public void propertyChange(PropertyChangeEvent evt)
{
if (GridField.PROPERTY.equals(evt.getPropertyName()))
{
int tableID = tableIDValue != null ? Integer.parseInt(String.valueOf(tableIDValue)) : 0;
if (tableID > 0) {
MTable table = MTable.get(tableID);
String recordUU = Objects.toString(evt.getNewValue(), "");
if (tableID > 0 && recordUU.length() > 0)
table.getPOByUU(recordUU, null); // calls po.checkCrossTenant() method
}
setValue(evt.getNewValue(), false);
}
}
@Override
public String toKeyValue(Object value) {
return value != null ? value.toString() : null;
}
@Override
protected String getKeyColumn(MTable mTable) {
return PO.getUUIDColumnName(mTable.getTableName());
}
@Override
public String validateTableIdValue(int tableId) {
MTable table = MTable.get(tableId);
if (! table.hasUUIDKey())
return "TableHasNoKeyColumn";
return null;
}
}

View File

@ -38,6 +38,7 @@ import org.adempiere.webui.editor.WPasswordEditor;
import org.adempiere.webui.editor.WPaymentEditor;
import org.adempiere.webui.editor.WRadioGroupEditor;
import org.adempiere.webui.editor.WRecordIDEditor;
import org.adempiere.webui.editor.WRecordUUIDEditor;
import org.adempiere.webui.editor.WSearchEditor;
import org.adempiere.webui.editor.WStringEditor;
import org.adempiere.webui.editor.WTableDirEditor;
@ -232,9 +233,13 @@ public class DefaultEditorFactory implements IEditorFactory {
{
editor = new WTimeZoneEditor(gridField, tableEditor);
}
else if (displayType == DisplayType.RecordID || displayType == DisplayType.RecordUU)
else if (displayType == DisplayType.RecordID)
{
editor = new WRecordIDEditor(gridField, tableEditor, editorConfiguration);
}
else if (displayType == DisplayType.RecordUU)
{
editor = new WRecordUUIDEditor(gridField, tableEditor, editorConfiguration);
}
else
{

View File

@ -4,6 +4,7 @@
package org.adempiere.webui.info;
import org.compiere.model.GridField;
import org.compiere.model.MAsset;
import org.compiere.util.Env;
/**
@ -78,7 +79,7 @@ public class InfoAssetWindow extends InfoWindow {
super.saveSelectionDetail();
// publish for Callout to read
Integer ID = getSelectedRowKey();
Integer ID = getIntSelectedRowKey(MAsset.Table_ID);
Env.setContext(Env.getCtx(), p_WindowNo, Env.TAB_INFO, "A_Asset_ID", ID == null ? "0" : ID.toString());
}

View File

@ -5,6 +5,7 @@ package org.adempiere.webui.info;
import org.adempiere.webui.panel.InvoiceHistory;
import org.compiere.model.GridField;
import org.compiere.model.MBPartner;
import org.compiere.util.Env;
/**
@ -86,7 +87,7 @@ public class InfoBPartnerWindow extends InfoWindow {
protected void showHistory()
{
log.info("");
Integer C_BPartner_ID = getSelectedRowKey();
Integer C_BPartner_ID = getIntSelectedRowKey(MBPartner.Table_ID);
if (C_BPartner_ID == null)
return;
InvoiceHistory ih = new InvoiceHistory (this, C_BPartner_ID.intValue(),
@ -105,7 +106,7 @@ public class InfoBPartnerWindow extends InfoWindow {
super.saveSelectionDetail();
// publish for Callout to read
Integer ID = getSelectedRowKey();
Integer ID = getIntSelectedRowKey(MBPartner.Table_ID);
Env.setContext(Env.getCtx(), p_WindowNo, Env.TAB_INFO, "C_BPartner_ID", ID == null ? "0" : ID.toString());
}

View File

@ -4,6 +4,7 @@
package org.adempiere.webui.info;
import org.compiere.model.GridField;
import org.compiere.model.MInvoice;
import org.compiere.util.Env;
/**
@ -76,7 +77,7 @@ public class InfoInvoiceWindow extends InfoWindow {
super.saveSelectionDetail();
// publish for Callout to read
Integer ID = getSelectedRowKey();
Integer ID = getIntSelectedRowKey(MInvoice.Table_ID);
Env.setContext(Env.getCtx(), p_WindowNo, Env.TAB_INFO, "C_Invoice_ID", ID == null ? "0" : ID.toString());
}

View File

@ -57,6 +57,7 @@ import org.compiere.minigrid.EmbedWinInfo;
import org.compiere.model.GridField;
import org.compiere.model.MDocType;
import org.compiere.model.MInfoWindow;
import org.compiere.model.MProduct;
import org.compiere.model.MRole;
import org.compiere.model.MSysConfig;
import org.compiere.util.DB;
@ -366,7 +367,7 @@ public class InfoProductWindow extends InfoWindow {
public void onEvent(Event event) throws Exception {
if (contentPanel.getLayout() != null) {
int M_Warehouse_ID = getSelectedWarehouseId();
Integer m_M_Product_ID = getSelectedRowKey();
Integer m_M_Product_ID = getIntSelectedRowKey(MProduct.Table_ID);
if (m_M_Product_ID != null)
initAtpTab(M_Warehouse_ID, m_M_Product_ID);
}
@ -470,7 +471,7 @@ public class InfoProductWindow extends InfoWindow {
* handle on click event for product attribute
*/
protected void onPAttributeClick() {
Integer productInteger = getSelectedRowKey();
Integer productInteger = getIntSelectedRowKey(MProduct.Table_ID);
if (productInteger == null) {
m_PAttributeButton.setEnabled(false);
return;
@ -707,7 +708,7 @@ public class InfoProductWindow extends InfoWindow {
*/
protected void refresh(int M_Warehouse_ID, int M_PriceList_Version_ID)
{
int m_M_Product_ID = getSelectedRowKey();
int m_M_Product_ID = getIntSelectedRowKey(MProduct.Table_ID);
String sql = m_sqlWarehouse;
if (log.isLoggable(Level.FINEST)) log.finest(sql);
PreparedStatement pstmt = null;
@ -951,7 +952,7 @@ public class InfoProductWindow extends InfoWindow {
@Override
protected void showHistory() {
log.info("");
Integer M_Product_ID = getSelectedRowKey();
Integer M_Product_ID = getIntSelectedRowKey(MProduct.Table_ID);
if (M_Product_ID == null)
return;
int M_Warehouse_ID = getSelectedWarehouseId();
@ -991,7 +992,7 @@ public class InfoProductWindow extends InfoWindow {
String.valueOf(m_M_Locator_ID));
}
// publish for Callout to read
Integer ID = getSelectedRowKey();
Integer ID = getIntSelectedRowKey(MProduct.Table_ID);
Env.setContext(Env.getCtx(), p_WindowNo, Env.TAB_INFO, "M_Product_ID", ID == null ? "0" : ID.toString());
}

View File

@ -37,6 +37,7 @@ import org.adempiere.webui.event.WTableModelEvent;
import org.adempiere.webui.util.ZKUpdateUtil;
import org.compiere.minigrid.ColumnInfo;
import org.compiere.minigrid.IDColumn;
import org.compiere.model.MAsset;
import org.compiere.model.MLookupFactory;
import org.compiere.model.MQuery;
import org.compiere.util.DisplayType;
@ -47,10 +48,10 @@ import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zul.Borderlayout;
import org.zkoss.zul.Center;
import org.zkoss.zul.North;
import org.zkoss.zul.South;
import org.zkoss.zul.Div;
import org.zkoss.zul.North;
import org.zkoss.zul.Separator;
import org.zkoss.zul.South;
import org.zkoss.zul.Vbox;
/**
@ -358,7 +359,7 @@ public class InfoAssetPanel extends InfoPanel implements ValueChangeListener, Ev
// publish for Callout to read
Integer ID = getSelectedRowKey();
Integer ID = getIntSelectedRowKey(MAsset.Table_ID);
Env.setContext(Env.getCtx(), p_WindowNo, Env.TAB_INFO, "A_Asset_ID", ID == null ? "0" : ID.toString());
} // saveSelectionDetail
@ -389,7 +390,7 @@ public class InfoAssetPanel extends InfoPanel implements ValueChangeListener, Ev
public void zoom()
{
log.info( "InfoAsset.zoom");
Integer A_Asset_ID = getSelectedRowKey();
Integer A_Asset_ID = getIntSelectedRowKey(MAsset.Table_ID);
if (A_Asset_ID == null)
return;

View File

@ -17,6 +17,9 @@
package org.adempiere.webui.panel;
import static org.compiere.model.SystemIDs.COLUMN_S_RESOURCEASSIGNMENT_S_RESOURCE_ID;
import static org.compiere.model.SystemIDs.COLUMN_S_RESOURCE_S_RESOURCETYPE_ID;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;
@ -42,9 +45,8 @@ import org.compiere.minigrid.ColumnInfo;
import org.compiere.minigrid.IDColumn;
import org.compiere.model.MLookupFactory;
import org.compiere.model.MQuery;
import static org.compiere.model.SystemIDs.*;
import org.compiere.model.MResourceAssignment;
import org.compiere.model.SystemIDs;
import org.compiere.util.DB;
import org.compiere.util.DisplayType;
import org.compiere.util.Env;
@ -54,10 +56,10 @@ import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zul.Borderlayout;
import org.zkoss.zul.Center;
import org.zkoss.zul.North;
import org.zkoss.zul.South;
import org.zkoss.zul.Div;
import org.zkoss.zul.North;
import org.zkoss.zul.Separator;
import org.zkoss.zul.South;
import org.zkoss.zul.Vbox;
/**
@ -396,18 +398,19 @@ public class InfoAssignmentPanel extends InfoPanel implements EventListener<Even
public void zoom()
{
if (getSelectedRowKey() != null && getSelectedRowKey() instanceof Integer && ((Integer)getSelectedRowKey()).intValue() > 0)
int id = getIntSelectedRowKey(MResourceAssignment.Table_ID);
if (id > 0)
{
MQuery zoomQuery = new MQuery(); // ColumnName might be changed in MTab.validateQuery
String column = getKeyColumn();
//strip off table name, fully qualify name doesn't work when zoom into detail tab
if (column.indexOf(".") > 0)
column = column.substring(column.indexOf(".")+1);
zoomQuery.addRestriction(column, MQuery.EQUAL, getSelectedRowKey());
zoomQuery.addRestriction(column, MQuery.EQUAL, id);
zoomQuery.setRecordCount(1);
zoomQuery.setTableName(column.substring(0, column.length() - 3));
AEnv.zoom(236, zoomQuery);
AEnv.zoom(SystemIDs.WINDOW_RESOURCE, zoomQuery);
}
}

View File

@ -37,6 +37,7 @@ import org.adempiere.webui.event.WTableModelListener;
import org.adempiere.webui.util.ZKUpdateUtil;
import org.compiere.minigrid.ColumnInfo;
import org.compiere.minigrid.IDColumn;
import org.compiere.model.MBPartner;
import org.compiere.model.MQuery;
import org.compiere.util.CLogger;
import org.compiere.util.Env;
@ -510,7 +511,7 @@ public class InfoBPartnerPanel extends InfoPanel implements EventListener<Event>
C_BPartner_Location_ID = ((KeyNamePair)data).getKey();
}
// publish for Callout to read
Integer ID = getSelectedRowKey();
Integer ID = getIntSelectedRowKey(MBPartner.Table_ID);
Env.setContext(Env.getCtx(), p_WindowNo, Env.TAB_INFO, "C_BPartner_ID", ID == null ? "0" : ID.toString());
Env.setContext(Env.getCtx(), p_WindowNo, Env.TAB_INFO, "AD_User_ID", String.valueOf(AD_User_ID));
Env.setContext(Env.getCtx(), p_WindowNo, Env.TAB_INFO, "C_BPartner_Location_ID", String.valueOf(C_BPartner_Location_ID));
@ -524,7 +525,7 @@ public class InfoBPartnerPanel extends InfoPanel implements EventListener<Event>
protected void showHistory()
{
log.info("");
Integer C_BPartner_ID = getSelectedRowKey();
Integer C_BPartner_ID = getIntSelectedRowKey(MBPartner.Table_ID);
if (C_BPartner_ID == null)
return;
InvoiceHistory ih = new InvoiceHistory (this, C_BPartner_ID.intValue(),
@ -548,7 +549,7 @@ public class InfoBPartnerPanel extends InfoPanel implements EventListener<Event>
public void zoom()
{
log.info( "InfoBPartner.zoom");
Integer C_BPartner_ID = getSelectedRowKey();
Integer C_BPartner_ID = getIntSelectedRowKey(MBPartner.Table_ID);
if (C_BPartner_ID == null)
return;
// AEnv.zoom(MBPartner.Table_ID, C_BPartner_ID.intValue(), true); // SO

View File

@ -502,7 +502,7 @@ public class InfoGeneralPanel extends InfoPanel implements EventListener<Event>
+ " (f.IsEncrypted='N' AND f.ObscureType IS NULL)) "
+ " AND c.IsActive = 'Y' "
+ "ORDER BY ");
if (table.isUUIDKeyTable())
if (table.isUUIDKeyTable() || p_keyColumn.endsWith("_UU"))
sqlc.append("CASE WHEN c.columnname=").append(DB.TO_STRING(uucolName)).append("THEN 0 ELSE 1 END");
else
sqlc.append("c.IsKey DESC");
@ -514,6 +514,7 @@ public class InfoGeneralPanel extends InfoPanel implements EventListener<Event>
pstmt.setInt(1, AD_Table_ID);
pstmt.setInt(2, AD_Window_ID);
rs = pstmt.executeQuery();
boolean keyDefined = false;
while (rs.next())
{
String columnName = rs.getString(1);
@ -534,11 +535,12 @@ public class InfoGeneralPanel extends InfoPanel implements EventListener<Event>
StringBuffer colSql = new StringBuffer(columnSql);
Class<?> colClass = null;
if (isKey)
if (isKey && !keyDefined)
colClass = IDColumn.class;
else if (uucolName.equals(columnName) && table.isUUIDKeyTable())
else if (uucolName.equals(columnName) && (table.isUUIDKeyTable() || p_keyColumn.endsWith("_UU"))) {
colClass = UUIDColumn.class;
else if (!isDisplayed)
keyDefined = true;
} else if (!isDisplayed)
;
else if (displayType == DisplayType.YesNo)
colClass = Boolean.class;

View File

@ -41,6 +41,7 @@ import org.adempiere.webui.event.WTableModelEvent;
import org.adempiere.webui.util.ZKUpdateUtil;
import org.compiere.minigrid.ColumnInfo;
import org.compiere.minigrid.IDColumn;
import org.compiere.model.MInOut;
import org.compiere.model.MLookupFactory;
import org.compiere.model.MQuery;
import org.compiere.util.DisplayType;
@ -52,11 +53,11 @@ import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zul.Borderlayout;
import org.zkoss.zul.Center;
import org.zkoss.zul.North;
import org.zkoss.zul.South;
import org.zkoss.zul.Div;
import org.zkoss.zul.Hbox;
import org.zkoss.zul.North;
import org.zkoss.zul.Separator;
import org.zkoss.zul.South;
import org.zkoss.zul.Vbox;
/**
@ -414,7 +415,7 @@ public class InfoInOutPanel extends InfoPanel implements ValueChangeListener, Ev
public void zoom()
{
log.info( "InfoInOut.zoom");
Integer M_InOut_ID = getSelectedRowKey();
Integer M_InOut_ID = getIntSelectedRowKey(MInOut.Table_ID);
if (M_InOut_ID == null)
return;
MQuery query = new MQuery("M_InOut");

View File

@ -42,6 +42,7 @@ import org.adempiere.webui.event.WTableModelEvent;
import org.adempiere.webui.util.ZKUpdateUtil;
import org.compiere.minigrid.ColumnInfo;
import org.compiere.minigrid.IDColumn;
import org.compiere.model.MInvoice;
import org.compiere.model.MLookup;
import org.compiere.model.MLookupFactory;
import org.compiere.model.MQuery;
@ -53,11 +54,11 @@ import org.compiere.util.Util;
import org.zkoss.zk.ui.WrongValueException;
import org.zkoss.zul.Borderlayout;
import org.zkoss.zul.Center;
import org.zkoss.zul.North;
import org.zkoss.zul.South;
import org.zkoss.zul.Div;
import org.zkoss.zul.Hbox;
import org.zkoss.zul.North;
import org.zkoss.zul.Separator;
import org.zkoss.zul.South;
import org.zkoss.zul.Vbox;
/**
@ -544,7 +545,7 @@ public class InfoInvoicePanel extends InfoPanel implements ValueChangeListener
public void zoom()
{
log.info( "InfoInvoice.zoom");
Integer C_Invoice_ID = getSelectedRowKey();
Integer C_Invoice_ID = getIntSelectedRowKey(MInvoice.Table_ID);
if (C_Invoice_ID == null)
return;
MQuery query = new MQuery("C_Invoice");
@ -584,7 +585,7 @@ public class InfoInvoicePanel extends InfoPanel implements ValueChangeListener
protected void saveSelectionDetail()
{
// publish for Callout to read
Integer ID = getSelectedRowKey();
Integer ID = getIntSelectedRowKey(MInvoice.Table_ID);
Env.setContext(Env.getCtx(), p_WindowNo, Env.TAB_INFO, "C_Invoice_ID", ID == null ? "0" : ID.toString());
//
int C_InvoicePaySchedule_ID = 0;

View File

@ -44,6 +44,7 @@ import org.compiere.minigrid.ColumnInfo;
import org.compiere.minigrid.IDColumn;
import org.compiere.model.MLookup;
import org.compiere.model.MLookupFactory;
import org.compiere.model.MOrder;
import org.compiere.model.MQuery;
import org.compiere.util.DisplayType;
import org.compiere.util.Env;
@ -52,11 +53,11 @@ import org.compiere.util.Util;
import org.zkoss.zk.ui.WrongValueException;
import org.zkoss.zul.Borderlayout;
import org.zkoss.zul.Center;
import org.zkoss.zul.North;
import org.zkoss.zul.South;
import org.zkoss.zul.Div;
import org.zkoss.zul.Hbox;
import org.zkoss.zul.North;
import org.zkoss.zul.Separator;
import org.zkoss.zul.South;
import org.zkoss.zul.Vbox;
/**
@ -515,7 +516,7 @@ public class InfoOrderPanel extends InfoPanel implements ValueChangeListener
public void zoom()
{
log.info("");
Integer C_Order_ID = getSelectedRowKey();
Integer C_Order_ID = getIntSelectedRowKey(MOrder.Table_ID);
if (C_Order_ID == null)
return;
MQuery query = new MQuery("C_Order");

View File

@ -133,7 +133,7 @@ public abstract class InfoPanel extends Window implements EventListener<Event>,
/**
*
*/
private static final long serialVersionUID = -6216075383041481835L;
private static final long serialVersionUID = -3055980415629613992L;
protected static final String ON_USER_QUERY_ATTR = "ON_USER_QUERY";
protected static final String INFO_QUERY_TIME_OUT_ERROR = "InfoQueryTimeOutError";
@ -1538,6 +1538,26 @@ public abstract class InfoPanel extends Window implements EventListener<Event>,
return key;
} // getSelectedRowKey
/**
* Get the integer key of currently selected row
* @param tableId
* @return selected key
*/
protected Integer getIntSelectedRowKey(int tableId)
{
Object key = getSelectedRowKey();
if (key == null)
return Integer.valueOf(-1);
if (key instanceof Integer)
return (Integer) key;
MTable table = MTable.get(tableId);
table.getPOByUU((String) key, null);
return Integer.valueOf(table.get_ID());
} // getIntSelectedRowKey
/**
* Get the keys of selected row/s based on layout defined in prepareTable
* @deprecated

View File

@ -42,6 +42,7 @@ import org.adempiere.webui.util.ZKUpdateUtil;
import org.compiere.minigrid.ColumnInfo;
import org.compiere.minigrid.IDColumn;
import org.compiere.model.MLookupFactory;
import org.compiere.model.MPayment;
import org.compiere.model.MQuery;
import org.compiere.util.DisplayType;
import org.compiere.util.Env;
@ -477,7 +478,7 @@ public class InfoPaymentPanel extends InfoPanel implements ValueChangeListener,
public void zoom()
{
log.info( "InfoPayment.zoom");
Integer C_Payment_ID = getSelectedRowKey();
Integer C_Payment_ID = getIntSelectedRowKey(MPayment.Table_ID);
if (C_Payment_ID == null)
return;
MQuery query = new MQuery("C_Payment");

View File

@ -69,6 +69,7 @@ import org.adempiere.webui.util.ZKUpdateUtil;
import org.compiere.minigrid.ColumnInfo;
import org.compiere.minigrid.IDColumn;
import org.compiere.model.MDocType;
import org.compiere.model.MProduct;
import org.compiere.model.MQuery;
import org.compiere.model.MRole;
import org.compiere.util.CLogMgt;
@ -690,7 +691,7 @@ public class InfoProductPanel extends InfoPanel implements EventListener<Event>
rs = null; pstmt = null;
}
m_M_Product_ID = getSelectedRowKey();
m_M_Product_ID = getIntSelectedRowKey(MProduct.Table_ID);
sql = "SELECT DocumentNote FROM M_Product WHERE M_Product_ID=?";
fieldDescription.setText(DB.getSQLValueString(null, sql, m_M_Product_ID));
@ -1170,7 +1171,7 @@ public class InfoProductPanel extends InfoPanel implements EventListener<Event>
protected void showHistory()
{
log.info("");
Integer M_Product_ID = getSelectedRowKey();
Integer M_Product_ID = getIntSelectedRowKey(MProduct.Table_ID);
if (M_Product_ID == null)
return;
int M_Warehouse_ID = 0;
@ -1204,7 +1205,7 @@ public class InfoProductPanel extends InfoPanel implements EventListener<Event>
public void zoom()
{
log.info("");
Integer M_Product_ID = getSelectedRowKey();
Integer M_Product_ID = getIntSelectedRowKey(MProduct.Table_ID);
if (M_Product_ID == null)
return;
@ -1248,7 +1249,7 @@ public class InfoProductPanel extends InfoPanel implements EventListener<Event>
protected void saveSelectionDetail()
{
// publish for Callout to read
Integer ID = getSelectedRowKey();
Integer ID = getIntSelectedRowKey(MProduct.Table_ID);
Env.setContext(Env.getCtx(), p_WindowNo, Env.TAB_INFO, "M_Product_ID", ID == null ? "0" : ID.toString());
ListItem pickPL = (ListItem)pickPriceList.getSelectedItem();
if (pickPL!=null)
@ -1399,7 +1400,7 @@ public class InfoProductPanel extends InfoPanel implements EventListener<Event>
int row = contentPanel != null ? contentPanel.getSelectedRow() : -1;
if (component.equals(m_PAttributeButton) && row != -1)
{
Integer productInteger = getSelectedRowKey();
Integer productInteger = getIntSelectedRowKey(MProduct.Table_ID);
String productName = (String)contentPanel.getValueAt(row, INDEX_NAME);
ListItem warehouse = pickWarehouse.getSelectedItem();

View File

@ -31,7 +31,7 @@ import org.adempiere.webui.component.ConfirmPanel;
import org.adempiere.webui.component.Textbox;
import org.adempiere.webui.component.Window;
import org.adempiere.webui.editor.WEditor;
import org.adempiere.webui.editor.WRecordIDEditor;
import org.adempiere.webui.editor.WRecordEditor;
import org.adempiere.webui.editor.WSearchEditor;
import org.adempiere.webui.editor.WTableDirEditor;
import org.adempiere.webui.event.ValueChangeEvent;
@ -44,6 +44,7 @@ import org.compiere.model.PO;
import org.compiere.util.DisplayType;
import org.compiere.util.Env;
import org.compiere.util.Msg;
import org.compiere.util.Util;
import org.zkoss.zhtml.Text;
import org.zkoss.zk.ui.HtmlBasedComponent;
import org.zkoss.zk.ui.Page;
@ -60,14 +61,13 @@ import org.zkoss.zul.Vlayout;
*
*/
public class WRecordIDDialog extends Window implements EventListener<Event>, ValueChangeListener {
/**
* generated serial id
*/
private static final long serialVersionUID = 8126107952514403099L;
private static final long serialVersionUID = 1791159320699080384L;
/** Record_ID editor from which the window is opened */
private WRecordIDEditor editor;
private WRecordEditor<?> editor;
/** Current tab's AD_Table_ID GrodField */
private GridField tableIDGridField;
/** Current Record_ID value from {@link #editor} */
@ -93,7 +93,7 @@ public class WRecordIDDialog extends Window implements EventListener<Event>, Val
* @param editor
* @param tableIDGridField
*/
public WRecordIDDialog(Page page, WRecordIDEditor editor, GridField tableIDGridField) {
public WRecordIDDialog(Page page, WRecordEditor<?> editor, GridField tableIDGridField) {
super();
this.editor = editor;
@ -109,17 +109,7 @@ public class WRecordIDDialog extends Window implements EventListener<Event>, Val
this.tableIDGridField = tableIDGridField;
if(editor.getValue() instanceof Integer) {
this.recordIDValue = (Integer)editor.getValue();
} else {
if (editor.getValue() == null)
this.recordIDValue = null;
else {
MTable table = MTable.get(tableIDValue);
if (editor.getValue() instanceof String && table != null && table.isUUIDKeyTable())
this.recordIDValue = editor.getValue().toString();
}
}
this.recordIDValue = editor.toKeyValue(editor.getValue());
init(page);
}
@ -145,7 +135,7 @@ public class WRecordIDDialog extends Window implements EventListener<Event>, Val
int tableID = tableIDValue != null ? tableIDValue.intValue() : 0;
MLookup recordsLookup = editor.getRecordsLookup(tableID);
if(recordsLookup != null)
recordsEditor = new WSearchEditor("Record_ID", false, false, true, recordsLookup);
recordsEditor = new WSearchEditor(editor.getColumnName(), false, false, true, recordsLookup);
setPage(page);
setClosable(true);
@ -159,13 +149,13 @@ public class WRecordIDDialog extends Window implements EventListener<Event>, Val
if (editor.getGridField().getGridTab() != null) {
parentTextBox = new Textbox();
parentTextBox.setReadonly(true);
MTable table = MTable.get(tableID);
Object recordId;
if (table.isUUIDKeyTable())
recordId = editor.getGridField().getGridTab().getValue(PO.getUUIDColumnName(table.getTableName()));
MTable parentTable = MTable.get(editor.getGridField().getGridTab().getAD_Table_ID());
Object parentRecordId;
if (parentTable.isUUIDKeyTable())
parentRecordId = editor.getGridField().getGridTab().getValue(PO.getUUIDColumnName(parentTable.getTableName()));
else
recordId = editor.getGridField().getGridTab().getRecord_ID();
parentTextBox.setValue(editor.getIdentifier(tableID, recordId));
parentRecordId = editor.getGridField().getGridTab().getRecord_ID();
parentTextBox.setValue(editor.getParentIdentifier(parentTable.getAD_Table_ID(), parentRecordId));
}
if (recordsEditor != null)
@ -233,10 +223,9 @@ public class WRecordIDDialog extends Window implements EventListener<Event>, Val
if (evt.getSource().equals(tableIDEditor)) {
int tableID = Integer.parseInt(Objects.toString(evt.getNewValue(), "-1"));
if (tableID > 0) {
MTable table = MTable.get(tableID);
if (table.isUUIDKeyTable()) {
if (! editor.getColumnName().endsWith("_UU"))
throw new WrongValueException(tableIDEditor.getComponent(), Msg.getMsg(Env.getCtx(), "UUTableNotCompatibleWithRecordID"));
String error = editor.validateTableIdValue(tableID);
if (!Util.isEmpty(error)) {
throw new WrongValueException(tableIDEditor.getComponent(), Msg.getMsg(Env.getCtx(), error));
}
}
@ -248,7 +237,7 @@ public class WRecordIDDialog extends Window implements EventListener<Event>, Val
}
MLookup recordsLookup = editor.getRecordsLookup(tableID);
if(recordsLookup != null) {
recordsEditor = new WSearchEditor("Record_ID", false, false, true, recordsLookup);
recordsEditor = new WSearchEditor(editor.getColumnName(), false, false, true, recordsLookup);
labelsDiv.appendChild(recordsEditorLabel);
fieldsDiv.appendChild(recordsEditor.getComponent());
recordsEditor.getComponent().focus();