@pinyazhin @klaus @nurmuhammad.abdurash
Hello Everyone
For your information, it is possible to open a DetailView (Editor) from the main Menu using a menu item bean. It is documented here MenuConfig :: Jmix Documentation under the Item Attributes section.
I have implemented this myself (below) and it works for both dialogWindows.detail() (commented out in my code below) and viewNavigators.detailView() methods. I have added a check at the beginning of each method, so that the DetailView cannot be opened multiple times on top of itself. I retrieve the user’s “Member” entity with a memberService bean that I previously built; each user has only one Member instance, so they can open it directly from their main Menu.
I hope that this information is helpful.
Best regards
Chris
menu.xml
<menu id="personal-nf" title="msg://menu-config.personal-nf" opened="true">
<item bean="nf_MainViewMenuService" beanMethod="showMemberView" title="msg://com.company.nf.view.member/memberDetailView.title"/>
<item bean="nf_MainViewMenuService" beanMethod="showProfileDefaultsView" title="msg://menu-config.nf_ProfileDefaults.edit"/>
</menu>
MainViewMenuService.java (Bean)
@Component("nf_MainViewMenuService")
public class MainViewMenuService {
private static final Logger log = LoggerFactory.getLogger(MainViewMenuService.class);
//############# Data Components ###############
//############# Components ####################
//############# Actions #######################
//############# View API ######################
private final DialogWindows dialogWindows;
private final ViewNavigators viewNavigators;
private final Notifications notifications;
//############# Infrastructure ################
private final Messages messages;
//############# Project Beans #################
private final CurrentUserService currentUserService;
private final ProfileDefaultsService profileDefaultsService;
private final MemberService memberService;
private final MembershipService membershipService;
//############# Project Properties ############
//############# Other Beans ###################
//############# Other Properties ##############
//#############################################
public MainViewMenuService(
CurrentUserService currentUserService,
MemberService memberService,
MembershipService membershipService,
ProfileDefaultsService profileDefaultsService,
DialogWindows dialogWindows,
ViewNavigators viewNavigators,
Notifications notifications,
Messages messages) {
this.currentUserService = currentUserService;
this.memberService = memberService;
this.membershipService = membershipService;
this.profileDefaultsService = profileDefaultsService;
this.dialogWindows = dialogWindows;
this.viewNavigators = viewNavigators;
this.notifications = notifications;
this.messages = messages;
}
public void showMemberView() {
if (UI.getCurrent().getCurrentView() instanceof MemberDetailView) {
notifications.create("Member view is already open") // TODO create new message
.withType(Notifications.Type.WARNING)
.withPosition(Notification.Position.MIDDLE)
.withThemeVariant(NotificationVariant.LUMO_WARNING)
.withCloseable(false)
.withDuration(3000)
.show();
return;
}
/*
dialogWindows.detail((View<?>) UI.getCurrent().getCurrentView(), Member.class)
.withViewClass(MemberDetailView.class)
.editEntity(memberService.getMember(currentUserService.getCurrentUser().getUsername()))
.open();
*/
viewNavigators.detailView(Member.class)
.withViewClass(MemberDetailView.class)
.editEntity(memberService.getMember(currentUserService.getCurrentUser().getUsername()))
.navigate();
}
more menu item bean methods......... e.g. showProfileDefaultsView()
}```