Search in sources :

Example 1 with Lookup

use of com.haulmont.cuba.core.entity.annotation.Lookup in project cuba by cuba-platform.

the class Param method createEntityLookup.

protected Component createEntityLookup(final ValueProperty valueProperty) {
    Metadata metadata = AppBeans.get(Metadata.NAME);
    MetaClass metaClass = metadata.getSession().getClassNN(javaClass);
    ThemeConstants theme = AppBeans.get(ThemeConstantsManager.class).getConstants();
    PersistenceManagerService persistenceManager = AppBeans.get(PersistenceManagerService.NAME);
    LookupType type = null;
    if (property != null && property.getRange().isClass()) {
        type = (LookupType) metadata.getTools().getMetaAnnotationAttributes(property.getAnnotations(), Lookup.class).get("type");
    }
    boolean useLookupScreen = type != null ? type == LookupType.SCREEN : persistenceManager.useLookupScreen(metaClass.getName());
    if (useLookupScreen) {
        if (inExpr) {
            ListEditor listEditor = componentsFactory.createComponent(ListEditor.class);
            listEditor.setItemType(ListEditor.ItemType.ENTITY);
            listEditor.setEntityName(metaClass.getName());
            initListEditor(listEditor, valueProperty);
            return listEditor;
        } else {
            PickerField picker = componentsFactory.createComponent(PickerField.class);
            picker.setMetaClass(metaClass);
            picker.setWidth(theme.get("cuba.gui.filter.Param.textComponent.width"));
            picker.setFrame(datasource.getDsContext().getFrameContext().getFrame());
            picker.addLookupAction();
            picker.addClearAction();
            picker.addValueChangeListener(e -> _setValue(e.getValue(), valueProperty));
            picker.setValue(_getValue(valueProperty));
            return picker;
        }
    } else {
        CollectionDatasource<Entity<Object>, Object> optionsDataSource = createOptionsDataSource(metaClass);
        if (inExpr) {
            ListEditor listEditor = componentsFactory.createComponent(ListEditor.class);
            listEditor.setItemType(ListEditor.ItemType.ENTITY);
            listEditor.setEntityName(metaClass.getName());
            listEditor.setUseLookupField(true);
            listEditor.setEntityWhereClause(entityWhere);
            initListEditor(listEditor, valueProperty);
            return listEditor;
        } else {
            final LookupPickerField lookup = componentsFactory.createComponent(LookupPickerField.class);
            lookup.addClearAction();
            lookup.setWidth(theme.get("cuba.gui.filter.Param.textComponent.width"));
            lookup.setOptionsDatasource(optionsDataSource);
            // noinspection unchecked
            optionsDataSource.addCollectionChangeListener(e -> lookup.setValue(null));
            lookup.addValueChangeListener(e -> _setValue(e.getValue(), valueProperty));
            lookup.setValue(_getValue(valueProperty));
            return lookup;
        }
    }
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) ThemeConstantsManager(com.haulmont.cuba.gui.theme.ThemeConstantsManager) LookupType(com.haulmont.cuba.core.entity.annotation.LookupType) PersistenceManagerService(com.haulmont.cuba.core.app.PersistenceManagerService) ThemeConstants(com.haulmont.cuba.gui.theme.ThemeConstants) MetaClass(com.haulmont.chile.core.model.MetaClass) Lookup(com.haulmont.cuba.core.entity.annotation.Lookup)

Aggregations

MetaClass (com.haulmont.chile.core.model.MetaClass)1 PersistenceManagerService (com.haulmont.cuba.core.app.PersistenceManagerService)1 Entity (com.haulmont.cuba.core.entity.Entity)1 Lookup (com.haulmont.cuba.core.entity.annotation.Lookup)1 LookupType (com.haulmont.cuba.core.entity.annotation.LookupType)1 ThemeConstants (com.haulmont.cuba.gui.theme.ThemeConstants)1 ThemeConstantsManager (com.haulmont.cuba.gui.theme.ThemeConstantsManager)1