OpenType.DIALOG in v 7

studio-7plus

(mkhan) #1

In the legacy version of the platform we could select the OpenType of the Editor from the table event designer without writing any code but I don’t see it anymore.

Do we need to code it under @Subscribe in the controller? Thanks for guiding to the right process CUBA being a RAD tool!


(Gleb Gorelov) #2

Hi,

for the new API you need to subscribe on ActionPerformedEvent and provide a custom implementation, e.g.

@UiController("sales_Product.browse")
@UiDescriptor("product-browse.xml")
@LookupComponent("productsTable")
@LoadDataBeforeShow
public class ProductBrowse extends StandardLookup<Product> {
    @Inject
    private GroupTable<Product> productsTable;

    @Inject
    private ScreenBuilders screenBuilders;

    @Subscribe("productsTable.create")
    private void onProductsTableCreate(Action.ActionPerformedEvent event) {
        screenBuilders.editor(Product.class, this)
                .newEntity()
                .withLaunchMode(OpenMode.DIALOG)
                .build()
                .show();
    }

    @Subscribe("productsTable.edit")
    private void onProductsTableEdit(Action.ActionPerformedEvent event) {
        screenBuilders.editor(productsTable)
                .withLaunchMode(OpenMode.DIALOG)
                .build()
                .show();
    }
}

You can read more about opening screens in the doc.

Gleb


(Gleb Gorelov) #3

The easiest way is to set forceDialog="true" for the <dialogMode/> element of an editor screen.

...
<dialogMode height="600" 
            width="800"
            forceDialog="true"/>
...

(mkhan) #4

Thanks Gleb.

The difference is, in V6x only selection of openMode in the screen builder used to do all it needs. Now the lines of codes to open the screen making the platform moving away a bit from a RAD tool and this is only an example (there are many more such example I am coming across). I hope this is not how it is planned but matter of time to get those RAD functionalities back in V7 soon.


(Gleb Gorelov) #5

Hi,

The third possible approach is to implement custom Create/Edit actions that can be used independently of the standard ones.

Take a look at the demo project that illustrates the above dialog-actions.zip (81.7 KB).

DialogCreateAction and DialogEditAction are custom actions and both are used in the product-browse.xml:

@ActionType(DialogCreateAction.ID)
public class DialogCreateAction extends CreateAction {

    public static final String ID = "create_dialog";

    public DialogCreateAction() {
        this(ID);
    }

    public DialogCreateAction(String id) {
        super(id);
    }

    @SuppressWarnings("unchecked")
    @Override
    public void actionPerform(Component component) {
        // if standard behaviour
        if (!hasSubscriptions(ActionPerformedEvent.class)) {
            Screen editor = screenBuilders.editor(target)
                    .newEntity()
                    .withOpenMode(OpenMode.DIALOG)
                    .build();
            editor.show();
        } else {
            super.actionPerform(component);
        }
    }
}
@ActionType(DialogEditAction.ID)
public class DialogEditAction extends EditAction {

    public static final String ID = "edit_dialog";

    public DialogEditAction() {
        super(ID);
    }

    public DialogEditAction(String id) {
        super(id);
    }

    @SuppressWarnings("unchecked")
    @Override
    public void actionPerform(Component component) {
        // if standard behaviour
        if (!hasSubscriptions(ActionPerformedEvent.class)) {
            Entity editedEntity = target.getSingleSelected();
            Screen editor = screenBuilders.editor(target)
                    .editEntity(editedEntity)
                    .withOpenMode(OpenMode.DIALOG)
                    .build();
            editor.show();
        } else {
            super.actionPerform(component);
        }
    }
}
<actions>
    <action id="create" type="create_dialog"/>
    <action id="edit" type="edit_dialog"/>
...
</actions>

Similarly to screens, the actions base package must be registered in the web-springs.xml

<gui:actions base-packages="com.company.demo.gui.actions"/>

Regards,
Gleb


Questions about cuba 7 after migration
(mkhan) #6

In this case, do I force it in the browser or Editor xml file?


(Gleb Gorelov) #7

In the screen you want to be opened as dialog.


(mkhan) #8

Thank you so much Gleb


(Anjingjing) #9

@gorelov but we still have xml attribute openType for element action. Consider this is a bug?


(Yuriy Artamonov) #10

It is available only for legacy screens. Unfortunately, we cannot remove it since we use the same XSD for old/new screens.


(Anjingjing) #11

Thanks Yuriy, but in this case it would be confused. Especially for those who move from v6 to v7.

BTW,can I know why remove it? There is chanllege in the China forum.:blush: