Search in sources :

Example 6 with LookupField

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]);
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) UUID(java.util.UUID) User(com.haulmont.cuba.security.entity.User) ArrayList(java.util.ArrayList) Group(com.haulmont.cuba.security.entity.Group) List(java.util.List) Ignore(org.junit.Ignore) LookupField(com.haulmont.cuba.gui.components.LookupField) Component(com.haulmont.cuba.gui.components.Component) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) Assert.assertEquals(org.junit.Assert.assertEquals) Group(com.haulmont.cuba.security.entity.Group) User(com.haulmont.cuba.security.entity.User) LookupField(com.haulmont.cuba.gui.components.LookupField) UUID(java.util.UUID) Component(com.haulmont.cuba.gui.components.Component) Test(org.junit.Test)

Example 7 with LookupField

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());
}
Also used : User(com.haulmont.cuba.security.entity.User) LookupField(com.haulmont.cuba.gui.components.LookupField) Test(org.junit.Test)

Example 8 with LookupField

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;
        }
    });
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) FieldGroup(com.haulmont.cuba.gui.components.FieldGroup) LookupField(com.haulmont.cuba.gui.components.LookupField) Component(com.haulmont.cuba.gui.components.Component) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 9 with LookupField

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());
}
Also used : Locale(java.util.Locale) GlobalConfig(com.haulmont.cuba.core.global.GlobalConfig) WebComponentRenderer(com.haulmont.cuba.web.gui.components.renderers.WebComponentRenderer) User(com.haulmont.cuba.security.entity.User) Inject(javax.inject.Inject) AbstractWindow(com.haulmont.cuba.gui.components.AbstractWindow) ComponentsFactory(com.haulmont.cuba.gui.xml.layout.ComponentsFactory) TreeMap(java.util.TreeMap) Configuration(com.haulmont.cuba.core.global.Configuration) Locale(java.util.Locale) Map(java.util.Map) LookupField(com.haulmont.cuba.gui.components.LookupField) DataGrid(com.haulmont.cuba.gui.components.DataGrid) Component(com.haulmont.cuba.gui.components.Component) User(com.haulmont.cuba.security.entity.User) GlobalConfig(com.haulmont.cuba.core.global.GlobalConfig) DataGrid(com.haulmont.cuba.gui.components.DataGrid) WebComponentRenderer(com.haulmont.cuba.web.gui.components.renderers.WebComponentRenderer) LookupField(com.haulmont.cuba.gui.components.LookupField) TreeMap(java.util.TreeMap) Component(com.haulmont.cuba.gui.components.Component) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 10 with LookupField

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;
}
Also used : LookupField(com.haulmont.cuba.gui.components.LookupField)

Aggregations

LookupField (com.haulmont.cuba.gui.components.LookupField)14 User (com.haulmont.cuba.security.entity.User)10 Component (com.haulmont.cuba.gui.components.Component)9 Datasource (com.haulmont.cuba.gui.data.Datasource)9 Test (org.junit.Test)9 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)8 Group (com.haulmont.cuba.security.entity.Group)7 ArrayList (java.util.ArrayList)7 List (java.util.List)7 UUID (java.util.UUID)7 Assert.assertEquals (org.junit.Assert.assertEquals)7 Assert.assertTrue (org.junit.Assert.assertTrue)7 Ignore (org.junit.Ignore)7 Map (java.util.Map)3 TreeMap (java.util.TreeMap)2 ParamsMap (com.haulmont.bali.util.ParamsMap)1 Configuration (com.haulmont.cuba.core.global.Configuration)1 GlobalConfig (com.haulmont.cuba.core.global.GlobalConfig)1 GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)1 AbstractWindow (com.haulmont.cuba.gui.components.AbstractWindow)1