MenuBar conditional command

The below conditional code doesn’t work for some reason. The green works, red doesn’t. An inner class didn’t help.

private Command menuCommand = new Command() {

		@Override
		public void menuSelected(MenuItem selectedItem) {
			//getWindow().showNotification("Action " + selectedItem.getText());
			[color=#045518]
if (selectedItem.equals(method1) && selectedItem.getParent().equals(newPrognosis)) {
				PrognosisSplitPanel prognosisSplitPanel = new PrognosisSplitPanel(SplitPanel.ORIENTATION_HORIZONTAL);
				getApplication().getMainWindow().getContent().addComponent(prognosisSplitPanel);
				((VerticalLayout)getApplication().getMainWindow().getLayout()).setExpandRatio(prognosisSplitPanel, 1);
			}
[/color]
			[color=#B81D00]
if (selectedItem.equals(save))
				if(save.getParent().equals(newPrognosis))
					getWindow().showNotification("Action " + selectedItem.getText());
			if (selectedItem.equals(exit))
				getWindow().showNotification("Action " + selectedItem.getText());
		}
[/color]
        
    };

Hi,

At this time in the morning, I did not see anything obvious w/o the rest of the code available. More context could help.

Did you run it in the debugger?

Best Regards,
Marc

No, i have issues debugging with this framework, however you can test the concept in a simple menu like copying the one from the sampler and get same result. It should work, but it doesn’t, reason unknown. One solution is having one command for each menu item, otherwise i can’t spend time on it if i can’t properly debug.

Not really sure what you are getting at here. A simple case like

[code]
private MenuBar createMenu() {
menubar = new MenuBar();
folder = menubar.addItem(“New Folder”, menuCommand);
project = menubar.addItem(“New Project”, menuCommand);

    return menubar;
}

private Command menuCommand = new Command() {
    public void menuSelected(MenuItem selectedItem) {
        if (selectedItem == folder)
            menubar.getWindow().showNotification("Folder");
        if (selectedItem == project)
            menubar.getWindow().showNotification("Project");
    }
};

[/code] works like a charm.

Also to debug you just need to make sure you have a debug connection to the server (unless you are running it in debug mode from your IDE, then you will have it automatically). Then just set the breakpoint at “if (selectedItem == folder)” for instance and you can check that the variables are indeed the same.

The problem was i was still on 6.2. I upgraded to 6.34 and i got the debug working, wich is vital. The menu also works now. Thank you! :grin: