Search in sources :

Example 16 with FrameOwner

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);
}
Also used : ContainerDataUnit(io.jmix.ui.component.data.meta.ContainerDataUnit) DataUnit(io.jmix.ui.component.data.DataUnit) FrameOwner(io.jmix.ui.screen.FrameOwner) ContainerDataUnit(io.jmix.ui.component.data.meta.ContainerDataUnit)

Example 17 with FrameOwner

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;
}
Also used : EntityDataUnit(io.jmix.ui.component.data.meta.EntityDataUnit) DataUnit(io.jmix.ui.component.data.DataUnit) FrameOwner(io.jmix.ui.screen.FrameOwner) EntityDataUnit(io.jmix.ui.component.data.meta.EntityDataUnit)

Example 18 with FrameOwner

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;
}
Also used : EntityDataUnit(io.jmix.ui.component.data.meta.EntityDataUnit) DataUnit(io.jmix.ui.component.data.DataUnit) FrameOwner(io.jmix.ui.screen.FrameOwner) EntityDataUnit(io.jmix.ui.component.data.meta.EntityDataUnit)

Example 19 with FrameOwner

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));
        }
    }
}
Also used : FrameOwner(io.jmix.ui.screen.FrameOwner) Method(java.lang.reflect.Method) LegacyFragmentAdapter(com.haulmont.cuba.gui.components.compatibility.LegacyFragmentAdapter)

Example 20 with FrameOwner

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();
    }
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) FrameOwner(io.jmix.ui.screen.FrameOwner) Notifications(io.jmix.ui.Notifications)

Aggregations

FrameOwner (io.jmix.ui.screen.FrameOwner)51 ScreenData (io.jmix.ui.model.ScreenData)18 GuiDevelopmentException (io.jmix.ui.GuiDevelopmentException)17 InstanceContainer (io.jmix.ui.model.InstanceContainer)11 CollectionContainer (io.jmix.ui.model.CollectionContainer)9 Component (io.jmix.ui.component.Component)7 Method (java.lang.reflect.Method)6 LegacyFragmentAdapter (com.haulmont.cuba.gui.components.compatibility.LegacyFragmentAdapter)5 MetaClass (io.jmix.core.metamodel.model.MetaClass)5 Screens (io.jmix.ui.Screens)5 Screen (io.jmix.ui.screen.Screen)5 ScreenFragment (io.jmix.ui.screen.ScreenFragment)5 WindowInfo (io.jmix.ui.WindowInfo)4 Frame (io.jmix.ui.component.Frame)4 Element (org.dom4j.Element)4 Fragment (io.jmix.ui.component.Fragment)3 DataUnit (io.jmix.ui.component.data.DataUnit)3 DataLoader (io.jmix.ui.model.DataLoader)3 LegacyFrame (com.haulmont.cuba.gui.screen.compatibility.LegacyFrame)2 Notifications (io.jmix.ui.Notifications)2