use of com.haulmont.cuba.gui.components.data.meta.EntityDataUnit in project cuba by cuba-platform.
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 extends Entity> 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;
}
use of com.haulmont.cuba.gui.components.data.meta.EntityDataUnit in project cuba by cuba-platform.
the class ViewAction method isPermitted.
@Override
protected boolean isPermitted() {
if (target == null || !(target.getItems() instanceof EntityDataUnit)) {
return false;
}
MetaClass metaClass = ((EntityDataUnit) target.getItems()).getEntityMetaClass();
if (metaClass == null) {
return true;
}
boolean entityOpPermitted = security.isEntityOpPermitted(metaClass, EntityOp.READ);
if (!entityOpPermitted) {
return false;
}
return super.isPermitted();
}
use of com.haulmont.cuba.gui.components.data.meta.EntityDataUnit in project cuba by cuba-platform.
the class ViewAction method execute.
/**
* Executes the action.
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void execute() {
if (target == null) {
throw new IllegalStateException("ViewAction target is not set");
}
if (!(target.getItems() instanceof EntityDataUnit)) {
throw new IllegalStateException("ViewAction target dataSource is null or does not implement EntityDataUnit");
}
MetaClass metaClass = ((EntityDataUnit) target.getItems()).getEntityMetaClass();
if (metaClass == null) {
throw new IllegalStateException("Target is not bound to entity");
}
Entity editedEntity = target.getSingleSelected();
if (editedEntity == null) {
throw new IllegalStateException("There is not selected item in ViewAction target");
}
EditorBuilder builder = screenBuilders.editor(target).editEntity(editedEntity);
builder = screenInitializer.initBuilder(builder);
if (transformation != null) {
builder.withTransformation(transformation);
}
Screen editor = builder.build();
if (afterCommitHandler != null) {
editor.addAfterCloseListener(afterCloseEvent -> {
CloseAction closeAction = afterCloseEvent.getCloseAction();
if (closeAction.equals(WINDOW_COMMIT_AND_CLOSE_ACTION)) {
Entity committedEntity = ((EditorScreen) editor).getEditedEntity();
afterCommitHandler.accept((E) committedEntity);
}
});
}
screenInitializer.initScreen(editor);
if (editor instanceof ReadOnlyAwareScreen) {
((ReadOnlyAwareScreen) editor).setReadOnly(true);
} else {
throw new IllegalStateException(String.format("Screen '%s' does not implement ReadOnlyAwareScreen: %s", editor.getId(), editor.getClass()));
}
editor.show();
}
use of com.haulmont.cuba.gui.components.data.meta.EntityDataUnit in project cuba by cuba-platform.
the class BulkEditAction method execute.
/**
* Executes the action.
*/
@SuppressWarnings("unchecked")
@Override
public void execute() {
if (!(target.getItems() instanceof EntityDataUnit)) {
throw new IllegalStateException("BulkEditAction target Items is null " + "or does not implement EntityDataUnit");
}
MetaClass metaClass = ((EntityDataUnit) target.getItems()).getEntityMetaClass();
if (metaClass == null) {
throw new IllegalStateException("Target is not bound to entity");
}
if (!security.isSpecificPermitted(BulkEditor.PERMISSION)) {
Notifications notifications = getScreenContext(target.getFrame()).getNotifications();
notifications.create(NotificationType.ERROR).withCaption(messages.getMainMessage("accessDenied.message")).show();
return;
}
if (target.getSelected().isEmpty()) {
Notifications notifications = getScreenContext(target.getFrame()).getNotifications();
notifications.create(NotificationType.ERROR).withCaption(messages.getMainMessage("actions.BulkEdit.emptySelection")).show();
return;
}
Window window = ComponentsHelper.getWindowNN(target);
BulkEditors.EditorBuilder builder = bulkEditors.builder(metaClass, target.getSelected(), window.getFrameOwner()).withListComponent(target);
if (columnsMode != null) {
builder = builder.withColumnsMode(columnsMode);
}
if (exclude != null) {
builder = builder.withExclude(exclude);
}
if (fieldSorter != null) {
builder = builder.withFieldSorter(fieldSorter);
}
if (includeProperties != null) {
builder = builder.withIncludeProperties(includeProperties);
}
if (openMode != null) {
builder = builder.withLaunchMode(openMode);
}
if (loadDynamicAttributes != null) {
builder = builder.withLoadDynamicAttributes(loadDynamicAttributes);
}
if (useConfirmDialog != null) {
builder = builder.withUseConfirmDialog(useConfirmDialog);
}
builder.create().show();
}
use of com.haulmont.cuba.gui.components.data.meta.EntityDataUnit in project cuba by cuba-platform.
the class AddToSetAction method actionPerform.
@Override
public void actionPerform(Component component) {
MetaClass entityMetaClass;
if (target.getItems() instanceof EntityDataUnit) {
entityMetaClass = ((EntityDataUnit) target.getItems()).getEntityMetaClass();
} else {
throw new UnsupportedOperationException("Unsupported data unit " + target.getItems());
}
String query;
if (filter.getDatasource() != null) {
query = filter.getDatasource().getQuery();
} else {
query = filter.getDataLoader().getQuery();
}
String[] strings = ValuePathHelper.parse(ComponentsHelper.getFilterComponentPath(filter));
String componentId = ValuePathHelper.pathSuffix(strings);
Set ownerSelection = target.getSelected();
Map<String, Object> params = new HashMap<>();
params.put("entityType", entityMetaClass.getName());
params.put("items", ownerSelection);
params.put("componentPath", ComponentsHelper.getFilterComponentPath(filter));
params.put("componentId", componentId);
params.put("foldersPane", filterHelper.getFoldersPane());
params.put("entityClass", entityMetaClass.getJavaClass().getName());
params.put("query", query);
Screens screens = ComponentsHelper.getScreenContext(filter).getScreens();
screens.create("saveSetInFolder", OpenMode.DIALOG, new MapScreenOptions(params)).show();
}
Aggregations