
com.sibvisions.rad.ui.vaadin.impl.menu.VaadinMenuBar Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jvxvaadin-server Show documentation
Show all versions of jvxvaadin-server Show documentation
Vaadin UI implementation for JVx
The newest version!
/*
* Copyright 2012 SIB Visions GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*
*
* History
*
* 23.10.2012 - [CB] - creation
* 24.09.2013 - [JR] - support VaadinSeparator
* - fixed resetMenuItem (recursion check didn't work)
*/
package com.sibvisions.rad.ui.vaadin.impl.menu;
import java.util.List;
import jvx.rad.ui.IComponent;
import jvx.rad.ui.IContainer;
import jvx.rad.ui.menu.IMenu;
import jvx.rad.ui.menu.IMenuBar;
import com.sibvisions.rad.ui.vaadin.impl.VaadinComponent;
import com.sibvisions.rad.ui.vaadin.impl.VaadinContainer;
import com.sibvisions.util.type.CommonUtil;
import com.vaadin.ui.MenuBar.Command;
import com.vaadin.ui.MenuBar.MenuItem;
/**
* The VaadinMenuBar
class is the vaadin implementation of {@link IMenuBar}.
*
* @author Benedikt Cermak
*/
public class VaadinMenuBar extends VaadinContainer
implements IMenuBar
{
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Initialization
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
* Creates a new instance of VaadinMenuBar
.
*
* @see jvx.rad.ui.menu.IMenuBar
*/
public VaadinMenuBar()
{
super(new WrappedMenuBar());
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Overwritten methods
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
* {@inheritDoc}
*/
@Override
public void addToVaadin(IComponent pComponent, Object pConstraints, int pIndex)
{
addMenuItem(this, pComponent, pIndex);
}
/**
* {@inheritDoc}
*/
@Override
public void removeFromVaadin(IComponent pComponent)
{
removeMenuItem(pComponent);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// User-defined methods
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
* Adds a menu item to the Menu.
*
* @param pParent the parent Container
* @param pItem the item to add
* @param pIndex the index
*/
public void addMenuItem(IContainer pParent, IComponent pItem, int pIndex)
{
createMenuItem(pParent, pItem, pIndex);
if (pItem instanceof IMenu)
{
IMenu menu = (IMenu)pItem;
IComponent comp;
for (int i = 0, anz = menu.getComponentCount(); i < anz; i++)
{
comp = menu.getComponent(i);
if (comp instanceof IMenu)
{
addMenuItem(menu, (IMenu)comp, i);
}
else
{
createMenuItem(menu, comp, i);
}
}
}
}
/**
* Creates a {@link MenuItem}.
*
* @param pParent the parent Container
* @param pComponent the MenuItem to add
* @param pIndex the index
*/
private void createMenuItem(IContainer pParent, IComponent pComponent, int pIndex)
{
MenuItem miNew;
if (pParent instanceof IMenuBar)
{
VaadinMenuItem menuItem = (VaadinMenuItem)pComponent;
WrappedMenuItem wmiComponent = menuItem.getResource();
MenuItem miComponent = wmiComponent.getMenuItem();
if (miComponent == null)
{
int menuSize = ((VaadinMenuBar)pParent).getResource().getMenuBar().getSize();
Command cmd = null;
//if the item is not a menu
if (!(menuItem instanceof VaadinMenu))
{
cmd = menuItem.getVaadinCommand();
}
if (pIndex < 0 || menuSize <= 0)
{
miNew = ((VaadinMenuBar)pParent).getResource().getMenuBar().addItem(CommonUtil.nvl(menuItem.getText(), ""),
menuItem.getIcon(),
cmd);
}
else
{
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy