Search in sources :

Example 21 with FrameOwner

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

the class FormLoader method loadDataContainer.

protected void loadDataContainer(Form resultComponent, Element element) {
    String containerId = element.attributeValue("dataContainer");
    if (!Strings.isNullOrEmpty(containerId)) {
        FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
        ScreenData screenData = UiControllerUtils.getScreenData(frameOwner);
        InstanceContainer container = screenData.getContainer(containerId);
        // noinspection unchecked
        resultComponent.setValueSourceProvider(new ContainerValueSourceProvider(container));
    }
}
Also used : ContainerValueSourceProvider(io.jmix.ui.component.data.value.ContainerValueSourceProvider) FrameOwner(io.jmix.ui.screen.FrameOwner) InstanceContainer(io.jmix.ui.model.InstanceContainer) ScreenData(io.jmix.ui.model.ScreenData)

Example 22 with FrameOwner

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

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

the class CalendarLoader method loadDataContainer.

@SuppressWarnings("unchecked")
protected void loadDataContainer(Calendar component, Element element) {
    String containerId = element.attributeValue("dataContainer");
    if (Strings.isNullOrEmpty(containerId)) {
        return;
    }
    FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
    ScreenData screenData = UiControllerUtils.getScreenData(frameOwner);
    InstanceContainer container = screenData.getContainer(containerId);
    if (!(container instanceof CollectionContainer)) {
        throw new GuiDevelopmentException("Not a CollectionContainer: " + containerId, context);
    }
    component.setEventProvider(new ContainerCalendarEventProvider<>(((CollectionContainer) container)));
}
Also used : FrameOwner(io.jmix.ui.screen.FrameOwner) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) InstanceContainer(io.jmix.ui.model.InstanceContainer) CollectionContainer(io.jmix.ui.model.CollectionContainer) ScreenData(io.jmix.ui.model.ScreenData)

Example 24 with FrameOwner

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

the class TestScreenDependencyInjector method inject.

@Override
public void inject(InjectionContext injectionContext) {
    FrameOwner frameOwner = injectionContext.getFrameOwner();
    Class screenClass = frameOwner.getClass();
    List<Field> fields = Arrays.asList(screenClass.getDeclaredFields());
    for (Field field : fields) {
        if (field.isAnnotationPresent(TestScreenParam.class)) {
            field.setAccessible(true);
            try {
                field.set(frameOwner, STR_VALUE);
            } catch (IllegalAccessException e) {
                throw new RuntimeException("CDI - Unable to assign value to field ");
            }
        }
    }
}
Also used : Field(java.lang.reflect.Field) FrameOwner(io.jmix.ui.screen.FrameOwner)

Example 25 with FrameOwner

use of io.jmix.ui.screen.FrameOwner in project jmix-sneferu by mariodavid.

the class PetBrowse method onPetsTableOpenPetById.

@Subscribe("petsTable.openPetById")
public void onPetsTableOpenPetById(Action.ActionPerformedEvent event) {
    FrameOwner frameOwner = this;
    dialogs.createInputDialog(frameOwner).withParameter(InputParameter.stringParameter("id").withRequired(true).withCaption(messageBundle.getMessage("id"))).withCloseListener(inputDialogCloseEvent -> {
        if (inputDialogCloseEvent.closedWith(DialogOutcome.OK)) {
            final String id = inputDialogCloseEvent.getValue("id");
            if (StringUtils.hasText(id)) {
                final Optional<Pet> pet = dataManager.load(Pet.class).query("e.identificationNumber = ?1", id).optional();
                if (pet.isPresent()) {
                    screenBuilders.editor(Pet.class, frameOwner).editEntity(pet.get()).withOpenMode(OpenMode.DIALOG).show();
                } else {
                    noPetFoundForIdWarning(id);
                }
            } else {
                noPetFoundForIdWarning(id);
            }
        }
    }).show();
}
Also used : Id(io.jmix.core.Id) MessageBundle(io.jmix.ui.screen.MessageBundle) Subscribe(io.jmix.ui.screen.Subscribe) FrameOwner(io.jmix.ui.screen.FrameOwner) Autowired(org.springframework.beans.factory.annotation.Autowired) UiDescriptor(io.jmix.ui.screen.UiDescriptor) Notifications(io.jmix.ui.Notifications) InputDialog(io.jmix.ui.app.inputdialog.InputDialog) ScreenBuilders(io.jmix.ui.ScreenBuilders) LookupComponent(io.jmix.ui.screen.LookupComponent) Owner(io.jmix.petclinic.entity.owner.Owner) Pet(io.jmix.petclinic.entity.pet.Pet) Slider(io.jmix.ui.component.Slider) DialogOutcome(io.jmix.ui.app.inputdialog.DialogOutcome) Action(io.jmix.ui.action.Action) TextField(io.jmix.ui.component.TextField) DataManager(io.jmix.core.DataManager) Route(io.jmix.ui.navigation.Route) UiController(io.jmix.ui.screen.UiController) PetType(io.jmix.petclinic.entity.pet.PetType) Dialogs(io.jmix.ui.Dialogs) UUID(java.util.UUID) StandardLookup(io.jmix.ui.screen.StandardLookup) OpenMode(io.jmix.ui.screen.OpenMode) EntityComboBox(io.jmix.ui.component.EntityComboBox) Optional(java.util.Optional) InputParameter(io.jmix.ui.app.inputdialog.InputParameter) StringUtils(org.springframework.util.StringUtils) FrameOwner(io.jmix.ui.screen.FrameOwner) Optional(java.util.Optional) Pet(io.jmix.petclinic.entity.pet.Pet) Subscribe(io.jmix.ui.screen.Subscribe)

Aggregations

FrameOwner (io.jmix.ui.screen.FrameOwner)51 ScreenData (io.jmix.ui.model.ScreenData)18 GuiDevelopmentException (io.jmix.ui.GuiDevelopmentException)17 InstanceContainer (io.jmix.ui.model.InstanceContainer)11 CollectionContainer (io.jmix.ui.model.CollectionContainer)9 Component (io.jmix.ui.component.Component)7 Method (java.lang.reflect.Method)6 LegacyFragmentAdapter (com.haulmont.cuba.gui.components.compatibility.LegacyFragmentAdapter)5 MetaClass (io.jmix.core.metamodel.model.MetaClass)5 Screens (io.jmix.ui.Screens)5 Screen (io.jmix.ui.screen.Screen)5 ScreenFragment (io.jmix.ui.screen.ScreenFragment)5 WindowInfo (io.jmix.ui.WindowInfo)4 Frame (io.jmix.ui.component.Frame)4 Element (org.dom4j.Element)4 Fragment (io.jmix.ui.component.Fragment)3 DataUnit (io.jmix.ui.component.data.DataUnit)3 DataLoader (io.jmix.ui.model.DataLoader)3 LegacyFrame (com.haulmont.cuba.gui.screen.compatibility.LegacyFrame)2 Notifications (io.jmix.ui.Notifications)2