From 21b6ec1016853930876a9464c99ce1d816d36197 Mon Sep 17 00:00:00 2001 From: hieplq Date: Sun, 1 Oct 2023 21:13:47 +0700 Subject: [PATCH] =?UTF-8?q?IDEMPIERE-5866:=20different=20identifiers=20of?= =?UTF-8?q?=20info=20window=20and=20m=5Ftable=20cause=20in=E2=80=A6=20(#20?= =?UTF-8?q?29)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * IDEMPIERE-5866:difference identify of info window and m_table make info window fill query text to wrong parameter * IDEMPIERE-5864:correct comment code, thanks to hengsin * IDEMPIERE-5864:InfoWindow testCount call too much when open infowindow from search editor refractory: clear logic find out search editor for auto complete separate logic query for auto complete and query for all identifies editor * IDEMPIERE-5864:split code to functions * IDEMPIERE-5864:change order test for each identifies and test for split query to reduce test * IDEMPIERE-5864:fix review from hengsin --- .../org/adempiere/webui/info/InfoWindow.java | 157 ++++++++++++++---- 1 file changed, 121 insertions(+), 36 deletions(-) diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/info/InfoWindow.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/info/InfoWindow.java index bb076e9145..9fb9498101 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/info/InfoWindow.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/info/InfoWindow.java @@ -31,6 +31,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.function.Consumer; import java.util.Properties; import java.util.TreeMap; import java.util.logging.Level; @@ -102,6 +103,7 @@ import org.compiere.model.Lookup; import org.compiere.model.MAuthorizationAccount; import org.compiere.model.MInfoColumn; import org.compiere.model.MInfoWindow; +import org.compiere.model.MLookup; import org.compiere.model.MLookupFactory; import org.compiere.model.MLookupInfo; import org.compiere.model.MProcess; @@ -617,43 +619,21 @@ public class InfoWindow extends InfoPanel implements ValueChangeListener, EventL */ protected void processQueryValue() { isQueryByUser = true; - for (int i = 0; i < identifiers.size(); i++) { - WEditor editor = identifiers.get(i); - if (isAutoComplete) { - if (!Util.isEmpty(autoCompleteSearchColumn)) { - if (!editor.getColumnName().equals(autoCompleteSearchColumn)) - continue; - } - } - try{ - editor.setValue(queryValue); - }catch(Exception ex){ - log.log(Level.SEVERE, "error", ex.getCause()); - } - - testCount(false); - if (isAutoComplete) - break; - if (m_count > 0) { - break; - } else { - editor.setValue(null); - } - } - boolean splitValue = false; - if (!isAutoComplete) { - if (m_count <= 0) { - String separator = MSysConfig.getValue(MSysConfig.IDENTIFIER_SEPARATOR, "_", Env.getAD_Client_ID(Env.getCtx())); - String[] values = queryValue.split("[" + separator.trim()+"]"); - if (values.length == 2) { - splitValue = true; - for(int i = 0; i < values.length && i < identifiers.size(); i++) { - WEditor editor = identifiers.get(i); - editor.setValue(values[i].trim()); - } - testCount(false); - } + + if (isAutoComplete) { + testQueryForAutoComplete(); + }else { + String separator = MSysConfig.getValue(MSysConfig.IDENTIFIER_SEPARATOR, "_", Env.getAD_Client_ID(Env.getCtx())); + String[] values = queryValue.split("[" + separator.trim()+"]"); + + if (values.length > 1) { + splitValue = true; + testQueryForSplit(values); + } + + if (m_count <= 0) { + testQueryForEachIdentifier(); } } @@ -666,6 +646,111 @@ public class InfoWindow extends InfoPanel implements ValueChangeListener, EventL isQueryByUser = false; } + protected void testQueryForAutoComplete() { + WEditor autocompleteEditor = null; + + if (Util.isEmpty(autoCompleteSearchColumn) && identifiers.size() > 0) { + autocompleteEditor = identifiers.get(0); + }else if (!Util.isEmpty(autoCompleteSearchColumn) && identifiers.size() > 0) { + autocompleteEditor = identifiers.stream() + .filter(editor -> editor.getColumnName().equals(autoCompleteSearchColumn)) + .findFirst().orElse(null); + } + + + if (autocompleteEditor != null) { + try{ + autocompleteEditor.setValue(queryValue); + testCount(false); + + }catch(Exception ex){ + // => don't run test in case not success set value + log.log(Level.SEVERE, "error", ex.getCause()); + } + }else { + // => don't run test in case not found auto complete column + if(!Util.isEmpty(autoCompleteSearchColumn)) + log.log(Level.SEVERE, String.format("Auto complete search column (%s) not found for field %s (field id %s). ", + autoCompleteSearchColumn, m_gridfield.getColumnName(), m_gridfield.getAD_Column_ID())); + else if (identifiers.size() == 0) + log.log(Level.SEVERE, String.format("Info window (%s) has no identifier columns", this.infoWindow.getName())); + } + } + + protected void testQueryForEachIdentifier() { + for (int i = 0; i < identifiers.size(); i++) { + WEditor editor = identifiers.get(i); + + try{ + editor.setValue(queryValue); + }catch(Exception ex){ + log.log(Level.SEVERE, "error", ex.getCause()); + } + + testCount(false); + + if (m_count > 0) { + break; + } else { + editor.setValue(null); + } + } + } + + protected void testQueryForSplit(String [] values) { + // store identifiers on info window, sort to follow identifier on m_table + List fillIdentifiers = new ArrayList<>(); + // store query value, ignore value for identifier not exists on info window + // this list is sync with fillIdentifiers (size and order) + List fillValues = new ArrayList<>(); + + List tableIdentifiers = null; + if (m_gridfield != null && m_gridfield.getLookup() != null + && m_gridfield.getLookup() instanceof MLookup) { + + MLookup mLookup = (MLookup)m_gridfield.getLookup(); + if (mLookup.getLookupInfo().lookupDisplayColumnNames.size() > 0) + tableIdentifiers = mLookup.getLookupInfo().lookupDisplayColumnNames; + } + + if (tableIdentifiers != null) { + for (int i = 0; i < tableIdentifiers.size(); i++) { + // final local variable to access inside lambda expression + int indexFinal = i; + List tableIdentifiersFinal = tableIdentifiers; + + // sort identifiers of info window to follow m_table + // ignore identifiers exists on m_table but not exists on info window + identifiers.forEach((Consumer)(identifierEditor) -> { + if (identifierEditor.getColumnName().equals(tableIdentifiersFinal.get(indexFinal))) { + fillIdentifiers.add(identifierEditor); + fillValues.add(values[indexFinal]); + } + }); + } + } + + // case not exists mLookup.getLookupInfo().lookupDisplayColumnNames + // or no identifiers on info window exists on m_table + // fall back to old logic and just set values to identifiers + if (fillIdentifiers.size() == 0) { + for(int i = 0; i < values.length && i < identifiers.size(); i++) { + fillIdentifiers.add(identifiers.get(i)); + fillValues.add(values[i]); + } + } + + + + // do fill value to editor (for both corrected order and fall back) + for(int i = 0; i < fillIdentifiers.size(); i++) { + WEditor editor = fillIdentifiers.get(i); + editor.setValue(fillValues.get(i).trim()); + } + testCount(false); + + } + @Override protected void loadInfoWindowData (){ if (m_infoWindowID > 0) {