Search in sources :

Example 1 with ContainerOptions

use of com.haulmont.cuba.gui.components.data.options.ContainerOptions in project cuba by cuba-platform.

the class BulkEditorFieldFactory method createEntityField.

protected Field createEntityField(Datasource datasource, MetaProperty property) {
    Lookup lookup = property.getAnnotatedElement().getAnnotation(Lookup.class);
    if (lookup != null && lookup.type() == LookupType.DROPDOWN) {
        DataComponents dataComponents = AppBeans.get(DataComponents.class);
        Metadata metadata = AppBeans.get(Metadata.class);
        MetaClass metaClass = metadata.getClassNN(property.getJavaType());
        CollectionContainer<Entity> container = dataComponents.createCollectionContainer(metaClass.getJavaClass());
        CollectionLoader<Entity> loader = dataComponents.createCollectionLoader();
        loader.setQuery("select e from " + metaClass.getName() + " e");
        loader.setView(View.MINIMAL);
        loader.setContainer(container);
        loader.load();
        LookupPickerField<Entity> lookupPickerField = componentsFactory.createComponent(LookupPickerField.NAME);
        lookupPickerField.setDatasource(datasource, property.getName());
        lookupPickerField.setOptions(new ContainerOptions(container));
        GuiActionSupport guiActionSupport = AppBeans.get(GuiActionSupport.NAME);
        guiActionSupport.createActionsByMetaAnnotations(lookupPickerField);
        return lookupPickerField;
    }
    PickerField<Entity> pickerField = componentsFactory.createComponent(PickerField.NAME);
    pickerField.setDatasource(datasource, property.getName());
    GuiActionSupport guiActionSupport = AppBeans.get(GuiActionSupport.NAME);
    guiActionSupport.createActionById(pickerField, PickerField.ActionType.LOOKUP.getId());
    if (lookup == null || !guiActionSupport.createActionsByMetaAnnotations(pickerField)) {
        guiActionSupport.createActionById(pickerField, PickerField.ActionType.CLEAR.getId());
    }
    return pickerField;
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) ContainerOptions(com.haulmont.cuba.gui.components.data.options.ContainerOptions) MetaClass(com.haulmont.chile.core.model.MetaClass) Metadata(com.haulmont.cuba.core.global.Metadata) Lookup(com.haulmont.cuba.core.entity.annotation.Lookup) GuiActionSupport(com.haulmont.cuba.gui.components.actions.GuiActionSupport) DataComponents(com.haulmont.cuba.gui.model.DataComponents)

Example 2 with ContainerOptions

use of com.haulmont.cuba.gui.components.data.options.ContainerOptions in project cuba by cuba-platform.

the class InputDialog method createEntityField.

@SuppressWarnings("unchecked")
protected Field createEntityField(InputParameter parameter) {
    MetaClass metaClass = metadata.getClassNN(parameter.getEntityClass());
    Action lookupAction = actions.create(LookupAction.ID);
    Action clearAction = actions.create(ClearAction.ID);
    if (persistenceManagerService.useLookupScreen(metaClass.getName())) {
        PickerField pickerField = uiComponents.create(PickerField.NAME);
        pickerField.setMetaClass(metadata.getClass(parameter.getEntityClass()));
        pickerField.addAction(lookupAction);
        pickerField.addAction(clearAction);
        pickerField.setWidthFull();
        return pickerField;
    } else {
        LookupPickerField lookupPickerField = uiComponents.create(LookupPickerField.NAME);
        lookupPickerField.addAction(lookupAction);
        lookupPickerField.addAction(clearAction);
        lookupPickerField.setWidthFull();
        CollectionContainer container = dataComponents.createCollectionContainer(parameter.getEntityClass());
        CollectionLoader loader = dataComponents.createCollectionLoader();
        loader.setQuery("select e from " + metaClass.getName() + " e");
        loader.setView(View.MINIMAL);
        loader.setContainer(container);
        loader.load();
        lookupPickerField.setOptions(new ContainerOptions(container));
        return lookupPickerField;
    }
}
Also used : ContainerOptions(com.haulmont.cuba.gui.components.data.options.ContainerOptions) LookupAction(com.haulmont.cuba.gui.actions.picker.LookupAction) ClearAction(com.haulmont.cuba.gui.actions.picker.ClearAction) InputDialogAction(com.haulmont.cuba.gui.components.inputdialog.InputDialogAction) CollectionLoader(com.haulmont.cuba.gui.model.CollectionLoader) MetaClass(com.haulmont.chile.core.model.MetaClass) CollectionContainer(com.haulmont.cuba.gui.model.CollectionContainer)

Example 3 with ContainerOptions

use of com.haulmont.cuba.gui.components.data.options.ContainerOptions in project cuba by cuba-platform.

the class TwinColumnLoader method loadOptionsContainer.

protected void loadOptionsContainer(TwinColumn component, 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);
        }
        // noinspection unchecked
        component.setOptions(new ContainerOptions((CollectionContainer) container));
    }
}
Also used : ContainerOptions(com.haulmont.cuba.gui.components.data.options.ContainerOptions) FrameOwner(com.haulmont.cuba.gui.screen.FrameOwner) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) InstanceContainer(com.haulmont.cuba.gui.model.InstanceContainer) CollectionContainer(com.haulmont.cuba.gui.model.CollectionContainer) ScreenData(com.haulmont.cuba.gui.model.ScreenData)

Example 4 with ContainerOptions

use of com.haulmont.cuba.gui.components.data.options.ContainerOptions in project cuba by cuba-platform.

the class FormLoader method createField.

@SuppressWarnings("unchecked")
protected Field createField(Element element) {
    String property = element.attributeValue("property");
    if (Strings.isNullOrEmpty(property)) {
        throw new GuiDevelopmentException("Field element has no 'property' attribute", context);
    }
    InstanceContainer container = loadContainer(element, property).orElseThrow(() -> new GuiDevelopmentException(String.format("Can't infer component for field '%s'. " + "No data container associated with it", property), context));
    MetaClass metaClass = container.getEntityMetaClass();
    ComponentGenerationContext context = new ComponentGenerationContext(metaClass, property);
    context.setComponentClass(Form.class);
    context.setValueSource(new ContainerValueSource<>(container, property));
    context.setXmlDescriptor(element);
    loadOptionsContainer(element).ifPresent(optionsContainer -> context.setOptions(new ContainerOptions(optionsContainer)));
    Component component = getUiComponentsGenerator().generate(context);
    Preconditions.checkState(component instanceof Field, "Form field '%s' must implement com.haulmont.cuba.gui.components.Field", property);
    return (Field) component;
}
Also used : ContainerOptions(com.haulmont.cuba.gui.components.data.options.ContainerOptions) MetaClass(com.haulmont.chile.core.model.MetaClass) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException)

Example 5 with ContainerOptions

use of com.haulmont.cuba.gui.components.data.options.ContainerOptions in project cuba by cuba-platform.

the class TokenListLoader method loadOptionsContainer.

protected void loadOptionsContainer(TokenList component, 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);
        }
        // noinspection unchecked
        component.setOptions(new ContainerOptions((CollectionContainer) container));
    }
}
Also used : ContainerOptions(com.haulmont.cuba.gui.components.data.options.ContainerOptions) FrameOwner(com.haulmont.cuba.gui.screen.FrameOwner) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) InstanceContainer(com.haulmont.cuba.gui.model.InstanceContainer) CollectionContainer(com.haulmont.cuba.gui.model.CollectionContainer) ScreenData(com.haulmont.cuba.gui.model.ScreenData)

Aggregations

ContainerOptions (com.haulmont.cuba.gui.components.data.options.ContainerOptions)8 MetaClass (com.haulmont.chile.core.model.MetaClass)6 CollectionContainer (com.haulmont.cuba.gui.model.CollectionContainer)5 Entity (com.haulmont.cuba.core.entity.Entity)3 Lookup (com.haulmont.cuba.core.entity.annotation.Lookup)3 GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)3 CategoryAttribute (com.haulmont.cuba.core.entity.CategoryAttribute)2 DatasourceOptions (com.haulmont.cuba.gui.components.data.options.DatasourceOptions)2 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)2 CollectionLoader (com.haulmont.cuba.gui.model.CollectionLoader)2 DataComponents (com.haulmont.cuba.gui.model.DataComponents)2 Nullable (javax.annotation.Nullable)2 Strings (com.google.common.base.Strings)1 ImmutableList (com.google.common.collect.ImmutableList)1 EventHub (com.haulmont.bali.events.EventHub)1 Subscription (com.haulmont.bali.events.Subscription)1 ParamsMap (com.haulmont.bali.util.ParamsMap)1 Datatype (com.haulmont.chile.core.datatypes.Datatype)1 DatatypeRegistry (com.haulmont.chile.core.datatypes.DatatypeRegistry)1 Datatypes (com.haulmont.chile.core.datatypes.Datatypes)1