I thing, I found a small solution for this problem, but with another concept - only one class (and one interface); in this class I have one main method, which choose correct 'method to open'; in this example I check by int:
/-------------------------------------------/
Example loop in main part of program:
/-------------------------------------------/
(...)
MenuBar menu = new MenuBar(true);
for (int k = 0; k < 5; k++) {
int ii=k;
menu.addItem(tekst + k, new Command() {
@Override
public void execute() {
ClassMetodInterface metoda = (ClassMetodInterface) GWT.create(Method2.class);
vPanel.clear(); //clearing before I open a new widget.
/*I sent int (easier to tests), but I can sent string[i] too*/
/* logging - instance of main class to communicate with 'subclasses', in my project necessery*/
vPanel.add(metoda.defaultMethod(ii, logging));
}
});
}
(...)
/*-------------------------------------------*/
ClassMetodInterface, only for implementation class Method2 :
/*-------------------------------------------*/
public interface ClassMetodInterface {
Widget defaultMethod(int g, Logging logging);
}
/*-------------------------------------------*/
class Method2 with swich:
/*-------------------------------------------*/
public class Method2 implements ClassMetodInterface {
public Widget zapisUsera(int g, Logging logging) {
Logging logging;
HorizontalPanel lPanel = new HorizontalPanel();
switch(g) {
case 1: {
Window.alert("switch for test no:"+g);
MenuWindow1(logging);
break;
}
case 2:{
Window.alert("switch for test no:"+g);
break;
}
default:
Window.alert("switch default - loop >2 && <1");
break;
}
return lPanel; //all methods will be void - they will be add widgets and Panels to lPanel
}
public Widget MenuWindow1(Logging logging) {
this.logging = logging;
lPanel.setBorderWidth(2);
this.lPanel.setPixelSize(100, 50);
Button b1 = new Button("test button, not used");
lPanel.add(b1);
Label lbl = new Label("label no "+logging.i);
lPanel.add(lbl);
Button addGlobal = new Button("+");
Button removeGlobal = new Button("-");
lPanel.add(addGlobal);
addGlobal.addClickHandler(new addGlobal());
removeGlobal.addClickHandler(new removeGlobal());
lPanel.add(removeGlobal);
return lPanel;
}
//for tests communication with class, where I have menu and global variable
public class addGlobal implements ClickHandler {
@Override
public void onClick(ClickEvent event) {
logging.i++;
}
}
public class removeGlobal implements ClickHandler {
@Override
public void onClick(ClickEvent event) {
logging.i--;
}
}
}
It is not finished, but you can show main idea. If I need to add new options to menu, I will update db and replace one class for version with more methods.