Search in sources :

Example 1 with DatePicker

use of com.haulmont.cuba.gui.components.DatePicker in project cuba by cuba-platform.

the class DatePickerDsTest method testUnsubscribeDsListener.

@Test
public void testUnsubscribeDsListener() {
    DatePicker datePicker = (DatePicker) factory.createComponent(DatePicker.NAME);
    Datasource<User> userDs = getTestUserDatasource();
    User user = userDs.getItem();
    Date updateTs = new Date();
    user.setUpdateTs(updateTs);
    datePicker.setDatasource(userDs, "updateTs");
    // unbind
    datePicker.setDatasource(null, null);
    Datasource.ItemPropertyChangeListener<User> propertyChangeListener = e -> {
        throw new RuntimeException("Value was changed externally");
    };
    userDs.addItemPropertyChangeListener(propertyChangeListener);
    datePicker.setValue(new Date());
    assertEquals(updateTs, user.getUpdateTs());
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) DatePicker(com.haulmont.cuba.gui.components.DatePicker) Datasource(com.haulmont.cuba.gui.data.Datasource) Ignore(org.junit.Ignore) Date(java.util.Date) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Component(com.haulmont.cuba.gui.components.Component) User(com.haulmont.cuba.security.entity.User) Assert.assertEquals(org.junit.Assert.assertEquals) User(com.haulmont.cuba.security.entity.User) DatePicker(com.haulmont.cuba.gui.components.DatePicker) Date(java.util.Date) Test(org.junit.Test)

Example 2 with DatePicker

use of com.haulmont.cuba.gui.components.DatePicker in project cuba by cuba-platform.

the class DatePickerDsTest method testValueChangeListener.

@Test
public void testValueChangeListener() {
    DatePicker datePicker = (DatePicker) factory.createComponent(DatePicker.NAME);
    Datasource<User> userDs = getTestUserDatasource();
    User user = userDs.getItem();
    user.setUpdateTs(new Date());
    // listener before datasource
    Boolean[] valueWasChanged = { false };
    Component.ValueChangeListener listener = e -> valueWasChanged[0] = true;
    datePicker.addValueChangeListener(listener);
    datePicker.setDatasource(userDs, "updateTs");
    assertEquals(true, valueWasChanged[0]);
    // reset state
    datePicker.setDatasource(null, null);
    datePicker.removeValueChangeListener(listener);
    valueWasChanged[0] = false;
    // datasource before listener
    datePicker.setDatasource(userDs, "updateTs");
    datePicker.addValueChangeListener(listener);
    user.setUpdateTs(new Date());
    assertEquals(true, valueWasChanged[0]);
}
Also used : DatePicker(com.haulmont.cuba.gui.components.DatePicker) Datasource(com.haulmont.cuba.gui.data.Datasource) Ignore(org.junit.Ignore) Date(java.util.Date) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Component(com.haulmont.cuba.gui.components.Component) User(com.haulmont.cuba.security.entity.User) Assert.assertEquals(org.junit.Assert.assertEquals) User(com.haulmont.cuba.security.entity.User) DatePicker(com.haulmont.cuba.gui.components.DatePicker) Component(com.haulmont.cuba.gui.components.Component) Date(java.util.Date) Test(org.junit.Test)

Example 3 with DatePicker

use of com.haulmont.cuba.gui.components.DatePicker in project cuba by cuba-platform.

the class DatePickerDsTest method testUnsubscribeComponentListener.

@Test
public void testUnsubscribeComponentListener() {
    DatePicker datePicker = (DatePicker) factory.createComponent(DatePicker.NAME);
    Datasource<User> userDs = getTestUserDatasource();
    User user = userDs.getItem();
    Date updateTs = new Date();
    user.setUpdateTs(updateTs);
    datePicker.setDatasource(userDs, "updateTs");
    // unbind
    datePicker.setDatasource(null, null);
    Component.ValueChangeListener valueChangeListener = e -> {
        throw new RuntimeException("Value was changed externally");
    };
    datePicker.addValueChangeListener(valueChangeListener);
    user.setUpdateTs(new Date());
    assertEquals(updateTs, datePicker.getValue());
}
Also used : DatePicker(com.haulmont.cuba.gui.components.DatePicker) Datasource(com.haulmont.cuba.gui.data.Datasource) Ignore(org.junit.Ignore) Date(java.util.Date) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Component(com.haulmont.cuba.gui.components.Component) User(com.haulmont.cuba.security.entity.User) Assert.assertEquals(org.junit.Assert.assertEquals) User(com.haulmont.cuba.security.entity.User) DatePicker(com.haulmont.cuba.gui.components.DatePicker) Component(com.haulmont.cuba.gui.components.Component) Date(java.util.Date) Test(org.junit.Test)

Example 4 with DatePicker

use of com.haulmont.cuba.gui.components.DatePicker in project cuba by cuba-platform.

the class DatePickerDsTest method testUnsubscribeSubscribeComponentListener.

@Test
public void testUnsubscribeSubscribeComponentListener() {
    DatePicker datePicker = (DatePicker) factory.createComponent(DatePicker.NAME);
    Datasource<User> userDs = getTestUserDatasource();
    User user = userDs.getItem();
    Date updateTs = new Date();
    user.setUpdateTs(updateTs);
    datePicker.setDatasource(userDs, "updateTs");
    // unbind
    datePicker.setDatasource(null, null);
    // datasource before listener
    datePicker.setDatasource(userDs, "updateTs");
    assertEquals(updateTs, datePicker.getValue());
    boolean[] valueWasChanged = { false };
    Component.ValueChangeListener listener = e -> valueWasChanged[0] = true;
    datePicker.addValueChangeListener(listener);
    Date updateTs2 = new Date();
    user.setUpdateTs(updateTs2);
    assertEquals(true, valueWasChanged[0]);
    assertEquals(updateTs2, datePicker.getValue());
    // reset state
    datePicker.removeValueChangeListener(listener);
    datePicker.setDatasource(null, null);
    valueWasChanged[0] = false;
    datePicker.setValue(updateTs);
    // listener before datasource
    datePicker.addValueChangeListener(listener);
    datePicker.setDatasource(userDs, "updateTs");
    assertEquals(true, valueWasChanged[0]);
    assertEquals(updateTs2, datePicker.getValue());
}
Also used : DatePicker(com.haulmont.cuba.gui.components.DatePicker) Datasource(com.haulmont.cuba.gui.data.Datasource) Ignore(org.junit.Ignore) Date(java.util.Date) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Component(com.haulmont.cuba.gui.components.Component) User(com.haulmont.cuba.security.entity.User) Assert.assertEquals(org.junit.Assert.assertEquals) User(com.haulmont.cuba.security.entity.User) DatePicker(com.haulmont.cuba.gui.components.DatePicker) Component(com.haulmont.cuba.gui.components.Component) Date(java.util.Date) Test(org.junit.Test)

Example 5 with DatePicker

use of com.haulmont.cuba.gui.components.DatePicker in project cuba by cuba-platform.

the class DatePickerDsTest method testUnsubscribeSubscribeDsListener.

@Test
public void testUnsubscribeSubscribeDsListener() {
    DatePicker datePicker = (DatePicker) factory.createComponent(DatePicker.NAME);
    Datasource<User> userDs = getTestUserDatasource();
    User user = userDs.getItem();
    Date updateTs = new Date();
    user.setUpdateTs(updateTs);
    datePicker.setDatasource(userDs, "updateTs");
    // unbind
    datePicker.setDatasource(null, null);
    // setup
    boolean[] valueWasChanged = { false };
    Datasource.ItemPropertyChangeListener<User> listener = e -> valueWasChanged[0] = true;
    userDs.addItemPropertyChangeListener(listener);
    datePicker.setDatasource(userDs, "updateTs");
    Date updateTs2 = new Date();
    datePicker.setValue(updateTs2);
    assertEquals(true, valueWasChanged[0]);
    assertEquals(updateTs2, user.getUpdateTs());
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) DatePicker(com.haulmont.cuba.gui.components.DatePicker) Datasource(com.haulmont.cuba.gui.data.Datasource) Ignore(org.junit.Ignore) Date(java.util.Date) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Component(com.haulmont.cuba.gui.components.Component) User(com.haulmont.cuba.security.entity.User) Assert.assertEquals(org.junit.Assert.assertEquals) User(com.haulmont.cuba.security.entity.User) DatePicker(com.haulmont.cuba.gui.components.DatePicker) Date(java.util.Date) Test(org.junit.Test)

Aggregations

DatePicker (com.haulmont.cuba.gui.components.DatePicker)6 User (com.haulmont.cuba.security.entity.User)6 Date (java.util.Date)6 Test (org.junit.Test)6 Component (com.haulmont.cuba.gui.components.Component)5 Datasource (com.haulmont.cuba.gui.data.Datasource)5 Assert.assertEquals (org.junit.Assert.assertEquals)5 Assert.assertTrue (org.junit.Assert.assertTrue)5 Ignore (org.junit.Ignore)5