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
This commit is contained in:
Peter Takács 2023-03-16 12:06:51 +01:00 committed by GitHub
parent 9c2dc06dcc
commit 21e4f610eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 76 additions and 32 deletions

View File

@ -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')
;

View File

@ -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')
;

View File

@ -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) : "";
}
/**

View File

@ -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<Event> {
public class WRecordIDDialog extends Window implements EventListener<Event>, ValueChangeListener {
/**
* generated serial id
@ -71,7 +78,7 @@ public class WRecordIDDialog extends Window implements EventListener<Event> {
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,11 +124,21 @@ public class WRecordIDDialog extends Window implements EventListener<Event> {
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);
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;
recordsEditor = tableID > 0 ? new WSearchEditor("Record_ID", false, false, true, editor.getRecordsLookup(tableID)) : null;
MLookup recordsLookup = editor.getRecordsLookup(tableID);
if(recordsLookup != null)
recordsEditor = new WSearchEditor("Record_ID", false, false, true, recordsLookup);
setPage(page);
setClosable(true);
@ -139,8 +156,6 @@ public class WRecordIDDialog extends Window implements EventListener<Event> {
editor.getGridField().getGridTab().getAD_Table_ID(), editor.getGridField().getGridTab().getRecord_ID()));
}
tableIDEditor.getComponent().addEventListener(Events.ON_SELECT, this);
if (recordsEditor != null)
recordsEditor.setValue(recordIDValue);
@ -180,7 +195,8 @@ public class WRecordIDDialog extends Window implements EventListener<Event> {
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<Event> {
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<Event> {
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();
}
}
}

View File

@ -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;
}