use of com.haulmont.cuba.gui.components.data.options.ContainerOptions 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;
}
use of com.haulmont.cuba.gui.components.data.options.ContainerOptions in project cuba by cuba-platform.
the class InputDialog method createEntityField.
@SuppressWarnings("unchecked")
protected Field createEntityField(InputParameter parameter) {
MetaClass metaClass = metadata.getClassNN(parameter.getEntityClass());
Action lookupAction = actions.create(LookupAction.ID);
Action clearAction = actions.create(ClearAction.ID);
if (persistenceManagerService.useLookupScreen(metaClass.getName())) {
PickerField pickerField = uiComponents.create(PickerField.NAME);
pickerField.setMetaClass(metadata.getClass(parameter.getEntityClass()));
pickerField.addAction(lookupAction);
pickerField.addAction(clearAction);
pickerField.setWidthFull();
return pickerField;
} else {
LookupPickerField lookupPickerField = uiComponents.create(LookupPickerField.NAME);
lookupPickerField.addAction(lookupAction);
lookupPickerField.addAction(clearAction);
lookupPickerField.setWidthFull();
CollectionContainer container = dataComponents.createCollectionContainer(parameter.getEntityClass());
CollectionLoader loader = dataComponents.createCollectionLoader();
loader.setQuery("select e from " + metaClass.getName() + " e");
loader.setView(View.MINIMAL);
loader.setContainer(container);
loader.load();
lookupPickerField.setOptions(new ContainerOptions(container));
return lookupPickerField;
}
}
use of com.haulmont.cuba.gui.components.data.options.ContainerOptions in project cuba by cuba-platform.
the class TwinColumnLoader method loadOptionsContainer.
protected void loadOptionsContainer(TwinColumn component, Element element) {
String containerId = element.attributeValue("optionsContainer");
if (containerId != null) {
FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
ScreenData screenData = UiControllerUtils.getScreenData(frameOwner);
InstanceContainer container = screenData.getContainer(containerId);
if (!(container instanceof CollectionContainer)) {
throw new GuiDevelopmentException("Not a CollectionContainer: " + containerId, context);
}
// noinspection unchecked
component.setOptions(new ContainerOptions((CollectionContainer) container));
}
}
use of com.haulmont.cuba.gui.components.data.options.ContainerOptions in project cuba by cuba-platform.
the class FormLoader method createField.
@SuppressWarnings("unchecked")
protected Field createField(Element element) {
String property = element.attributeValue("property");
if (Strings.isNullOrEmpty(property)) {
throw new GuiDevelopmentException("Field element has no 'property' attribute", context);
}
InstanceContainer container = loadContainer(element, property).orElseThrow(() -> new GuiDevelopmentException(String.format("Can't infer component for field '%s'. " + "No data container associated with it", property), context));
MetaClass metaClass = container.getEntityMetaClass();
ComponentGenerationContext context = new ComponentGenerationContext(metaClass, property);
context.setComponentClass(Form.class);
context.setValueSource(new ContainerValueSource<>(container, property));
context.setXmlDescriptor(element);
loadOptionsContainer(element).ifPresent(optionsContainer -> context.setOptions(new ContainerOptions(optionsContainer)));
Component component = getUiComponentsGenerator().generate(context);
Preconditions.checkState(component instanceof Field, "Form field '%s' must implement com.haulmont.cuba.gui.components.Field", property);
return (Field) component;
}
use of com.haulmont.cuba.gui.components.data.options.ContainerOptions in project cuba by cuba-platform.
the class TokenListLoader method loadOptionsContainer.
protected void loadOptionsContainer(TokenList component, Element element) {
String containerId = element.attributeValue("optionsContainer");
if (containerId != null) {
FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
ScreenData screenData = UiControllerUtils.getScreenData(frameOwner);
InstanceContainer container = screenData.getContainer(containerId);
if (!(container instanceof CollectionContainer)) {
throw new GuiDevelopmentException("Not a CollectionContainer: " + containerId, context);
}
// noinspection unchecked
component.setOptions(new ContainerOptions((CollectionContainer) container));
}
}
Aggregations