0
我有一個vaadin應用程序,它在登錄到帶有標題/左側菜單和主面板的視圖後重定向。vaadin應用程序菜單
我怎麼可以設置菜單或任何鏈接根據具體內容
切換主面板如果我點擊聯繫它在主面板中設置ContactLayout。
PS:我知道如何設置菜單,如vaadin documentation,但我想知道如何設置菜單項的命令。
感謝
我有一個vaadin應用程序,它在登錄到帶有標題/左側菜單和主面板的視圖後重定向。vaadin應用程序菜單
我怎麼可以設置菜單或任何鏈接根據具體內容
切換主面板如果我點擊聯繫它在主面板中設置ContactLayout。
PS:我知道如何設置菜單,如vaadin documentation,但我想知道如何設置菜單項的命令。
感謝
我建議你保持一個Map<MenuItem,AbstractLayout>
並在單擊菜單項時,請取出面板的所有組件,並添加布局從地圖得到。
視覺:
public class TestApplication extends Application {
private VerticalLayout contactLayout;
private Panel mainPanel;
Map<MenuItem, AbstractLayout> swapContentMap;
@Override
public void init() {
Window mainWindow = new Window("Test Application");
mainPanel = new Panel("Main Panel");
mainWindow.addComponent(mainPanel);
// Create all of your layout
// For now, I just create a fake contact layout
contactLayout = new VerticalLayout();
// Here add your default layout to the right panel
mainPanel.addComponent(contactLayout);
Command myCommand = new MyCommand();
MenuBar menuBar = new MenuBar();
MenuItem menuItem = menuBar.addItem("Contact", myCommand);
//add your other menu item
swapContentMap = new HashMap<MenuBar.MenuItem, AbstractLayout>();
swapContentMap.put(menuItem, contactLayout);
//add your other menu item to the map.
setMainWindow(mainWindow);
}
private class MyCommand implements Command
{
public void menuSelected(MenuItem selectedItem)
{
TestApplication.this.mainPanel.removeAllComponents();
TestApplication.this.mainPanel.addComponent(swapContentMap.get(selectedItem));
}
}
}
希望它會工作。
問候
埃裏克