All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.wicketstuff.menu.Menu Maven / Gradle / Ivy

There is a newer version: 1.4.21
Show newest version
package org.wicketstuff.menu;


import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.model.Model;


/**
 * The {@code Menu} class represents a complete menu within a {@link MenuBarPanel}. A
 * {@link MenuBarPanel} consist of a {@code List} of {@link Menu}s. 
 *
 * @author Stefan Lindner ([email protected])
 */
public class Menu implements Serializable {

	private static final long serialVersionUID = 1L;

	private final Model model;
	private final List menuItems;
	private boolean visible = true;

	/**
	 * Constructs a menu.
	 *
	 * @param model The {@link Model} that name of the menu
	 * @param menuItems A {@code List} of the {@link MenuItem}s that belong to this {@link Menu}.
	 */
	public Menu(final Model model, final List menuItems) {
		if (model == null) {
			throw new IllegalArgumentException("argument [model] cannot be null");
		}
		if (menuItems == null) {
			throw new IllegalArgumentException("argument [menuItems] cannot be null");
		}

		this.model = model;
		this.menuItems = menuItems;
	}


	public Menu(final Model model) {
		this(model, new ArrayList());
	}
	
	
	public Menu addMenuItem(final IMenuLink item) {
		menuItems.add(item);
		return this;
	}

	
	/**
	 * Gets the model. It returns the object that wraps the backing model. The model of a
	 * {@link Menu} is used to hold the {@code String} that is used to disply the title
	 * of a menu.
	 * 
	 * @return The model
	 */
	public Model getModel() {
		return this.model;
	}


	/**
	 * Gets the {@link MenuItem}s of this {@link Menu}.
	 *
	 * @return All {@link MenuItem}s of this {@link Menu}.
	 */
	public List getMenuItems() {
		return this.menuItems;
	}


	/**
	 * Sets wheter the complete {@link Menu} is visible.
	 *
	 * @param visible {@code true} if this {@link Menu} should be visible.
	 * @return this
	 */
	public Menu setVisible(boolean visible) {
		this.visible = visible;
		return this;
	}


	/**
	 * Gets whether the {@link Menu} is visible.
	 *
	 * @return {@code true} if the {@link Menu} is visible.
	 */
	public boolean isVisible() {
		return this.visible;
	}
	
	
	
	
	
	private Component associatedComponent;
	public Menu setAssociatedComponent(final Component c) {
		this.associatedComponent = c;
		return this;
	}


	public void redraw(final AjaxRequestTarget target) {
		if (this.associatedComponent != null) {
			target.addComponent(this.associatedComponent);
		}
	}



	public String toString() {
		return "Menu: " + getModel().getObject() + " visible = " + isVisible();
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy