use of io.jmix.ui.screen.FrameOwner in project jmix by jmix-framework.
the class DsContextImpl method get.
@Override
public Datasource get(String id) {
checkNotNullArgument(id, "Null datasource ID");
id = aliasesMap.getOrDefault(id, id);
Datasource ds = null;
if (!id.contains(".")) {
ds = datasourceMap.get(id);
if (ds == null && parent != null) {
ds = parent.get(id);
}
} else {
if (windowContext != null) {
String nestedFramePath = id.substring(0, id.indexOf("."));
Component nestedFrame = getFrameContext().getFrame().getComponent(nestedFramePath);
if (nestedFrame instanceof Frame) {
String nestedDsId = id.substring(id.indexOf(".") + 1);
FrameOwner frameOwner = ((Frame) nestedFrame).getFrameOwner();
if (frameOwner instanceof LegacyFrame) {
ds = ((LegacyFrame) frameOwner).getDsContext().get(nestedDsId);
}
}
}
}
return ds;
}
use of io.jmix.ui.screen.FrameOwner in project jmix by jmix-framework.
the class DeclarativeAction method actionPerform.
@Override
public void actionPerform(Component component) {
if (StringUtils.isEmpty(methodName)) {
return;
}
FrameOwner controller = frame.getFrameOwner();
if (controller instanceof LegacyFragmentAdapter) {
controller = ((LegacyFragmentAdapter) controller).getRealScreen();
}
Method method;
try {
method = controller.getClass().getMethod(methodName, Component.class);
} catch (NoSuchMethodException e) {
try {
method = controller.getClass().getMethod(methodName);
} catch (NoSuchMethodException e1) {
throw new IllegalStateException(String.format("No suitable methods named %s for action %s", methodName, id));
}
}
try {
if (method.getParameterCount() == 1) {
method.invoke(controller, component);
} else {
method.invoke(controller);
}
} catch (Exception e) {
throw new RuntimeException("Exception on action handling", e);
}
}
use of io.jmix.ui.screen.FrameOwner in project jmix by jmix-framework.
the class AbstractComponentLoader method loadContainer.
protected Optional<InstanceContainer> loadContainer(Element element, @Nullable String property) {
String containerId = element.attributeValue("dataContainer");
// For instance, a component is placed within the Form component
if (Strings.isNullOrEmpty(containerId) && property != null) {
containerId = getParentDataContainer(element);
}
if (!Strings.isNullOrEmpty(containerId)) {
if (property == null) {
throw new GuiDevelopmentException(String.format("Can't set container '%s' for component '%s' because 'property' " + "attribute is not defined", containerId, element.attributeValue("id")), context);
}
FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
ScreenData screenData = UiControllerUtils.getScreenData(frameOwner);
return Optional.of(screenData.getContainer(containerId));
}
return Optional.empty();
}
use of io.jmix.ui.screen.FrameOwner in project jmix by jmix-framework.
the class AbstractComponentLoader method loadOptionsContainer.
protected Optional<CollectionContainer> loadOptionsContainer(Element element) {
String containerId = element.attributeValue("optionsContainer");
if (containerId != null) {
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);
}
return Optional.of((CollectionContainer) container);
}
return Optional.empty();
}
use of io.jmix.ui.screen.FrameOwner in project jmix by jmix-framework.
the class DeclarativeColumnGenerator method generateCell.
@Override
public Component generateCell(Object entity) {
if (unableToFindMethod) {
return null;
}
FrameOwner controller = getFrameOwner();
if (method == null) {
method = findGeneratorMethod(controller.getClass(), methodName);
if (method == null) {
this.unableToFindMethod = true;
String tableId = table.getId() == null ? "" : table.getId();
throw new IllegalStateException(String.format("No suitable method named %s for column generator of table %s", methodName, tableId));
}
}
try {
return (Component) method.invoke(controller, entity);
} catch (Exception e) {
throw new RuntimeException("Exception in declarative Table column generator " + methodName, e);
}
}
Aggregations