IDEMPIERE-2352 Unaccented Menu Search
This commit is contained in:
parent
65591f0ccb
commit
000825464c
|
@ -22,12 +22,14 @@ import java.io.UnsupportedEncodingException;
|
|||
import java.sql.Timestamp;
|
||||
import java.text.AttributedCharacterIterator;
|
||||
import java.text.AttributedString;
|
||||
import java.text.Normalizer;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.swing.Action;
|
||||
import javax.swing.ActionMap;
|
||||
|
@ -237,7 +239,19 @@ public class Util
|
|||
else
|
||||
return str.length() == 0;
|
||||
} // isEmpty
|
||||
|
||||
|
||||
/**
|
||||
* Remove accents from string
|
||||
* @param str string
|
||||
* @return Unaccented String
|
||||
*/
|
||||
public static String deleteAccents(String text) {
|
||||
String nfdNormalizedString = Normalizer.normalize(text, Normalizer.Form.NFD);
|
||||
Pattern pattern = Pattern.compile("\\p{InCombiningDiacriticalMarks}+");
|
||||
text = pattern.matcher(nfdNormalizedString).replaceAll("");
|
||||
return text;
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
* Find index of search character in str.
|
||||
* This ignores content in () and 'texts'
|
||||
|
|
|
@ -84,4 +84,9 @@ public class MenuItem {
|
|||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return label != null ? label : super.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -313,7 +313,7 @@ public class MenuSearchController implements EventListener<Event>{
|
|||
}
|
||||
|
||||
public void search(String value) {
|
||||
listbox.setModel((ListModel)null);
|
||||
listbox.setModel((ListModel<?>)null);
|
||||
Events.echoEvent(ON_SEARCH_ECHO, layout, value);
|
||||
}
|
||||
|
||||
|
@ -349,20 +349,20 @@ public class MenuSearchController implements EventListener<Event>{
|
|||
private String compare;
|
||||
|
||||
private MenuListComparator(String compare) {
|
||||
this.compare = compare;
|
||||
this.compare = Util.deleteAccents(compare.toLowerCase().trim());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(MenuItem o1, MenuItem o2) {
|
||||
compare = compare.toLowerCase().trim();
|
||||
String label2 = Util.deleteAccents(o2.getLabel().toLowerCase());
|
||||
boolean match = false;
|
||||
if (compare.length() < 3)
|
||||
{
|
||||
match = o2.getLabel().toLowerCase().startsWith(compare);
|
||||
match = label2.startsWith(compare);
|
||||
}
|
||||
else
|
||||
{
|
||||
match = o2.getLabel().toLowerCase().contains(compare);
|
||||
match = label2.contains(compare);
|
||||
}
|
||||
return match ? 0 : -1;
|
||||
}
|
||||
|
|
|
@ -16,10 +16,8 @@
|
|||
*****************************************************************************/
|
||||
package org.adempiere.webui.apps.form;
|
||||
|
||||
import java.text.Normalizer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.logging.Level;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.adempiere.util.Callback;
|
||||
import org.adempiere.webui.LayoutUtils;
|
||||
|
@ -43,6 +41,7 @@ import org.compiere.model.MTreeNode;
|
|||
import org.compiere.util.Env;
|
||||
import org.compiere.util.KeyNamePair;
|
||||
import org.compiere.util.Msg;
|
||||
import org.compiere.util.Util;
|
||||
import org.zkoss.zk.ui.event.Event;
|
||||
import org.zkoss.zk.ui.event.EventListener;
|
||||
import org.zkoss.zk.ui.event.Events;
|
||||
|
@ -262,17 +261,10 @@ public class WTreeMaintenance extends TreeMaintenance implements IFormController
|
|||
|
||||
private void searchElement() {
|
||||
String filter = searchBox.getText() == null ? "" : searchBox.getText();
|
||||
filter = deleteAccents(filter.trim().toUpperCase());
|
||||
filter = Util.deleteAccents(filter.trim().toUpperCase());
|
||||
action_loadTree(filter);
|
||||
}
|
||||
|
||||
private String deleteAccents(String text) {
|
||||
String nfdNormalizedString = Normalizer.normalize(text, Normalizer.Form.NFD);
|
||||
Pattern pattern = Pattern.compile("\\p{InCombiningDiacriticalMarks}+");
|
||||
text = pattern.matcher(nfdNormalizedString).replaceAll("");
|
||||
return text;
|
||||
}
|
||||
|
||||
private void action_loadTree() {
|
||||
action_loadTree(null);
|
||||
}
|
||||
|
@ -304,9 +296,13 @@ public class WTreeMaintenance extends TreeMaintenance implements IFormController
|
|||
SimpleListModel model = new SimpleListModel();
|
||||
ArrayList<ListItem> items = getTreeItemData();
|
||||
for (ListItem item : items) {
|
||||
String valueItem = item.toString() == null ? "" : deleteAccents(item.toString().toUpperCase());
|
||||
if (filter == null || filter.length() == 0 || valueItem.contains(filter)) {
|
||||
if (Util.isEmpty(filter)) {
|
||||
model.addElement(item);
|
||||
} else {
|
||||
String valueItem = item.toString() == null ? "" : Util.deleteAccents(item.toString().toUpperCase());
|
||||
if (valueItem.contains(filter)) {
|
||||
model.addElement(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue