IDEMPIERE-1540 Autocomplete for field type "Search" (#88)

Fix search column for auto complete
This commit is contained in:
hengsin 2020-05-30 00:08:39 +08:00 committed by GitHub
parent ed7952945a
commit fc56a2a205
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 50 additions and 8 deletions

View File

@ -20,6 +20,7 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import java.util.Properties; import java.util.Properties;
import java.util.logging.Level; import java.util.logging.Level;
@ -618,7 +619,12 @@ public class MLookupFactory
retValue.DisplayColumn = lookupDisplayColumn; retValue.DisplayColumn = lookupDisplayColumn;
retValue.InfoWindowId = infoWindowId; retValue.InfoWindowId = infoWindowId;
retValue.QueryDirect = MRole.getDefault().addAccessSQL(directQuery, TableName, true, false); retValue.QueryDirect = MRole.getDefault().addAccessSQL(directQuery, TableName, true, false);
List<String> lookupDisplayColumns = new ArrayList<String>();
if (isValueDisplayed)
lookupDisplayColumns.add("Value");
lookupDisplayColumns.add(lookupDisplayColumn != null ? lookupDisplayColumn : DisplayColumn);
s_cacheRefTable.put(key.toString(), retValue.cloneIt()); s_cacheRefTable.put(key.toString(), retValue.cloneIt());
retValue.lookupDisplayColumns = lookupDisplayColumns;
return retValue; return retValue;
} // getLookup_Table } // getLookup_Table
@ -850,6 +856,11 @@ public class MLookupFactory
msginf.toString(), ZoomWindow, ZoomWindowPO, zoomQuery); msginf.toString(), ZoomWindow, ZoomWindowPO, zoomQuery);
lInfo.DisplayColumn = displayColumn.toString(); lInfo.DisplayColumn = displayColumn.toString();
lInfo.QueryDirect = MRole.getDefault().addAccessSQL(directQuery, TableName, true, false); lInfo.QueryDirect = MRole.getDefault().addAccessSQL(directQuery, TableName, true, false);
List<String> lookupDisplayColumns = new ArrayList<String>();
for (LookupDisplayColumn ldc : list) {
lookupDisplayColumns.add(ldc.ColumnName);
}
lInfo.lookupDisplayColumns = lookupDisplayColumns;
s_cacheRefTable.put(cacheKey.toString(), lInfo.cloneIt()); s_cacheRefTable.put(cacheKey.toString(), lInfo.cloneIt());
return lInfo; return lInfo;
} // getLookup_TableDir } // getLookup_TableDir

View File

@ -20,6 +20,7 @@ import java.io.Serializable;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.List;
import java.util.Properties; import java.util.Properties;
import java.util.logging.Level; import java.util.logging.Level;
@ -208,6 +209,8 @@ public class MLookupInfo implements Serializable, Cloneable
public int InfoWindowId; public int InfoWindowId;
public List<String> lookupDisplayColumns = null;
/** /**
* String representation * String representation
* @return info * @return info

View File

@ -21,6 +21,7 @@ import static org.compiere.model.SystemIDs.COLUMN_C_INVOICELINE_M_PRODUCT_ID;
import static org.compiere.model.SystemIDs.COLUMN_C_INVOICE_C_BPARTNER_ID; import static org.compiere.model.SystemIDs.COLUMN_C_INVOICE_C_BPARTNER_ID;
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeEvent;
import java.util.List;
import java.util.Properties; import java.util.Properties;
import java.util.logging.Level; import java.util.logging.Level;
@ -226,6 +227,15 @@ public class WSearchEditor extends WEditor implements ContextMenuListener, Value
.append(",") .append(",")
.append("pagesize:") .append("pagesize:")
.append(MAX_AUTO_COMPLETE_ROWS); .append(MAX_AUTO_COMPLETE_ROWS);
if (lookup instanceof MLookup) {
MLookup mlookup = (MLookup) lookup;
List<String> displayColumns = mlookup.getLookupInfo().lookupDisplayColumns;
if (displayColumns != null && displayColumns.size() > 0) {
query.append(",")
.append("searchcolumn:")
.append(displayColumns.get(0));
}
}
query.append("}"); query.append("}");
s = query.toString(); s = query.toString();
} }

View File

@ -506,8 +506,11 @@ public class InfoWindow extends InfoPanel implements ValueChangeListener, EventL
isQueryByUser = true; isQueryByUser = true;
for (int i = 0; i < identifiers.size(); i++) { for (int i = 0; i < identifiers.size(); i++) {
WEditor editor = identifiers.get(i); WEditor editor = identifiers.get(i);
if (isAutoComplete && i > 0) { if (isAutoComplete) {
break; if (!Util.isEmpty(autoCompleteSearchColumn)) {
if (!editor.getColumnName().equals(autoCompleteSearchColumn))
continue;
}
} }
try{ try{
editor.setValue(queryValue); editor.setValue(queryValue);
@ -516,6 +519,8 @@ public class InfoWindow extends InfoPanel implements ValueChangeListener, EventL
} }
testCount(false); testCount(false);
if (isAutoComplete)
break;
if (m_count > 0) { if (m_count > 0) {
break; break;
} else { } else {
@ -1452,8 +1457,7 @@ public class InfoWindow extends InfoPanel implements ValueChangeListener, EventL
row.appendChild(checkAND); row.appendChild(checkAND);
} }
} }
if (!isAutoComplete) evalDisplayLogic();
evalDisplayLogic();
if (!update) if (!update)
initParameters(); initParameters();
if (!isAutoComplete) if (!isAutoComplete)

View File

@ -160,22 +160,32 @@ public class InfoGeneralPanel extends InfoPanel implements EventListener<Event>
if (queryValue != null && queryValue.length() > 0) if (queryValue != null && queryValue.length() > 0)
{ {
Textbox[] txts = new Textbox[] {txt1, txt2, txt3, txt4}; Textbox[] txts = new Textbox[] {txt1, txt2, txt3, txt4};
int i = 0;
for(Textbox t : txts) for(Textbox t : txts)
{ {
if (t != null && t.isVisible()) if (t != null && t.isVisible())
{ {
if (isAutoComplete)
{
if (!Util.isEmpty(autoCompleteSearchColumn))
{
if (!autoCompleteSearchColumn.equals(m_queryColumns.get(i)))
continue;
}
}
t.setValue(queryValue); t.setValue(queryValue);
testCount(); testCount();
if (m_count <= 0) if (m_count <= 0)
t.setValue(null); t.setValue(null);
else else
break; break;
}
if (isAutoComplete) if (isAutoComplete)
break; break;
}
i++;
} }
if (m_count <= 0) if (m_count <= 0 && !isAutoComplete)
{ {
txt1.setValue(queryValue); txt1.setValue(queryValue);
} }

View File

@ -318,6 +318,8 @@ public abstract class InfoPanel extends Window implements EventListener<Event>,
if (t > 0) if (t > 0)
this.pageSize = t; this.pageSize = t;
} catch (Exception e) {} } catch (Exception e) {}
} else if (pair[0].equalsIgnoreCase("searchcolumn")) {
this.autoCompleteSearchColumn = pair[1];
} }
} }
} }
@ -462,6 +464,8 @@ public abstract class InfoPanel extends Window implements EventListener<Event>,
protected int queryTimeout = 0; protected int queryTimeout = 0;
protected String autoCompleteSearchColumn = null;
protected String queryValue; protected String queryValue;
/** /**