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

com.jwebmp.plugins.jstree.JSTreeListItem Maven / Gradle / Ivy

There is a newer version: 1.2.2.1-jre17
Show newest version
package com.jwebmp.plugins.jstree;

import com.jwebmp.core.base.html.Link;
import com.jwebmp.core.base.html.ListItem;
import com.jwebmp.core.base.html.interfaces.children.ListItemChildren;
import com.jwebmp.plugins.jstree.enumerations.JSTreeAttributes;
import com.jwebmp.plugins.jstree.interfaces.IJSTreeListItem;
import com.jwebmp.plugins.jstree.interfaces.JSTreeChildren;
import com.jwebmp.plugins.jstree.options.JSTreeNodeOptions;

import javax.validation.constraints.NotNull;

import static com.guicedee.guicedinjection.json.StaticStrings.STRING_EMPTY;
import static com.jwebmp.core.utilities.StaticStrings.*;

public class JSTreeListItem>
		extends ListItem
		implements JSTreeChildren, com.jwebmp.plugins.jstree.interfaces.IJSTreeListItem
{
	private Link link;
	private boolean asParent;
	private boolean asLink;
	private JSTreeNodeOptions options;
	private JSTreeList childItems;

	public JSTreeListItem()
	{
		this(null);
	}

	public JSTreeListItem(String text)
	{
		super(text);
	}

	public JSTreeListItem(String text, JSTreeNodeOptions options)
	{
		this(text);
		this.options = options;
	}

	/**
	 * Returns the link for the node
	 *
	 * @return
	 */
	@Override
	@NotNull
	public Link getLink()
	{
		return link;
	}

	/**
	 * Adds a new expansion on the child list
	 *
	 * @return
	 */
	@Override
	public JSTreeList asParent()
	{
		asParent = true;
		if (childItems == null)
		{
			childItems = new JSTreeList<>();
		}
		return childItems;
	}

	@Override
	@SuppressWarnings("unchecked")
	@NotNull
	public J asLink(boolean asLink)
	{
		this.asLink = asLink;
		return (J) this;
	}

	@Override
	public JSTreeNodeOptions> getOptions()
	{
		if (options == null)
		{
			setOptions(new JSTreeNodeOptions<>());
		}
		return options;
	}

	@Override
	@SuppressWarnings("unchecked")
	@NotNull
	public J setOptions(JSTreeNodeOptions options)
	{
		this.options = options;
		return (J) this;
	}

	/**
	 * Returns a cleaner version of myself
	 *
	 * @return
	 */
	public IJSTreeListItem asMe()
	{
		return this;
	}

	@SuppressWarnings("unchecked")
	@NotNull
	public J setAsParent(boolean asParent)
	{
		this.asParent = asParent;
		return (J) this;
	}

	@SuppressWarnings("unchecked")
	@NotNull
	public J setAsLink(boolean asLink)
	{
		this.asLink = asLink;
		return (J) this;
	}

	@Override
	public int hashCode()
	{
		return super.hashCode();
	}

	@Override
	public boolean equals(Object o)
	{
		return super.equals(o);
	}

	/**
	 * Method add ...
	 *
	 * @param newChild
	 * 		of type ListItemChildren
	 *
	 * @return J
	 */
	public @NotNull J add(@NotNull JSTreeListItem newChild)
	{
		asParent = true;
		getChildItems().add((JSTreeListItem) newChild);
		return (J) this;
	}

	public JSTreeList getChildItems()
	{
		if (childItems == null)
		{
			childItems = new JSTreeList<>();
			add(childItems);
		}
		return childItems;
	}

	@Override
	public void preConfigure()
	{
		String dataValue = options == null ? STRING_EMPTY : options.toString(true);
		if (asLink)
		{
			link = new Link<>();
			if (!dataValue.isEmpty())
			{
				link.addAttribute(JSTreeAttributes.Data_JsTree.toString(), dataValue);
			}
			add(link);
		}
		else
		{
			if (!dataValue.isEmpty())
			{
				addAttribute(JSTreeAttributes.Data_JsTree.toString(), dataValue);
			}
			setInvertColonRender(true);
		}
		super.preConfigure();
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy