Search in sources :

Example 6 with Component

use of io.jmix.ui.component.Component in project jmix by jmix-framework.

the class LookupFieldTest method testValueLoadFromOptions.

@Test
public void testValueLoadFromOptions() {
    LookupField component = create(LookupField.class);
    // noinspection unchecked
    Datasource<User> testDs = new DsBuilder().setId("testDs").setJavaClass(User.class).setView(viewRepository.getFetchPlan(User.class, FetchPlan.LOCAL)).buildDatasource();
    testDs.setItem(new User());
    ((DatasourceImpl) testDs).valid();
    assertNull(component.getValue());
    Group g = new Group();
    testDs.getItem().setGroup(g);
    // noinspection unchecked
    CollectionDatasource<Group, UUID> groupsDs = new DsBuilder().setId("testDs").setJavaClass(Group.class).setView(viewRepository.getFetchPlan(Group.class, FetchPlan.LOCAL)).setRefreshMode(CollectionDatasource.RefreshMode.NEVER).setAllowCommit(false).buildCollectionDatasource();
    groupsDs.includeItem(g);
    Group g1 = new Group();
    g1.setId(g.getId());
    groupsDs.includeItem(g1);
    Group g2 = new Group();
    groupsDs.includeItem(g2);
    component.setOptionsDatasource(groupsDs);
    component.setDatasource(testDs, "group");
    assertSame(g, component.getValue(), "Value should be from value ds");
    component.setValue(g2);
    Consumer<HasValue.ValueChangeEvent> listener1 = e -> {
        assertEquals(g2, e.getPrevValue());
        assertEquals(g1, e.getValue());
    };
    component.addValueChangeListener(listener1);
    component.setValue(g);
}
Also used : Arrays(java.util.Arrays) Datasource(com.haulmont.cuba.gui.data.Datasource) Subscription(io.jmix.core.common.event.Subscription) DsBuilder(com.haulmont.cuba.gui.data.DsBuilder) FetchPlan(io.jmix.core.FetchPlan) UUID(java.util.UUID) Disabled(org.junit.jupiter.api.Disabled) Group(com.haulmont.cuba.core.model.common.Group) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) Component(io.jmix.ui.component.Component) HasValue(io.jmix.ui.component.HasValue) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DatasourceImpl(com.haulmont.cuba.gui.data.impl.DatasourceImpl) Assertions(org.junit.jupiter.api.Assertions) LookupField(com.haulmont.cuba.gui.components.LookupField) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) User(com.haulmont.cuba.core.model.common.User) Group(com.haulmont.cuba.core.model.common.Group) User(com.haulmont.cuba.core.model.common.User) DatasourceImpl(com.haulmont.cuba.gui.data.impl.DatasourceImpl) LookupField(com.haulmont.cuba.gui.components.LookupField) UUID(java.util.UUID) DsBuilder(com.haulmont.cuba.gui.data.DsBuilder) Test(org.junit.jupiter.api.Test)

Example 7 with Component

use of io.jmix.ui.component.Component in project jmix by jmix-framework.

the class LookupFieldTest method testNew.

@Test
public void testNew() {
    Component component = create(LookupField.NAME);
    assertNotNull(component);
    assertTrue(component instanceof LookupField);
}
Also used : LookupField(com.haulmont.cuba.gui.components.LookupField) Component(io.jmix.ui.component.Component) Test(org.junit.jupiter.api.Test)

Example 8 with Component

use of io.jmix.ui.component.Component in project jmix by jmix-framework.

the class LookupPickerFieldTest method testNew.

@Test
public void testNew() {
    Component component = create(LookupPickerField.NAME);
    assertNotNull(component);
    assertTrue(component instanceof LookupPickerField);
}
Also used : LookupPickerField(com.haulmont.cuba.gui.components.LookupPickerField) Component(io.jmix.ui.component.Component) Test(org.junit.jupiter.api.Test)

Example 9 with Component

use of io.jmix.ui.component.Component in project jmix by jmix-framework.

the class LookupPickerFieldTest method testValueLoadFromOptions.

@Test
public void testValueLoadFromOptions() {
    LookupPickerField component = create(LookupPickerField.class);
    // noinspection unchecked
    Datasource<User> testDs = new DsBuilder().setId("testDs").setJavaClass(User.class).setView(viewRepository.getFetchPlan(User.class, FetchPlan.LOCAL)).buildDatasource();
    testDs.setItem(new User());
    ((DatasourceImpl) testDs).valid();
    assertNull(component.getValue());
    Group g = new Group();
    testDs.getItem().setGroup(g);
    // noinspection unchecked
    CollectionDatasource<Group, UUID> groupsDs = new DsBuilder().setId("testDs").setJavaClass(Group.class).setView(viewRepository.getFetchPlan(Group.class, FetchPlan.LOCAL)).setRefreshMode(CollectionDatasource.RefreshMode.NEVER).setAllowCommit(false).buildCollectionDatasource();
    groupsDs.includeItem(g);
    Group g1 = new Group();
    g1.setId(g.getId());
    groupsDs.includeItem(g1);
    Group g2 = new Group();
    groupsDs.includeItem(g2);
    component.setOptionsDatasource(groupsDs);
    component.setDatasource(testDs, "group");
    assertSame(g, component.getValue(), "Value should be from options ds");
    component.setValue(g2);
    Consumer<HasValue.ValueChangeEvent> listener1 = e -> {
        assertEquals(g2, e.getPrevValue());
        assertEquals(g1, e.getValue());
    };
    component.addValueChangeListener(listener1);
    component.setValue(g);
}
Also used : Arrays(java.util.Arrays) Datasource(com.haulmont.cuba.gui.data.Datasource) LookupPickerField(com.haulmont.cuba.gui.components.LookupPickerField) Subscription(io.jmix.core.common.event.Subscription) DsBuilder(com.haulmont.cuba.gui.data.DsBuilder) FetchPlan(io.jmix.core.FetchPlan) UUID(java.util.UUID) Disabled(org.junit.jupiter.api.Disabled) Group(com.haulmont.cuba.core.model.common.Group) Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) Component(io.jmix.ui.component.Component) HasValue(io.jmix.ui.component.HasValue) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DatasourceImpl(com.haulmont.cuba.gui.data.impl.DatasourceImpl) Assertions(org.junit.jupiter.api.Assertions) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) User(com.haulmont.cuba.core.model.common.User) LookupPickerField(com.haulmont.cuba.gui.components.LookupPickerField) Group(com.haulmont.cuba.core.model.common.Group) User(com.haulmont.cuba.core.model.common.User) DatasourceImpl(com.haulmont.cuba.gui.data.impl.DatasourceImpl) UUID(java.util.UUID) DsBuilder(com.haulmont.cuba.gui.data.DsBuilder) Test(org.junit.jupiter.api.Test)

Example 10 with Component

use of io.jmix.ui.component.Component in project jmix by jmix-framework.

the class OptionsGroupTest method testValueChangeListener.

@Test
public void testValueChangeListener() {
    OptionsGroup component = create(OptionsGroup.class);
    final AtomicInteger counter = new AtomicInteger(0);
    assertNull(component.getValue());
    Consumer<HasValue.ValueChangeEvent> listener1 = e -> {
        assertNull(e.getPrevValue());
        assertEquals("Two", e.getValue());
        counter.addAndGet(1);
    };
    Subscription subscription = component.addValueChangeListener(listener1);
    component.setOptionsList(new ArrayList<>(Arrays.asList("One", "Two", "Three")));
    component.setValue("Two");
    subscription.remove();
    assertEquals(1, counter.get());
    Consumer<HasValue.ValueChangeEvent> listener2 = e -> {
        assertEquals("Two", e.getPrevValue());
        assertEquals("One", e.getValue());
        counter.addAndGet(1);
    };
    subscription = component.addValueChangeListener(listener2);
    component.setValue("One");
    assertEquals("One", component.getValue());
    assertEquals(2, counter.get());
    subscription.remove();
    Consumer<HasValue.ValueChangeEvent> listener3 = e -> {
        assertEquals("One", e.getPrevValue());
        assertEquals("Three", e.getValue());
        counter.addAndGet(1);
    };
    component.addValueChangeListener(listener3);
    component.setValue("Three");
    assertEquals(3, counter.get());
}
Also used : OptionsGroup(com.haulmont.cuba.gui.components.OptionsGroup) Arrays(java.util.Arrays) Datasource(com.haulmont.cuba.gui.data.Datasource) Subscription(io.jmix.core.common.event.Subscription) DsBuilder(com.haulmont.cuba.gui.data.DsBuilder) FetchPlan(io.jmix.core.FetchPlan) UUID(java.util.UUID) Disabled(org.junit.jupiter.api.Disabled) Group(com.haulmont.cuba.core.model.common.Group) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) Component(io.jmix.ui.component.Component) HasValue(io.jmix.ui.component.HasValue) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DatasourceImpl(com.haulmont.cuba.gui.data.impl.DatasourceImpl) Assertions(org.junit.jupiter.api.Assertions) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) User(com.haulmont.cuba.core.model.common.User) OptionsGroup(com.haulmont.cuba.gui.components.OptionsGroup) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Subscription(io.jmix.core.common.event.Subscription) Test(org.junit.jupiter.api.Test)

Aggregations

Component (io.jmix.ui.component.Component)81 GuiDevelopmentException (io.jmix.ui.GuiDevelopmentException)16 Datasource (com.haulmont.cuba.gui.data.Datasource)12 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)11 Test (org.junit.jupiter.api.Test)11 Element (org.dom4j.Element)10 Consumer (java.util.function.Consumer)9 ListComponent (com.haulmont.cuba.gui.components.ListComponent)8 MetaClass (io.jmix.core.metamodel.model.MetaClass)7 Action (io.jmix.ui.action.Action)7 HasValue (io.jmix.ui.component.HasValue)7 FrameOwner (io.jmix.ui.screen.FrameOwner)7 ArrayList (java.util.ArrayList)7 DatasourceImpl (com.haulmont.cuba.gui.data.impl.DatasourceImpl)6 FetchPlan (io.jmix.core.FetchPlan)6 UUID (java.util.UUID)6 Nullable (javax.annotation.Nullable)6 User (com.haulmont.cuba.core.model.common.User)5 DsBuilder (com.haulmont.cuba.gui.data.DsBuilder)5 Entity (io.jmix.core.Entity)5