Ordering menu items fed from multiple modules.

I have a main application that can load modules (or plugins). Each modules can define one or more links (or items) that will be displayed in a side menu defined in the main application.

Right now, my main application execute a list of ItemProviders which are loaded from the modules. These ItemProviders return a list of items to display in the side menu.

My question now is how am I supposed to order these items since they are not aware their siblings in the menu? Keep in mind that there is not a particular logic in the order, it depends on what the client wants.

My primary solution was to give them an order number (an index). The problem with this approach is that my modules would no longer be completely independent, the “order number” would depend on other modules’ number.

What would be the proper way to handle this particular case?

2

Use Reference To Application Menu

The main application has a set of menus for the side menu already. For each menu item associate a human readable key-id for each item. You can then use this key-id later in modules to reference where new menu items should be positioned.

When loading modules their menu items can have an optional parameter called after that indicates which menu item from the main application it should appear under.

If the key-id in the application does not exist. You can append the menu item to the bottom of the sidebar.

You can still use an order numeric value to sort menu items, but respect the after parameter first.

Data might look like this grouped by title and order.

 Application Menu
      "File", 0
      "Edit", 1
      "View", 2
      "Tools", 3

A module could have a menu defined like this.

 Module Menu
      after:"File"
         "Window", 0
         "Help", 1
      after:"Tools"
         "Features",0
         "Navigate",1
         "Program",2

You could have other parameters like insert or child for submenus. The key is to use a human readable reference point back to the main application’s menu. This makes extending the menu easy.

If the user is aware that these menu items are provided by multiple plug-ins, I would either give each plug-in a sub-menu to fill, or put separators in the menu to separate the entries of the different plug-ins.

Within the set of entries from one plug-in, the plug-in would be responsible for ordering the menu items.

2

Precondition: You know what modules / plugins are loaded.

Create another module that has the only responsibility to manage / order the menu items.

Because this is the responsibilty of the module, it is allowed to know the menu items provided by the other modules. This module reads the menu items provided by the other modules (say IMenuItem) and orders them according to your or your clients preferences.

Yes, this module is completely aware of the menu items and orders them hard-coded or lets the menu items be sorted e.g. via an xml (which allows to change the order after compile time). Using an xml can avoid the knowledge of the menu items within the code, making the menu module itself more flexible and independent.

This module can be interchanged for applications using different modules, so application, menu module and the other modules are loosely coupled.

The module implements IMenuItemProvider which is then consumed by the main application and returns IMenuItem instances in the correct order.

As stated above, for this solution you have to have knowledge of the loaded modules otherwise there is only the possibility of ordering alphabetically or some other generic sorting.

@cgTag’s answer is also a possibility but then the knowledge of ordering is within the modules themselves, which is what you wanted to avoid.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật