Search in sources :

Example 1 with WidgetTemplate

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

Example 2 with WidgetTemplate

use of io.jmix.dashboards.entity.WidgetTemplate in project jmix by jmix-framework.

the class PaletteFragment method updateWidgetTemplates.

protected void updateWidgetTemplates() {
    ddWidgetTemplateBox.removeAll();
    Collection<WidgetTemplate> templates = widgetTemplatesDc.getItems().stream().sorted(Comparator.comparing(WidgetTemplate::getName)).collect(Collectors.toList());
    for (WidgetTemplate wt : templates) {
        try {
            PaletteButton widgetBtn = factory.createWidgetTemplateButton(wt);
            ddWidgetTemplateBox.add(widgetBtn);
        } catch (Exception e) {
            log.error(String.format("Unable to create widget template %s <%s>. Cause: %s", wt.getName(), wt.getId(), e.getMessage()), e);
        }
    }
}
Also used : PaletteButton(io.jmix.dashboardsui.component.impl.PaletteButton) WidgetTemplate(io.jmix.dashboards.entity.WidgetTemplate)

Example 3 with WidgetTemplate

use of io.jmix.dashboards.entity.WidgetTemplate 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 4 with WidgetTemplate

use of io.jmix.dashboards.entity.WidgetTemplate 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)

Aggregations

WidgetTemplate (io.jmix.dashboards.entity.WidgetTemplate)4 Widget (io.jmix.dashboards.model.Widget)3 PaletteButton (io.jmix.dashboardsui.component.impl.PaletteButton)1 BaseAction (io.jmix.ui.action.BaseAction)1 EventListener (org.springframework.context.event.EventListener)1