Reputation: 33
I have 2 components which should not depend upon each other but it should contribute to same menu.
I want a Context menu called "ABC" and it should contain 2 sub menu say "XYZ" and "PQR".
First component creating "XYZ" and Second componet creating "PQR" then it should come under "ABC"
In my implemented code it is showing 2 "ABC" menu.
Please help me.
code snippet:
1st component
MenuManager showInSubMenu = new MenuManager("ABC");
showInSubMenu.add("XYZ");
menu.appendToGroup("group.open", showInSubMenu);
2nd component
MenuManager showInSubMenu = new MenuManager("ABC");
showInSubMenu.add("PQR");
menu.appendToGroup("group.open", showInSubMenu);
Upvotes: 1
Views: 67
Reputation: 140467
I think your requirements and your design idea do not match up.
If those two components need to work on the same menu then they must have some sort of dependency.
I am guessing that your problem is that those two components should be working with the same MenuManager instance. You see, your code is creating two menu managers; and adding information into that; and then you are surprised that your menus show up twice?
In that sense: the only solution I see is: step back, and figure those parts that your two components both need to talk to. Then create that new component C (which represents those common parts); and then your other two existing components have to work with that new C thingy.
Upvotes: 2