use of io.jmix.ui.component.data.DataUnit 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.component.data.DataUnit in project jmix by jmix-framework.
the class AbstractDataGrid method setupPaginationDataSourceProvider.
public void setupPaginationDataSourceProvider() {
if (pagination == null) {
return;
}
DataUnit items = getItems();
PaginationDataBinder provider;
if (items instanceof ContainerDataUnit) {
provider = applicationContext.getBean(PaginationDataUnitBinder.class, items);
} else if (items instanceof EmptyDataUnit && items instanceof EntityDataUnit) {
provider = new PaginationEmptyBinder(((EntityDataUnit) items).getEntityMetaClass());
} else {
throw new IllegalStateException("Unsupported data unit type: " + items);
}
pagination.setDataBinder(provider);
}
use of io.jmix.ui.component.data.DataUnit in project jmix by jmix-framework.
the class RemoveOperation method builder.
/**
* Creates a remove builder using list component, e.g. {@link Table} or {@link DataGrid}.
*
* @param listComponent list component
* @param <E> type of entity
*/
public <E> RemoveBuilder<E> builder(ListComponent<E> listComponent) {
checkNotNullArgument(listComponent);
checkNotNullArgument(listComponent.getFrame());
FrameOwner frameOwner = listComponent.getFrame().getFrameOwner();
Class<E> entityClass;
DataUnit items = listComponent.getItems();
if (items instanceof ContainerDataUnit) {
entityClass = ((ContainerDataUnit) items).getEntityMetaClass().getJavaClass();
} else {
throw new IllegalStateException(String.format("Component %s is not bound to data", listComponent));
}
return builder(entityClass, frameOwner).withListComponent(listComponent);
}
use of io.jmix.ui.component.data.DataUnit in project jmix by jmix-framework.
the class ScreenBuilders method lookup.
/**
* Creates a screen builder using list component.
* <p>
* Example of building a lookup screen for adding row to table / tree component:
* <pre>{@code
* SomeCustomerListScreen screen = screenBuilders.lookup(customersTable)
* .withScreen(SomeCustomerListScreen.class)
* .build();
* }</pre>
*
* @param listComponent {@link Table}, {@link DataGrid} or another component containing the list of entities
* @param <E> type of entity
* @see #lookup(Class, FrameOwner)
*/
public <E> LookupBuilder<E> lookup(ListComponent<E> listComponent) {
checkNotNullArgument(listComponent);
checkNotNullArgument(listComponent.getFrame());
FrameOwner frameOwner = listComponent.getFrame().getFrameOwner();
Class<E> entityClass;
DataUnit items = listComponent.getItems();
if (items instanceof EntityDataUnit) {
entityClass = ((EntityDataUnit) items).getEntityMetaClass().getJavaClass();
} else {
throw new IllegalStateException(String.format("Component %s is not bound to data", listComponent));
}
LookupBuilder<E> builder = new LookupBuilder<>(frameOwner, entityClass, lookupBuilderProcessor::buildLookup);
builder.withListComponent(listComponent);
return builder;
}
use of io.jmix.ui.component.data.DataUnit in project jmix by jmix-framework.
the class ScreenBuilders method editor.
/**
* Creates a screen builder using list component.
* <p>
* Example of building a screen for editing a currently selected entity:
* <pre>{@code
* SomeCustomerEditor screen = screenBuilders.editor(customersTable)
* .withScreen(SomeCustomerEditor.class)
* .build();
* }</pre>
* <p>
* Example of building a screen for creating a new entity instance:
* <pre>{@code
* SomeCustomerEditor screen = screenBuilders.editor(customersTable)
* .withScreen(SomeCustomerEditor.class)
* .newEntity()
* .build();
* }</pre>
*
* @param listComponent {@link Table}, {@link DataGrid} or another component containing the list of entities
* @see #editor(Class, FrameOwner)
*/
public <E> EditorBuilder<E> editor(ListComponent<E> listComponent) {
checkNotNullArgument(listComponent);
checkNotNullArgument(listComponent.getFrame());
FrameOwner frameOwner = listComponent.getFrame().getFrameOwner();
Class<E> entityClass;
DataUnit items = listComponent.getItems();
if (items instanceof EntityDataUnit) {
entityClass = ((EntityDataUnit) items).getEntityMetaClass().getJavaClass();
} else {
throw new IllegalStateException(String.format("Component %s is not bound to data", listComponent));
}
EditorBuilder<E> builder = new EditorBuilder<>(frameOwner, entityClass, editorBuilderProcessor::buildEditor);
builder.withListComponent(listComponent);
builder.editEntity(listComponent.getSingleSelected());
return builder;
}
Aggregations