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());
}
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);
}
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);
}
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);
}
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;
}
Aggregations