Search in sources :

Example 61 with Component

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

the class LookupPickerFieldTest method testValueChangeListener.

@Test
public void testValueChangeListener() {
    LookupPickerField component = create(LookupPickerField.class);
    final AtomicInteger counter = new AtomicInteger(0);
    // 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());
    final 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();
    groupsDs.includeItem(g1);
    Group g2 = new Group();
    groupsDs.includeItem(g2);
    component.setOptionsDatasource(groupsDs);
    Consumer<HasValue.ValueChangeEvent> listener1 = e -> {
        assertNull(e.getPrevValue());
        assertEquals(g2, e.getValue());
        counter.addAndGet(1);
    };
    Subscription subscription = component.addValueChangeListener(listener1);
    component.setValue(g2);
    subscription.remove();
    assertEquals(1, counter.get());
    Consumer<HasValue.ValueChangeEvent> listener2 = e -> {
        assertEquals(g2, e.getPrevValue());
        assertEquals(g, e.getValue());
        counter.addAndGet(1);
    };
    subscription = component.addValueChangeListener(listener2);
    component.setDatasource(testDs, "group");
    assertEquals(g, component.getValue());
    assertEquals(2, counter.get());
    subscription.remove();
    component.setValue(g1);
    assertEquals(g1, testDs.getItem().getGroup());
    assertEquals(2, counter.get());
    Consumer<HasValue.ValueChangeEvent> listener3 = e -> {
        assertEquals(g1, e.getPrevValue());
        assertEquals(g2, e.getValue());
        counter.addAndGet(1);
    };
    component.addValueChangeListener(listener3);
    testDs.getItem().setGroup(g2);
    assertEquals(g2, component.getValue());
    assertEquals(3, counter.get());
}
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) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) UUID(java.util.UUID) Subscription(io.jmix.core.common.event.Subscription) DsBuilder(com.haulmont.cuba.gui.data.DsBuilder) Test(org.junit.jupiter.api.Test)

Example 62 with Component

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

the class OptionsGroupTest method testNew.

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

Example 63 with Component

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

the class DateFieldTest method testNew.

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

Example 64 with Component

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

the class FieldGroupTest method newFieldGroup.

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

Example 65 with Component

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

the class CanvasUiComponentsFactory method createCanvasWidgetLayout.

@Override
public CanvasWidgetLayout createCanvasWidgetLayout(CanvasFragment canvasFragment, WidgetLayout widgetLayout) {
    Widget widget = widgetLayout.getWidget();
    Optional<WidgetTypeInfo> widgetTypeOpt = widgetRepository.getWidgetTypesInfo().stream().filter(widgetType -> StringUtils.equals(widget.getFragmentId(), widgetType.getFragmentId())).findFirst();
    if (!widgetTypeOpt.isPresent()) {
        CanvasWidgetLayout layout = components.create(CanvasWidgetLayout.class).init(widgetLayout);
        Label<String> label = components.create(Label.class);
        String message = messages.formatMessage(CanvasUiComponentsFactory.class, "widgetNotFound", widget.getCaption(), widget.getName());
        label.setValue(message);
        layout.addComponent(label);
        log.error(message);
        return layout;
    }
    widget.setDashboard(canvasFragment.getDashboardModel());
    String fragmentId = widgetTypeOpt.get().getFragmentId();
    Map<String, Object> params = new HashMap<>(ParamsMap.of(WIDGET, widget, DASHBOARD_MODEL, canvasFragment.getDashboardModel(), DASHBOARD, canvasFragment.getDashboard()));
    params.putAll(widgetRepository.getWidgetParams(widget));
    ScreenFragment screenFragment = AppUI.getCurrent().getFragments().create(canvasFragment, fragmentId, new MapScreenOptions(params)).init();
    Fragment fragment = screenFragment.getFragment();
    fragment.setSizeFull();
    Component widgetComponent = fragment;
    if (BooleanUtils.isTrue(widget.getShowWidgetCaption())) {
        VBoxLayout vBoxLayout = components.create(VBoxLayout.class);
        vBoxLayout.setSpacing(true);
        vBoxLayout.setMargin(true);
        vBoxLayout.setSizeFull();
        Label<String> label = components.create(Label.class);
        label.setValue(widget.getCaption());
        label.setStyleName("h2");
        vBoxLayout.add(label);
        vBoxLayout.add(fragment);
        vBoxLayout.expand(fragment);
        widgetComponent = vBoxLayout;
    } else {
        fragment.setMargin(true);
    }
    CanvasWidgetLayout layout = components.create(CanvasWidgetLayout.class).init(widgetLayout);
    layout.setUuid(UUID.randomUUID());
    layout.addComponent(widgetComponent);
    layout.setWidgetComponent(screenFragment);
    layout.setInnerLayout(widgetComponent);
    layout.setWidget(widget);
    layout.getDelegate().expand(widgetComponent);
    layout.setSizeFull();
    return layout;
}
Also used : ScreenFragment(io.jmix.ui.screen.ScreenFragment) Dashboard(io.jmix.dashboardsui.component.Dashboard) Fragment(io.jmix.ui.component.Fragment) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) ParamsMap(io.jmix.core.common.util.ParamsMap) BooleanUtils(org.apache.commons.lang3.BooleanUtils) HashMap(java.util.HashMap) Widget(io.jmix.dashboards.model.Widget) StringUtils(org.apache.commons.lang3.StringUtils) Messages(io.jmix.core.Messages) WidgetRepository(io.jmix.dashboardsui.repository.WidgetRepository) Component(io.jmix.ui.component.Component) CanvasComponentsFactory(io.jmix.dashboardsui.dashboard.tools.factory.CanvasComponentsFactory) UiComponents(io.jmix.ui.UiComponents) VBoxLayout(io.jmix.ui.component.VBoxLayout) Map(java.util.Map) MapScreenOptions(io.jmix.ui.screen.MapScreenOptions) Logger(org.slf4j.Logger) UUID(java.util.UUID) io.jmix.dashboards.model.visualmodel(io.jmix.dashboards.model.visualmodel) CanvasLayout(io.jmix.dashboardsui.component.CanvasLayout) Label(io.jmix.ui.component.Label) AppUI(io.jmix.ui.AppUI) Optional(java.util.Optional) io.jmix.dashboardsui.component.impl(io.jmix.dashboardsui.component.impl) CanvasFragment(io.jmix.dashboardsui.screen.dashboard.editor.canvas.CanvasFragment) WidgetTypeInfo(io.jmix.dashboardsui.repository.WidgetTypeInfo) VBoxLayout(io.jmix.ui.component.VBoxLayout) HashMap(java.util.HashMap) Widget(io.jmix.dashboards.model.Widget) WidgetTypeInfo(io.jmix.dashboardsui.repository.WidgetTypeInfo) ScreenFragment(io.jmix.ui.screen.ScreenFragment) Fragment(io.jmix.ui.component.Fragment) CanvasFragment(io.jmix.dashboardsui.screen.dashboard.editor.canvas.CanvasFragment) ScreenFragment(io.jmix.ui.screen.ScreenFragment) MapScreenOptions(io.jmix.ui.screen.MapScreenOptions) Component(io.jmix.ui.component.Component)

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