use of io.jmix.ui.screen.FrameOwner in project jmix by jmix-framework.
the class CubaFragmentLoader method loadDsContext.
protected void loadDsContext(@Nullable Element dsContextElement) {
DsContext dsContext = null;
if (resultComponent.getFrameOwner() instanceof LegacyFrame) {
DsContextLoader dsContextLoader;
DsContext parentDsContext = ((ComponentLoaderContext) getComponentContext().getParent()).getDsContext();
if (parentDsContext != null) {
dsContextLoader = new DsContextLoader(parentDsContext.getDataSupplier());
} else {
dsContextLoader = new DsContextLoader(new GenericDataSupplier());
}
dsContext = dsContextLoader.loadDatasources(dsContextElement, parentDsContext, getComponentContext().getAliasesMap());
((ComponentLoaderContext) context).setDsContext(dsContext);
}
if (dsContext != null) {
FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
if (frameOwner instanceof LegacyFrame) {
LegacyFrame frame = (LegacyFrame) frameOwner;
frame.setDsContext(dsContext);
for (Datasource ds : dsContext.getAll()) {
if (ds instanceof DatasourceImplementation) {
((DatasourceImplementation) ds).initialized();
}
}
dsContext.setFrameContext(resultComponent.getContext());
}
}
}
use of io.jmix.ui.screen.FrameOwner in project jmix by jmix-framework.
the class LookupFieldLoader method loadNewOptionHandler.
protected void loadNewOptionHandler(LookupField component, Element element) {
String newOptionHandlerMethod = element.attributeValue("newOptionHandler");
if (StringUtils.isNotEmpty(newOptionHandlerMethod)) {
FrameOwner controller = getComponentContext().getFrame().getFrameOwner();
Class<? extends FrameOwner> windowClass = controller.getClass();
Method newOptionHandler;
try {
newOptionHandler = windowClass.getMethod(newOptionHandlerMethod, ComboBox.class, String.class);
} catch (NoSuchMethodException e) {
Map<String, Object> params = ParamsMap.of("LookupField Id", component.getId(), "Method name", newOptionHandlerMethod);
throw new GuiDevelopmentException("Unable to find new option handler method for lookup field", context, params);
}
component.setNewOptionHandler(caption -> {
try {
newOptionHandler.invoke(controller, component, caption);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException("Unable to invoke new option handler", e);
}
});
}
}
use of io.jmix.ui.screen.FrameOwner in project jmix by jmix-framework.
the class StockChartLoader method loadDataSet.
protected void loadDataSet(DataSet dataSet, Element dataSetElement) {
loadFieldMappings(dataSet, dataSetElement);
loadStockEvents(dataSet, dataSetElement);
String id = dataSetElement.attributeValue("id");
if (StringUtils.isNotEmpty(id)) {
dataSet.setId(id);
}
checkMultipleDatasources(dataSetElement);
String categoryField = dataSetElement.attributeValue("categoryField");
if (StringUtils.isNotEmpty(categoryField)) {
dataSet.setCategoryField(categoryField);
}
String color = dataSetElement.attributeValue("color");
if (StringUtils.isNotEmpty(color)) {
dataSet.setColor(Color.valueOf(color));
}
String compared = dataSetElement.attributeValue("compared");
if (StringUtils.isNotEmpty(compared)) {
dataSet.setCompared(Boolean.valueOf(compared));
}
String dataContainerId = dataSetElement.attributeValue("dataContainer");
if (StringUtils.isNotEmpty(dataContainerId)) {
FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
ScreenData screenData = UiControllerUtils.getScreenData(frameOwner);
CollectionContainer dataContainer;
InstanceContainer container = screenData.getContainer(dataContainerId);
if (container instanceof CollectionContainer) {
dataContainer = (CollectionContainer) container;
} else {
throw new GuiDevelopmentException("Not a CollectionContainer: " + dataContainerId, context);
}
dataSet.setDataProvider(new ContainerDataProvider(dataContainer));
}
String showInCompare = dataSetElement.attributeValue("showInCompare");
if (StringUtils.isNotEmpty(showInCompare)) {
dataSet.setShowInCompare(Boolean.valueOf(showInCompare));
}
String showInSelect = dataSetElement.attributeValue("showInSelect");
if (StringUtils.isNotEmpty(showInSelect)) {
dataSet.setShowInSelect(Boolean.valueOf(showInSelect));
}
String title = dataSetElement.attributeValue("title");
if (StringUtils.isNotEmpty(title)) {
dataSet.setTitle(title);
}
}
use of io.jmix.ui.screen.FrameOwner in project jmix by jmix-framework.
the class RelatedEntitiesSupportImpl method createScreen.
protected Screen createScreen(RelatedEntitiesBuilder builder, MetaClass metaClass, MetaProperty metaProperty) {
FrameOwner origin = builder.getOrigin();
Screens screens = UiControllerUtils.getScreenContext(origin).getScreens();
if (builder instanceof RelatedEntitiesClassBuilder) {
return screens.create(((RelatedEntitiesClassBuilder<?>) builder).getScreenClass(), builder.getOpenMode(), builder.getOptions());
} else {
String screenId = builder.getScreenId();
if (Strings.isNullOrEmpty(screenId)) {
// try to get default browse screen id
screenId = windowConfig.getBrowseScreenId(metaProperty.getRange().asClass());
if (Strings.isNullOrEmpty(screenId)) {
String message = String.format("Can't create related entities screen: passed screen id is null and " + "there is no default browse screen for %s", metaClass.getName());
throw new IllegalStateException(message);
}
}
return screens.create(screenId, builder.getOpenMode(), builder.getOptions());
}
}
use of io.jmix.ui.screen.FrameOwner in project jmix by jmix-framework.
the class AbstractSuggestionField method showSuggestions.
protected void showSuggestions(List<I> suggestions, boolean userOriginated) {
FrameOwner frameOwner = getFrame().getFrameOwner();
Collection<Screen> dialogScreens = UiControllerUtils.getScreenContext(frameOwner).getScreens().getOpenedScreens().getDialogScreens();
Screen lastDialog = null;
for (Screen dialogScreen : dialogScreens) {
lastDialog = dialogScreen;
}
if (frameOwner instanceof ScreenFragment) {
frameOwner = ComponentsHelper.getScreen((ScreenFragment) frameOwner);
}
if (lastDialog == null || Objects.equals(frameOwner, lastDialog)) {
component.showSuggestions(suggestions, userOriginated);
}
}
Aggregations