2011-08-25 7 views
0

ログイン後、ヘッダ/左メニューとメインパネルのあるビューにリダイレクトするvaadinアプリケーションがあります。vaadinアプリケーションメニュー

は、どのように私はそれがメインパネルにContactLayoutを設定連絡クリックすると具体的な内容

に応じて、メインパネルを切り替えるには、メニューまたは任意のリンクを設定することができます。

PS:私はvaadin documentationのようなメニューを設定する方法を知っていますが、メニュー項目のコマンドとして何を設定するのかを知りたいと思います。

おかげ

答えて

1

私はあなたがMap<MenuItem,AbstractLayout>を維持したMenuItemがクリックされたときに、あなたのパネルのすべてのコンポーネントを削除し、レイアウトを地図から取得追加することをお勧めします。

視覚:

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)); 
    } 

} 

}

は、それが動作します願っています。

よろしく

エリック