use of io.jmix.ui.component.data.ValueSource in project jmix by jmix-framework.
the class InspectorFormBuilder method addField.
/**
* Adds field to the specified form.
* If the field should be custom, adds it to the specified customFields collection
* which can be used later to create fieldGenerators
*
* @param metaProperty meta property of the item's property which field is creating
* @param form field group to which created field will be added
*/
protected void addField(InstanceContainer container, Form form, MetaProperty metaProperty, boolean isReadonly) {
MetaClass metaClass = container.getEntityMetaClass();
Range range = metaProperty.getRange();
boolean isRequired = isRequired(metaProperty);
UiEntityAttributeContext attributeContext = new UiEntityAttributeContext(metaClass, metaProperty.getName());
accessManager.applyRegisteredConstraints(attributeContext);
if (!attributeContext.canView())
return;
if (range.isClass()) {
UiEntityContext entityContext = new UiEntityContext(range.asClass());
accessManager.applyRegisteredConstraints(entityContext);
if (!entityContext.isViewPermitted()) {
return;
}
}
ValueSource valueSource = new ContainerValueSource<>(container, metaProperty.getName());
ComponentGenerationContext componentContext = new ComponentGenerationContext(metaClass, metaProperty.getName());
componentContext.setValueSource(valueSource);
Field field = (Field) uiComponentsGenerator.generate(componentContext);
if (requireTextArea(metaProperty, getItem(), MAX_TEXTFIELD_STRING_LENGTH)) {
field = uiComponents.create(TextArea.NAME);
}
if (isBoolean(metaProperty)) {
field = createBooleanField();
}
if (range.isClass()) {
EntityPicker pickerField = uiComponents.create(EntityPicker.class);
EntityLookupAction lookupAction = actions.create(EntityLookupAction.class);
lookupAction.setScreenClass(EntityInspectorBrowser.class);
lookupAction.setScreenOptionsSupplier(() -> new MapScreenOptions(ParamsMap.of("entity", metaProperty.getRange().asClass().getName())));
lookupAction.setOpenMode(OpenMode.THIS_TAB);
pickerField.addAction(lookupAction);
pickerField.addAction(actions.create(EntityClearAction.class));
field = pickerField;
}
field.setValueSource(valueSource);
field.setCaption(getPropertyCaption(metaClass, metaProperty));
field.setRequired(isRequired);
isReadonly = isReadonly || (disabledProperties != null && disabledProperties.contains(metaProperty.getName()));
if (range.isClass() && !metadataTools.isEmbedded(metaProperty)) {
field.setEditable(metadataTools.isOwningSide(metaProperty) && !isReadonly);
} else {
field.setEditable(!isReadonly);
}
field.setWidth(fieldWidth);
if (isRequired) {
field.setRequiredMessage(messageTools.getDefaultRequiredMessage(metaClass, metaProperty.getName()));
}
form.add(field);
}
use of io.jmix.ui.component.data.ValueSource in project jmix by jmix-framework.
the class DynamicAttributesPanel method generateFieldComponent.
protected Component generateFieldComponent(AttributeDefinition attribute) {
MetaProperty metaProperty = attribute.getMetaProperty();
ValueSource valueSource = new ContainerValueSource<>(instanceContainer, metaProperty.getName());
ComponentGenerationContext componentContext = new ComponentGenerationContext(instanceContainer.getEntityMetaClass(), metaProperty.getName());
componentContext.setValueSource(valueSource);
Component resultComponent = uiComponentsGenerator.generate(componentContext);
setWidth(resultComponent, attribute);
return resultComponent;
}
use of io.jmix.ui.component.data.ValueSource in project jmix by jmix-framework.
the class GuiActionSupport method createActionsByMetaAnnotations.
public boolean createActionsByMetaAnnotations(PickerField pickerField) {
ValueSource valueSource = pickerField.getValueSource();
if (!(valueSource instanceof EntityValueSource)) {
return false;
}
EntityValueSource entityValueSource = (EntityValueSource) pickerField.getValueSource();
MetaPropertyPath mpp = entityValueSource.getMetaPropertyPath();
if (mpp == null) {
return false;
}
String[] actionIds = (String[]) metadataTools.getMetaAnnotationAttributes(mpp.getMetaProperty().getAnnotations(), Lookup.class).get("actions");
if (actionIds != null && actionIds.length > 0) {
for (String actionId : actionIds) {
createActionById(pickerField, actionId);
}
return true;
}
return false;
}
use of io.jmix.ui.component.data.ValueSource in project jmix by jmix-framework.
the class DatePickerLoader method getJavaType.
protected Class getJavaType(DatePicker resultComponent) {
ValueSource valueSource = resultComponent.getValueSource();
if (valueSource instanceof EntityValueSource) {
MetaProperty metaProperty = ((EntityValueSource) valueSource).getMetaPropertyPath().getMetaProperty();
return metaProperty.getRange().asDatatype().getJavaClass();
}
Datatype datatype = resultComponent.getDatatype();
return datatype == null ? Date.class : datatype.getJavaClass();
}
use of io.jmix.ui.component.data.ValueSource in project jmix-docs by jmix-framework.
the class ColorComponentGenerationStrategy method createComponent.
@Nullable
@Override
public Component createComponent(ComponentGenerationContext context) {
String property = context.getProperty();
MetaPropertyPath mpp = context.getMetaClass().getPropertyPath(property);
if (mpp != null) {
Range mppRange = mpp.getRange();
if (mppRange.isDatatype() && (Datatype) mppRange.asDatatype() instanceof ColorDatatype) {
ColorPicker colorPicker = uiComponents.create(ColorPicker.class);
colorPicker.setDefaultCaptionEnabled(true);
ValueSource valueSource = context.getValueSource();
if (valueSource != null) {
colorPicker.setValueSource(valueSource);
}
return colorPicker;
}
}
return null;
}
Aggregations