IDEMPIERE-5924 WSearchEditor - add API to allow form to turn on the auto complete feature (#2105)
This commit is contained in:
parent
14bff68342
commit
75be677f2e
|
@ -105,6 +105,7 @@ public class WSearchEditor extends WEditor implements ContextMenuListener, Value
|
||||||
|
|
||||||
/** ADWindow instance that own this editor */
|
/** ADWindow instance that own this editor */
|
||||||
protected ADWindow adwindow;
|
protected ADWindow adwindow;
|
||||||
|
private EventListener<InputEvent> autoCompleteListener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -252,18 +253,7 @@ public class WSearchEditor extends WEditor implements ContextMenuListener, Value
|
||||||
getComponent().getCombobox().setPlaceholder(gridField.getPlaceholder());
|
getComponent().getCombobox().setPlaceholder(gridField.getPlaceholder());
|
||||||
|
|
||||||
if (gridField != null && gridField.isAutocomplete()) {
|
if (gridField != null && gridField.isAutocomplete()) {
|
||||||
setTableAndKeyColumn();
|
enableAutoComplete();
|
||||||
listModel = new InfoListSubModel(lookup, gridField, m_tableName, m_keyColumnName);
|
|
||||||
int maxRows = MSysConfig.getIntValue(MSysConfig.ZK_SEARCH_AUTO_COMPLETE_MAX_ROWS, DEFAULT_MAX_AUTO_COMPLETE_ROWS, Env.getAD_Client_ID(Env.getCtx()));
|
|
||||||
getComponent().getCombobox().setModel(listModel.getSubModel(null, maxRows));
|
|
||||||
|
|
||||||
getComponent().getCombobox().addEventListener(Events.ON_CHANGING, (EventListener<InputEvent>)(e) -> {
|
|
||||||
if (!e.isChangingBySelectBack()) {
|
|
||||||
listModel.setWhereClause(getWhereClause());
|
|
||||||
String s = e.getValue();
|
|
||||||
getComponent().getCombobox().setModel(listModel.getSubModel(s, maxRows));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
getComponent().getCombobox().setAutodrop(false);
|
getComponent().getCombobox().setAutodrop(false);
|
||||||
}
|
}
|
||||||
|
@ -271,6 +261,44 @@ public class WSearchEditor extends WEditor implements ContextMenuListener, Value
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Turn on auto complete for editor
|
||||||
|
*/
|
||||||
|
public void enableAutoComplete() {
|
||||||
|
if (autoCompleteListener != null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (m_tableName == null)
|
||||||
|
setTableAndKeyColumn();
|
||||||
|
listModel = new InfoListSubModel(lookup, gridField, m_tableName, m_keyColumnName);
|
||||||
|
int maxRows = MSysConfig.getIntValue(MSysConfig.ZK_SEARCH_AUTO_COMPLETE_MAX_ROWS, DEFAULT_MAX_AUTO_COMPLETE_ROWS, Env.getAD_Client_ID(Env.getCtx()));
|
||||||
|
getComponent().getCombobox().setModel(listModel.getSubModel(null, maxRows));
|
||||||
|
|
||||||
|
autoCompleteListener = e -> {
|
||||||
|
if (!e.isChangingBySelectBack()) {
|
||||||
|
listModel.setWhereClause(getWhereClause());
|
||||||
|
String s = e.getValue();
|
||||||
|
getComponent().getCombobox().setModel(listModel.getSubModel(s, maxRows));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
getComponent().getCombobox().addEventListener(Events.ON_CHANGING, autoCompleteListener);
|
||||||
|
getComponent().getCombobox().setAutodrop(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Turn off auto complete for editor
|
||||||
|
*/
|
||||||
|
public void disableAutoComplete() {
|
||||||
|
if (autoCompleteListener != null) {
|
||||||
|
getComponent().getCombobox().removeEventListener(Events.ON_CHANGING, autoCompleteListener);
|
||||||
|
getComponent().getCombobox().setAutodrop(false);
|
||||||
|
getComponent().getCombobox().setModel(null);
|
||||||
|
listModel = null;
|
||||||
|
autoCompleteListener = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setValue(Object value)
|
public void setValue(Object value)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue