diff --git a/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopFilter.java b/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopFilter.java index 00978a8b98..4c596edc20 100644 --- a/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopFilter.java +++ b/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopFilter.java @@ -70,7 +70,7 @@ public class DesktopFilter extends DesktopAbstractComponent implements F setWidth("100%"); - delegate.addExpandedStateChangeListener(e -> fireExpandStateChange(e.isExpanded())); + delegate.setExpandedStateChangeListener(e -> fireExpandStateChange(e.isExpanded())); delegate.setCaptionChangedListener(this::updateCaption); } diff --git a/modules/gui/src/com/haulmont/cuba/gui/components/filter/FilterDelegate.java b/modules/gui/src/com/haulmont/cuba/gui/components/filter/FilterDelegate.java index 7857869476..d40bdc522f 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/components/filter/FilterDelegate.java +++ b/modules/gui/src/com/haulmont/cuba/gui/components/filter/FilterDelegate.java @@ -166,15 +166,7 @@ public interface FilterDelegate { } } - /** - * Listener to expanded state change events. - */ - interface FDExpandedStateChangeListener { - void expandedStateChanged(FDExpandedStateChangeEvent e); - } - - void addExpandedStateChangeListener(FDExpandedStateChangeListener listener); - void removeExpandedStateChangeListener(FDExpandedStateChangeListener listener); + void setExpandedStateChangeListener(Consumer listener); void setBorderVisible(boolean visible); boolean isBorderVisible(); diff --git a/modules/gui/src/com/haulmont/cuba/gui/components/filter/FilterDelegateImpl.java b/modules/gui/src/com/haulmont/cuba/gui/components/filter/FilterDelegateImpl.java index f82323b393..b6b70069ab 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/components/filter/FilterDelegateImpl.java +++ b/modules/gui/src/com/haulmont/cuba/gui/components/filter/FilterDelegateImpl.java @@ -36,11 +36,8 @@ import com.haulmont.cuba.core.entity.Entity; import com.haulmont.cuba.core.global.*; import com.haulmont.cuba.core.global.filter.*; import com.haulmont.cuba.core.global.queryconditions.JpqlCondition; -import com.haulmont.cuba.gui.ComponentsHelper; -import com.haulmont.cuba.gui.WindowManager; +import com.haulmont.cuba.gui.*; import com.haulmont.cuba.gui.WindowManager.OpenType; -import com.haulmont.cuba.gui.WindowManagerProvider; -import com.haulmont.cuba.gui.WindowParams; import com.haulmont.cuba.gui.components.*; import com.haulmont.cuba.gui.components.Action.Status; import com.haulmont.cuba.gui.components.Component.Alignment; @@ -149,7 +146,7 @@ public class FilterDelegateImpl implements FilterDelegate { protected List filterEntityChangeListeners = new ArrayList<>(); protected GroupBoxLayout groupBoxLayout; - protected BoxLayout layout; + protected GroupBoxLayout layout; // layout for all nested panels protected PopupButton filtersPopupButton; protected ComponentContainer conditionsLayout; protected BoxLayout maxResultsLayout; @@ -200,7 +197,7 @@ public class FilterDelegateImpl implements FilterDelegate { protected SaveAsFolderAction saveAsSearchFolderAction; protected LookupField filtersLookup; - protected List expandedStateChangeListeners; + protected Consumer expandedStateChangeListener; protected Filter.BeforeFilterAppliedHandler beforeFilterAppliedHandler; @@ -239,22 +236,28 @@ public class FilterDelegateImpl implements FilterDelegate { groupBoxLayout.addExpandedStateChangeListener(e -> fireExpandStateChange()); groupBoxLayout.setOrientation(GroupBoxLayout.Orientation.VERTICAL); groupBoxLayout.setWidth("100%"); - layout = componentsFactory.createComponent(VBoxLayout.class); - layout.setWidth("100%"); - groupBoxLayout.add(layout); - if (caption == null) + + layout = groupBoxLayout; + layout.setSpacing(true); + + if (caption == null) { setCaption(getMainMessage("filter.groupBoxCaption")); + } } else { Collection components = layout.getComponents(); for (Component component : components) { layout.remove(component); } } - layout.setSpacing(true); appliedFiltersLayout = componentsFactory.createComponent(VBoxLayout.class); - conditionsLayout = componentsFactory.createComponent(HBoxLayout.class); + if (AppConfig.getClientType() == ClientType.DESKTOP) { + conditionsLayout = componentsFactory.createComponent(HBoxLayout.class); + } else { + conditionsLayout = componentsFactory.createComponent(CssLayout.class); + } + conditionsLayout.setVisible(false); // initially hidden conditionsLayout.setWidth("100%"); conditionsLayout.setStyleName("filter-conditions"); @@ -2073,44 +2076,27 @@ public class FilterDelegateImpl implements FilterDelegate { } @Override - public void addExpandedStateChangeListener(FDExpandedStateChangeListener listener) { - if (expandedStateChangeListeners == null) { - expandedStateChangeListeners = new ArrayList<>(); - } - if (!expandedStateChangeListeners.contains(listener)) { - expandedStateChangeListeners.add(listener); - } - } - - @Override - public void removeExpandedStateChangeListener(FDExpandedStateChangeListener listener) { - if (expandedStateChangeListeners != null) { - expandedStateChangeListeners.remove(listener); - } + public void setExpandedStateChangeListener(Consumer listener) { + expandedStateChangeListener = listener; } protected void fireExpandStateChange() { - if (expandedStateChangeListeners != null) { + if (expandedStateChangeListener != null) { FDExpandedStateChangeEvent event = new FDExpandedStateChangeEvent(this, isExpanded()); - - for (FDExpandedStateChangeListener listener : expandedStateChangeListeners) { - listener.expandedStateChanged(event); - } + expandedStateChangeListener.accept(event); } } @Override public void setFilter(Filter filter) { this.filter = filter; - addConditionHelper = new AddConditionHelper(filter, new AddConditionHelper.Handler() { - @Override - public void handle(AbstractCondition condition) { - try { - addCondition(condition); - } catch (Exception e) { - conditions.removeCondition(condition); - throw e; - } + + addConditionHelper = new AddConditionHelper(filter, condition -> { + try { + addCondition(condition); + } catch (Exception e) { + conditions.removeCondition(condition); + throw e; } }); } diff --git a/modules/web/src/com/haulmont/cuba/web/gui/components/WebFilter.java b/modules/web/src/com/haulmont/cuba/web/gui/components/WebFilter.java index 7e123e0aaf..c9b9f50edc 100644 --- a/modules/web/src/com/haulmont/cuba/web/gui/components/WebFilter.java +++ b/modules/web/src/com/haulmont/cuba/web/gui/components/WebFilter.java @@ -18,26 +18,24 @@ package com.haulmont.cuba.web.gui.components; import com.haulmont.bali.events.Subscription; import com.haulmont.chile.core.model.MetaClass; -import com.haulmont.cuba.core.global.AppBeans; import com.haulmont.cuba.gui.components.*; import com.haulmont.cuba.gui.components.filter.FilterDelegate; import com.haulmont.cuba.gui.data.CollectionDatasource; import com.haulmont.cuba.gui.model.CollectionLoader; import com.haulmont.cuba.security.entity.FilterEntity; -import com.haulmont.cuba.web.widgets.CubaCssActionsLayout; import com.vaadin.server.Sizeable; -import com.vaadin.shared.ui.MarginInfo; import org.dom4j.Element; import org.slf4j.LoggerFactory; import javax.annotation.Nullable; +import javax.inject.Inject; import java.util.List; import java.util.function.Consumer; /** * Generic filter implementation for the web-client. */ -public class WebFilter extends WebAbstractComponent implements Filter, FilterImplementation { +public class WebFilter extends WebAbstractComponent implements Filter, FilterImplementation { protected static final String FILTER_STYLENAME = "c-generic-filter"; @@ -45,20 +43,23 @@ public class WebFilter extends WebAbstractComponent implem protected boolean settingsEnabled = true; protected PropertiesFilterPredicate propertiesFilterPredicate; - protected FilterDelegate.FDExpandedStateChangeListener fdExpandedStateChangeListener; public WebFilter() { - delegate = AppBeans.get(FilterDelegate.class); // todo use injection + } + + @Inject + protected void setDelegate(FilterDelegate delegate) { + this.delegate = delegate; + delegate.setFilter(this); - component = new CubaCssActionsLayout(); + ComponentContainer layout = delegate.getLayout(); - com.vaadin.ui.Component vLayout = layout.unwrapComposition(com.vaadin.ui.Component.class); - component.addComponent(vLayout); + component = layout.unwrapComposition(com.vaadin.ui.Component.class); component.setWidth(100, Sizeable.Unit.PERCENTAGE); - component.setPrimaryStyleName(FILTER_STYLENAME); + component.addStyleName(FILTER_STYLENAME); - delegate.addExpandedStateChangeListener(e -> fireExpandStateChange(e.isExpanded())); + delegate.setExpandedStateChangeListener(e -> fireExpandStateChange(e.isExpanded())); delegate.setCaptionChangedListener(this::updateCaptions); } @@ -171,16 +172,14 @@ public class WebFilter extends WebAbstractComponent implem @Override public void setMargin(com.haulmont.cuba.gui.components.MarginInfo marginInfo) { - MarginInfo vMargin = new MarginInfo(marginInfo.hasTop(), marginInfo.hasRight(), marginInfo.hasBottom(), - marginInfo.hasLeft()); - component.setMargin(vMargin); + HasOuterMargin layout = (HasOuterMargin) delegate.getLayout(); + layout.setOuterMargin(marginInfo); } @Override public com.haulmont.cuba.gui.components.MarginInfo getMargin() { - MarginInfo vMargin = component.getMargin(); - return new com.haulmont.cuba.gui.components.MarginInfo(vMargin.hasTop(), vMargin.hasRight(), vMargin.hasBottom(), - vMargin.hasLeft()); + HasOuterMargin layout = (HasOuterMargin) delegate.getLayout(); + return layout.getOuterMargin(); } @Override @@ -209,16 +208,6 @@ public class WebFilter extends WebAbstractComponent implem } } - @Override - public String getDescription() { - return null; // vaadin8 why ?? - } - - @Override - public void setDescription(String description) { - // vaadin8 why ?? - } - @Override public void setParamValue(String paramName, Object value) { delegate.setParamValue(paramName, value); @@ -271,15 +260,7 @@ public class WebFilter extends WebAbstractComponent implem @Override public Subscription addExpandedStateChangeListener(Consumer listener) { - if (fdExpandedStateChangeListener == null) { - fdExpandedStateChangeListener = e -> { - ExpandedStateChangeEvent event = new ExpandedStateChangeEvent(this, e.isExpanded()); - getEventHub().publish(ExpandedStateChangeEvent.class, event); - }; - delegate.addExpandedStateChangeListener(fdExpandedStateChangeListener); - } getEventHub().subscribe(ExpandedStateChangeEvent.class, listener); - return () -> removeExpandedStateChangeListener(listener); }