Search in sources :

Example 6 with ScreenFragment

use of io.jmix.ui.screen.ScreenFragment in project jmix by jmix-framework.

the class FragmentComponentLoader method createComponent.

@Override
public void createComponent() {
    WindowInfo windowInfo = createWindowInfo(element);
    String fragmentId;
    if (element.attributeValue("id") != null) {
        fragmentId = element.attributeValue("id");
    } else {
        fragmentId = windowInfo.getId();
    }
    Timer.Sample createSample = Timer.start(getMeterRegistry());
    Fragment fragment = createComponentInternal();
    FragmentHelper fragmentHelper = getFragmentHelper();
    ScreenFragment controller = fragmentHelper.createController(windowInfo, fragment);
    // setup screen and controller
    ComponentLoaderContext parentContext = (ComponentLoaderContext) getContext();
    FrameOwner hostController = parentContext.getFrame().getFrameOwner();
    setHostController(controller, hostController);
    setWindowId(controller, windowInfo.getId());
    setFrame(controller, fragment);
    setupScreenContext(controller, new ScreenContextImpl(windowInfo, parentContext.getOptions(), getScreenContext(hostController)));
    setScreenData(controller, applicationContext.getBean(ScreenData.class));
    FragmentImplementation fragmentImpl = (FragmentImplementation) fragment;
    fragmentImpl.setFrameOwner(controller);
    fragmentImpl.setId(fragmentId);
    FragmentContextImpl frameContext = new FragmentContextImpl(fragment, innerContext);
    ((FrameImplementation) fragment).setContext(frameContext);
    if (windowInfo.getTemplate() != null) {
        String frameId = fragmentId;
        if (parentContext.getFullFrameId() != null) {
            frameId = parentContext.getFullFrameId() + "." + frameId;
        }
        innerContext = createInnerContext();
        innerContext.setCurrentFrameId(fragmentId);
        innerContext.setFullFrameId(frameId);
        innerContext.setFrame(fragment);
        innerContext.setParent(parentContext);
        innerContext.setProperties(loadProperties(element));
        LayoutLoader layoutLoader = getLayoutLoader(innerContext);
        ScreenXmlLoader screenXmlLoader = applicationContext.getBean(ScreenXmlLoader.class);
        Element rootElement = screenXmlLoader.load(windowInfo.getTemplate(), windowInfo.getId(), getComponentContext().getParams());
        innerContext.setMessageGroup(fragmentHelper.findMessageGroup(rootElement, windowInfo.getTemplate()));
        loadAdditionalData(rootElement);
        this.fragmentLoader = layoutLoader.createFragmentContent(fragment, rootElement);
    }
    createSample.stop(createScreenTimer(getMeterRegistry(), ScreenLifeCycle.CREATE, windowInfo.getId()));
    this.resultComponent = fragment;
}
Also used : FragmentImplementation(io.jmix.ui.component.impl.FragmentImplementation) Element(org.dom4j.Element) FrameImplementation(io.jmix.ui.component.impl.FrameImplementation) ScreenFragment(io.jmix.ui.screen.ScreenFragment) Fragment(io.jmix.ui.component.Fragment) WindowInfo(io.jmix.ui.WindowInfo) Timer(io.micrometer.core.instrument.Timer) UiMonitoring.createScreenTimer(io.jmix.ui.monitoring.UiMonitoring.createScreenTimer) ScreenFragment(io.jmix.ui.screen.ScreenFragment) FrameOwner(io.jmix.ui.screen.FrameOwner) ScreenData(io.jmix.ui.model.ScreenData)

Example 7 with ScreenFragment

use of io.jmix.ui.screen.ScreenFragment in project jmix by jmix-framework.

the class RuntimePropertiesFrameLoader method createComponent.

@Override
public void createComponent() {
    String src = element.attributeValue("src");
    String screenId = element.attributeValue("id");
    if (src == null) {
        src = DEFAULT_DESCRIPTOR;
    }
    String fragmentId = screenId != null ? screenId : src;
    FragmentHelper fragmentHelper = getFragmentHelper();
    FrameHelper frameHelper = getFrameHelper();
    WindowInfo windowInfo = frameHelper.createFakeWindowInfo(src, fragmentId);
    UiComponents uiComponents = applicationContext.getBean(UiComponents.class);
    Fragment fragment = uiComponents.create(Fragment.NAME);
    ScreenFragment controller = fragmentHelper.createController(windowInfo, fragment);
    // setup screen and controller
    ComponentLoaderContext parentContext = (ComponentLoaderContext) getContext();
    FrameOwner hostController = parentContext.getFrame().getFrameOwner();
    // setup screen and controller
    setHostController(controller, hostController);
    setWindowId(controller, windowInfo.getId());
    setFrame(controller, fragment);
    setScreenContext(controller, new ScreenContextImpl(windowInfo, parentContext.getOptions(), getScreenContext(hostController)));
    setScreenData(controller, applicationContext.getBean(ScreenData.class));
    FragmentImplementation fragmentImpl = (FragmentImplementation) fragment;
    fragmentImpl.setFrameOwner(controller);
    fragmentImpl.setId(fragmentId);
    FragmentContextImpl frameContext = new FragmentContextImpl(fragment, innerContext);
    ((FrameImplementation) fragment).setContext(frameContext);
    if (windowInfo.getTemplate() != null) {
        String frameId = fragmentId;
        if (parentContext.getFullFrameId() != null) {
            frameId = parentContext.getFullFrameId() + "." + frameId;
        }
        innerContext = new ComponentLoaderContext(getContext().getOptions());
        innerContext.setMessageGroup(fragmentHelper.getMessageGroup(windowInfo.getTemplate()));
        innerContext.setCurrentFrameId(fragmentId);
        innerContext.setFullFrameId(frameId);
        innerContext.setFrame(fragment);
        innerContext.setParent(parentContext);
        LayoutLoader layoutLoader = getLayoutLoader(innerContext);
        ScreenXmlLoader screenXmlLoader = applicationContext.getBean(ScreenXmlLoader.class);
        Element rootElement = screenXmlLoader.load(windowInfo.getTemplate(), windowInfo.getId(), getContext().getParams());
        String messagesPack = rootElement.attributeValue("messagesPack");
        if (messagesPack != null) {
            innerContext.setMessageGroup(messagesPack);
        }
        this.fragmentLoader = layoutLoader.createFragmentContent(fragment, rootElement);
    }
    this.resultComponent = fragment;
}
Also used : LayoutLoader(io.jmix.ui.xml.layout.loader.LayoutLoader) FrameHelper(com.haulmont.cuba.gui.sys.FrameHelper) UiComponents(com.haulmont.cuba.gui.UiComponents) FragmentImplementation(io.jmix.ui.component.impl.FragmentImplementation) Element(org.dom4j.Element) FragmentContextImpl(io.jmix.ui.sys.FragmentContextImpl) FrameImplementation(io.jmix.ui.component.impl.FrameImplementation) ScreenFragment(io.jmix.ui.screen.ScreenFragment) Fragment(io.jmix.ui.component.Fragment) WindowInfo(io.jmix.ui.WindowInfo) ScreenFragment(io.jmix.ui.screen.ScreenFragment) FrameOwner(io.jmix.ui.screen.FrameOwner) FragmentHelper(io.jmix.ui.sys.FragmentHelper) ScreenContextImpl(io.jmix.ui.sys.ScreenContextImpl) ScreenXmlLoader(io.jmix.ui.sys.ScreenXmlLoader) ScreenData(io.jmix.ui.model.ScreenData)

Example 8 with ScreenFragment

use of io.jmix.ui.screen.ScreenFragment in project jmix by jmix-framework.

the class CubaScreens method openFrame.

@Override
public Frame openFrame(Frame parentFrame, Component parent, @Nullable String id, WindowInfo windowInfo, Map<String, Object> params) {
    ScreenFragment screenFragment;
    Fragments fragments = ui.getFragments();
    if (params != null && !params.isEmpty()) {
        screenFragment = fragments.create(parentFrame.getFrameOwner(), windowInfo.getId(), new MapScreenOptions(params));
    } else {
        screenFragment = fragments.create(parentFrame.getFrameOwner(), windowInfo.getId());
    }
    if (id != null) {
        screenFragment.getFragment().setId(id);
    }
    fragments.init(screenFragment);
    if (parent instanceof ComponentContainer) {
        ComponentContainer container = (ComponentContainer) parent;
        for (Component c : container.getComponents()) {
            if (c instanceof Component.Disposable) {
                Component.Disposable disposable = (Component.Disposable) c;
                if (!disposable.isDisposed()) {
                    disposable.dispose();
                }
            }
            container.remove(c);
        }
        container.add(screenFragment.getFragment());
    }
    if (screenFragment instanceof LegacyFragmentAdapter) {
        return ((LegacyFragmentAdapter) screenFragment).getRealScreen();
    }
    return screenFragment instanceof Frame ? (Frame) screenFragment : new ScreenFragmentWrapper(screenFragment);
}
Also used : LegacyFrame(com.haulmont.cuba.gui.screen.compatibility.LegacyFrame) ScreenFragment(io.jmix.ui.screen.ScreenFragment) MapScreenOptions(io.jmix.ui.screen.MapScreenOptions) LegacyFragmentAdapter(com.haulmont.cuba.gui.components.compatibility.LegacyFragmentAdapter) ScreenFragmentWrapper(com.haulmont.cuba.gui.screen.compatibility.ScreenFragmentWrapper)

Example 9 with ScreenFragment

use of io.jmix.ui.screen.ScreenFragment 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 10 with ScreenFragment

use of io.jmix.ui.screen.ScreenFragment 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)

Aggregations

ScreenFragment (io.jmix.ui.screen.ScreenFragment)13 Component (io.jmix.ui.component.Component)5 FrameOwner (io.jmix.ui.screen.FrameOwner)5 Screen (io.jmix.ui.screen.Screen)5 Fragment (io.jmix.ui.component.Fragment)4 WindowInfo (io.jmix.ui.WindowInfo)3 Messages (io.jmix.core.Messages)2 Widget (io.jmix.dashboards.model.Widget)2 WidgetRepository (io.jmix.dashboardsui.repository.WidgetRepository)2 WidgetTypeInfo (io.jmix.dashboardsui.repository.WidgetTypeInfo)2 MapScreenOptions (io.jmix.ui.screen.MapScreenOptions)2 StringUtils (org.apache.commons.lang3.StringUtils)2 Element (org.dom4j.Element)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 UiComponents (com.haulmont.cuba.gui.UiComponents)1 LegacyFragmentAdapter (com.haulmont.cuba.gui.components.compatibility.LegacyFragmentAdapter)1 LegacyFrame (com.haulmont.cuba.gui.screen.compatibility.LegacyFrame)1 ScreenFragmentWrapper (com.haulmont.cuba.gui.screen.compatibility.ScreenFragmentWrapper)1