use of io.jmix.dashboards.model.Widget in project jmix by jmix-framework.
the class PaletteFragment method getSketchWidgets.
protected List<? extends Widget> getSketchWidgets() {
return widgetRepository.getWidgetTypesInfo().stream().map(type -> {
Widget widget = metadata.create(Widget.class);
widget.setName(type.getName());
widget.setFragmentId(type.getFragmentId());
widget.setDashboard(dashboardModel);
return widget;
}).sorted(Comparator.comparing(Widget::getName)).collect(Collectors.toList());
}
use of io.jmix.dashboards.model.Widget in project jmix by jmix-framework.
the class PaletteFragment method onCreateWidgetTemplate.
@EventListener
public void onCreateWidgetTemplate(CreateWidgetTemplateEvent event) {
Widget widget = event.getSource();
WidgetTemplate widgetTemplate = metadata.create(WidgetTemplate.class);
widgetTemplate.setWidgetModel(converter.widgetToJson(widget));
screenBuilders.editor(WidgetTemplate.class, this).newEntity(widgetTemplate).withContainer(widgetTemplatesDc).withOpenMode(OpenMode.DIALOG).build().show();
}
use of io.jmix.dashboards.model.Widget in project jmix by jmix-framework.
the class WidgetEdit method validateAdditionalRules.
@Override
protected void validateAdditionalRules(ValidationErrors errors) {
super.validateAdditionalRules(errors);
if (errors.isEmpty()) {
Widget widget = widgetDc.getItem();
if (widget.getDashboard() != null) {
List<Widget> dashboardWidgets = widget.getDashboard().getWidgets();
long cnt = dashboardWidgets.stream().filter(w -> !w.getId().equals(widget.getId()) && w.getWidgetId().equals(widget.getWidgetId())).count();
if (cnt > 0) {
errors.add(widgetId, messages.getMessage(WidgetEdit.class, "uniqueWidgetId"));
}
}
}
}
use of io.jmix.dashboards.model.Widget in project jmix by jmix-framework.
the class WidgetTemplateEdit method createEditWidgetButton.
private Button createEditWidgetButton() {
Button editWidgetButton = components.create(Button.class);
editWidgetButton.setWidth("100%");
editWidgetButton.setCaption(messages.getMessage(WidgetTemplateEdit.class, "customize"));
editWidgetButton.setIconFromSet(JmixIcon.GEAR);
editWidgetButton.setAction(new BaseAction("openWidgetEditor") {
@Override
public void actionPerform(Component component) {
WidgetTemplate widgetTemplate = widgetTemplateDc.getItem();
if (StringUtils.isNotEmpty(widgetTemplate.getWidgetModel())) {
Widget widget = converter.widgetFromJson(widgetTemplateDc.getItem().getWidgetModel());
widget = dataContext.merge(widget);
openWidgetEditor(widget);
}
}
});
return editWidgetButton;
}
use of io.jmix.dashboards.model.Widget in project jmix by jmix-framework.
the class DashboardLayoutManager method createWidgetLayout.
/**
* Creates a {@link WidgetLayout} with specified widget.
* @param widget widget
* @param fromTemplate specifies whether new layout is created from {@link WidgetTemplateLayout} or not
* @return created widget layout
*/
public WidgetLayout createWidgetLayout(Widget widget, boolean fromTemplate) {
WidgetLayout widgetLayout = metadata.create(WidgetLayout.class);
Widget newWidget;
if (fromTemplate) {
newWidget = metadataTools.copy(widget);
newWidget.setId(UUID.randomUUID());
} else {
newWidget = metadata.create(widget.getClass());
newWidget.setFragmentId(widget.getFragmentId());
newWidget.setName(widget.getName());
}
newWidget.setDashboard(widget.getDashboard());
widgetLayout.setWidget(newWidget);
return widgetLayout;
}
Aggregations