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;
}
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[]
}
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();
}
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;
}
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;
}
Aggregations