Search in sources :

Example 1 with GuiActionSupport

use of com.haulmont.cuba.gui.components.actions.GuiActionSupport 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 GuiActionSupport

use of com.haulmont.cuba.gui.components.actions.GuiActionSupport in project cuba by cuba-platform.

the class LookupPickerFieldLoader method loadComponent.

@Override
public void loadComponent() {
    super.loadComponent();
    LookupPickerField lookupPickerField = (LookupPickerField) resultComponent;
    String metaClass = element.attributeValue("metaClass");
    if (!StringUtils.isEmpty(metaClass)) {
        lookupPickerField.setMetaClass(getMetadata().getClass(metaClass));
    }
    loadActions(lookupPickerField, element);
    if (lookupPickerField.getActions().isEmpty()) {
        GuiActionSupport guiActionSupport = getGuiActionSupport();
        boolean actionsByMetaAnnotations = guiActionSupport.createActionsByMetaAnnotations(lookupPickerField);
        if (!actionsByMetaAnnotations) {
            if (isLegacyFrame()) {
                lookupPickerField.addLookupAction();
                lookupPickerField.addClearAction();
            } else {
                Actions actions = getActions();
                lookupPickerField.addAction(actions.create(LookupAction.ID));
                lookupPickerField.addAction(actions.create(ClearAction.ID));
            }
        }
    }
    String refreshOptionsOnLookupClose = element.attributeValue("refreshOptionsOnLookupClose");
    if (refreshOptionsOnLookupClose != null) {
        lookupPickerField.setRefreshOptionsOnLookupClose(Boolean.parseBoolean(refreshOptionsOnLookupClose));
    }
}
Also used : LookupPickerField(com.haulmont.cuba.gui.components.LookupPickerField) Actions(com.haulmont.cuba.gui.components.Actions) GuiActionSupport(com.haulmont.cuba.gui.components.actions.GuiActionSupport)

Example 3 with GuiActionSupport

use of com.haulmont.cuba.gui.components.actions.GuiActionSupport in project cuba by cuba-platform.

the class PickerFieldLoader method loadComponent.

@Override
public void loadComponent() {
    super.loadComponent();
    loadTabIndex(resultComponent, element);
    String captionProperty = element.attributeValue("captionProperty");
    if (!StringUtils.isEmpty(captionProperty)) {
        resultComponent.setCaptionMode(CaptionMode.PROPERTY);
        resultComponent.setCaptionProperty(captionProperty);
    }
    final String metaClass = element.attributeValue("metaClass");
    if (!StringUtils.isEmpty(metaClass)) {
        resultComponent.setMetaClass(getMetadata().getClassNN(metaClass));
    }
    loadActions(resultComponent, element);
    if (resultComponent.getActions().isEmpty()) {
        GuiActionSupport guiActionSupport = getGuiActionSupport();
        boolean actionsByMetaAnnotations = guiActionSupport.createActionsByMetaAnnotations(resultComponent);
        if (!actionsByMetaAnnotations) {
            if (isLegacyFrame()) {
                resultComponent.addLookupAction();
                resultComponent.addClearAction();
            } else {
                Actions actions = getActions();
                resultComponent.addAction(actions.create(LookupAction.ID));
                resultComponent.addAction(actions.create(ClearAction.ID));
            }
        }
    }
    loadBuffered(resultComponent, element);
}
Also used : GuiActionSupport(com.haulmont.cuba.gui.components.actions.GuiActionSupport)

Aggregations

GuiActionSupport (com.haulmont.cuba.gui.components.actions.GuiActionSupport)3 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 Actions (com.haulmont.cuba.gui.components.Actions)1 LookupPickerField (com.haulmont.cuba.gui.components.LookupPickerField)1 ContainerOptions (com.haulmont.cuba.gui.components.data.options.ContainerOptions)1 DataComponents (com.haulmont.cuba.gui.model.DataComponents)1