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));
}
}
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;
}
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)));
}
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 ");
}
}
}
}
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();
}
Aggregations