Search in sources :

Example 1 with DataComponents

use of com.haulmont.cuba.gui.model.DataComponents 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)

Aggregations

MetaClass (com.haulmont.chile.core.model.MetaClass)1 Entity (com.haulmont.cuba.core.entity.Entity)1 Lookup (com.haulmont.cuba.core.entity.annotation.Lookup)1 Metadata (com.haulmont.cuba.core.global.Metadata)1 GuiActionSupport (com.haulmont.cuba.gui.components.actions.GuiActionSupport)1 ContainerOptions (com.haulmont.cuba.gui.components.data.options.ContainerOptions)1 DataComponents (com.haulmont.cuba.gui.model.DataComponents)1