Search in sources :

Example 1 with EntityPicker

use of io.jmix.ui.component.EntityPicker in project jmix by jmix-framework.

the class EntityFieldCreationSupport method createEntityField.

public EntityPicker createEntityField(MetaPropertyPath metaPropertyPath, @Nullable Options options) {
    MetaClass metaClass = metaPropertyPath.getMetaProperty().getRange().asClass();
    EntityPicker field = createFieldComponent(metaClass, options);
    createFieldActions(metaClass, metaPropertyPath.getMetaProperty().getType(), field);
    return field;
}
Also used : EntityPicker(io.jmix.ui.component.EntityPicker) MetaClass(io.jmix.core.metamodel.model.MetaClass)

Example 2 with EntityPicker

use of io.jmix.ui.component.EntityPicker in project jmix-docs by Haulmont.

the class EntityPickerScreen method onInit.

// tag::on-init-start[]
@Subscribe
public void onInit(InitEvent event) {
    // end::on-init-start[]
    // tag::addAction2[]
    entityPicker.addAction(actions.create(EntityOpenAction.class));
    // end::addAction2[]
    // tag::set-entity-lookup-action[]
    entityLookupAction.setOpenMode(OpenMode.DIALOG);
    entityLookupAction.setScreenClass(CustomerBrowse.class);
    // end::set-entity-lookup-action[]
    // tag::set-entity-open-action[]
    openAction.setOpenMode(OpenMode.DIALOG);
    openAction.setScreenClass(CustomerEdit.class);
    // end::set-entity-open-action[]
    // tag::add-custom-action[]
    customerEp.addAction(new BaseAction("showLevel").withCaption(null).withDescription(null).withIcon(JmixIcon.VIEW_ACTION.source()).withHandler(e -> {
        Customer customer = customerEp.getValue();
        if (customer != null) {
            notifications.create().withCaption(customer.getFirstName() + " " + customer.getLastName() + "'s level is " + customer.getLevel()).show();
        } else {
            notifications.create().withCaption("Choose a customer").show();
        }
    }));
    // end::add-custom-action[]
    // tag::userPicker3[]
    EntityPicker<User> userPicker = uiComponents.create(EntityPicker.of(User.class));
    userPicker.setMetaClass(metadata.getClass(User.class));
    userPicker.addAction(actions.create(EntityLookupAction.class));
    userPicker.addAction(actions.create(EntityOpenAction.class));
    userPicker.addAction(actions.create(EntityClearAction.class));
    vbox.add(userPicker);
// tag::on-init-end[]
}
Also used : Customer(ui.ex1.entity.Customer) EntityOpenAction(io.jmix.ui.action.entitypicker.EntityOpenAction) Collection(java.util.Collection) Autowired(org.springframework.beans.factory.annotation.Autowired) Metadata(io.jmix.core.Metadata) ParamsMap(io.jmix.core.common.util.ParamsMap) CustomerEdit(ui.ex1.screen.entity.customer.CustomerEdit) JmixIcon(io.jmix.ui.icon.JmixIcon) HasValue(io.jmix.ui.component.HasValue) io.jmix.ui.screen(io.jmix.ui.screen) VBoxLayout(io.jmix.ui.component.VBoxLayout) CustomerBrowse(ui.ex1.screen.entity.customer.CustomerBrowse) User(ui.ex1.entity.User) Action(io.jmix.ui.action.Action) BaseAction(io.jmix.ui.action.BaseAction) EntityClearAction(io.jmix.ui.action.entitypicker.EntityClearAction) Named(javax.inject.Named) DialogAction(io.jmix.ui.action.DialogAction) MetadataTools(io.jmix.core.MetadataTools) io.jmix.ui(io.jmix.ui) EntityLookupAction(io.jmix.ui.action.entitypicker.EntityLookupAction) EntityPicker(io.jmix.ui.component.EntityPicker) User(ui.ex1.entity.User) EntityClearAction(io.jmix.ui.action.entitypicker.EntityClearAction) Customer(ui.ex1.entity.Customer) EntityLookupAction(io.jmix.ui.action.entitypicker.EntityLookupAction) BaseAction(io.jmix.ui.action.BaseAction) EntityOpenAction(io.jmix.ui.action.entitypicker.EntityOpenAction)

Example 3 with EntityPicker

use of io.jmix.ui.component.EntityPicker in project jmix by jmix-framework.

the class EntityClearAction method execute.

/**
 * Executes the action.
 */
@Override
public void execute() {
    EntityPicker entityPicker = getEntityPicker();
    // remove entity if it is a composition
    Object value = entityPicker.getValue();
    ValueSource valueSource = entityPicker.getValueSource();
    if (value != null && !value.equals(entityPicker.getEmptyValue()) && valueSource instanceof EntityValueSource) {
        EntityValueSource entityValueSource = (EntityValueSource) entityPicker.getValueSource();
        Object entity = entityPicker.getValue();
        if (entityValueSource.getMetaPropertyPath() != null && entityValueSource.getMetaPropertyPath().getMetaProperty().getType() == MetaProperty.Type.COMPOSITION) {
            FrameOwner screen = entityPicker.getFrame().getFrameOwner();
            DataContext dataContext = UiControllerUtils.getScreenData(screen).getDataContext();
            dataContext.remove(entity);
        }
    }
    super.execute();
}
Also used : EntityPicker(io.jmix.ui.component.EntityPicker) EntityValueSource(io.jmix.ui.component.data.meta.EntityValueSource) DataContext(io.jmix.ui.model.DataContext) FrameOwner(io.jmix.ui.screen.FrameOwner) ValueSource(io.jmix.ui.component.data.ValueSource) EntityValueSource(io.jmix.ui.component.data.meta.EntityValueSource)

Example 4 with EntityPicker

use of io.jmix.ui.component.EntityPicker in project jmix by jmix-framework.

the class EntityFieldCreationSupport method createFieldComponent.

protected EntityPicker createFieldComponent(MetaClass metaClass, @Nullable Options options) {
    String componentName = componentProperties.getEntityFieldType().get(metaClass.getName());
    EntityPicker field;
    if (options != null || EntityComboBox.NAME.equals(componentName)) {
        EntityComboBox entityComboBox = uiComponents.create(EntityComboBox.class);
        entityComboBox.setOptions(options != null ? options : new ContainerOptions(createCollectionContainer(metaClass)));
        field = entityComboBox;
    } else {
        if (componentName == null || EntityPicker.NAME.equals(componentName)) {
            field = uiComponents.create(EntityPicker.class);
            field.setMetaClass(metaClass);
        } else {
            EntityPicker component = uiComponents.create(componentName);
            if (component instanceof OptionsField) {
                ((OptionsField) component).setOptions(new ContainerOptions(createCollectionContainer(metaClass)));
            }
            field = component;
        }
    }
    return field;
}
Also used : ContainerOptions(io.jmix.ui.component.data.options.ContainerOptions) EntityPicker(io.jmix.ui.component.EntityPicker) EntityComboBox(io.jmix.ui.component.EntityComboBox) OptionsField(io.jmix.ui.component.OptionsField)

Example 5 with EntityPicker

use of io.jmix.ui.component.EntityPicker in project jmix by jmix-framework.

the class EntityFieldCreationSupport method createEntityField.

public EntityPicker createEntityField(MetaClass metaclass, @Nullable Options options) {
    EntityPicker field = createFieldComponent(metaclass, options);
    createFieldActions(metaclass, MetaProperty.Type.ASSOCIATION, field);
    return field;
}
Also used : EntityPicker(io.jmix.ui.component.EntityPicker)

Aggregations

EntityPicker (io.jmix.ui.component.EntityPicker)5 Metadata (io.jmix.core.Metadata)1 MetadataTools (io.jmix.core.MetadataTools)1 ParamsMap (io.jmix.core.common.util.ParamsMap)1 MetaClass (io.jmix.core.metamodel.model.MetaClass)1 io.jmix.ui (io.jmix.ui)1 Action (io.jmix.ui.action.Action)1 BaseAction (io.jmix.ui.action.BaseAction)1 DialogAction (io.jmix.ui.action.DialogAction)1 EntityClearAction (io.jmix.ui.action.entitypicker.EntityClearAction)1 EntityLookupAction (io.jmix.ui.action.entitypicker.EntityLookupAction)1 EntityOpenAction (io.jmix.ui.action.entitypicker.EntityOpenAction)1 EntityComboBox (io.jmix.ui.component.EntityComboBox)1 HasValue (io.jmix.ui.component.HasValue)1 OptionsField (io.jmix.ui.component.OptionsField)1 VBoxLayout (io.jmix.ui.component.VBoxLayout)1 ValueSource (io.jmix.ui.component.data.ValueSource)1 EntityValueSource (io.jmix.ui.component.data.meta.EntityValueSource)1 ContainerOptions (io.jmix.ui.component.data.options.ContainerOptions)1 JmixIcon (io.jmix.ui.icon.JmixIcon)1