Search in sources :

Example 6 with LegacyFrame

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;
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) EmbeddedDatasource(com.haulmont.cuba.gui.data.EmbeddedDatasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) Iterables(com.google.common.collect.Iterables) java.util(java.util) FieldGroupFieldFactory(com.haulmont.cuba.gui.components.FieldGroupFieldFactory) Datasource(com.haulmont.cuba.gui.data.Datasource) DynamicAttributesGuiTools(com.haulmont.cuba.gui.dynamicattributes.DynamicAttributesGuiTools) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) DynamicAttributesUtils(com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributesUtils) BooleanUtils(org.apache.commons.lang3.BooleanUtils) StringUtils(org.apache.commons.lang3.StringUtils) Function(java.util.function.Function) MetaClass(com.haulmont.chile.core.model.MetaClass) Strings(com.google.common.base.Strings) MetadataTools(com.haulmont.cuba.core.global.MetadataTools) CategoryAttribute(com.haulmont.cuba.core.entity.CategoryAttribute) EmbeddedDatasource(com.haulmont.cuba.gui.data.EmbeddedDatasource) Preconditions.checkNotNullArgument(com.haulmont.bali.util.Preconditions.checkNotNullArgument) Component(com.haulmont.cuba.gui.components.Component) FieldGroup(com.haulmont.cuba.gui.components.FieldGroup) DsContext(com.haulmont.cuba.gui.data.DsContext) Nullable(javax.annotation.Nullable) LegacyFrame(com.haulmont.cuba.gui.screen.compatibility.LegacyFrame) LayoutLoader(com.haulmont.cuba.gui.xml.layout.LayoutLoader) MetaProperty(com.haulmont.chile.core.model.MetaProperty) DeclarativeFieldGenerator(com.haulmont.cuba.gui.xml.DeclarativeFieldGenerator) Collectors(java.util.stream.Collectors) ComponentLoader(com.haulmont.cuba.gui.xml.layout.ComponentLoader) Consumer(java.util.function.Consumer) EntityOp(com.haulmont.cuba.security.entity.EntityOp) EntityAttrAccess(com.haulmont.cuba.security.entity.EntityAttrAccess) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) FieldCaptionAlignment(com.haulmont.cuba.gui.components.FieldGroup.FieldCaptionAlignment) Element(org.dom4j.Element) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) MessageTools(com.haulmont.cuba.core.global.MessageTools) LayoutLoader(com.haulmont.cuba.gui.xml.layout.LayoutLoader) DsContext(com.haulmont.cuba.gui.data.DsContext) FieldGroup(com.haulmont.cuba.gui.components.FieldGroup) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) Element(org.dom4j.Element) LegacyFrame(com.haulmont.cuba.gui.screen.compatibility.LegacyFrame) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) ComponentLoader(com.haulmont.cuba.gui.xml.layout.ComponentLoader) Function(java.util.function.Function) CategoryAttribute(com.haulmont.cuba.core.entity.CategoryAttribute) MetaClass(com.haulmont.chile.core.model.MetaClass) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) Component(com.haulmont.cuba.gui.components.Component)

Example 7 with LegacyFrame

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);
}
Also used : AbstractFrame(com.haulmont.cuba.gui.components.AbstractFrame) Element(org.dom4j.Element) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) LegacyFrame(com.haulmont.cuba.gui.screen.compatibility.LegacyFrame)

Example 8 with LegacyFrame

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;
    }
}
Also used : DsContextImplementation(com.haulmont.cuba.gui.data.impl.DsContextImplementation) DsContext(com.haulmont.cuba.gui.data.DsContext) LegacyFrame(com.haulmont.cuba.gui.screen.compatibility.LegacyFrame)

Example 9 with LegacyFrame

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);
        }
    });
}
Also used : Window(com.haulmont.cuba.gui.components.Window) Entity(com.haulmont.cuba.core.entity.Entity) OpenType(com.haulmont.cuba.gui.WindowManager.OpenType) Table(com.haulmont.cuba.gui.components.Table) Messages(com.haulmont.cuba.core.global.Messages) SoftDelete(com.haulmont.cuba.core.entity.SoftDelete) LegacyFrame(com.haulmont.cuba.gui.screen.compatibility.LegacyFrame) DataManager(com.haulmont.cuba.core.global.DataManager) AbstractEditor(com.haulmont.cuba.gui.components.AbstractEditor) WindowManager(com.haulmont.cuba.gui.WindowManager) WindowConfig(com.haulmont.cuba.gui.config.WindowConfig) DataSupplier(com.haulmont.cuba.gui.data.DataSupplier)

Example 10 with LegacyFrame

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;
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) FrameOwner(com.haulmont.cuba.gui.screen.FrameOwner) ScreenFragment(com.haulmont.cuba.gui.screen.ScreenFragment) LegacyFrame(com.haulmont.cuba.gui.screen.compatibility.LegacyFrame) Nullable(javax.annotation.Nullable)

Aggregations

LegacyFrame (com.haulmont.cuba.gui.screen.compatibility.LegacyFrame)23 Entity (com.haulmont.cuba.core.entity.Entity)5 WindowConfig (com.haulmont.cuba.gui.config.WindowConfig)5 Datasource (com.haulmont.cuba.gui.data.Datasource)5 DsContext (com.haulmont.cuba.gui.data.DsContext)5 GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)4 MetaClass (com.haulmont.chile.core.model.MetaClass)3 DsContextImplementation (com.haulmont.cuba.gui.data.impl.DsContextImplementation)3 MetaProperty (com.haulmont.chile.core.model.MetaProperty)2 SoftDelete (com.haulmont.cuba.core.entity.SoftDelete)2 DevelopmentException (com.haulmont.cuba.core.global.DevelopmentException)2 Messages (com.haulmont.cuba.core.global.Messages)2 WindowManager (com.haulmont.cuba.gui.WindowManager)2 OpenType (com.haulmont.cuba.gui.WindowManager.OpenType)2 com.haulmont.cuba.gui.components (com.haulmont.cuba.gui.components)2 Component (com.haulmont.cuba.gui.components.Component)2 Filter (com.haulmont.cuba.gui.components.Filter)2 Frame (com.haulmont.cuba.gui.components.Frame)2 WindowInfo (com.haulmont.cuba.gui.config.WindowInfo)2 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)2