use of io.jmix.dashboards.model.Widget in project jmix by jmix-framework.
the class WidgetTemplateEdit method openWidgetEditor.
protected void openWidgetEditor(Widget widget) {
if (openWidgetEditor) {
screenBuilders.editor(Widget.class, this).withOpenMode(OpenMode.THIS_TAB).editEntity(widget).withParentDataContext(dataContext).build().show().addAfterCloseListener(e -> {
StandardCloseAction closeAction = (StandardCloseAction) e.getCloseAction();
if (COMMIT_ACTION_ID.equals(closeAction.getActionId())) {
WidgetTemplate widgetTemplate = widgetTemplateDc.getItem();
widgetTemplate.setWidgetModel(converter.widgetToJson(widget));
} else {
Widget prevWidget = converter.widgetFromJson(widgetTemplateDc.getItem().getWidgetModel());
openWidgetEditor = false;
setWidgetTypeComboBoxValue(prevWidget, widgetTypeComboBox);
openWidgetEditor = true;
}
});
}
}
use of io.jmix.dashboards.model.Widget in project jmix by jmix-framework.
the class WidgetTemplateEdit method onBeforeShow.
@Subscribe
protected void onBeforeShow(BeforeShowEvent event) {
form.add(generateWidgetTypeField(), 0, 2);
if (entityStates.isNew(getEditedEntity())) {
getEditedEntity().setCreatedBy(accessHelper.getCurrentUsername());
if (getEditedEntity().getWidgetModel() != null) {
widgetTypeComboBox.setEditable(false);
}
} else {
widgetTypeComboBox.setEditable(false);
}
if (StringUtils.isNotEmpty(getEditedEntity().getWidgetModel())) {
Widget widget = converter.widgetFromJson(getEditedEntity().getWidgetModel());
setWidgetTypeComboBoxValue(widget, widgetTypeComboBox);
}
if (!accessHelper.getCurrentUsername().equals(getEditedEntity().getCreatedBy())) {
isAvailableForAllUsersChkBox.setVisible(false);
}
openWidgetEditor = true;
}
use of io.jmix.dashboards.model.Widget 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.dashboards.model.Widget in project jmix by jmix-framework.
the class WidgetRepositoryImpl method initializeWidgetFields.
@Override
public void initializeWidgetFields(ScreenFragment widgetFragment, Widget widget) {
List<Parameter> widgetFieldValues = widget.getWidgetFields();
List<Field> parameterFields = FieldUtils.getFieldsListWithAnnotation(widgetFragment.getClass(), WidgetParam.class);
for (Field parameterField : parameterFields) {
Optional<Parameter> fieldValueOpt = widgetFieldValues.stream().filter(p -> p.getName().equals(parameterField.getName())).findFirst();
if (fieldValueOpt.isPresent()) {
Parameter p = fieldValueOpt.get();
Object rawValue = parameterTransformer.transform(p.getValue());
try {
FieldUtils.writeField(parameterField, widgetFragment, rawValue, true);
} catch (IllegalAccessException e) {
throw new RuntimeException(String.format("Error on widget field %s initialization", p.getAlias()), e);
}
}
}
}
use of io.jmix.dashboards.model.Widget in project jmix by jmix-framework.
the class DashboardImpl method assignItemSelectedHandler.
private void assignItemSelectedHandler(LookupWidget widget) {
ListComponent lookupComponent = widget.getLookupComponent();
DataUnit items = lookupComponent.getItems();
if (items != null) {
items.addStateChangeListener(e -> {
uiEventPublisher.publishEvent(new ItemsSelectedEvent((Widget) widget, lookupComponent.getSelected()));
});
}
}
Aggregations