use of com.haulmont.cuba.gui.screen.FrameOwner in project cuba by cuba-platform.
the class CompanionDependencyInjector method getInjectedInstance.
private Object getInjectedInstance(Class<?> type, String name, AnnotatedElement element) {
if (Component.class.isAssignableFrom(type)) {
// Injecting a UI component
return frameOwner.getComponent(name);
} else if (Datasource.class.isAssignableFrom(type)) {
// Injecting a datasource
return frameOwner.getDsContext().get(name);
} else if (DsContext.class.isAssignableFrom(type)) {
// Injecting the DsContext
return frameOwner.getDsContext();
} else if (DataSupplier.class.isAssignableFrom(type)) {
// Injecting the DataSupplier
return frameOwner.getDsContext().getDataSupplier();
} else if (FrameContext.class.isAssignableFrom(type)) {
// Injecting the FrameContext
return frameOwner.getContext();
} else if (Action.class.isAssignableFrom(type)) {
// Injecting an action
return ComponentsHelper.findAction(name, frameOwner.getWrappedFrame());
} else if (ExportDisplay.class.isAssignableFrom(type)) {
// Injecting an ExportDisplay
ExportDisplay exportDisplay = beanLocator.get(ExportDisplay.NAME);
exportDisplay.setFrame(frameOwner.getWrappedFrame());
return exportDisplay;
} else if (ThemeConstants.class.isAssignableFrom(type)) {
// Injecting a Theme
ThemeConstantsManager themeManager = beanLocator.get(ThemeConstantsManager.NAME);
return themeManager.getConstants();
} else if (Logger.class == type && element instanceof Field) {
return LoggerFactory.getLogger(((Field) element).getDeclaringClass());
} else if (Config.class.isAssignableFrom(type)) {
ClientConfiguration configuration = beanLocator.get(Configuration.NAME);
// noinspection unchecked
return configuration.getConfigCached((Class<? extends Config>) type);
} else {
Object instance;
// Try to find a Spring bean
Map<String, ?> beans = beanLocator.getAll(type);
if (!beans.isEmpty()) {
instance = beans.get(name);
// If a bean with required name found, return it. Otherwise return first found.
if (instance != null)
return instance;
else
return beans.values().iterator().next();
}
// There are no Spring beans of required type - the last option is Frame
if (type.isAssignableFrom(FrameOwner.class)) {
return frameOwner;
}
return null;
}
}
use of com.haulmont.cuba.gui.screen.FrameOwner in project cuba by cuba-platform.
the class WebDataLoadCoordinator method configureAutomatically.
@Override
public void configureAutomatically() {
FrameOwner frameOwner = getFrameOwner();
ScreenData screenData = UiControllerUtils.getScreenData(frameOwner);
getUnconfiguredLoaders(screenData).forEach(loader -> configureAutomatically(loader, frameOwner));
}
use of com.haulmont.cuba.gui.screen.FrameOwner in project cuba by cuba-platform.
the class LookupBuilderProcessor method buildLookup.
@SuppressWarnings("unchecked")
public <E extends Entity> Screen buildLookup(LookupBuilder<E> builder) {
FrameOwner origin = builder.getOrigin();
Screens screens = getScreenContext(origin).getScreens();
Screen screen = createScreen(builder, screens);
if (!(screen instanceof LookupScreen)) {
throw new IllegalArgumentException(String.format("Screen %s does not implement LookupScreen: %s", screen.getId(), screen.getClass()));
}
LookupScreen<E> lookupScreen = (LookupScreen) screen;
if (builder.getField() != null) {
HasValue<E> field = builder.getField();
if (field instanceof com.haulmont.cuba.gui.components.Component.Focusable) {
screen.addAfterCloseListener(event -> {
// move focus to owner
((com.haulmont.cuba.gui.components.Component.Focusable) field).focus();
});
}
lookupScreen.setSelectHandler(items -> handleSelectionWithField(builder, field, items));
}
CollectionContainer<E> container = null;
if (builder.getListComponent() != null) {
ListComponent<E> listComponent = builder.getListComponent();
if (listComponent instanceof com.haulmont.cuba.gui.components.Component.Focusable) {
screen.addAfterCloseListener(event -> {
// move focus to owner
((com.haulmont.cuba.gui.components.Component.Focusable) listComponent).focus();
});
}
if (listComponent.getItems() instanceof ContainerDataUnit) {
container = ((ContainerDataUnit<E>) listComponent.getItems()).getContainer();
}
}
if (builder.getContainer() != null) {
container = builder.getContainer();
}
if (container != null) {
CollectionContainer<E> collectionDc = container;
lookupScreen.setSelectHandler(items -> handleSelectionWithContainer(builder, collectionDc, items));
}
if (builder.getSelectHandler() != null) {
lookupScreen.setSelectHandler(builder.getSelectHandler());
}
if (builder.getSelectValidator() != null) {
lookupScreen.setSelectValidator(builder.getSelectValidator());
}
if (builder instanceof LookupClassBuilder) {
@SuppressWarnings("unchecked") Consumer<AfterScreenCloseEvent> closeListener = ((LookupClassBuilder) builder).getCloseListener();
if (closeListener != null) {
screen.addAfterCloseListener(new AfterCloseListenerAdapter(closeListener));
}
}
return screen;
}
use of com.haulmont.cuba.gui.screen.FrameOwner in project cuba by cuba-platform.
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 extends Entity> 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 com.haulmont.cuba.gui.screen.FrameOwner in project cuba by cuba-platform.
the class ScreenBuilders method lookup.
/**
* Creates a screen builder using {@link PickerField} component.
* <p>
* Example of building a lookup screen for setting value to PickerField:
* <pre>{@code
* SomeCustomerListScreen screen = screenBuilders.lookup(customerPickerField)
* .withScreen(SomeCustomerListScreen.class)
* .build();
* }</pre>
*
* @param field {@link PickerField}, {@link LookupPickerField} or another picker component
* @param <E> type of entity
* @see #lookup(Class, FrameOwner)
*/
public <E extends Entity> LookupBuilder<E> lookup(PickerField<E> field) {
checkNotNullArgument(field);
checkNotNullArgument(field.getFrame());
FrameOwner frameOwner = field.getFrame().getFrameOwner();
Class<E> entityClass;
MetaClass metaClass = field.getMetaClass();
if (metaClass != null) {
entityClass = metaClass.getJavaClass();
} else {
throw new IllegalStateException(String.format("Component %s is not bound to meta class", field));
}
LookupBuilder<E> builder = new LookupBuilder<>(frameOwner, entityClass, lookupBuilderProcessor::buildLookup);
builder.withField(field);
return builder;
}
Aggregations