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

com.cooldatasoft.common.MenuItem Maven / Gradle / Ivy

There is a newer version: 7.0.0.4
Show newest version
package com.cooldatasoft.common;

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

import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxFallbackLink;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.link.Link;

/**
 * 
 * @author Fatih Mehmet UCAR - [email protected]
 * 
 */

@Data
@Slf4j
public class MenuItem implements Serializable {

	private static final long serialVersionUID = 1L;

	private String menuText;
	// possible menu inputs
	private Class responsePageClass;
	private WebPage responsePage;
	private String externalLink;
	private Link ajaxLink;

	private DestinationType destinationType;
	// submenu list
	private List subMenuItemList = new ArrayList();

	private boolean seperator = false;
	private boolean submenuTitle = false;

	public MenuItem(boolean seperator) {
		log.trace("Creating MenuItem with seperator = {} ", seperator);
		setSeperator(true);
		setDestinationType(DestinationType.NONE);
	}

	public MenuItem(Link ajaxLink) {
		setAjaxLink(ajaxLink);
		setDestinationType(DestinationType.AJAX_TARGET);
	}

	public MenuItem(String menuText, Link ajaxLink) {
		setMenuText(menuText);
		setAjaxLink(ajaxLink);
		setDestinationType(DestinationType.AJAX_TARGET);
	}

	public MenuItem(final Component... componentsToUpdate) {

		// TODO id needs to be on html
		setAjaxLink(new AjaxFallbackLink("menuLink") {
			private static final long serialVersionUID = 1L;

			@Override
			public void onClick(AjaxRequestTarget target) {
				target.add(componentsToUpdate);
			}
		});
		setDestinationType(DestinationType.AJAX_TARGET);
	}

	public MenuItem(String submenuTitle) {
		setSubmenuTitle(true);
		setMenuText(submenuTitle);
		setDestinationType(DestinationType.NONE);
	}

	public  MenuItem(String menuText, T destinationPage) {
		setMenuText(menuText);
		setResponsePage(destinationPage);
		setSubMenuItemList(new ArrayList());
		setDestinationType(DestinationType.WEB_PAGE_INSTANCE);
	}

	public MenuItem(String menuText, Class destinationPageClass) {
		setMenuText(menuText);
		setResponsePageClass(destinationPageClass);
		setSubMenuItemList(new ArrayList());
		setDestinationType(DestinationType.WEB_PAGE_CLASS);
	}

	public MenuItem(String menuText, Class destinationWebPage, List subMenuItemList)
			throws InstantiationException, IllegalAccessException {
		this(menuText, destinationWebPage.newInstance(), subMenuItemList);
		setDestinationType(DestinationType.WEB_PAGE_CLASS);
	}

	public  MenuItem(String menuText, T destinationPage, List subMenuItemList) {
		setMenuText(menuText);
		setResponsePage(destinationPage);
		setSubMenuItemList(subMenuItemList);
		setDestinationType(DestinationType.WEB_PAGE_INSTANCE);
	}

	public static MenuItem getMenuSeperator() {
		return new MenuItem(true);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy