use of com.haulmont.cuba.gui.screen.FrameOwner in project cuba by cuba-platform.
the class CalendarLoader method loadDataContainer.
@SuppressWarnings("unchecked")
protected void loadDataContainer(Calendar component, Element element) {
String containerId = element.attributeValue("dataContainer");
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 com.haulmont.cuba.gui.screen.FrameOwner in project cuba by cuba-platform.
the class FilterLoader method loadComponent.
@Override
public void loadComponent() {
assignXmlDescriptor(resultComponent, element);
assignFrame(resultComponent);
loadAlign(resultComponent, element);
loadVisible(resultComponent, element);
loadEnable(resultComponent, element);
loadStyleName(resultComponent, element);
loadCss(resultComponent, element);
loadMargin(resultComponent, element);
loadIcon(resultComponent, element);
loadHtmlSanitizerEnabled(resultComponent, element);
loadCaption(resultComponent, element);
loadDescription(resultComponent, element);
loadContextHelp(resultComponent, element);
loadWidth(resultComponent, element, "100%");
loadCollapsible(resultComponent, element, true);
loadSettingsEnabled(resultComponent, element);
loadBorderVisible(resultComponent, element);
loadWindowCaptionUpdateEnabled(resultComponent, element);
String useMaxResults = element.attributeValue("useMaxResults");
resultComponent.setUseMaxResults(useMaxResults == null || Boolean.parseBoolean(useMaxResults));
String textMaxResults = element.attributeValue("textMaxResults");
resultComponent.setTextMaxResults(Boolean.parseBoolean(textMaxResults));
final String manualApplyRequired = element.attributeValue("manualApplyRequired");
resultComponent.setManualApplyRequired(BooleanUtils.toBooleanObject(manualApplyRequired));
String editable = element.attributeValue("editable");
resultComponent.setEditable(editable == null || Boolean.parseBoolean(editable));
String columnsCount = element.attributeValue("columnsCount");
if (!Strings.isNullOrEmpty(columnsCount)) {
resultComponent.setColumnsCount(Integer.parseInt(columnsCount));
}
String folderActionsEnabled = element.attributeValue("folderActionsEnabled");
if (folderActionsEnabled != null) {
resultComponent.setFolderActionsEnabled(Boolean.parseBoolean(folderActionsEnabled));
}
String dataLoaderId = element.attributeValue("dataLoader");
if (StringUtils.isNotBlank(dataLoaderId)) {
FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
ScreenData screenData = UiControllerUtils.getScreenData(frameOwner);
DataLoader dataLoader = screenData.getLoader(dataLoaderId);
if (!(dataLoader instanceof CollectionLoader) && !(dataLoader instanceof KeyValueCollectionLoader)) {
throw new IllegalStateException(String.format("Filter cannot work with %s because it is not a CollectionLoader or a KeyValueCollectionLoader", dataLoaderId));
}
resultComponent.setDataLoader((BaseCollectionLoader) dataLoader);
} else {
String datasource = element.attributeValue("datasource");
if (StringUtils.isNotBlank(datasource)) {
if (getComponentContext().getDsContext() == null) {
throw new IllegalStateException("'datasource' attribute can be used only in screens with 'dsContext' element. " + "In a screen with 'data' element use 'dataContainer' attribute.");
}
CollectionDatasource ds = (CollectionDatasource) getComponentContext().getDsContext().get(datasource);
if (ds == null) {
throw new GuiDevelopmentException("Can't find datasource by name: " + datasource, context);
}
resultComponent.setDatasource(ds);
}
}
Frame frame = getComponentContext().getFrame();
String applyTo = element.attributeValue("applyTo");
if (!StringUtils.isEmpty(applyTo)) {
getComponentContext().addPostInitTask((c, w) -> {
Component applyToComponent = frame.getComponent(applyTo);
if (c == null) {
throw new GuiDevelopmentException("Can't apply component to component with ID: " + applyTo, context);
}
resultComponent.setApplyTo(applyToComponent);
});
}
String modeSwitchVisible = element.attributeValue("modeSwitchVisible");
if (StringUtils.isNotEmpty(modeSwitchVisible)) {
resultComponent.setModeSwitchVisible(Boolean.parseBoolean(modeSwitchVisible));
}
String immediatelySearch = element.attributeValue("applyImmediately");
if (!Strings.isNullOrEmpty(immediatelySearch)) {
resultComponent.setApplyImmediately(Boolean.parseBoolean(immediatelySearch));
}
getComponentContext().addPostInitTask((context1, window) -> {
String controlsLayoutTemplate = element.attributeValue("controlsLayoutTemplate");
if (!Strings.isNullOrEmpty(controlsLayoutTemplate)) {
resultComponent.setControlsLayoutTemplate(controlsLayoutTemplate);
resultComponent.createLayout();
}
((FilterImplementation) resultComponent).loadFiltersAndApplyDefault();
String defaultMode = element.attributeValue("defaultMode");
if (FTS_MODE_VALUE.equals(defaultMode)) {
resultComponent.switchFilterMode(FilterDelegate.FilterMode.FTS_MODE);
}
});
}
use of com.haulmont.cuba.gui.screen.FrameOwner in project cuba by cuba-platform.
the class DeclarativeTrackingAction 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 com.haulmont.cuba.gui.screen.FrameOwner in project cuba by cuba-platform.
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 com.haulmont.cuba.gui.screen.FrameOwner in project cuba by cuba-platform.
the class AbstractComponentLoader method loadContainer.
protected Optional<InstanceContainer> loadContainer(Element element, 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();
}
Aggregations