use of io.jmix.ui.GuiDevelopmentException in project jmix by jmix-framework.
the class CubaFilterLoader 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 io.jmix.ui.GuiDevelopmentException 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.GuiDevelopmentException in project jmix by jmix-framework.
the class BulkEditorLoader method loadComponent.
@Override
public void loadComponent() {
assignXmlDescriptor(resultComponent, element);
assignFrame(resultComponent);
Window window = ComponentsHelper.getWindow(resultComponent);
if (window != null && !(window.getFrameOwner() instanceof LegacyFrame)) {
throw new GuiDevelopmentException("BulkEditor component can be used only in legacy screens based on AbstractWindow", context);
}
loadEnable(resultComponent, element);
loadVisible(resultComponent, element);
loadStyleName(resultComponent, element);
loadHtmlSanitizerEnabled(resultComponent, element);
loadCaption(resultComponent, element);
loadDescription(resultComponent, element);
loadIcon(resultComponent, element);
loadWidth(resultComponent, element);
loadAlign(resultComponent, element);
loadResponsive(resultComponent, element);
loadCss(resultComponent, element);
loadColumns(resultComponent, element);
loadTabIndex(resultComponent, element);
Security security = AppBeans.get(Security.class);
if (!security.isSpecificPermitted(BulkEditor.PERMISSION)) {
resultComponent.setVisible(false);
}
String openType = element.attributeValue("openType");
if (StringUtils.isNotEmpty(openType)) {
resultComponent.setOpenType(OpenType.valueOf(openType));
}
String exclude = element.attributeValue("exclude");
String includeProperties = element.attributeValue("includeProperties");
if (StringUtils.isNotBlank(exclude) && StringUtils.isNotBlank(includeProperties)) {
throw new GuiDevelopmentException("BulkEditor cannot define simultaneously exclude and includeProperties attributes", getContext());
}
if (StringUtils.isNotBlank(exclude)) {
resultComponent.setExcludePropertiesRegex(exclude.replace(" ", ""));
}
if (StringUtils.isNotBlank(includeProperties)) {
resultComponent.setIncludeProperties(Splitter.on(',').omitEmptyStrings().trimResults().splitToList(includeProperties));
}
String listComponent = element.attributeValue("for");
if (StringUtils.isEmpty(listComponent)) {
throw new GuiDevelopmentException("'for' attribute of bulk editor is not specified", context, "componentId", resultComponent.getId());
}
String loadDynamicAttributes = element.attributeValue("loadDynamicAttributes");
if (StringUtils.isNotEmpty(loadDynamicAttributes)) {
resultComponent.setLoadDynamicAttributes(Boolean.parseBoolean(loadDynamicAttributes));
}
String useConfirmDialog = element.attributeValue("useConfirmDialog");
if (StringUtils.isNotEmpty(useConfirmDialog)) {
resultComponent.setUseConfirmDialog(Boolean.parseBoolean(useConfirmDialog));
}
getComponentContext().addPostInitTask((c, w) -> {
if (resultComponent.getListComponent() == null) {
Component bindComponent = resultComponent.getFrame().getComponent(listComponent);
if (!(bindComponent instanceof ListComponent)) {
throw new GuiDevelopmentException("Specify 'for' attribute: id of table or tree", context, "componentId", resultComponent.getId());
}
resultComponent.setListComponent((ListComponent) bindComponent);
}
});
loadValidators(resultComponent, element);
loadFocusable(resultComponent, element);
}
use of io.jmix.ui.GuiDevelopmentException in project jmix by jmix-framework.
the class CubaCalendarLoader method loadDataContainer.
@SuppressWarnings("rawtypes")
@Override
protected void loadDataContainer(Calendar component, Element element) {
String datasource = element.attributeValue("datasource");
ComponentLoaderContext loaderContext = (ComponentLoaderContext) getComponentContext();
CollectionDatasource ds = (CollectionDatasource) loaderContext.getDsContext().get(datasource);
if (ds == null) {
throw new GuiDevelopmentException(String.format("Datasource '%s' is not defined", datasource), getContext(), "Component ID", component.getId());
}
((com.haulmont.cuba.gui.components.Calendar) component).setDatasource(ds);
}
use of io.jmix.ui.GuiDevelopmentException in project jmix by jmix-framework.
the class CubaRelatedEntitiesLoader method loadPropertyOption.
@Override
protected void loadPropertyOption(Element routeElement) {
String property = loadString(routeElement, "name").orElseThrow(() -> new GuiDevelopmentException("Name attribute for related entities property is not specified", context, "componentId", resultComponent.getId()));
String caption = loadResourceString(routeElement.attributeValue("caption"));
String filterCaption = loadResourceString(routeElement.attributeValue("filterCaption"));
String screen = routeElement.attributeValue("screen");
if (StringUtils.isNotEmpty(screen)) {
if (getWindowConfig().findWindowInfo(screen) == null) {
throw new GuiDevelopmentException("Screen for custom route in related entities not found", context, "componentId", resultComponent.getId());
}
}
resultComponent.addPropertyOption(new PropertyOption(property, screen, caption, filterCaption));
}
Aggregations