Allow user to specify id for menu item
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.8k
- Forks
- 717
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 3
Description
Originally by bootlaces
Hi,
I have a menu bar with lots of menu items. I wish to attach only one command object to each menu item and then in the body of menuSelected(final MenuItem selectedItem) to switch on either an index or an arbitrary value I pass in, i.e.,
private static final ADD = 1;
private static final DELETE = 2;
MenuItem main = addItem("Items", null, null);
main.addItem(ADD, "Add Item", null, command);
main.addItem(DELETE, "Delete Item", null, command);
...
...
command = new Command() {
@Override
public void menuSelected(final MenuItem selectedItem) {
switch(selectedItem.getIndex()) {
case ADD:
doSomethingWonderful();
break;
case DELETE:
doSomethingNotSoWonderful();
break;
}
}
}
This would be a great help. Otherwise, I have to do a string comparision, and since my application is I18N aware, it means doing a ResourceBundle lookup each time for the string...slooooow.
Thanks
-=bootlaces=-
Imported from https://dev.vaadin.com/ issue #3873
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the MenuItem and addItem entry points used in the example, then trace how menuSelected receives the selected item. Implement a way for callers to provide an arbitrary value and retrieve it from the selected item, so one command can distinguish ADD from DELETE without comparing localized labels.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100