Search in sources :

Example 11 with FrameOwner

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;
    }
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) Action(com.haulmont.cuba.gui.components.Action) ThemeConstantsManager(com.haulmont.cuba.gui.theme.ThemeConstantsManager) Config(com.haulmont.cuba.core.config.Config) Logger(org.slf4j.Logger) ThemeConstants(com.haulmont.cuba.gui.theme.ThemeConstants) Field(java.lang.reflect.Field) FrameOwner(com.haulmont.cuba.gui.screen.FrameOwner) DataSupplier(com.haulmont.cuba.gui.data.DataSupplier) ExportDisplay(com.haulmont.cuba.gui.export.ExportDisplay) ClientConfiguration(com.haulmont.cuba.client.ClientConfiguration)

Example 12 with FrameOwner

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));
}
Also used : FrameOwner(com.haulmont.cuba.gui.screen.FrameOwner) ScreenData(com.haulmont.cuba.gui.model.ScreenData)

Example 13 with 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;
}
Also used : LookupScreen(com.haulmont.cuba.gui.screen.LookupScreen) Screen(com.haulmont.cuba.gui.screen.Screen) LookupScreen(com.haulmont.cuba.gui.screen.LookupScreen) Screens(com.haulmont.cuba.gui.Screens) FrameOwner(com.haulmont.cuba.gui.screen.FrameOwner) ContainerDataUnit(com.haulmont.cuba.gui.components.data.meta.ContainerDataUnit)

Example 14 with FrameOwner

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;
}
Also used : DataUnit(com.haulmont.cuba.gui.components.data.DataUnit) EntityDataUnit(com.haulmont.cuba.gui.components.data.meta.EntityDataUnit) FrameOwner(com.haulmont.cuba.gui.screen.FrameOwner) EntityDataUnit(com.haulmont.cuba.gui.components.data.meta.EntityDataUnit)

Example 15 with FrameOwner

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;
}
Also used : FrameOwner(com.haulmont.cuba.gui.screen.FrameOwner) MetaClass(com.haulmont.chile.core.model.MetaClass)

Aggregations

FrameOwner (com.haulmont.cuba.gui.screen.FrameOwner)38 GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)15 ScreenData (com.haulmont.cuba.gui.model.ScreenData)9 Component (com.haulmont.cuba.gui.components.Component)7 InstanceContainer (com.haulmont.cuba.gui.model.InstanceContainer)7 Element (org.dom4j.Element)7 LegacyFragmentAdapter (com.haulmont.cuba.gui.components.compatibility.LegacyFragmentAdapter)6 CollectionContainer (com.haulmont.cuba.gui.model.CollectionContainer)6 ScreenFragment (com.haulmont.cuba.gui.screen.ScreenFragment)6 Method (java.lang.reflect.Method)6 MetaClass (com.haulmont.chile.core.model.MetaClass)5 Frame (com.haulmont.cuba.gui.components.Frame)5 Datasource (com.haulmont.cuba.gui.data.Datasource)5 WindowInfo (com.haulmont.cuba.gui.config.WindowInfo)4 Screen (com.haulmont.cuba.gui.screen.Screen)4 Fragment (com.haulmont.cuba.gui.components.Fragment)3 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)3 LegacyFrame (com.haulmont.cuba.gui.screen.compatibility.LegacyFrame)3 Screens (com.haulmont.cuba.gui.Screens)2 FragmentImplementation (com.haulmont.cuba.gui.components.sys.FragmentImplementation)2