use of io.jmix.ui.model.InstanceContainer in project jmix by jmix-framework.
the class AbstractTable method clearFieldDatasources.
@SuppressWarnings("unchecked")
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);
}
}
fieldDatasources.clear();
}
use of io.jmix.ui.model.InstanceContainer in project jmix by jmix-framework.
the class DataLoadCoordinatorImpl method configureAutomatically.
private void configureAutomatically(DataLoader loader, FrameOwner frameOwner) {
List<String> queryParameters = DataLoadersHelper.getQueryParameters(loader);
List<String> allParameters = new ArrayList<>(queryParameters);
allParameters.addAll(getConditionParameters(loader));
// add triggers on container/component events
for (String parameter : allParameters) {
if (parameter.startsWith(containerPrefix)) {
InstanceContainer container = UiControllerUtils.getScreenData(frameOwner).getContainer(parameter.substring(containerPrefix.length()));
addOnContainerItemChangedLoadTrigger(loader, container, parameter);
} else if (parameter.startsWith(componentPrefix)) {
String componentId = parameter.substring(componentPrefix.length());
Component component = frameOwner instanceof Screen ? ((Screen) frameOwner).getWindow().getComponentNN(componentId) : ((ScreenFragment) frameOwner).getFragment().getComponentNN(componentId);
LikeClause likeClause = findLikeClause(loader, parameter);
addOnComponentValueChangedLoadTrigger(loader, component, parameter, likeClause);
}
}
// if the loader has no parameters in query, add trigger on BeforeShowEvent/AttachEvent
if (queryParameters.isEmpty()) {
Class eventClass = frameOwner instanceof Screen ? Screen.BeforeShowEvent.class : ScreenFragment.AttachEvent.class;
addOnFrameOwnerEventLoadTrigger(loader, eventClass);
}
}
use of io.jmix.ui.model.InstanceContainer in project jmix by jmix-framework.
the class StockChartLoader method loadDataSet.
protected void loadDataSet(DataSet dataSet, Element dataSetElement) {
loadFieldMappings(dataSet, dataSetElement);
loadStockEvents(dataSet, dataSetElement);
String id = dataSetElement.attributeValue("id");
if (StringUtils.isNotEmpty(id)) {
dataSet.setId(id);
}
checkMultipleDatasources(dataSetElement);
String categoryField = dataSetElement.attributeValue("categoryField");
if (StringUtils.isNotEmpty(categoryField)) {
dataSet.setCategoryField(categoryField);
}
String color = dataSetElement.attributeValue("color");
if (StringUtils.isNotEmpty(color)) {
dataSet.setColor(Color.valueOf(color));
}
String compared = dataSetElement.attributeValue("compared");
if (StringUtils.isNotEmpty(compared)) {
dataSet.setCompared(Boolean.valueOf(compared));
}
String dataContainerId = dataSetElement.attributeValue("dataContainer");
if (StringUtils.isNotEmpty(dataContainerId)) {
FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
ScreenData screenData = UiControllerUtils.getScreenData(frameOwner);
CollectionContainer dataContainer;
InstanceContainer container = screenData.getContainer(dataContainerId);
if (container instanceof CollectionContainer) {
dataContainer = (CollectionContainer) container;
} else {
throw new GuiDevelopmentException("Not a CollectionContainer: " + dataContainerId, context);
}
dataSet.setDataProvider(new ContainerDataProvider(dataContainer));
}
String showInCompare = dataSetElement.attributeValue("showInCompare");
if (StringUtils.isNotEmpty(showInCompare)) {
dataSet.setShowInCompare(Boolean.valueOf(showInCompare));
}
String showInSelect = dataSetElement.attributeValue("showInSelect");
if (StringUtils.isNotEmpty(showInSelect)) {
dataSet.setShowInSelect(Boolean.valueOf(showInSelect));
}
String title = dataSetElement.attributeValue("title");
if (StringUtils.isNotEmpty(title)) {
dataSet.setTitle(title);
}
}
use of io.jmix.ui.model.InstanceContainer in project jmix by jmix-framework.
the class ViewAction method isReadOnlyCompositionEditor.
/**
* In case of composition relation, editor for nested entities should be in read-only mode with hidden
* "enableEditing" action if master editor is in read-only mode too.
*
* @param editor editor to check
* @return {@code true} if the relation between entities is a composition
*/
protected boolean isReadOnlyCompositionEditor(Screen editor) {
Frame frame = target.getFrame();
if (frame == null) {
throw new IllegalStateException("Component is not attached to the Frame");
}
FrameOwner origin = target.getFrame().getFrameOwner();
if (!(origin instanceof ReadOnlyAwareScreen) || !((ReadOnlyAwareScreen) origin).isReadOnly() || !(editor instanceof StandardEditor)) {
return false;
}
DataUnit items = target.getItems();
if (!(items instanceof ContainerDataUnit)) {
return false;
}
CollectionContainer container = ((ContainerDataUnit) target.getItems()).getContainer();
if (!(container instanceof CollectionPropertyContainer)) {
return false;
}
InstanceContainer masterContainer = ((CollectionPropertyContainer) container).getMaster();
String property = ((CollectionPropertyContainer) container).getProperty();
MetaClass metaClass = masterContainer.getEntityMetaClass();
MetaProperty metaProperty = metaClass.getProperty(property);
return metaProperty.getType() == MetaProperty.Type.COMPOSITION;
}
use of io.jmix.ui.model.InstanceContainer in project jmix by jmix-framework.
the class FormLoader method loadDataContainer.
protected void loadDataContainer(Form resultComponent, Element element) {
String containerId = element.attributeValue("dataContainer");
if (!Strings.isNullOrEmpty(containerId)) {
FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
ScreenData screenData = UiControllerUtils.getScreenData(frameOwner);
InstanceContainer container = screenData.getContainer(containerId);
// noinspection unchecked
resultComponent.setValueSourceProvider(new ContainerValueSourceProvider(container));
}
}
Aggregations