Search in sources :

Example 21 with FrameOwner

use of com.haulmont.cuba.gui.screen.FrameOwner in project cuba by cuba-platform.

the class ScreenBuilderProcessor method buildScreen.

@SuppressWarnings("unchecked")
public Screen buildScreen(ScreenBuilder builder) {
    FrameOwner origin = builder.getOrigin();
    Screens screens = getScreenContext(origin).getScreens();
    Screen screen;
    if (builder instanceof ScreenClassBuilder) {
        ScreenClassBuilder screenClassBuilder = (ScreenClassBuilder) builder;
        Class screenClass = screenClassBuilder.getScreenClass();
        if (screenClass == null) {
            throw new IllegalArgumentException("Screen class is not set");
        }
        screen = screens.create(screenClass, builder.getLaunchMode(), builder.getOptions());
        @SuppressWarnings("unchecked") Consumer<AfterScreenCloseEvent> closeListener = screenClassBuilder.getCloseListener();
        if (closeListener != null) {
            screen.addAfterCloseListener(new AfterCloseListenerAdapter(closeListener));
        }
    } else {
        if (builder.getScreenId() == null) {
            throw new IllegalArgumentException("Screen id is not set");
        }
        screen = screens.create(builder.getScreenId(), builder.getLaunchMode(), builder.getOptions());
    }
    return screen;
}
Also used : FrameOwner(com.haulmont.cuba.gui.screen.FrameOwner) Screen(com.haulmont.cuba.gui.screen.Screen) Screens(com.haulmont.cuba.gui.Screens)

Example 22 with FrameOwner

use of com.haulmont.cuba.gui.screen.FrameOwner in project cuba by cuba-platform.

the class ClearAction method execute.

/**
 * Executes the action.
 */
@SuppressWarnings("unchecked")
@Override
public void execute() {
    // remove entity if it is a composition
    Object value = pickerField.getValue();
    ValueSource valueSource = pickerField.getValueSource();
    if (value != null && !value.equals(pickerField.getEmptyValue()) && valueSource instanceof EntityValueSource) {
        EntityValueSource entityValueSource = (EntityValueSource) pickerField.getValueSource();
        Entity entity = (Entity) pickerField.getValue();
        if (entityValueSource.getMetaPropertyPath() != null && entityValueSource.getMetaPropertyPath().getMetaProperty().getType() == MetaProperty.Type.COMPOSITION) {
            FrameOwner screen = pickerField.getFrame().getFrameOwner();
            DataContext dataContext = UiControllerUtils.getScreenData(screen).getDataContext();
            dataContext.remove(entity);
        }
    }
    // Set the value as if the user had set it
    pickerField.setValueFromUser(pickerField.getEmptyValue());
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) EntityValueSource(com.haulmont.cuba.gui.components.data.meta.EntityValueSource) DataContext(com.haulmont.cuba.gui.model.DataContext) FrameOwner(com.haulmont.cuba.gui.screen.FrameOwner) ValueSource(com.haulmont.cuba.gui.components.data.ValueSource) EntityValueSource(com.haulmont.cuba.gui.components.data.meta.EntityValueSource)

Example 23 with FrameOwner

use of com.haulmont.cuba.gui.screen.FrameOwner 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;
}
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 24 with FrameOwner

use of com.haulmont.cuba.gui.screen.FrameOwner in project cuba by cuba-platform.

the class ScreenBuilders method editor.

/**
 * Creates a screen builder using {@link PickerField} component.
 * <p>
 * Example of building a screen for editing a currently set value:
 * <pre>{@code
 * SomeCustomerEditor screen = screenBuilders.editor(customerPickerField)
 *          .withScreen(SomeCustomerEditor.class)
 *          .build();
 * }</pre>
 * <p>
 * Example of building a screen for creating a new entity instance:
 * <pre>{@code
 * SomeCustomerEditor screen = screenBuilders.editor(customerPickerField)
 *          .withScreen(SomeCustomerEditor.class)
 *          .newEntity()
 *          .build();
 * }</pre>
 *
 * @param field {@link PickerField}, {@link LookupPickerField} or another picker component
 * @see #editor(Class, FrameOwner)
 */
public <E extends Entity> EditorBuilder<E> editor(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));
    }
    EditorBuilder<E> builder = new EditorBuilder<>(frameOwner, entityClass, editorBuilderProcessor::buildEditor);
    builder.withField(field);
    builder.editEntity(field.getValue());
    return builder;
}
Also used : FrameOwner(com.haulmont.cuba.gui.screen.FrameOwner) MetaClass(com.haulmont.chile.core.model.MetaClass)

Example 25 with FrameOwner

use of com.haulmont.cuba.gui.screen.FrameOwner in project cuba by cuba-platform.

the class ScreensHelper method isEntityAvailable.

protected boolean isEntityAvailable(Element window, Class<? extends FrameOwner> controllerClass, Class entityClass, ScreenType filterScreenType, boolean useComplexSearch) {
    Element dsContext = window.element("dsContext");
    Element data = window.element("data");
    if (dsContext == null && data == null) {
        return false;
    }
    Element dataElement = data != null ? data : dsContext;
    if (!useComplexSearch) {
        String dataElementId = data != null ? getDataContainerId(window, controllerClass, filterScreenType) : getDatasourceId(window, filterScreenType);
        if (StringUtils.isEmpty(dataElementId)) {
            return false;
        }
        return isEntityAvailableInDataElement(entityClass, dataElement, dataElementId);
    }
    if (!checkWindowType(controllerClass, filterScreenType)) {
        return false;
    }
    List<Element> dataElements = dataElement.elements();
    List<String> dataElementIds = dataElements.stream().filter(de -> isEntityAvailableInDataElement(entityClass, de)).map(de -> de.attributeValue("id")).collect(Collectors.toList());
    if (!ScreenType.BROWSER.equals(filterScreenType)) {
        String editedEntityDataElementId = data != null ? resolveEditedEntityContainerId(controllerClass) : window.attributeValue("datasource");
        dataElementIds.addAll(getDataElementsIdForComposition(dataElement, entityClass, editedEntityDataElementId));
    }
    return dataElementIds.size() > 0;
}
Also used : Fragment(com.haulmont.cuba.gui.components.Fragment) Document(org.dom4j.Document) java.util(java.util) RowsCount(com.haulmont.cuba.gui.components.RowsCount) Dom4jTools(com.haulmont.cuba.core.sys.xmlparsing.Dom4jTools) ReflectionHelper(com.haulmont.bali.util.ReflectionHelper) Table(com.haulmont.cuba.gui.components.Table) LoggerFactory(org.slf4j.LoggerFactory) StringUtils(org.apache.commons.lang3.StringUtils) MetaClass(com.haulmont.chile.core.model.MetaClass) Metadata(com.haulmont.cuba.core.global.Metadata) Inject(javax.inject.Inject) Strings(com.google.common.base.Strings) MetadataTools(com.haulmont.cuba.core.global.MetadataTools) ImmutableList(com.google.common.collect.ImmutableList) Window(com.haulmont.cuba.gui.components.Window) EditedEntityContainer(com.haulmont.cuba.gui.screen.EditedEntityContainer) LayoutLoaderConfig(com.haulmont.cuba.gui.xml.layout.LayoutLoaderConfig) XmlInheritanceProcessor(com.haulmont.cuba.gui.xml.XmlInheritanceProcessor) FieldGroup(com.haulmont.cuba.gui.components.FieldGroup) Nullable(javax.annotation.Nullable) Frame(com.haulmont.cuba.gui.components.Frame) Collections.emptyMap(java.util.Collections.emptyMap) ScreenComponentDescriptor(com.haulmont.cuba.gui.components.ScreenComponentDescriptor) WindowInfo(com.haulmont.cuba.gui.config.WindowInfo) Logger(org.slf4j.Logger) ImmutableMap(com.google.common.collect.ImmutableMap) Form(com.haulmont.cuba.gui.components.Form) MetaProperty(com.haulmont.chile.core.model.MetaProperty) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) FrameOwner(com.haulmont.cuba.gui.screen.FrameOwner) LookupComponent(com.haulmont.cuba.gui.screen.LookupComponent) UserSessionSource(com.haulmont.cuba.core.global.UserSessionSource) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) ComponentLoader(com.haulmont.cuba.gui.xml.layout.ComponentLoader) Component(org.springframework.stereotype.Component) Resources(com.haulmont.cuba.core.global.Resources) WindowConfig(com.haulmont.cuba.gui.config.WindowConfig) BeanLocator(com.haulmont.cuba.core.global.BeanLocator) Element(org.dom4j.Element) MessageTools(com.haulmont.cuba.core.global.MessageTools) Element(org.dom4j.Element)

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