Improve menu lookup's responsiveness
- Use startwith when search text is less than 3 character - Avoid always rebuild the comboitems list
This commit is contained in:
parent
6684b928fd
commit
10affb0a75
|
@ -18,6 +18,7 @@
|
||||||
package org.adempiere.webui.component;
|
package org.adempiere.webui.component;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
import org.zkoss.zk.ui.event.InputEvent;
|
import org.zkoss.zk.ui.event.InputEvent;
|
||||||
import org.zkoss.zul.Comboitem;
|
import org.zkoss.zul.Comboitem;
|
||||||
|
@ -98,69 +99,53 @@ public class AutoComplete extends Combobox
|
||||||
public void onChanging(InputEvent evt)
|
public void onChanging(InputEvent evt)
|
||||||
{
|
{
|
||||||
if (!evt.isChangingBySelectBack())
|
if (!evt.isChangingBySelectBack())
|
||||||
|
{
|
||||||
refresh(evt.getValue());
|
refresh(evt.getValue());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Refresh comboitem based on the specified value.
|
* Refresh comboitem based on the specified value.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private void refresh(String val)
|
private void refresh(String val)
|
||||||
{
|
{
|
||||||
val = val.toLowerCase();
|
if ((val == null) || (val.trim().length() == 0)) {
|
||||||
|
super.getChildren().clear();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* int j = Arrays.binarySearch(comboItemsL, val);
|
String compare = val.toLowerCase().trim();
|
||||||
|
|
||||||
if (j < 0)
|
Iterator<?> it = getItems().iterator();
|
||||||
j = -j-1;
|
for (int i = 0; i < comboItems.length; i++)
|
||||||
|
|
||||||
Iterator it = getItems().iterator();
|
|
||||||
|
|
||||||
for (; j < comboItems.length; ++j)
|
|
||||||
{
|
{
|
||||||
if (!comboItemsL[j].contains(val))
|
boolean match = false;
|
||||||
break;
|
if (compare.length() < 3)
|
||||||
|
|
||||||
if (it != null && it.hasNext())
|
|
||||||
{
|
{
|
||||||
((Comboitem)it.next()).setLabel(comboItems[j]);
|
match = comboItems[i].toLowerCase().startsWith(compare);
|
||||||
|
|
||||||
//if (strDescription[j] != null)
|
|
||||||
// comboitem.setDescription(strDescription[j]);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
match = comboItems[i].toLowerCase().contains(compare);
|
||||||
|
}
|
||||||
|
if (match)
|
||||||
|
{
|
||||||
|
Comboitem comboitem = null;
|
||||||
|
if (it != null && it.hasNext()) {
|
||||||
|
comboitem = ((Comboitem)it.next());
|
||||||
|
} else {
|
||||||
it = null;
|
it = null;
|
||||||
|
comboitem = new Comboitem();
|
||||||
Comboitem comboitem = new Comboitem(comboItems[j]);
|
|
||||||
|
|
||||||
if (strDescription[j] != null)
|
|
||||||
comboitem.setDescription(strDescription[j]);
|
|
||||||
|
|
||||||
comboitem.setParent(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
while (it != null && it.hasNext())
|
|
||||||
{
|
|
||||||
it.next();
|
|
||||||
it.remove();
|
|
||||||
}*/
|
|
||||||
|
|
||||||
super.getChildren().clear();
|
|
||||||
|
|
||||||
if ((val == null) || (val.trim() == null))
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (int i = 0; i < comboItems.length; i++)
|
|
||||||
{
|
|
||||||
if (comboItems[i].toLowerCase().contains(val))
|
|
||||||
{
|
|
||||||
Comboitem comboitem = new Comboitem();
|
|
||||||
comboitem.setLabel(comboItems[i]);
|
|
||||||
comboitem.setDescription(strDescription[i]);
|
|
||||||
super.appendChild(comboitem);
|
super.appendChild(comboitem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
comboitem.setLabel(comboItems[i]);
|
||||||
|
comboitem.setDescription(strDescription[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (it != null && it.hasNext()) {
|
||||||
|
it.next();
|
||||||
|
it.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,6 @@ public class MenuSearchPanel extends Panel implements EventListener
|
||||||
cmbSearch.setAutodrop(true);
|
cmbSearch.setAutodrop(true);
|
||||||
|
|
||||||
cmbSearch.addEventListener(Events.ON_CHANGE, this);
|
cmbSearch.addEventListener(Events.ON_CHANGE, this);
|
||||||
cmbSearch.addEventListener(Events.ON_CHANGING, this);
|
|
||||||
|
|
||||||
this.appendChild(lblSearch);
|
this.appendChild(lblSearch);
|
||||||
this.appendChild(cmbSearch);
|
this.appendChild(cmbSearch);
|
||||||
|
@ -100,7 +99,7 @@ public class MenuSearchPanel extends Panel implements EventListener
|
||||||
|
|
||||||
public void onEvent(Event event)
|
public void onEvent(Event event)
|
||||||
{
|
{
|
||||||
if (cmbSearch.equals(event.getTarget()) && (event.getName() != Events.ON_CHANGING))
|
if (cmbSearch.equals(event.getTarget()) && (event.getName().equals(Events.ON_CHANGE)))
|
||||||
{
|
{
|
||||||
String value = cmbSearch.getValue();
|
String value = cmbSearch.getValue();
|
||||||
Treeitem treeItem = treeNodeItemMap.get(value);
|
Treeitem treeItem = treeNodeItemMap.get(value);
|
||||||
|
|
Loading…
Reference in New Issue