use of com.haulmont.cuba.core.model.common.User in project jmix by jmix-framework.
the class LookupFieldDsTest method testUnsubscribeSubscribeComponentListener.
@Test
public void testUnsubscribeSubscribeComponentListener() {
LookupField lookupField = uiComponents.create(LookupField.class);
CollectionDatasource<Group, UUID> groupsDs = getTestCollectionDatasource();
lookupField.setOptionsDatasource(groupsDs);
Datasource<User> userDs = createTestDatasource(User.class);
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 };
Consumer<HasValue.ValueChangeEvent> listener = e -> valueWasChanged[0] = true;
// datasource before listener
lookupField.setDatasource(userDs, "group");
Subscription subscription = lookupField.addValueChangeListener(listener);
user.setGroup(metadata.create(Group.class));
assertTrue(valueWasChanged[0]);
// reset state
valueWasChanged[0] = false;
lookupField.setDatasource(null, null);
subscription.remove();
lookupField.setValue(null);
// listener before datasource
lookupField.addValueChangeListener(listener);
lookupField.setDatasource(userDs, "group");
assertTrue(valueWasChanged[0]);
}
use of com.haulmont.cuba.core.model.common.User in project jmix by jmix-framework.
the class LookupFieldDsTest method testUnsubscribeDsListener.
@Test
public void testUnsubscribeDsListener() {
LookupField lookupField = uiComponents.create(LookupField.class);
CollectionDatasource<Group, UUID> groupsDs = getTestCollectionDatasource();
lookupField.setOptionsDatasource(groupsDs);
Datasource<User> userDs = createTestDatasource(User.class);
Group group = groupsDs.getItems().iterator().next();
userDs.getItem().setGroup(group);
lookupField.setDatasource(userDs, "group");
// unbind
lookupField.setDatasource(null, null);
Datasource.ItemPropertyChangeListener<User> propertyChangeListener = e -> {
throw new RuntimeException("Value was changed externally");
};
userDs.addItemPropertyChangeListener(propertyChangeListener);
lookupField.setValue(metadata.create(Group.class));
}
use of com.haulmont.cuba.core.model.common.User in project jmix by jmix-framework.
the class LookupFieldDsTest method testUnsubscribeComponentListener.
@Test
public void testUnsubscribeComponentListener() {
LookupField lookupField = uiComponents.create(LookupField.class);
CollectionDatasource<Group, UUID> groupsDs = getTestCollectionDatasource();
lookupField.setOptionsDatasource(groupsDs);
Datasource<User> userDs = createTestDatasource(User.class);
Group group = groupsDs.getItems().iterator().next();
User user = userDs.getItem();
user.setGroup(group);
lookupField.setDatasource(userDs, "group");
// unbind
lookupField.setDatasource(null, null);
Consumer<HasValue.ValueChangeEvent> listener = e -> {
throw new RuntimeException("Value was changed externally");
};
lookupField.addValueChangeListener(listener);
user.setGroup(metadata.create(Group.class));
}
use of com.haulmont.cuba.core.model.common.User in project jmix by jmix-framework.
the class LookupFieldDsTest method testDatasourceRepeatableAssign.
@Test
public void testDatasourceRepeatableAssign() {
LookupField lookupField = uiComponents.create(LookupField.NAME);
lookupField.setDatasource(null, null);
lookupField.setDatasource(null, null);
Datasource<User> userDs1 = createTestDatasource(User.class);
boolean exceptionWasThrown = false;
/*try { todo web tests
lookupField.setDatasource(userDs1, null);
} catch (Exception e) {
exceptionWasThrown = true;
}
assertTrue(exceptionWasThrown);*/
exceptionWasThrown = false;
try {
lookupField.setDatasource(null, "name");
} catch (Exception e) {
exceptionWasThrown = true;
}
assertTrue(exceptionWasThrown);
lookupField.setDatasource(userDs1, "name");
lookupField.setDatasource(userDs1, "name");
userDs1.getItem().setName("Test name");
lookupField.setDatasource(userDs1, "name");
Datasource<User> userDs2 = createTestDatasource(User.class);
lookupField.setDatasource(userDs2, "name");
lookupField.setValue(null);
assertEquals("Test name", userDs1.getItem().getName());
}
use of com.haulmont.cuba.core.model.common.User in project jmix by jmix-framework.
the class LookupPickerFieldDsTest method testValueChangeListener.
@Test
public void testValueChangeListener() {
LookupPickerField component = uiComponents.create(LookupPickerField.NAME);
CollectionDatasource<Group, UUID> groupsDs = getTestCollectionDatasource();
component.setOptionsDatasource(groupsDs);
List<Group> groups = new ArrayList<>(groupsDs.getItems());
Datasource<User> userDs = createTestDatasource(User.class);
User user = userDs.getItem();
user.setGroup(groups.get(0));
// listener before datasource
boolean[] valueWasChanged = { false };
Consumer<HasValue.ValueChangeEvent> listener = e -> valueWasChanged[0] = true;
Subscription subscription = component.addValueChangeListener(listener);
component.setDatasource(userDs, "group");
assertTrue(valueWasChanged[0]);
// reset state
valueWasChanged[0] = false;
subscription.remove();
component.setDatasource(null, null);
// datasource before listener
component.setDatasource(userDs, "group");
component.addValueChangeListener(listener);
user.setGroup(null);
assertTrue(valueWasChanged[0]);
}
Aggregations