use of com.haulmont.cuba.gui.components.LookupField in project cuba by cuba-platform.
the class LookupFieldDsTest method testUnsubscribeSubscribeComponentListener.
@Test
public void testUnsubscribeSubscribeComponentListener() {
LookupField lookupField = factory.createComponent(LookupField.class);
CollectionDatasource<Group, UUID> groupsDs = getTestCollectionDatasource();
lookupField.setOptionsDatasource(groupsDs);
Datasource<User> userDs = getTestUserDatasource();
Group group = groupsDs.getItems().iterator().next();
User user = userDs.getItem();
user.setGroup(group);
lookupField.setDatasource(userDs, "group");
// unbind
lookupField.setDatasource(null, null);
// setup
boolean[] valueWasChanged = { false };
Component.ValueChangeListener listener = e -> valueWasChanged[0] = true;
// datasource before listener
lookupField.setDatasource(userDs, "group");
lookupField.addValueChangeListener(listener);
user.setGroup(metadata.create(Group.class));
assertEquals(true, valueWasChanged[0]);
// reset state
valueWasChanged[0] = false;
lookupField.setDatasource(null, null);
lookupField.removeValueChangeListener(listener);
lookupField.setValue(null);
// listener before datasource
lookupField.addValueChangeListener(listener);
lookupField.setDatasource(userDs, "group");
assertEquals(true, valueWasChanged[0]);
}
use of com.haulmont.cuba.gui.components.LookupField in project cuba by cuba-platform.
the class LookupFieldDsTest method testSetValueWithoutOptions.
@Test
public void testSetValueWithoutOptions() {
LookupField lookupField = (LookupField) factory.createComponent(LookupField.NAME);
// noinspection unchecked
Datasource<User> userDs = getTestUserDatasource();
User user = userDs.getItem();
user.setName("Test name");
lookupField.setDatasource(userDs, "name");
assertEquals("Test name", lookupField.getValue());
}
use of com.haulmont.cuba.gui.components.LookupField in project cuba by cuba-platform.
the class SessionAttributeEditor method init.
@Override
public void init(Map<String, Object> params) {
datasource = getDsContext().get("attribute");
FieldGroup fields = (FieldGroup) getComponent("fields");
FieldGroup.FieldConfig field = fields.getField("datatype");
fields.addCustomField(field, new FieldGroup.CustomFieldGenerator() {
@Override
public Component generateField(Datasource datasource, String propertyId) {
LookupField lookup = AppConfig.getFactory().createComponent(LookupField.class);
lookup.setDatasource(datasource, propertyId);
lookup.setRequiredMessage(getMessage("datatypeMsg"));
lookup.setRequired(true);
lookup.setPageLength(15);
Map<String, Object> options = new TreeMap<>();
String mainMessagePack = AppConfig.getMessagesPack();
for (String datatypeId : Datatypes.getIds()) {
options.put(messages.getMessage(mainMessagePack, "Datatype." + datatypeId), datatypeId);
}
lookup.setOptionsMap(options);
return lookup;
}
});
}
use of com.haulmont.cuba.gui.components.LookupField in project documentation by cuba-platform.
the class Users method init.
@Override
public void init(Map<String, Object> params) {
Map<String, Locale> locales = configuration.getConfig(GlobalConfig.class).getAvailableLocales();
Map<String, Object> options = new TreeMap<>();
for (Map.Entry<String, Locale> entry : locales.entrySet()) {
options.put(entry.getKey(), messages.getTools().localeToString(entry.getValue()));
}
DataGrid.Column column = usersGrid.addGeneratedColumn("language", new DataGrid.ColumnGenerator<User, Component>() {
@Override
public Component getValue(DataGrid.ColumnGeneratorEvent<User> event) {
LookupField component = componentsFactory.createComponent(LookupField.class);
component.setOptionsMap(options);
component.setWidth("100%");
User user = event.getItem();
component.setValue(user.getLanguage());
component.addValueChangeListener(e -> user.setLanguage((String) e.getValue()));
return component;
}
@Override
public Class<Component> getType() {
return Component.class;
}
});
column.setRenderer(new WebComponentRenderer());
}
use of com.haulmont.cuba.gui.components.LookupField in project cuba by cuba-platform.
the class MaxResultsFieldHelper method createMaxResultsLookupField.
public LookupField createMaxResultsLookupField() {
LookupField maxResultsLookupField = componentsFactory.createComponent(LookupField.class);
setUpMaxResultsLookupField(maxResultsLookupField);
return maxResultsLookupField;
}
Aggregations