use of io.jmix.ui.screen.FrameOwner 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.screen.FrameOwner 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.screen.FrameOwner 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;
}
use of io.jmix.ui.screen.FrameOwner in project jmix by jmix-framework.
the class CubaLinkCellClickListener method callControllerInvoke.
protected void callControllerInvoke(Entity rowItem, String columnId, String invokeMethodName) {
FrameOwner controller = table.getFrame().getFrameOwner();
if (controller instanceof LegacyFragmentAdapter) {
controller = ((LegacyFragmentAdapter) controller).getRealScreen();
}
Method method;
method = findLinkInvokeMethod(controller.getClass(), invokeMethodName);
if (method != null) {
try {
method.invoke(controller, rowItem, columnId);
} catch (Exception e) {
throw new RuntimeException("Unable to cal linkInvoke method for table column", e);
}
} else {
try {
method = controller.getClass().getMethod(invokeMethodName);
try {
method.invoke(controller);
} catch (Exception e1) {
throw new RuntimeException("Unable to call linkInvoke method for table column", e1);
}
} catch (NoSuchMethodException e1) {
throw new IllegalStateException(String.format("No suitable methods named %s for invoke", invokeMethodName));
}
}
}
use of io.jmix.ui.screen.FrameOwner in project jmix by jmix-framework.
the class EditorPrintFormAction method actionPerform.
@Override
public void actionPerform(Component component) {
Object entity = editor.getEditedEntity();
if (entity != null) {
MetaClass metaClass = metadata.getClass(entity);
openRunReportScreen((Screen) editor, entity, metaClass, reportOutputName);
} else {
Notifications notifications = UiControllerUtils.getScreenContext((FrameOwner) editor).getNotifications();
notifications.create().withCaption(messages.getMessage(getClass(), "notifications.noSelectedEntity")).show();
}
}
Aggregations