From 21e4f610eb94632ead5ece2e930e4a8814d02798 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Tak=C3=A1cs?= <93127072+PeterTakacs300@users.noreply.github.com> Date: Thu, 16 Mar 2023 12:06:51 +0100 Subject: [PATCH] IDEMPIERE-5238 - Support of Search display type for AD_Table_ID (#1726) * IDEMPIERE-5238 - Support of Search display type for AD_Table_ID * IDEMPIERE-5238 - no key column error * IDEMPIERE-5238 - fix css * IDEMPIERE-5238 - move scripts to iD10 * IDEMPIERE-5238 - bug fixes - dialog did not open if AD_Table_ID = 0 - NPE if closing dialog with OK button and AD_Table_ID = 0 * IDEMPIERE-5238 - fix multiple tableID > 0 checks --- .../oracle/202303141224_IDEMPIERE-5238.sql | 10 +++ .../202303141224_IDEMPIERE-5238.sql | 7 ++ .../webui/editor/WRecordIDEditor.java | 6 +- .../webui/window/WRecordIDDialog.java | 83 ++++++++++++------- .../theme/default/css/fragment/window.css.dsp | 2 +- 5 files changed, 76 insertions(+), 32 deletions(-) create mode 100644 migration/iD10/oracle/202303141224_IDEMPIERE-5238.sql create mode 100644 migration/iD10/postgresql/202303141224_IDEMPIERE-5238.sql diff --git a/migration/iD10/oracle/202303141224_IDEMPIERE-5238.sql b/migration/iD10/oracle/202303141224_IDEMPIERE-5238.sql new file mode 100644 index 0000000000..9c269baf77 --- /dev/null +++ b/migration/iD10/oracle/202303141224_IDEMPIERE-5238.sql @@ -0,0 +1,10 @@ +-- IDEMPIERE-5238 +SELECT register_migration_script('202303141224_IDEMPIERE-5238.sql') FROM dual; + +SET SQLBLANKLINES ON +SET DEFINE OFF + +-- Mar 14, 2023, 12:24:54 PM CET +INSERT INTO AD_Message (MsgType,MsgText,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,AD_Message_ID,Value,EntityType,AD_Message_UU) VALUES ('E','This Table has no Key Column',0,0,'Y',TO_TIMESTAMP('2023-03-14 12:24:53','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2023-03-14 12:24:53','YYYY-MM-DD HH24:MI:SS'),100,200826,'TableHasNoKeyColumn','D','f157fa43-7351-43fe-beae-3870f0d76363') +; + diff --git a/migration/iD10/postgresql/202303141224_IDEMPIERE-5238.sql b/migration/iD10/postgresql/202303141224_IDEMPIERE-5238.sql new file mode 100644 index 0000000000..e34696b6cb --- /dev/null +++ b/migration/iD10/postgresql/202303141224_IDEMPIERE-5238.sql @@ -0,0 +1,7 @@ +-- IDEMPIERE-5238 +SELECT register_migration_script('202303141224_IDEMPIERE-5238.sql') FROM dual; + +-- Mar 14, 2023, 12:24:54 PM CET +INSERT INTO AD_Message (MsgType,MsgText,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,AD_Message_ID,Value,EntityType,AD_Message_UU) VALUES ('E','This Table has no Key Column',0,0,'Y',TO_TIMESTAMP('2023-03-14 12:24:53','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2023-03-14 12:24:53','YYYY-MM-DD HH24:MI:SS'),100,200826,'TableHasNoKeyColumn','D','f157fa43-7351-43fe-beae-3870f0d76363') +; + diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WRecordIDEditor.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WRecordIDEditor.java index f766a4fb79..a1dc8ebe79 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WRecordIDEditor.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WRecordIDEditor.java @@ -356,7 +356,7 @@ public class WRecordIDEditor extends WEditor implements ContextMenuListener, IZo /** * Get Lookup * @param tableID - * @return {@link MLookup} + * @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) @@ -366,6 +366,8 @@ public class WRecordIDEditor extends WEditor implements ContextMenuListener, IZo 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; @@ -382,7 +384,7 @@ public class WRecordIDEditor extends WEditor implements ContextMenuListener, IZo */ public String getIdentifier(int tableID, int recordID) { MLookup lookup = getRecordsLookup(tableID); - return lookup != null ? lookup.getDisplay(recordID) : null; + return lookup != null ? lookup.getDisplay(recordID) : ""; } /** diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WRecordIDDialog.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WRecordIDDialog.java index ca67921452..8f5357b2c9 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WRecordIDDialog.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WRecordIDDialog.java @@ -30,15 +30,22 @@ import org.adempiere.webui.component.Button; 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.WSearchEditor; import org.adempiere.webui.editor.WTableDirEditor; +import org.adempiere.webui.event.ValueChangeEvent; +import org.adempiere.webui.event.ValueChangeListener; import org.adempiere.webui.factory.ButtonFactory; import org.compiere.model.GridField; +import org.compiere.model.MLookup; +import org.compiere.util.DisplayType; import org.compiere.util.Env; import org.compiere.util.Msg; import org.zkoss.zhtml.Text; +import org.zkoss.zk.ui.HtmlBasedComponent; import org.zkoss.zk.ui.Page; +import org.zkoss.zk.ui.WrongValueException; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.EventListener; import org.zkoss.zk.ui.event.Events; @@ -50,7 +57,7 @@ import org.zkoss.zul.Vlayout; * @author Peter Takacs, Cloudempiere * */ -public class WRecordIDDialog extends Window implements EventListener { +public class WRecordIDDialog extends Window implements EventListener, ValueChangeListener { /** * generated serial id @@ -71,7 +78,7 @@ public class WRecordIDDialog extends Window implements EventListener { private Div labelsDiv; private Div fieldsDiv; private Div confirmPanelDiv; - private WTableDirEditor tableIDEditor; + private WEditor tableIDEditor; private Button okBtn; private Button cancelBtn; private Textbox parentTextBox; @@ -117,12 +124,22 @@ public class WRecordIDDialog extends Window implements EventListener { contentDiv = new Div(); confirmPanelDiv = new Div(); okBtn = ButtonFactory.createNamedButton(ConfirmPanel.A_OK, true, true); - cancelBtn = ButtonFactory.createNamedButton(ConfirmPanel.A_CANCEL, true, true);; - tableIDEditor = new WTableDirEditor("AD_Table_ID", false, false, true, tableIDGridField.getLookup(), true); - tableIDEditor.setValue(tableIDValue); - int tableID = tableIDValue != null ? tableIDValue.intValue() : 0; - recordsEditor = tableID > 0 ? new WSearchEditor("Record_ID", false, false, true, editor.getRecordsLookup(tableID)) : null; + cancelBtn = ButtonFactory.createNamedButton(ConfirmPanel.A_CANCEL, true, true); + if(DisplayType.Search == tableIDGridField.getDisplayType()) { + tableIDEditor = new WSearchEditor("AD_Table_ID", false, false, true, tableIDGridField.getLookup()); + } + else { + tableIDEditor = new WTableDirEditor("AD_Table_ID", false, false, true, tableIDGridField.getLookup(), true); + } + tableIDEditor.addValueChangeListener(this); + tableIDEditor.setValue(tableIDValue); + + int tableID = tableIDValue != null ? tableIDValue.intValue() : 0; + MLookup recordsLookup = editor.getRecordsLookup(tableID); + if(recordsLookup != null) + recordsEditor = new WSearchEditor("Record_ID", false, false, true, recordsLookup); + setPage(page); setClosable(true); setTitle(Msg.getMsg(Env.getCtx(), "ChooseRelatedRecord")); @@ -139,8 +156,6 @@ public class WRecordIDDialog extends Window implements EventListener { editor.getGridField().getGridTab().getAD_Table_ID(), editor.getGridField().getGridTab().getRecord_ID())); } - tableIDEditor.getComponent().addEventListener(Events.ON_SELECT, this); - if (recordsEditor != null) recordsEditor.setValue(recordIDValue); @@ -179,8 +194,9 @@ public class WRecordIDDialog extends Window implements EventListener { appendChild(vLayout); doHighlighted(); - - tableIDEditor.getComponent().focus(); + + if(tableIDEditor.getComponent() instanceof HtmlBasedComponent) + ((HtmlBasedComponent) tableIDEditor.getComponent()).focus(); } @Override @@ -189,7 +205,8 @@ public class WRecordIDDialog extends Window implements EventListener { if(event.getTarget().equals(okBtn)) { // set the selected values to the editors editor.setAD_Table_ID(tableIDEditor.getValue()); - editor.setValue(recordsEditor.getValue()); + if(recordsEditor != null) + editor.setValue(recordsEditor.getValue()); onClose(); } else if(event.getTarget().equals(cancelBtn)) { @@ -197,23 +214,31 @@ public class WRecordIDDialog extends Window implements EventListener { onClose(); } } - if(event.getName().equalsIgnoreCase(Events.ON_SELECT)) { - if (event.getTarget().equals(tableIDEditor.getComponent())) { - // the Record_ID should be cleared when a different AD_Table_ID is selected - if (recordsEditor != null) { - recordsEditor.setValue(null); - recordsEditorLabel.detach(); - recordsEditor.getComponent().detach(); - } - int tableID = Integer.parseInt(Objects.toString(tableIDEditor.getValue(), "-1")); - if(tableID > 0) { - recordsEditor = new WSearchEditor("Record_ID", false, false, true, editor.getRecordsLookup(tableID)); - labelsDiv.appendChild(recordsEditorLabel); - fieldsDiv.appendChild(recordsEditor.getComponent()); - recordsEditor.getComponent().focus(); - } else { - tableIDEditor.getComponent().focus(); - } + } + + @Override + public void valueChange(ValueChangeEvent evt) { + if (evt.getSource().equals(tableIDEditor)) { + // the Record_ID should be cleared when a different AD_Table_ID is selected + if (recordsEditor != null) { + recordsEditor.setValue(null); + recordsEditorLabel.detach(); + recordsEditor.getComponent().detach(); + } + int tableID = Integer.parseInt(Objects.toString(evt.getNewValue(), "-1")); + + MLookup recordsLookup = editor.getRecordsLookup(tableID); + if(recordsLookup != null) { + recordsEditor = new WSearchEditor("Record_ID", false, false, true, recordsLookup); + labelsDiv.appendChild(recordsEditorLabel); + fieldsDiv.appendChild(recordsEditor.getComponent()); + recordsEditor.getComponent().focus(); + } + else if(tableID > 0) { + throw new WrongValueException(tableIDEditor.getComponent(), Msg.getMsg(Env.getCtx(), "TableHasNoKeyColumn")); + } + else if(tableIDEditor.getComponent() instanceof HtmlBasedComponent) { + ((HtmlBasedComponent) tableIDEditor.getComponent()).focus(); } } } diff --git a/org.adempiere.ui.zk/WEB-INF/src/web/theme/default/css/fragment/window.css.dsp b/org.adempiere.ui.zk/WEB-INF/src/web/theme/default/css/fragment/window.css.dsp index 367bbaf7fa..4b479903e8 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/web/theme/default/css/fragment/window.css.dsp +++ b/org.adempiere.ui.zk/WEB-INF/src/web/theme/default/css/fragment/window.css.dsp @@ -169,7 +169,7 @@ input[type="checkbox"]:focus height: 24px; min-height: 24px; right: 0px; - top: 3px; + top: 1px; border: 1px solid #CFCFCF; border-radius: 0; }