Search in sources :

Example 11 with Label

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

the class LabelDsTest method testDatasourceRepeatableAssign.

@Test
public void testDatasourceRepeatableAssign() {
    Label label = (Label) factory.createComponent(Label.NAME);
    label.setDatasource(null, null);
    label.setDatasource(null, null);
    Datasource<User> userDs1 = getTestUserDatasource();
    boolean exceptionWasThrown = false;
    try {
        label.setDatasource(userDs1, null);
    } catch (Exception ignored) {
        exceptionWasThrown = true;
    }
    assertTrue(exceptionWasThrown);
    exceptionWasThrown = false;
    try {
        label.setDatasource(null, "name");
    } catch (Exception ignored) {
        exceptionWasThrown = true;
    }
    assertTrue(exceptionWasThrown);
    label.setDatasource(userDs1, "name");
    label.setDatasource(userDs1, "name");
    userDs1.getItem().setName("Test name");
    label.setDatasource(userDs1, "name");
    Datasource<User> userDs2 = getTestUserDatasource();
    label.setDatasource(userDs2, "name");
    label.setValue("Another name");
    assertEquals("Test name", userDs1.getItem().getName());
}
Also used : User(com.haulmont.cuba.security.entity.User) Label(com.haulmont.cuba.gui.components.Label) Test(org.junit.Test)

Example 12 with Label

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

the class LabelDsTest method testUnsubscribeComponentListener.

@Test
public void testUnsubscribeComponentListener() {
    Label label = (Label) factory.createComponent(Label.NAME);
    Datasource<User> userDs = getTestUserDatasource();
    User user = userDs.getItem();
    user.setName("testName");
    label.setDatasource(userDs, "name");
    // unbind
    label.setDatasource(null, null);
    assertNotNull(label.getValue());
    Component.ValueChangeListener listener = e -> {
        throw new RuntimeException("Value was changed externally");
    };
    label.addValueChangeListener(listener);
    user.setName("anotherName");
    assertEquals("testName", label.getValue());
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) Ignore(org.junit.Ignore) Label(com.haulmont.cuba.gui.components.Label) Test(org.junit.Test) Assert(org.junit.Assert) Component(com.haulmont.cuba.gui.components.Component) User(com.haulmont.cuba.security.entity.User) User(com.haulmont.cuba.security.entity.User) Label(com.haulmont.cuba.gui.components.Label) Component(com.haulmont.cuba.gui.components.Component) Test(org.junit.Test)

Example 13 with Label

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

the class LabelDsTest method testUnsubscribeDsListener.

@Test
public void testUnsubscribeDsListener() {
    Label label = (Label) factory.createComponent(Label.NAME);
    Datasource<User> userDs = getTestUserDatasource();
    User user = userDs.getItem();
    user.setName("testName");
    label.setDatasource(userDs, "name");
    // unbind
    label.setDatasource(null, null);
    assertNotNull(label.getValue());
    Datasource.ItemPropertyChangeListener<User> propertyChangeListener = e -> {
        throw new RuntimeException("Value was changed externally");
    };
    userDs.addItemPropertyChangeListener(propertyChangeListener);
    label.setValue("anotherName");
    assertEquals("testName", user.getName());
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) Datasource(com.haulmont.cuba.gui.data.Datasource) Ignore(org.junit.Ignore) Label(com.haulmont.cuba.gui.components.Label) Test(org.junit.Test) Assert(org.junit.Assert) Component(com.haulmont.cuba.gui.components.Component) User(com.haulmont.cuba.security.entity.User) User(com.haulmont.cuba.security.entity.User) Label(com.haulmont.cuba.gui.components.Label) Test(org.junit.Test)

Example 14 with Label

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

the class LabelDsTest method testUnsubscribeSubscribeDsListener.

@Test
public void testUnsubscribeSubscribeDsListener() {
    Label label = (Label) factory.createComponent(Label.NAME);
    Datasource<User> userDs = getTestUserDatasource();
    User user = userDs.getItem();
    user.setName("testName");
    label.setDatasource(userDs, "name");
    label.setDatasource(null, null);
    label.setDatasource(userDs, "name");
    boolean[] valueWasChanged = { false };
    Datasource.ItemPropertyChangeListener<User> propertyChangeListener = e -> valueWasChanged[0] = true;
    userDs.addItemPropertyChangeListener(propertyChangeListener);
    label.setValue("anotherName");
    assertEquals(true, valueWasChanged[0]);
    assertEquals("anotherName", user.getName());
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) Datasource(com.haulmont.cuba.gui.data.Datasource) Ignore(org.junit.Ignore) Label(com.haulmont.cuba.gui.components.Label) Test(org.junit.Test) Assert(org.junit.Assert) Component(com.haulmont.cuba.gui.components.Component) User(com.haulmont.cuba.security.entity.User) User(com.haulmont.cuba.security.entity.User) Label(com.haulmont.cuba.gui.components.Label) Test(org.junit.Test)

Aggregations

Label (com.haulmont.cuba.gui.components.Label)14 User (com.haulmont.cuba.security.entity.User)6 Test (org.junit.Test)6 Component (com.haulmont.cuba.gui.components.Component)5 Datasource (com.haulmont.cuba.gui.data.Datasource)5 Assert (org.junit.Assert)5 Ignore (org.junit.Ignore)5 PermissionVariant (com.haulmont.cuba.gui.app.security.entity.PermissionVariant)2 AttributePermissionVariant (com.haulmont.cuba.gui.app.security.entity.AttributePermissionVariant)1 AttributeTarget (com.haulmont.cuba.gui.app.security.entity.AttributeTarget)1 UiPermissionVariant (com.haulmont.cuba.gui.app.security.entity.UiPermissionVariant)1 ComponentsFactory (com.haulmont.cuba.gui.xml.layout.ComponentsFactory)1