Update: I decided to split into separate browse and edit screens Will try But decided not to delete this question. So this question doesn’t need replies for now
I want the following: There is Adress entity. It has name,latitude,longitude.
Name is full address. For example {name=“Калининград Улица петровская д11”,longitude=20.1,latitude=19.5}
I want to have such Browse screen. I saw on forum that you recomended customising lookup screen instead but I want this screen also to be available through menu. I have such layout
I want it to behave like this:
1)user opens the screen either chooses one from the bottom table or presses create but instead of openning Address$editor this screen just creates new Address entity and substitutes to top As far as I understand I’ll also have to override table’s create action…
2) User enter addres in userInput e.g. “Тверская 6” and clicks Найти адреса
3)Screen executes https://geocode-maps.yandex.ru/1.x/?geocode=Тверская+6. it gets map of points like
{
{"Россия,Москва,улица Тверская 6 ",{20.251,19.647}},
{"Россия,Москва,река Тверская 6 ",{21.251,18.647}},
}
Screen the assigns {"Россия,Москва,улица Тверская 6 ",{20.251,19.647}}, to 0
{"Россия,Москва,река Тверская 6 ",{21.251,18.647}} to 1
and does
Map<String, Integer> map = new LinkedHashMap<>();
map.put("Россия,Москва,улица Тверская 6", 0);
map.put("Россия,Москва,река Тверская 6", 1);
addresses.setOptionsMap(map);
where addresses is the dropdown.
4)User then for example chooses Россия,Москва,улица Тверская 6 from dropdown
5)Screen assignes latitude=20.251, longitude=9.647 to the currently edited Adress entity and sets name of that entity to Россия,Москва,улица Тверская 6
6)User clicks ok Selected Address entity is returned from the screen.
Currently I have
address-browse.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!--
~ Copyright (c) 2017 Haulmont Technology Ltd. All Rights Reserved.
~ Haulmont Technology proprietary and confidential.
~ Use is subject to license terms.
-->
<window xmlns="http://schemas.haulmont.com/cuba/window.xsd"
caption="msg://caption"
class="com.company.mapProject.web.address.AddressBrowse"
focusComponent="table"
lookupComponent="table"
messagesPack="com.company.mapProject.web.address">
<dsContext>
<groupDatasource id="addressesDs"
class="com.company.mapProject.entity.Address"
view="address-view">
<query>
<![CDATA[select e from mapProject$Address e]]>
</query>
</groupDatasource>
</dsContext>
<actions>
<action id="save"
caption="mainMsg://actions.Ok"
icon="icons/ok.png"
invoke="save"
shortcut="CTRL-ENTER"/>
<action id="cancel"
caption="mainMsg://actions.Cancel"
description="Esc"
icon="icons/cancel.png"
invoke="cancel"/>
</actions>
<dialogMode height="600"
width="800"/>
<layout>
<split id="split"
height="100%"
orientation="vertical"
reversePosition="true"
width="100%">
<vbox height="100%"
margin="false,false,false,true"
spacing="true">
<hbox expand="userInput"
width="100%">
<label value="msg://Введите адрес:"/>
<textField id="userInput"
datasource="addressesDs"
property="userInput"/>
<button id="findBtn"
caption="msg://Найти адрес"
invoke="onFindBtnClick"/>
</hbox>
<hbox expand="addresses"
width="100%">
<label description="msg://Выберите адрес:"
value="msg://Выберите адрес:"/>
<lookupField id="addresses"/>
</hbox>
<hbox expand="addressField"
width="100%">
<label value="msg://Выбранный адрес:"/>
<textField id="addressField"
datasource="addressesDs"
editable="false"
property="name"/>
</hbox>
<hbox id="actionsPane"
spacing="true"
visible="false">
<button id="saveBtn"
action="save"
invoke="onSaveBtnClick"/>
<button id="cancelBtn"
action="cancel"/>
</hbox>
</vbox>
<vbox id="lookupBox"
expand="table"
height="100%"
margin="false,true,false,false"
spacing="true">
<filter id="filter"
applyTo="table"
datasource="addressesDs">
<properties include=".*"/>
</filter>
<groupTable id="table"
width="100%">
<actions>
<action id="create"/>
<action id="edit"/>
<action id="remove"/>
</actions>
<columns>
<column id="name"/>
</columns>
<rows datasource="addressesDs"/>
<rowsCount/>
<buttonsPanel id="buttonsPanel"
alwaysVisible="true">
<button id="createBtn"
action="table.create"/>
<button id="editBtn"
action="table.edit"/>
<button id="removeBtn"
action="table.remove"/>
</buttonsPanel>
</groupTable>
</vbox>
</split>
</layout>
</window>
and
package com.company.mapProject.web.address;
import com.haulmont.cuba.gui.components.EntityCombinedScreen;
import com.haulmont.cuba.gui.components.LookupField;
import com.haulmont.cuba.gui.components.TextField;
import javax.inject.Inject;
import java.util.LinkedHashMap;
import java.util.Map;
public class AddressBrowse extends EntityCombinedScreen {
@Inject
private LookupField addresses;
@Inject
private TextField addressField;
public void onFindBtnClick() {
Map<String, Integer> map = new LinkedHashMap<>();
map.put("two", 2);
map.put("four", 4);
map.put("five", 5);
map.put("seven", 7);
addresses.setOptionsMap(map);
}
@Override
public void init(Map<String, Object> params) {
super.init(params);
addresses.addValueChangeListener(e -> {
addressField.setValue(addresses.getValue());
});
}
public void onSaveBtnClick() {
//
}
}
When the screen is invoked through menu item I get error (why?) in super.init() and so the screen doesn’t even open…
IllegalArgumentException: Not found component with id 'fieldGroup'
at com.haulmont.cuba.gui.components.Component$Container.getComponentNN(Component.java:263)
at com.haulmont.cuba.gui.components.EntityCombinedScreen.getFieldGroup(EntityCombinedScreen.java:72)
at com.haulmont.cuba.gui.components.EntityCombinedScreen.initBrowseItemChangeListener(EntityCombinedScreen.java:99)
at com.haulmont.cuba.gui.components.EntityCombinedScreen.init(EntityCombinedScreen.java:84)
at com.company.mapProject.web.address.AddressBrowse.init(AddressBrowse.java:31)
at com.haulmont.cuba.gui.WindowManager.init(WindowManager.java:1247)
....
How do I implement such business logic? I mean I need help with assigning properties to selected entity, commiting it to db if changed and returning selected entity from this combined screen. Which samples should I look at? I hope I’ll handle the rest.