| package org.eclipse.osbp.runtime.web.vaadin.components.fields.filter2; |
| |
| import java.beans.PropertyChangeListener; |
| import java.beans.PropertyChangeSupport; |
| 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.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 org.eclipse.osbp.ui.api.themes.IThemeResourceService.ThemeResourceType; |
| |
| import com.vaadin.data.Container.Filter; |
| import com.vaadin.ui.Component; |
| import com.vaadin.ui.CustomComponent; |
| |
| @SuppressWarnings("serial") |
| public abstract class CompareComponent extends CustomComponent |
| implements ISingleFilterComponent, ILocaleChangedService.LocaleListener { |
| |
| protected II18nService i18nService; |
| protected IThemeResourceService themeResourceService; |
| |
| Component mainLayout; |
| |
| protected final String propertyId; |
| protected final IViewContext viewContext; |
| |
| // used for decimal fields |
| Class<? extends Number> type; |
| |
| public CompareComponent(String propertyId, IViewContext viewContext) { |
| this.propertyId = propertyId; |
| this.viewContext = viewContext; |
| } |
| |
| public CompareComponent(String propertyId, Class<? extends Number> 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); |
| |
| ILocaleChangedService service = viewContext.getService(ILocaleChangedService.class.getName()); |
| service.addLocaleListener(this); |
| |
| mainLayout = createMainLayout(); |
| mainLayout.setSizeFull(); |
| |
| setCompositionRoot(mainLayout); |
| } |
| |
| 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); |
| } |
| |
| public abstract static class AbstractCompareBean { |
| protected final PropertyChangeSupport changeSupport = new PropertyChangeSupport(this); |
| |
| public void addPropertyChangeListener(String property, PropertyChangeListener listener) { |
| changeSupport.addPropertyChangeListener(property, listener); |
| } |
| |
| private final String property; |
| |
| private String caption; |
| |
| public AbstractCompareBean(String property) { |
| this.property = property; |
| } |
| |
| public String getProperty() { |
| return property; |
| } |
| |
| public String getCaption() { |
| return caption; |
| } |
| |
| public void setCaption(String caption) { |
| changeSupport.firePropertyChange("caption", this.caption, this.caption = caption); |
| } |
| |
| } |
| } |