Would it be possible to open a different editor screen based on a boolean value in the row?

Curious if the edit button could be overridden to open a different edit screen based on a boolean value in the row. My thought was to grab the value from the selected row, set a string with some logic and and use that to setWindowID(stringFromLogic). I am must unsure how to get a property from a selected row.

CreateAction createActionBroker = new CreateAction(shippingLogsSetsTable, WindowManager.OpenType.DIALOG, "createBroker");
createActionBroker.setWindowId("ljtsiapp$ShippingLogsSet.broker.edit");
createActionBroker.setCaption("Create Broker Ship Log");
shippingLogsSetsTable.addAction(createActionBroker);
 //
CreateAction createActionBco = new CreateAction(shippingLogsSetsTable, WindowManager.OpenType.DIALOG, "createBco");
createActionBco.setWindowId("ljtsiapp$ShippingLogsSet.bco.edit");
createActionBco.setCaption("Create BCO Ship Log");
shippingLogsSetsTable.addAction(createActionBco);

Hi, yes, of course you can replace default EditAction bean in web-spring.xml

<!-- Polymorphic-aware edit action -->
    <bean id="cuba_EditAction"
          class="ru.veleslab.grain.web.incubating.PolymorphicEditAction"
          scope="prototype"/>

For example:

public class PolymorphicEditAction extends EditAction {

    public PolymorphicEditAction(ListComponent target) {
        super(target);
    }

    public PolymorphicEditAction(ListComponent target, WindowManager.OpenType openType) {
        super(target, openType);
    }

    public PolymorphicEditAction(ListComponent target, WindowManager.OpenType openType, String id) {
        super(target, openType, id);
    }

    @Override
    public String getWindowId() {
        if (windowId != null) {
            return windowId;
        } else {
            final MetaClass metaClass;
            if (target.getSingleSelected() != null) {
                metaClass = target.getSingleSelected().getMetaClass();
            } else {
                metaClass = target.getDatasource().getMetaClass();
            }
            WindowConfig windowConfig = AppBeans.get(WindowConfig.NAME);
            return windowConfig.getEditorScreenId(metaClass);
        }
    }
}

Regards,
Ilia.

1 Like

Without overriding the action globally, you can add an ItemChangeListener to your datasource and use action.setWindowId() to set the screen depending on the current row values.

Regards,
Konstantin

2 Likes