In our project we extended FilterImpl
:
public class WpFilterImpl extends FilterImpl {
@Override
protected void initSelectConfigurationButton() {
var scrollBox = uiComponents.create(ScrollBoxLayout.class);
scrollBox.setWidthFull();
selectConfigurationButton.setPopupContent(scrollBox);
selectConfigurationButton.setPopupOpenDirection(PopupButton.PopupOpenDirection.BOTTOM_CENTER);
scrollBox.setHeight("35px");
selectConfigurationButton.setMenuWidth("300px");
scrollBox.add(createButton(createResetFilterAction()));
}
private Component createButton(Action action) {
var button = uiComponents.create(ButtonImpl.class);
button.setAction(action);
button.setStyleName(ThemeClassNames.BUTTON_BORDERLESS);
return button;
}
@Override
protected void addSelectConfigurationAction(Configuration configuration) {
Action configurationAction = new BaseAction("filter_select_" + configuration.getId())
.withCaption(getConfigurationCaption(configuration))
.withHandler(actionPerformedEvent -> {
setCurrentConfiguration(configuration);
apply();
});
((ScrollBoxLayout) selectConfigurationButton.getPopupContent()).add(createButton(configurationAction));
}
@Override
public void loadConfigurationsAndApplyDefault() {
super.loadConfigurationsAndApplyDefault();
setScrollBoxSize();
}
@Override
protected void updateSelectConfigurationButton() {
var scrollBox = ((ScrollBoxLayout) selectConfigurationButton.getPopupContent());
scrollBox.removeAll();
scrollBox.add(createButton(createResetFilterAction()));
for (Configuration configuration : getConfigurations()) {
addSelectConfigurationAction(configuration);
}
setScrollBoxSize();
}
private void setScrollBoxSize() {
var scrollBox = ((ScrollBoxLayout) selectConfigurationButton.getPopupContent());
var configurations = getConfigurations();
var size = (configurations.size() > 10 ? 10 : 1 + configurations.size()) * 35;
scrollBox.setHeight(size +"px");
}
}
@org.springframework.stereotype.Component
public class WpFilterSettingsBinderImpl extends FilterSettingsBinder {
@Override
public Class<? extends Component> getComponentClass() {
return WpFilterImpl.class;
}
}
@Bean
open fun wpFilter(): ComponentRegistration {
return ComponentRegistrationBuilder.create(Filter.NAME)
.withComponentClass(WpFilterImpl::class.java)
.build()
}