Search in sources :

Example 6 with Widget

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

Example 7 with Widget

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

Example 8 with Widget

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;
}
Also used : ScreenFragment(io.jmix.ui.screen.ScreenFragment) Dashboard(io.jmix.dashboardsui.component.Dashboard) Fragment(io.jmix.ui.component.Fragment) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) ParamsMap(io.jmix.core.common.util.ParamsMap) BooleanUtils(org.apache.commons.lang3.BooleanUtils) HashMap(java.util.HashMap) Widget(io.jmix.dashboards.model.Widget) StringUtils(org.apache.commons.lang3.StringUtils) Messages(io.jmix.core.Messages) WidgetRepository(io.jmix.dashboardsui.repository.WidgetRepository) Component(io.jmix.ui.component.Component) CanvasComponentsFactory(io.jmix.dashboardsui.dashboard.tools.factory.CanvasComponentsFactory) UiComponents(io.jmix.ui.UiComponents) VBoxLayout(io.jmix.ui.component.VBoxLayout) Map(java.util.Map) MapScreenOptions(io.jmix.ui.screen.MapScreenOptions) Logger(org.slf4j.Logger) UUID(java.util.UUID) io.jmix.dashboards.model.visualmodel(io.jmix.dashboards.model.visualmodel) CanvasLayout(io.jmix.dashboardsui.component.CanvasLayout) Label(io.jmix.ui.component.Label) AppUI(io.jmix.ui.AppUI) Optional(java.util.Optional) io.jmix.dashboardsui.component.impl(io.jmix.dashboardsui.component.impl) CanvasFragment(io.jmix.dashboardsui.screen.dashboard.editor.canvas.CanvasFragment) WidgetTypeInfo(io.jmix.dashboardsui.repository.WidgetTypeInfo) VBoxLayout(io.jmix.ui.component.VBoxLayout) HashMap(java.util.HashMap) Widget(io.jmix.dashboards.model.Widget) WidgetTypeInfo(io.jmix.dashboardsui.repository.WidgetTypeInfo) ScreenFragment(io.jmix.ui.screen.ScreenFragment) Fragment(io.jmix.ui.component.Fragment) CanvasFragment(io.jmix.dashboardsui.screen.dashboard.editor.canvas.CanvasFragment) ScreenFragment(io.jmix.ui.screen.ScreenFragment) MapScreenOptions(io.jmix.ui.screen.MapScreenOptions) Component(io.jmix.ui.component.Component)

Example 9 with Widget

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);
            }
        }
    }
}
Also used : ScreenFragment(io.jmix.ui.screen.ScreenFragment) DashboardWidget(io.jmix.dashboardsui.annotation.DashboardWidget) java.util(java.util) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Metadata(io.jmix.core.Metadata) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Field(java.lang.reflect.Field) Widget(io.jmix.dashboards.model.Widget) WidgetParam(io.jmix.dashboardsui.annotation.WidgetParam) StringUtils(org.apache.commons.lang3.StringUtils) Messages(io.jmix.core.Messages) ParameterTransformer(io.jmix.dashboardsui.transformation.ParameterTransformer) WindowConfig(io.jmix.ui.WindowConfig) Parameter(io.jmix.dashboards.model.parameter.Parameter) WidgetRepository(io.jmix.dashboardsui.repository.WidgetRepository) Component(org.springframework.stereotype.Component) WindowInfo(io.jmix.ui.WindowInfo) FieldUtils(org.apache.commons.lang3.reflect.FieldUtils) ParameterValue(io.jmix.dashboards.model.parameter.type.ParameterValue) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) WidgetTypeInfo(io.jmix.dashboardsui.repository.WidgetTypeInfo) Field(java.lang.reflect.Field) Parameter(io.jmix.dashboards.model.parameter.Parameter)

Example 10 with Widget

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()));
        });
    }
}
Also used : ItemsSelectedEvent(io.jmix.dashboardsui.event.ItemsSelectedEvent) DataUnit(io.jmix.ui.component.data.DataUnit) LookupWidget(io.jmix.dashboardsui.widget.LookupWidget) Widget(io.jmix.dashboards.model.Widget) RefreshableWidget(io.jmix.dashboardsui.widget.RefreshableWidget)

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