use of io.jmix.dashboardsui.repository.WidgetTypeInfo 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;
}
use of io.jmix.dashboardsui.repository.WidgetTypeInfo in project jmix by jmix-framework.
the class WidgetRepositoryImpl method initializeWidgets.
protected void initializeWidgets() {
widgetTypeInfos = new ArrayList<>();
for (WindowInfo windowInfo : windowConfig.getWindows()) {
if (StringUtils.isNotBlank(windowInfo.getTemplate())) {
Class clazz = windowInfo.getControllerClass();
if (clazz.isAnnotationPresent(DashboardWidget.class)) {
DashboardWidget widgetAnnotation = (DashboardWidget) clazz.getAnnotation(DashboardWidget.class);
String editFragmentId = widgetAnnotation.editFragmentId();
if (StringUtils.isNotBlank(editFragmentId) && !windowConfig.hasWindow(editFragmentId)) {
log.error("Unable to find {} edit screen in screen config for widget {}", editFragmentId, widgetAnnotation.name());
throw new IllegalArgumentException(String.format("Unable to find %s edit screen in screen config for widget %s", editFragmentId, widgetAnnotation.name()));
}
widgetTypeInfos.add(new WidgetTypeInfo(widgetAnnotation.name(), windowInfo.getId(), editFragmentId));
}
}
}
}
use of io.jmix.dashboardsui.repository.WidgetTypeInfo in project jmix by jmix-framework.
the class WidgetUtils method getWidgetCaptions.
public Map<String, String> getWidgetCaptions() {
Map<String, String> map = new HashMap<>();
List<WidgetTypeInfo> typesInfo = widgetRepository.getWidgetTypesInfo();
for (WidgetTypeInfo typeInfo : typesInfo) {
String browseFragmentId = typeInfo.getFragmentId();
String name = typeInfo.getName();
String property = format("dashboard-widget.%s", name);
String mainMessage = messages.getMessage(property);
String caption = mainMessage.equals(property) ? name : mainMessage;
map.put(caption, browseFragmentId);
}
return map;
}
use of io.jmix.dashboardsui.repository.WidgetTypeInfo in project jmix by jmix-framework.
the class WidgetEdit method setWidgetType.
protected void setWidgetType() {
String browseFragmentId = widgetDc.getItem().getFragmentId();
WidgetTypeInfo widgetType = typesInfo.stream().filter(typeInfo -> browseFragmentId.equals(typeInfo.getFragmentId())).findFirst().orElseThrow(() -> new RuntimeException("Unknown widget type"));
Map<String, Object> params = new HashMap<>(ParamsMap.of(ITEM_DC, widgetDc));
params.putAll(widgetRepository.getWidgetParams(widgetDc.getItem()));
if (StringUtils.isNotEmpty(widgetType.getEditFragmentId())) {
widgetEditFragment = fragments.create(this, widgetType.getEditFragmentId(), new MapScreenOptions(params)).init();
widgetEditBox.removeAll();
widgetEditBox.add(widgetEditFragment.getFragment());
}
}
Aggregations