use of com.haulmont.cuba.gui.screen.compatibility.LegacyFrame in project cuba by cuba-platform.
the class FieldGroupLoader method loadField.
protected FieldGroup.FieldConfig loadField(Element element, Datasource ds, String columnWidth) {
String id = element.attributeValue("id");
String property = element.attributeValue("property");
if (Strings.isNullOrEmpty(id) && Strings.isNullOrEmpty(property)) {
throw new GuiDevelopmentException(String.format("id/property is not defined for field of FieldGroup '%s'. " + "Set id or property attribute.", resultComponent.getId()), context);
}
if (Strings.isNullOrEmpty(property)) {
property = id;
} else if (Strings.isNullOrEmpty(id)) {
id = property;
}
Datasource targetDs = ds;
Datasource datasource = loadDatasource(element);
if (datasource != null) {
targetDs = datasource;
}
CollectionDatasource optionsDs = null;
String optDsName = element.attributeValue("optionsDatasource");
if (StringUtils.isNotBlank(optDsName)) {
LegacyFrame frame = (LegacyFrame) getComponentContext().getFrame().getFrameOwner();
DsContext dsContext = frame.getDsContext();
optionsDs = findDatasourceRecursively(dsContext, optDsName);
if (optionsDs == null) {
throw new GuiDevelopmentException(String.format("Options datasource %s not found for field %s", optDsName, id), context);
}
}
boolean customField = false;
String custom = element.attributeValue("custom");
if (StringUtils.isNotEmpty(custom)) {
customField = Boolean.parseBoolean(custom);
}
if (StringUtils.isNotEmpty(element.attributeValue("generator"))) {
customField = true;
}
List<Element> elements = element.elements();
List<Element> customElements = elements.stream().filter(e -> !("formatter".equals(e.getName()) || "validator".equals(e.getName()))).collect(Collectors.toList());
if (!customElements.isEmpty()) {
if (customElements.size() > 1) {
throw new GuiDevelopmentException(String.format("FieldGroup field %s element cannot contains two or more custom field definitions", id), context);
}
if (customField) {
throw new GuiDevelopmentException(String.format("FieldGroup field %s cannot use both custom/generator attribute and inline component definition", id), context);
}
customField = true;
}
if (!customField && targetDs == null) {
throw new GuiDevelopmentException(String.format("Datasource is not defined for FieldGroup field '%s'. " + "Only custom fields can have no datasource.", property), context);
}
FieldGroup.FieldConfig field = resultComponent.createField(id);
if (property != null) {
field.setProperty(property);
}
if (datasource != null) {
field.setDatasource(datasource);
}
if (optionsDs != null) {
field.setOptionsDatasource(optionsDs);
}
String stylename = element.attributeValue("stylename");
if (StringUtils.isNotEmpty(stylename)) {
field.setStyleName(stylename);
}
MetaPropertyPath metaPropertyPath = null;
if (targetDs != null && property != null) {
MetaClass metaClass = targetDs.getMetaClass();
metaPropertyPath = getMetadataTools().resolveMetaPropertyPath(targetDs.getMetaClass(), property);
if (metaPropertyPath == null) {
if (!customField) {
throw new GuiDevelopmentException(String.format("Property '%s' is not found in entity '%s'", property, metaClass.getName()), context);
}
}
}
String propertyName = metaPropertyPath != null ? metaPropertyPath.getMetaProperty().getName() : null;
if (metaPropertyPath != null && DynamicAttributesUtils.isDynamicAttribute(metaPropertyPath.getMetaProperty())) {
CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(metaPropertyPath.getMetaProperty());
field.setCaption(categoryAttribute != null ? categoryAttribute.getLocaleName() : propertyName);
field.setDescription(categoryAttribute != null ? categoryAttribute.getLocaleDescription() : null);
} else {
loadCaption(field, element);
if (field.getCaption() == null) {
field.setCaption(getDefaultCaption(field, targetDs));
}
}
loadDescription(field, element);
loadContextHelp(field, element);
field.setXmlDescriptor(element);
Function formatter = loadFormatter(element);
if (formatter != null) {
field.setFormatter(formatter);
}
String defaultWidth = element.attributeValue("width");
if (StringUtils.isEmpty(defaultWidth)) {
defaultWidth = columnWidth;
}
loadWidth(field, defaultWidth);
if (customField) {
field.setCustom(true);
}
String required = element.attributeValue("required");
if (StringUtils.isNotEmpty(required)) {
field.setRequired(Boolean.parseBoolean(required));
}
String requiredMsg = element.attributeValue("requiredMessage");
if (requiredMsg != null) {
requiredMsg = loadResourceString(requiredMsg);
field.setRequiredMessage(requiredMsg);
}
String tabIndex = element.attributeValue("tabIndex");
if (StringUtils.isNotEmpty(tabIndex)) {
field.setTabIndex(Integer.parseInt(tabIndex));
}
loadInputPrompt(field, element);
if (customElements.size() == 1) {
// load nested component defined as inline
Element customFieldElement = customElements.get(0);
LayoutLoader loader = getLayoutLoader();
ComponentLoader childComponentLoader = loader.createComponent(customFieldElement);
childComponentLoader.loadComponent();
Component customComponent = childComponentLoader.getResultComponent();
String inlineAttachMode = element.attributeValue("inlineAttachMode");
if (StringUtils.isNotEmpty(inlineAttachMode)) {
field.setComponent(customComponent, FieldGroup.FieldAttachMode.valueOf(inlineAttachMode));
} else {
field.setComponent(customComponent);
}
}
return field;
}
use of com.haulmont.cuba.gui.screen.compatibility.LegacyFrame in project cuba by cuba-platform.
the class FragmentLoader method loadComponent.
@Override
public void loadComponent() {
if (resultComponent.getFrameOwner() instanceof AbstractFrame) {
getScreenViewsLoader().deployViews(element);
}
ComponentContext componentContext = getComponentContext();
if (componentContext.getParent() == null) {
throw new IllegalStateException("FragmentLoader is always called within parent ComponentLoaderContext");
}
assignXmlDescriptor(resultComponent, element);
Element layoutElement = element.element("layout");
if (layoutElement == null) {
throw new GuiDevelopmentException("Required 'layout' element is not found", componentContext.getFullFrameId());
}
loadIcon(resultComponent, layoutElement);
loadCaption(resultComponent, layoutElement);
loadDescription(resultComponent, layoutElement);
loadVisible(resultComponent, layoutElement);
loadEnable(resultComponent, layoutElement);
loadActions(resultComponent, element);
loadSpacing(resultComponent, layoutElement);
loadMargin(resultComponent, layoutElement);
loadWidth(resultComponent, layoutElement);
loadHeight(resultComponent, layoutElement);
loadStyleName(resultComponent, layoutElement);
loadResponsive(resultComponent, layoutElement);
loadCss(resultComponent, element);
Element dataEl = element.element("data");
if (dataEl != null) {
loadScreenData(dataEl);
} else if (resultComponent.getFrameOwner() instanceof LegacyFrame) {
Element dsContextElement = element.element("dsContext");
loadDsContext(dsContextElement);
}
if (resultComponent.getFrameOwner() instanceof AbstractFrame) {
Element companionsElem = element.element("companions");
if (companionsElem != null) {
componentContext.addInjectTask(new FragmentLoaderCompanionTask(resultComponent));
}
}
loadSubComponentsAndExpand(resultComponent, layoutElement);
setComponentsRatio(resultComponent, layoutElement);
loadFacets(resultComponent, element);
}
use of com.haulmont.cuba.gui.screen.compatibility.LegacyFrame in project cuba by cuba-platform.
the class WebTabSheet method initComponentTabChangeListener.
private void initComponentTabChangeListener() {
// after all lazy tabs listeners
if (!componentTabChangeListenerInitialized) {
component.addSelectedTabChangeListener(event -> {
if (context instanceof ComponentLoader.ComponentContext) {
((ComponentLoader.ComponentContext) context).executeInjectTasks();
((ComponentLoader.ComponentContext) context).executeInitTasks();
}
// Fire GUI listener
fireTabChanged(new SelectedTabChangeEvent(WebTabSheet.this, getSelectedTab(), event.isUserOriginated()));
// We suppose that context.executePostInitTasks() executes a task once and then remove it from task list.
if (context instanceof ComponentLoader.ComponentContext) {
((ComponentLoader.ComponentContext) context).executePostInitTasks();
}
Window window = ComponentsHelper.getWindow(WebTabSheet.this);
if (window != null) {
if (window.getFrameOwner() instanceof LegacyFrame) {
DsContext dsContext = ((LegacyFrame) window.getFrameOwner()).getDsContext();
if (dsContext != null) {
((DsContextImplementation) dsContext).resumeSuspended();
}
}
} else {
LoggerFactory.getLogger(WebTabSheet.class).warn("Please specify Frame for TabSheet");
}
});
componentTabChangeListenerInitialized = true;
}
}
use of com.haulmont.cuba.gui.screen.compatibility.LegacyFrame in project cuba by cuba-platform.
the class LinkCellClickListener method onClick.
@Override
public void onClick(Entity rowItem, String columnId) {
Table.Column column = table.getColumn(columnId);
if (column.getXmlDescriptor() != null) {
String invokeMethodName = column.getXmlDescriptor().attributeValue("linkInvoke");
if (StringUtils.isNotEmpty(invokeMethodName)) {
callControllerInvoke(rowItem, columnId, invokeMethodName);
return;
}
}
Entity entity;
Object value = rowItem.getValueEx(columnId);
if (value instanceof Entity) {
entity = (Entity) value;
} else {
entity = rowItem;
}
WindowManager wm;
Window window = ComponentsHelper.getWindow(table);
if (window == null) {
throw new IllegalStateException("Please specify Frame for Table");
} else {
wm = window.getWindowManager();
}
Messages messages = beanLocator.get(Messages.NAME, Messages.class);
if (entity instanceof SoftDelete && ((SoftDelete) entity).isDeleted()) {
wm.showNotification(messages.getMainMessage("OpenAction.objectIsDeleted"), Frame.NotificationType.HUMANIZED);
return;
}
if (window.getFrameOwner() instanceof LegacyFrame) {
LegacyFrame frameOwner = (LegacyFrame) window.getFrameOwner();
DataSupplier dataSupplier = frameOwner.getDsContext().getDataSupplier();
entity = dataSupplier.reload(entity, View.MINIMAL);
} else {
DataManager dataManager = beanLocator.get(DataManager.NAME, DataManager.class);
entity = dataManager.reload(entity, View.MINIMAL);
}
WindowConfig windowConfig = beanLocator.get(WindowConfig.NAME, WindowConfig.class);
String windowAlias = null;
if (column.getXmlDescriptor() != null) {
windowAlias = column.getXmlDescriptor().attributeValue("linkScreen");
}
if (StringUtils.isEmpty(windowAlias)) {
windowAlias = windowConfig.getEditorScreenId(entity.getMetaClass());
}
OpenType screenOpenType = OpenType.THIS_TAB;
if (column.getXmlDescriptor() != null) {
String openTypeAttribute = column.getXmlDescriptor().attributeValue("linkScreenOpenType");
if (StringUtils.isNotEmpty(openTypeAttribute)) {
screenOpenType = OpenType.valueOf(openTypeAttribute);
}
}
AbstractEditor editor = (AbstractEditor) wm.openEditor(windowConfig.getWindowInfo(windowAlias), entity, screenOpenType);
editor.addCloseListener(actionId -> {
// move focus to component
table.focus();
if (Window.COMMIT_ACTION_ID.equals(actionId)) {
Entity editorItem = editor.getItem();
handleEditorCommit(editorItem, rowItem, columnId);
}
});
}
use of com.haulmont.cuba.gui.screen.compatibility.LegacyFrame in project cuba by cuba-platform.
the class UiControllerPropertyInjector method findDatasource.
@Nullable
protected Datasource findDatasource(String datasourceId) {
Datasource datasource = null;
if (sourceScreen instanceof LegacyFrame) {
((LegacyFrame) sourceScreen).getDsContext().get(datasourceId);
}
FrameOwner frameOwner = this.frameOwner instanceof ScreenFragment ? ((ScreenFragment) this.frameOwner).getHostController() : this.frameOwner;
if (frameOwner instanceof LegacyFrame) {
datasource = ((LegacyFrame) frameOwner).getDsContext().get(datasourceId);
}
return datasource;
}
Aggregations