How to sometimes disable Create and Edit from a browser screen?

I have a few cases where I’d like the Create button/action as well as the ability to edit the entity to be disabled on a browse screen; I want it to be for selecting only in these cases.

In most (probably all?) of these cases, it’s when the entity is being selected from a LookupPickerField.

So basically - how can I set up a LookupPickerField to call the browse screen with the ability to create and edit turned off?

Hi @jon.craig,

One possible solution is to use screen parameters.

Browse controller:

    private Boolean enableCreateEditActions = Boolean.TRUE;

    public Boolean getEnableCreateEditActions() {
        return enableCreateEditActions;
    }

    public void setEnableCreateEditActions(Boolean enableCreateEditActions) {
        this.enableCreateEditActions = enableCreateEditActions;
    }

    @Subscribe
    public void onAfterInit(AfterInitEvent event) {
        createAction.setEnabled(enableCreateEditActions);
        editAction.setEnabled(enableCreateEditActions);
    }

Calling screen:

	MyScreen screen = screenBuilders.screen(this)
			.withScreenClass(MyScreen.class)
			.build();
	screen.setEnableCreateEditActions(Boolean.FALSE);
	screen.show();

Hope it helps.

Regards,
Peterson.

1 Like

Hi,

As an option, you can define alwaysVisible ="false" for the buttonsPanel of the browser screen or remove it it it’s set to true. In this case, ButtonsPanel will be hidden if a screen is opened as a lookup, e.g. from the picker_lookup action.

Regards,
Gleb

1 Like

I implemented it this way (more or less) - I just wanted to make sure there wasn’t a .withReadOnlyMode() or similar that I was missing.

Though on second thought, Gleb’s solution is a lot cleaner. :slight_smile:

Hi @jon.craig,
It may not be a problem, but users are able to create/edit using mouse controls (right click on the table) if the panel is hidden but the actions are enabled:

image

You may need to implement both solutions. :slight_smile:

Regards,
Peterson.

1 Like

Argh, ok. :smiley: Thanks for the heads-up!

(EDIT: Actually, no, I just tested, and at least on 7.2.3, with @gorelov solution in place, right-clicking produces no context menu.)