use of com.haulmont.cuba.gui.GuiDevelopmentException in project cuba by cuba-platform.
the class EmbeddedLoader method loadComponent.
@Override
public void loadComponent() {
assignFrame(resultComponent);
String relativeSrc = element.attributeValue("relativeSrc");
if (StringUtils.isNotEmpty(relativeSrc)) {
resultComponent.setRelativeSource(relativeSrc);
}
String srcAttr = element.attributeValue("src");
if (srcAttr != null) {
if (srcAttr.startsWith(URL_PREFIX)) {
String src = srcAttr.substring(URL_PREFIX.length());
URL targetUrl;
try {
targetUrl = new URL(src);
} catch (MalformedURLException e) {
throw new GuiDevelopmentException("Incorrect URL in Embedded src attribute", context.getFullFrameId(), "src", srcAttr);
}
resultComponent.setType(Embedded.Type.BROWSER);
resultComponent.setSource(targetUrl);
} else if (srcAttr.startsWith(THEME_PREFIX)) {
resultComponent.setSource(srcAttr);
} else if (srcAttr.startsWith(FILE_PREFIX)) {
String src = srcAttr.substring(FILE_PREFIX.length());
resultComponent.setType(Embedded.Type.OBJECT);
resultComponent.setSource(src);
} else {
throw new GuiDevelopmentException("Illegal src attribute value. 'url://' or 'file://' or theme:// prefix expected", context.getFullFrameId(), "src", srcAttr);
}
}
String typeAttribute = element.attributeValue("type");
if (StringUtils.isNotEmpty(typeAttribute)) {
Embedded.Type type = Embedded.Type.valueOf(typeAttribute);
resultComponent.setType(type);
}
loadVisible(resultComponent, element);
loadEnable(resultComponent, element);
loadStyleName(resultComponent, element);
loadHeight(resultComponent, element);
loadWidth(resultComponent, element);
loadAlign(resultComponent, element);
loadCaption(resultComponent, element);
loadDescription(resultComponent, element);
loadIcon(resultComponent, element);
}
use of com.haulmont.cuba.gui.GuiDevelopmentException in project cuba by cuba-platform.
the class FieldGroupLoader method loadComponent.
@Override
public void loadComponent() {
assignFrame(resultComponent);
String fieldFactoryBean = element.attributeValue("fieldFactoryBean");
if (StringUtils.isNotEmpty(fieldFactoryBean)) {
FieldGroupFieldFactory fieldFactory = AppBeans.get(fieldFactoryBean, FieldGroupFieldFactory.class);
resultComponent.setFieldFactory(fieldFactory);
}
assignXmlDescriptor(resultComponent, element);
loadVisible(resultComponent, element);
loadWidth(resultComponent, element);
loadEditable(resultComponent, element);
loadEnable(resultComponent, element);
loadStyleName(resultComponent, element);
loadIcon(resultComponent, element);
loadCaption(resultComponent, element);
loadDescription(resultComponent, element);
loadHeight(resultComponent, element);
loadAlign(resultComponent, element);
loadCaptionAlignment(resultComponent, element);
loadFieldCaptionWidth(resultComponent, element);
Datasource ds = loadDatasource(element);
resultComponent.setDatasource(ds);
if (element.elements("column").isEmpty()) {
Iterable<FieldGroup.FieldConfig> rootFields = loadFields(resultComponent, element, ds, null);
Iterable<FieldGroup.FieldConfig> dynamicAttributeFields = loadDynamicAttributeFields(ds);
for (FieldGroup.FieldConfig field : dynamicAttributeFields) {
if (resultComponent.getWidth() > 0 && field.getWidth() == null) {
field.setWidth("100%");
}
}
for (FieldGroup.FieldConfig field : Iterables.concat(rootFields, dynamicAttributeFields)) {
resultComponent.addField(field);
}
} else {
@SuppressWarnings("unchecked") List<Element> columnElements = element.elements("column");
@SuppressWarnings("unchecked") List<Element> fieldElements = element.elements("field");
if (fieldElements.size() > 0) {
Map<String, Object> params = new HashMap<>();
String fieldGroupId = resultComponent.getId();
if (StringUtils.isNotEmpty(fieldGroupId)) {
params.put("FieldGroup ID", fieldGroupId);
}
throw new GuiDevelopmentException("FieldGroup field elements should be placed within its column.", context.getFullFrameId(), params);
}
resultComponent.setColumns(columnElements.size());
int colIndex = 0;
for (Element columnElement : columnElements) {
String flex = columnElement.attributeValue("flex");
if (StringUtils.isNotEmpty(flex)) {
resultComponent.setColumnExpandRatio(colIndex, Float.parseFloat(flex));
}
String columnWidth = loadThemeString(columnElement.attributeValue("width"));
Iterable<FieldGroup.FieldConfig> columnFields = loadFields(resultComponent, columnElement, ds, columnWidth);
if (colIndex == 0) {
columnFields = Iterables.concat(columnFields, loadDynamicAttributeFields(ds));
}
for (FieldGroup.FieldConfig field : columnFields) {
resultComponent.addField(field, colIndex);
}
String columnFieldCaptionWidth = columnElement.attributeValue("fieldCaptionWidth");
if (StringUtils.isNotEmpty(columnFieldCaptionWidth)) {
if (columnFieldCaptionWidth.startsWith(MessageTools.MARK)) {
columnFieldCaptionWidth = loadResourceString(columnFieldCaptionWidth);
}
if (columnFieldCaptionWidth.endsWith("px")) {
columnFieldCaptionWidth = columnFieldCaptionWidth.substring(0, columnFieldCaptionWidth.indexOf("px"));
}
resultComponent.setFieldCaptionWidth(colIndex, Integer.parseInt(columnFieldCaptionWidth));
}
colIndex++;
}
}
for (FieldGroup.FieldConfig field : resultComponent.getFields()) {
if (!field.isCustom()) {
if (!DynamicAttributesUtils.isDynamicAttribute(field.getProperty())) {
// the following does not make sense for dynamic attributes
loadValidators(resultComponent, field);
loadRequired(resultComponent, field);
loadEnable(resultComponent, field);
}
loadVisible(resultComponent, field);
loadEditable(resultComponent, field);
}
}
resultComponent.bind();
for (FieldGroup.FieldConfig field : resultComponent.getFields()) {
if (field.getXmlDescriptor() != null) {
String generator = field.getXmlDescriptor().attributeValue("generator");
if (generator != null) {
context.addPostWrapTask((boundContext, window) -> {
DeclarativeFieldGenerator fieldGenerator = new DeclarativeFieldGenerator(resultComponent, generator);
Component fieldComponent = fieldGenerator.generateField(field.getTargetDatasource(), field.getProperty());
field.setComponent(fieldComponent);
});
}
}
}
}
use of com.haulmont.cuba.gui.GuiDevelopmentException 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);
loadMargin(resultComponent, element);
loadIcon(resultComponent, element);
loadCaption(resultComponent, element);
loadDescription(resultComponent, element);
loadWidth(resultComponent, element, "100%");
loadCollapsible(resultComponent, element, true);
loadSettingsEnabled(resultComponent, element);
loadBorderVisible(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 datasource = element.attributeValue("datasource");
if (!StringUtils.isBlank(datasource)) {
CollectionDatasource ds = (CollectionDatasource) context.getDsContext().get(datasource);
if (ds == null) {
throw new GuiDevelopmentException("Can't find datasource by name: " + datasource, context.getCurrentFrameId());
}
resultComponent.setDatasource(ds);
}
Frame frame = context.getFrame();
String applyTo = element.attributeValue("applyTo");
if (!StringUtils.isEmpty(applyTo)) {
context.addPostInitTask((context1, window) -> {
Component c = frame.getComponent(applyTo);
if (c == null) {
throw new GuiDevelopmentException("Can't apply component to component with ID: " + applyTo, context1.getFullFrameId());
}
resultComponent.setApplyTo(c);
});
}
String modeSwitchVisible = element.attributeValue("modeSwitchVisible");
resultComponent.setModeSwitchVisible(modeSwitchVisible == null || Boolean.parseBoolean(modeSwitchVisible));
context.addPostInitTask((context1, window) -> {
((FilterImplementation) resultComponent).loadFiltersAndApplyDefault();
String defaultMode = element.attributeValue("defaultMode");
if (defaultMode != null && "fts".equals(defaultMode)) {
resultComponent.switchFilterMode(FilterDelegate.FilterMode.FTS_MODE);
}
});
}
use of com.haulmont.cuba.gui.GuiDevelopmentException in project cuba by cuba-platform.
the class FrameComponentLoader method createComponent.
@Override
public void createComponent() {
String src = element.attributeValue("src");
String screenId = element.attributeValue("screen");
if (src == null && screenId == null) {
throw new GuiDevelopmentException("Either 'src' or 'screen' must be specified for 'frame'", context.getFullFrameId());
}
if (src == null) {
WindowConfig windowConfig = AppBeans.get(WindowConfig.NAME);
WindowInfo windowInfo = windowConfig.getWindowInfo(screenId);
src = windowInfo.getTemplate();
if (src == null) {
throw new GuiDevelopmentException("Screen " + screenId + " doesn't have template path configured", context.getFullFrameId());
}
}
if (element.attributeValue("id") != null) {
frameId = element.attributeValue("id");
}
LayoutLoader layoutLoader = new LayoutLoader(context, factory, LayoutLoaderConfig.getFrameLoaders());
layoutLoader.setLocale(getLocale());
layoutLoader.setMessagesPack(getMessagesPack());
String currentFrameId = context.getCurrentFrameId();
context.setCurrentFrameId(frameId);
try {
Pair<ComponentLoader, Element> loaderElementPair = layoutLoader.createFrameComponent(src, frameId, context.getParams());
frameLoader = loaderElementPair.getFirst();
resultComponent = (Frame) frameLoader.getResultComponent();
} finally {
context.setCurrentFrameId(currentFrameId);
}
}
use of com.haulmont.cuba.gui.GuiDevelopmentException in project cuba by cuba-platform.
the class RelatedEntitiesLoader method loadComponent.
@Override
public void loadComponent() {
assignFrame(resultComponent);
loadCaption(resultComponent, element);
loadIcon(resultComponent, element);
loadWidth(resultComponent, element);
loadStyleName(resultComponent, element);
loadEnable(resultComponent, element);
loadVisible(resultComponent, element);
loadAlign(resultComponent, element);
String openType = element.attributeValue("openType");
if (StringUtils.isNotEmpty(openType)) {
resultComponent.setOpenType(OpenType.valueOf(openType));
}
String exclude = element.attributeValue("exclude");
if (StringUtils.isNotBlank(exclude)) {
resultComponent.setExcludePropertiesRegex(exclude);
}
for (Object routeObject : element.elements("property")) {
Element routeElement = (Element) routeObject;
String property = routeElement.attributeValue("name");
if (StringUtils.isEmpty(property)) {
throw new GuiDevelopmentException("Name attribute for related entities property is not specified", context.getFullFrameId(), "componentId", resultComponent.getId());
}
String caption = loadResourceString(routeElement.attributeValue("caption"));
String filterCaption = loadResourceString(routeElement.attributeValue("filterCaption"));
String screen = routeElement.attributeValue("screen");
if (StringUtils.isNotEmpty(screen)) {
WindowConfig windowConfig = AppBeans.get(WindowConfig.NAME);
if (windowConfig.findWindowInfo(screen) == null) {
throw new GuiDevelopmentException("Screen for custom route in related entities not found", context.getFullFrameId(), "componentId", resultComponent.getId());
}
}
resultComponent.addPropertyOption(property, screen, caption, filterCaption);
}
String listComponent = element.attributeValue("for");
if (StringUtils.isEmpty(listComponent)) {
throw new GuiDevelopmentException("'for' attribute of related entities is not specified", context.getFullFrameId(), "componentId", resultComponent.getId());
}
context.addPostInitTask((context1, window) -> {
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", context1.getFullFrameId(), "componentId", resultComponent.getId());
}
resultComponent.setListComponent((ListComponent) bindComponent);
}
});
loadFocusable(resultComponent, element);
loadTabIndex(resultComponent, element);
}
Aggregations