Разбираюсь, как создавать компоненты на этом примере.
Хочу в этом же примере в поле выбора городов прикрутить кнопку, которая вызывает dialogWindows (CityesListView). DialogWindows.view требует в параметрах контекст View<?>.
Подскажите как его получить?
Код:
Спойлер
“”"
public class AddressComponent extends Composite {
protected final Actions actions;
protected final DialogWindows dialogWindows;
protected final DataManager dataManager;
private final CollectionContainer<Country> countriesContainer;
private final CollectionContainer<City> citiesContainer;
private final TypedTextField<String> zipField;
private final EntityComboBox<Country> countryEntityComboBox;
private final EntityComboBox<City> cityEntityComboBox;
private final TypedTextField<String> addressLine;
@SuppressWarnings({"unchecked"})
public AddressComponent(UiComponents uiComponents, DataComponents dataComponents, DataManager dataManager, Actions actions, DialogWindows dialogWindows) {
this.dataManager = dataManager;
this.actions = actions;
this.dialogWindows = dialogWindows;
zipField = uiComponents.create(TypedTextField.class);
zipField.setMaxLength(32);
zipField.setLabel("Почтовый индекс");
countryEntityComboBox = uiComponents.create(EntityComboBox.class);
countryEntityComboBox.setLabel("Страна");
cityEntityComboBox = uiComponents.create(EntityComboBox.class);
cityEntityComboBox.setLabel("Город");
cityEntityComboBox.addAction(createEntityLookupAction());
cityEntityComboBox.addAction(createEntityClearAction());
addressLine = uiComponents.create(TypedTextField.class);
addressLine.setLabel("Адрес");
countriesContainer = dataComponents.createCollectionContainer(Country.class);
countriesContainer.addItemChangeListener(countryItemChangeEvent -> loadCities());
countryEntityComboBox.setItems(countriesContainer);
countryEntityComboBox.addAction(createEntityLookupAction());
countryEntityComboBox.addAction(createEntityClearAction());
citiesContainer = dataComponents.createCollectionContainer(City.class);
cityEntityComboBox.setItems(citiesContainer);
cityEntityComboBox.addAction(createEntityLookupAction());
cityEntityComboBox.addAction(createEntityClearAction());
}
protected Action createEntityClearAction() {
//entityClearAction.setIcon(VaadinIcon.BAN.create());
return actions.create(EntityClearAction.ID);
}
protected Action createEntityLookupAction() {
return new BaseAction("showCityes")
.withIcon(VaadinIcon.ACADEMY_CAP)
.withHandler(actionPerformedEvent -> {
Country country = countryEntityComboBox.getValue();
if (country != null) {
/* Как получить view?
dialogWindows.view(view, ContactListView.class)
.withAfterCloseListener(afterCloseEvent -> {
//if (afterCloseEvent.closedWith(StandardOutcome.SAVE)) {
// appSettingsDl.load();
// }
})
.open();
*/
} else {
}
});
}
private void loadCountries() {
List<Country> countries = dataManager.load(Country.class).all().sort(Sort.by("name")).list();
countriesContainer.setItems(countries);
}
private void loadCities() {
List<City> cities = dataManager.load(City.class)
.query("e.country = ?1", countriesContainer.getItemOrNull())
.list();
citiesContainer.setItems(cities);
}
@Override
protected FormLayout initContent() {
FormLayout content = super.initContent();
content.add(zipField, countryEntityComboBox, cityEntityComboBox, addressLine);
return content;
}
public void setDataContainer(InstanceContainer<Address> instanceContainer) {
zipField.setValueSource(new ContainerValueSource<>(instanceContainer, "zipcode"));
addressLine.setValueSource(new ContainerValueSource<>(instanceContainer, "street"));
countryEntityComboBox.setValueSource(new ContainerValueSource<>(instanceContainer, "country"));
cityEntityComboBox.setValueSource(new ContainerValueSource<>(instanceContainer, "city"));
loadCountries();
loadCities();
}
}
“”"