use of io.jmix.ui.model.InstanceContainer in project jmix by jmix-framework.
the class TableFieldFactoryImpl method createField.
@SuppressWarnings("unchecked")
@Override
public com.vaadin.v7.ui.Field<?> createField(com.vaadin.v7.data.Container container, Object itemId, Object propertyId, Component uiContext) {
String fieldPropertyId = String.valueOf(propertyId);
Table.Column columnConf = webTable.getColumnsInternal().get(propertyId);
TableDataContainer tableDataContainer = (TableDataContainer) container;
Object entity = tableDataContainer.getInternalItem(itemId);
InstanceContainer instanceContainer = webTable.getInstanceContainer((E) entity);
io.jmix.ui.component.Component columnComponent = createField(new ContainerValueSource(instanceContainer, fieldPropertyId), fieldPropertyId, columnConf.getXmlDescriptor());
if (columnComponent instanceof Field) {
Field jmixField = (Field) columnComponent;
Map<Table.Column, String> requiredColumns = webTable.getRequiredColumnsInternal();
if (requiredColumns != null && requiredColumns.containsKey(columnConf)) {
jmixField.setRequired(true);
jmixField.setRequiredMessage(requiredColumns.get(columnConf));
}
}
if (!(columnComponent instanceof CheckBox)) {
// todo get rid of concrete CheckBox class !
columnComponent.setWidthFull();
}
if (columnComponent instanceof BelongToFrame) {
BelongToFrame belongToFrame = (BelongToFrame) columnComponent;
if (belongToFrame.getFrame() == null) {
belongToFrame.setFrame(webTable.getFrame());
}
}
applyPermissions(columnComponent);
columnComponent.setParent(webTable);
Component componentImpl = getComponentImplementation(columnComponent);
if (componentImpl instanceof com.vaadin.v7.ui.Field) {
return (com.vaadin.v7.ui.Field<?>) componentImpl;
}
return new EditableColumnFieldWrapper(componentImpl, columnComponent);
}
use of io.jmix.ui.model.InstanceContainer in project jmix by jmix-framework.
the class TableFieldFactoryImpl method findOptionsContainer.
@Nullable
protected CollectionContainer findOptionsContainer(Table.Column columnConf) {
String optDcName = columnConf.getXmlDescriptor() != null ? columnConf.getXmlDescriptor().attributeValue("optionsContainer") : null;
if (Strings.isNullOrEmpty(optDcName)) {
return null;
} else {
ScreenData screenData = UiControllerUtils.getScreenData(webTable.getFrame().getFrameOwner());
InstanceContainer container = screenData.getContainer(optDcName);
if (container instanceof CollectionContainer) {
return (CollectionContainer) container;
}
throw new IllegalStateException(String.format("'%s' is not an instance of CollectionContainer", optDcName));
}
}
use of io.jmix.ui.model.InstanceContainer in project jmix by jmix-framework.
the class AbstractComponentLoader method loadOptionsContainer.
protected Optional<CollectionContainer> loadOptionsContainer(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);
}
return Optional.of((CollectionContainer) container);
}
return Optional.empty();
}
use of io.jmix.ui.model.InstanceContainer in project jmix by jmix-framework.
the class WebTokenList method getViewForField.
/**
* If the value for a component is selected from the lookup screen there may be cases when lookup screen contains a list of entities loaded with a
* view that doesn't contain all attributes, required by the token list.
* <p>
* The method evaluates the view that was is for loading entities in the token list
*
* @return a view or null if the view cannot be evaluated
*/
@Nullable
protected FetchPlan getViewForField() {
ValueSource valueSource = getValueSource();
if (valueSource instanceof ContainerValueSource) {
ContainerValueSource containerValueSource = (ContainerValueSource) valueSource;
InstanceContainer container = containerValueSource.getContainer();
FetchPlan view = container.getFetchPlan();
if (view != null) {
MetaPropertyPath metaPropertyPath = containerValueSource.getMetaPropertyPath();
FetchPlan curView = view;
if (metaPropertyPath != null) {
for (MetaProperty metaProperty : metaPropertyPath.getMetaProperties()) {
FetchPlanProperty viewProperty = curView.getProperty(metaProperty.getName());
if (viewProperty != null) {
curView = viewProperty.getFetchPlan();
if (curView == null)
return null;
}
}
MetaProperty inverseMetaProperty = metaPropertyPath.getMetaProperty().getInverse();
if (inverseMetaProperty != null && !inverseMetaProperty.getRange().getCardinality().isMany()) {
curView = fetchPlans.builder(curView).add(inverseMetaProperty.getName()).build();
}
}
if (curView != view) {
return curView;
}
}
}
return null;
}
use of io.jmix.ui.model.InstanceContainer in project jmix by jmix-framework.
the class WebTreeTable method clearFieldDatasources.
@Override
protected void clearFieldDatasources() {
if (fieldDatasources == null) {
return;
}
// detach instance containers from entities explicitly
for (Map.Entry<Object, Object> entry : fieldDatasources.entrySet()) {
if (entry.getValue() instanceof InstanceContainer) {
InstanceContainer container = (InstanceContainer) entry.getValue();
container.setItem(null);
} else if (entry.getValue() instanceof Datasource) {
Datasource datasource = (Datasource) entry.getValue();
datasource.setItem(null);
}
}
fieldDatasources.clear();
}
Aggregations