Default text field formatter that trims text for web6 client && Trim text in fts search field #PL-4748

This commit is contained in:
Maxim Gorbunkov 2015-01-29 13:40:36 +00:00
parent 49181800b6
commit 03a0272841
3 changed files with 26 additions and 9 deletions

View File

@ -13,9 +13,7 @@ import com.haulmont.cuba.core.entity.Entity;
import com.haulmont.cuba.core.global.*;
import com.haulmont.cuba.gui.AppConfig;
import com.haulmont.cuba.gui.WindowManager;
import com.haulmont.cuba.gui.components.Action;
import com.haulmont.cuba.gui.components.IFrame;
import com.haulmont.cuba.gui.components.ShowInfoAction;
import com.haulmont.cuba.gui.components.*;
import com.haulmont.cuba.gui.components.Window;
import com.haulmont.cuba.gui.config.WindowConfig;
import com.haulmont.cuba.gui.config.WindowInfo;
@ -23,6 +21,7 @@ import com.haulmont.cuba.gui.dev.LayoutAnalyzer;
import com.haulmont.cuba.gui.dev.LayoutTip;
import com.haulmont.cuba.gui.theme.ThemeConstants;
import com.haulmont.cuba.gui.theme.ThemeConstantsRepository;
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory;
import com.haulmont.cuba.security.app.UserSessionService;
import com.haulmont.cuba.security.entity.User;
import com.haulmont.cuba.security.entity.UserSubstitution;
@ -31,6 +30,7 @@ import com.haulmont.cuba.web.actions.ChangeSubstUserAction;
import com.haulmont.cuba.web.actions.DoNotChangeSubstUserAction;
import com.haulmont.cuba.web.app.UserSettingsTools;
import com.haulmont.cuba.web.app.folders.FoldersPane;
import com.haulmont.cuba.web.gui.WebComponentsFactory;
import com.haulmont.cuba.web.gui.components.WebComponentsHelper;
import com.haulmont.cuba.web.sys.MenuBuilder;
import com.haulmont.cuba.web.sys.WindowBreadCrumbs;
@ -43,6 +43,11 @@ import com.vaadin.server.ExternalResource;
import com.vaadin.server.Page;
import com.vaadin.shared.ui.MarginInfo;
import com.vaadin.ui.*;
import com.vaadin.ui.Button;
import com.vaadin.ui.Component;
import com.vaadin.ui.Label;
import com.vaadin.ui.TabSheet;
import com.vaadin.ui.TextField;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -626,7 +631,9 @@ public class AppWindow extends UIView implements UserSubstitutionListener, CubaH
HorizontalLayout searchLayout = new HorizontalLayout();
searchLayout.setMargin(new MarginInfo(false, true, false, true));
final TextField searchField = new CubaTextField();
ComponentsFactory componentsFactory = AppBeans.get(ComponentsFactory.class);
com.haulmont.cuba.gui.components.TextField searchFieldComponent = componentsFactory.createComponent(com.haulmont.cuba.gui.components.TextField.class);
final TextField searchField = WebComponentsHelper.unwrap(searchFieldComponent);
ThemeConstants theme = app.getThemeConstants();
searchField.setWidth(theme.get("cuba.web.AppWindow.searchField.width"));

View File

@ -17,6 +17,7 @@ import com.haulmont.cuba.gui.components.ShowInfoAction;
import com.haulmont.cuba.gui.config.WindowConfig;
import com.haulmont.cuba.gui.config.WindowInfo;
import com.haulmont.cuba.gui.theme.ThemeConstantsRepository;
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory;
import com.haulmont.cuba.security.app.UserSessionService;
import com.haulmont.cuba.security.entity.User;
import com.haulmont.cuba.security.entity.UserSubstitution;
@ -26,6 +27,7 @@ import com.haulmont.cuba.web.actions.DoNotChangeSubstUserAction;
import com.haulmont.cuba.web.app.UserSettingsTools;
import com.haulmont.cuba.web.app.folders.FoldersPane;
import com.haulmont.cuba.web.gui.WebTimer;
import com.haulmont.cuba.web.gui.components.WebComponentsHelper;
import com.haulmont.cuba.web.gui.components.WebSplitPanel;
import com.haulmont.cuba.web.sys.MenuBuilder;
import com.haulmont.cuba.web.sys.WindowBreadCrumbs;
@ -572,7 +574,9 @@ public class AppWindow extends FocusHandlerWindow implements UserSubstitutionLis
HorizontalLayout searchLayout = new HorizontalLayout();
searchLayout.setMargin(false, true, false, true);
final TextField searchField = new com.haulmont.cuba.web.toolkit.ui.TextField();
ComponentsFactory componentsFactory = AppBeans.get(ComponentsFactory.class);
com.haulmont.cuba.gui.components.TextField searchFieldComponent = componentsFactory.createComponent(com.haulmont.cuba.gui.components.TextField.class);
final TextField searchField = WebComponentsHelper.unwrap(searchFieldComponent);
searchField.setWidth(120, Sizeable.UNITS_PIXELS);
searchField.setDebugId("ftsField." + (int) (Math.random() * 1000000));
if (app.isTestMode()) {

View File

@ -63,13 +63,16 @@ public abstract class WebAbstractTextField<T extends AbstractTextField>
@Override
public String format(Object value) {
Datatype datatype = getActualDatatype();
String formattedValue = null;
if (datatype != null) {
return datatype.format(value, locale);
formattedValue = datatype.format(value, locale);
} else if (value != null) {
return value.toString();
} else {
return null;
formattedValue = value.toString();
}
if (trimming) {
formattedValue = StringUtils.trim(formattedValue);
}
return formattedValue;
}
@Override
@ -125,6 +128,9 @@ public abstract class WebAbstractTextField<T extends AbstractTextField>
Object value = super.getValue();
Datatype datatype = getActualDatatype();
if (value instanceof String && datatype != null) {
if (trimming) {
value = StringUtils.trim((String) value);
}
value = Strings.emptyToNull((String) value);
try {
return (V) datatype.parse((String) value, locale);