use of com.haulmont.cuba.gui.components.TextField in project cuba by cuba-platform.
the class TextFieldDsTest method testUnsubscribeComponentListener.
@Test
public void testUnsubscribeComponentListener() {
TextField textField = (TextField) factory.createComponent(TextField.NAME);
Datasource<User> userDs = getTestUserDatasource();
User user = userDs.getItem();
user.setName("testName");
textField.setDatasource(userDs, "name");
// unbind
textField.setDatasource(null, null);
Component.ValueChangeListener listener = e -> {
throw new RuntimeException("Value was changed externally");
};
textField.addValueChangeListener(listener);
user.setName("anotherName");
}
use of com.haulmont.cuba.gui.components.TextField in project cuba by cuba-platform.
the class TextFieldDsTest method testUnsubscribeSubscribeComponentListener.
@Test
public void testUnsubscribeSubscribeComponentListener() {
TextField textField = (TextField) factory.createComponent(TextField.NAME);
Datasource<User> userDs = getTestUserDatasource();
User user = userDs.getItem();
user.setName("testName");
textField.setDatasource(userDs, "name");
// unbind
textField.setDatasource(null, null);
// setup
boolean[] valueWasChanged = { false };
Component.ValueChangeListener listener = e -> valueWasChanged[0] = true;
// datasource before listener
textField.setDatasource(userDs, "name");
textField.addValueChangeListener(listener);
user.setName("anotherName");
assertEquals(true, valueWasChanged[0]);
// reset state
textField.removeValueChangeListener(listener);
textField.setDatasource(null, null);
valueWasChanged[0] = false;
textField.setValue("testName");
// listener before datasource
textField.addValueChangeListener(listener);
textField.setDatasource(userDs, "name");
assertEquals(true, valueWasChanged[0]);
}
use of com.haulmont.cuba.gui.components.TextField in project cuba by cuba-platform.
the class TextFieldDsTest method testUnsubscribeSubscribeDsListener.
@Test
public void testUnsubscribeSubscribeDsListener() {
TextField textField = (TextField) factory.createComponent(TextField.NAME);
Datasource<User> userDs = getTestUserDatasource();
userDs.getItem().setName("testName");
textField.setDatasource(userDs, "name");
// unbind
textField.setDatasource(null, null);
// setup
boolean[] valueWasChanged = { false };
Datasource.ItemPropertyChangeListener<User> listener = e -> valueWasChanged[0] = true;
userDs.addItemPropertyChangeListener(listener);
textField.setDatasource(userDs, "name");
textField.setValue("anotherName");
assertEquals(true, valueWasChanged[0]);
}
use of com.haulmont.cuba.gui.components.TextField in project cuba by cuba-platform.
the class TextFieldDsTest method testUnsubscribeDsListener.
@Test
public void testUnsubscribeDsListener() {
TextField textField = (TextField) factory.createComponent(TextField.NAME);
Datasource<User> userDs = getTestUserDatasource();
userDs.getItem().setName("testName");
textField.setDatasource(userDs, "name");
// unbind
textField.setDatasource(null, null);
Datasource.ItemPropertyChangeListener<User> propertyChangeListener = e -> {
throw new RuntimeException("Value was changed externally");
};
userDs.addItemPropertyChangeListener(propertyChangeListener);
textField.setValue("anotherName");
}
use of com.haulmont.cuba.gui.components.TextField in project cuba by cuba-platform.
the class TextFieldDsTest method testValueChangeListener.
@Test
public void testValueChangeListener() {
TextField textField = (TextField) factory.createComponent(TextField.NAME);
Datasource<User> userDs = getTestUserDatasource();
userDs.getItem().setName("testName");
// listener before datasource
boolean[] valueWasChanged = { false };
Component.ValueChangeListener listener = e -> valueWasChanged[0] = true;
textField.addValueChangeListener(listener);
textField.setDatasource(userDs, "name");
assertEquals(true, valueWasChanged[0]);
// reset state
valueWasChanged[0] = false;
textField.removeValueChangeListener(listener);
textField.setDatasource(null, null);
// datasource before listener
textField.setDatasource(userDs, "name");
textField.addValueChangeListener(listener);
userDs.getItem().setName("anotherName");
assertEquals(true, valueWasChanged[0]);
}
Aggregations