Search in sources :

Example 11 with Widget

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());
}
Also used : Widget(io.jmix.dashboards.model.Widget)

Example 12 with Widget

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();
}
Also used : Widget(io.jmix.dashboards.model.Widget) WidgetTemplate(io.jmix.dashboards.entity.WidgetTemplate) EventListener(org.springframework.context.event.EventListener)

Example 13 with Widget

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"));
            }
        }
    }
}
Also used : AccessConstraintsHelper(io.jmix.dashboardsui.dashboard.tools.AccessConstraintsHelper) DataContext(io.jmix.ui.model.DataContext) ValidationErrors(io.jmix.ui.component.ValidationErrors) Autowired(org.springframework.beans.factory.annotation.Autowired) ParamsMap(io.jmix.core.common.util.ParamsMap) HashMap(java.util.HashMap) Widget(io.jmix.dashboards.model.Widget) StringUtils(org.apache.commons.lang3.StringUtils) Messages(io.jmix.core.Messages) Parameter(io.jmix.dashboards.model.parameter.Parameter) WidgetRepository(io.jmix.dashboardsui.repository.WidgetRepository) ParametersFragment(io.jmix.dashboardsui.screen.parameter.ParametersFragment) List(java.util.List) OrderedContainer(io.jmix.ui.component.OrderedContainer) InstanceContainer(io.jmix.ui.model.InstanceContainer) io.jmix.ui.screen(io.jmix.ui.screen) Map(java.util.Map) Fragments(io.jmix.ui.Fragments) Qualifier(org.springframework.beans.factory.annotation.Qualifier) TextField(io.jmix.ui.component.TextField) WidgetTypeInfo(io.jmix.dashboardsui.repository.WidgetTypeInfo) Widget(io.jmix.dashboards.model.Widget)

Example 14 with Widget

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;
}
Also used : WidgetTemplate(io.jmix.dashboards.entity.WidgetTemplate) Widget(io.jmix.dashboards.model.Widget) BaseAction(io.jmix.ui.action.BaseAction)

Example 15 with Widget

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;
}
Also used : Widget(io.jmix.dashboards.model.Widget)

Aggregations

Widget (io.jmix.dashboards.model.Widget)15 Messages (io.jmix.core.Messages)4 ParamsMap (io.jmix.core.common.util.ParamsMap)3 WidgetTemplate (io.jmix.dashboards.entity.WidgetTemplate)3 Parameter (io.jmix.dashboards.model.parameter.Parameter)3 WidgetRepository (io.jmix.dashboardsui.repository.WidgetRepository)3 WidgetTypeInfo (io.jmix.dashboardsui.repository.WidgetTypeInfo)3 ScreenFragment (io.jmix.ui.screen.ScreenFragment)3 StringUtils (org.apache.commons.lang3.StringUtils)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 Metadata (io.jmix.core.Metadata)2 CanvasLayout (io.jmix.dashboardsui.component.CanvasLayout)2 Dashboard (io.jmix.dashboardsui.component.Dashboard)2 PaletteButton (io.jmix.dashboardsui.component.impl.PaletteButton)2 AccessConstraintsHelper (io.jmix.dashboardsui.dashboard.tools.AccessConstraintsHelper)2 ItemsSelectedEvent (io.jmix.dashboardsui.event.ItemsSelectedEvent)2 CanvasFragment (io.jmix.dashboardsui.screen.dashboard.editor.canvas.CanvasFragment)2 ParameterTransformer (io.jmix.dashboardsui.transformation.ParameterTransformer)2 LookupWidget (io.jmix.dashboardsui.widget.LookupWidget)2 RefreshableWidget (io.jmix.dashboardsui.widget.RefreshableWidget)2