Example usage for com.vaadin.ui MenuBar addItemBefore

List of usage examples for com.vaadin.ui MenuBar addItemBefore

Introduction

In this page you can find the example usage for com.vaadin.ui MenuBar addItemBefore.

Prototype

public MenuBar.MenuItem addItemBefore(String caption, Resource icon, MenuBar.Command command,
        MenuBar.MenuItem itemToAddBefore) 

Source Link

Document

Add an item before some item.

Usage

From source file:nz.co.senanque.perspectiveslibrary.MenuCloner.java

License:Apache License

public static void merge(MenuBar target, MenuBar source, List<MenuBar.MenuItem> added) {
    if (source != null) {
        List<MenuBar.MenuItem> targetItems = target.getItems();
        for (MenuBar.MenuItem sourceItem : source.getItems()) {
            MenuBar.MenuItem targetItem = findItem(sourceItem.getText(), targetItems);
            if (targetItem == null) {
                try {
                    int sizeOfTarget = target.getSize();
                    if (sizeOfTarget > 0) {
                        targetItem = target.addItemBefore(sourceItem.getText(), null, sourceItem.getCommand(),
                                target.getItems().get(sizeOfTarget - 1));
                    }// w w w  .j  a v  a 2s .com
                } catch (Exception e) {
                }
                if (targetItem == null) {
                    targetItem = target.addItem(sourceItem.getText(), sourceItem.getCommand());
                }
                fixMenuItem(targetItem, sourceItem);
                added.add(targetItem);
            }
            merge(targetItem, sourceItem, added);
        }
    }
}