package to.etc.domui.component.searchpanel.lookupcontrols;

import to.etc.webapp.query.QCriteria;

import javax.annotation.DefaultNonNull;
import javax.annotation.Nullable;

import static java.util.Objects.requireNonNull;

/**
 * @author <a href="mailto:jal@etc.to">Frits Jalvingh</a>
 * Created on 6-12-17.
 */
@DefaultNonNull
final public class ObjectLookupQueryBuilder<D> implements ILookupQueryBuilder<D> {
	private final String m_propertyName;

	public ObjectLookupQueryBuilder(String propertyName) {
		m_propertyName = requireNonNull(propertyName);
	}

	@Override public <T> LookupQueryBuilderResult appendCriteria(QCriteria<T> criteria, @Nullable D value) {
		if(value == null || (value instanceof String && ((String) value).trim().length() == 0))
			return LookupQueryBuilderResult.EMPTY;			// Is okay but has no data

		// FIXME Handle minimal-size restrictions on input (search field metadata)
		//-- Put the value into the criteria..
		if(value instanceof String) {
			String str = (String) value;
			str = str.trim().replace("*", "%") + "%";			// FIXME Do not search with wildcard by default 8-(
			criteria.ilike(m_propertyName, str);
		} else {
			criteria.eq(m_propertyName, value);				// property == value
		}
		return LookupQueryBuilderResult.VALID;
	}
}

@@ -404,16 +404,84 @@
 er%3CD%3E %7B%0A
+%09static private volatile boolean m_lookupWildcardByDefault = true;%0A%0A
 %09private
@@ -1070,16 +1070,84 @@
  value;%0A
+%0A%09%09%09if(m_lookupWildcardByDefault) %7B%0A%09%09%09%09if(! str.endsWith(%22.%22)) %7B%0A%09%09
 %09%09%09str =
@@ -1182,19 +1182,28 @@
 ) + %22%25%22;
-%09%09%09
+            
 // FIXME
@@ -1246,16 +1246,27 @@
 ult 8-(%0A
+%09%09%09%09%7D%0A%09%09%09%7D%0A
 %09%09%09crite
@@ -1418,11 +1418,152 @@
 ALID;%0A%09%7D
+%0A%0A%09public static void setLookupWildcardByDefault(boolean lookupWildcardByDefault) %7B%0A%09%09m_lookupWildcardByDefault = lookupWildcardByDefault;%0A%09%7D
 %0A%7D%0A

Allow us to disable the automatic addition of % in a String search of SearchPanel.