Example usage for com.vaadin.ui MenuBar.MenuItem addItemBefore

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

Introduction

In this page you can find the example usage for com.vaadin.ui MenuBar.MenuItem 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

private static void merge(MenuBar.MenuItem target, MenuBar.MenuItem source, List<MenuBar.MenuItem> added) {
    if (source.hasChildren()) {
        List<MenuBar.MenuItem> targetItems = target.getChildren();
        for (MenuBar.MenuItem sourceItem : source.getChildren()) {
            if (sourceItem.isSeparator()) {
                target.addSeparator();/*w ww.  j  a v a2s  . c  om*/
            } else {
                MenuBar.MenuItem targetItem = findItem(sourceItem.getText(), targetItems);
                if (targetItem == null) {
                    try {
                        int sizeOfTarget = target.getChildren().size();
                        if (sizeOfTarget > 0) {
                            targetItem = target.addItemBefore(sourceItem.getText(), null,
                                    sourceItem.getCommand(), target.getChildren().get(sizeOfTarget - 1));
                        }
                    } catch (Exception e) {
                    }
                    if (targetItem == null) {
                        targetItem = target.addItem(sourceItem.getText(), sourceItem.getCommand());
                    }
                    fixMenuItem(targetItem, sourceItem);
                    added.add(targetItem);
                }
                merge(targetItem, sourceItem, added);
            }
        }
    }
}