blob: 785a2b8bef550962dbb66ef442160c26d8917de0 [file] [log] [blame]
package org.eclipse.osbp.runtime.web.vaadin.components.fields.filter2;
import java.util.Locale;
import javax.annotation.PostConstruct;
import org.eclipse.osbp.ecview.core.common.context.ILocaleChangedService;
import org.eclipse.osbp.ecview.core.common.context.ILocaleChangedService.LocaleListener;
import org.eclipse.osbp.ecview.core.common.context.IViewContext;
import org.eclipse.osbp.runtime.common.i18n.II18nService;
import org.eclipse.osbp.ui.api.themes.EnumCssClass;
import org.eclipse.osbp.ui.api.themes.IThemeResourceService;
import com.vaadin.data.Container.Filter;
import com.vaadin.ui.Component;
import com.vaadin.ui.CustomComponent;
@SuppressWarnings("serial")
public abstract class BetweenComponent extends CustomComponent implements ISingleFilterComponent, LocaleListener {
protected final String propertyId;
protected final IViewContext viewContext;
Component mainLayout;
// used for decimal fields
protected Class<?> type;
protected II18nService i18nService;
protected IThemeResourceService themeResourceService;
public BetweenComponent(String propertyId, IViewContext viewContext) {
this.propertyId = propertyId;
this.viewContext = viewContext;
}
public BetweenComponent(String propertyId, Class<?> type, IViewContext viewContext) {
this.propertyId = propertyId;
this.type = type;
this.viewContext = viewContext;
}
@PostConstruct
public void init() {
setStyleName(EnumCssClass.BOX.styleName());
i18nService = viewContext.getService(II18nService.ID);
themeResourceService = viewContext.getService(IThemeResourceService.ID);
setLocale(viewContext.getLocale());
ILocaleChangedService service = viewContext.getService(ILocaleChangedService.class.getName());
service.addLocaleListener(this);
mainLayout = createMainLayout();
mainLayout.setSizeFull();
setCompositionRoot(mainLayout);
updateCaptions();
}
protected String getCaptionInternal() {
return Util.getCaption(i18nService, propertyId, propertyId, getLocale());
}
@Override
public void localeChanged(Locale locale) {
setLocale(locale);
updateCaptions();
}
protected abstract void updateCaptions();
protected abstract Component createMainLayout();
/**
* Returns a proper filter for this component.
*
* @return
*/
public abstract Filter getFilter();
public void dispose() {
ILocaleChangedService service = viewContext.getService(ILocaleChangedService.class.getName());
service.removeLocaleListener(this);
}
}