<commit_before>//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// This file is a part of the 'esoco-business' project.
// Copyright 2017 <NAME>, esoco GmbH, Flensburg, Germany
//
// 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.
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
package de.esoco.process.ui;

import de.esoco.entity.EntityRelationTypes;

import de.esoco.lib.property.HasProperties;
import de.esoco.lib.property.MutableProperties;
import de.esoco.lib.property.PropertyName;
import de.esoco.lib.property.StringProperties;

import de.esoco.process.ParameterWrapper;
import de.esoco.process.ui.style.SizeUnit;
import de.esoco.process.ui.style.UiStyle;

import org.obrel.core.RelationType;

import static de.esoco.lib.property.ContentProperties.LABEL;
import static de.esoco.lib.property.LayoutProperties.HTML_HEIGHT;
import static de.esoco.lib.property.LayoutProperties.HTML_WIDTH;
import static de.esoco.lib.property.StyleProperties.HIDE_LABEL;
import static de.esoco.lib.property.StyleProperties.SHOW_LABEL;


/********************************************************************
 * The base class for all process UI components.
 *
 * @author eso
 */
public abstract class UiComponent<T, C extends UiComponent<T, C>>
	extends ParameterWrapper<T, C>
{
	//~ Instance fields --------------------------------------------------------

	private final UiContainer<?> rParent;

	private UiLayout.Cell		 rLayoutCell;
	private UiStyle				 aStyle = new UiStyle();
	private UiImageDefinition<?> rImage = null;

	//~ Constructors -----------------------------------------------------------

	/***************************************
	 * Creates a new instance.
	 *
	 * @param rParent   The parent container
	 * @param rDatatype The datatype of the component value
	 */
	public UiComponent(UiContainer<?> rParent, Class<? super T> rDatatype)
	{
		super(rParent != null ? rParent.fragment() : null,
			  rDatatype != null
			  ? rParent.fragment().getTemporaryParameterType(rDatatype) : null);

		this.rParent = rParent;

		if (rParent != null && rDatatype != null)
		{
			attachTo(rParent);
		}

		String sComponentStyle = getComponentStyleName();

		if (sComponentStyle.length() > 0)
		{
			aStyle.styleName(sComponentStyle);
		}
	}

	//~ Methods ----------------------------------------------------------------

	/***************************************
	 * Returns the layout cell in which this component has been placed.
	 *
	 * @return The cell
	 */
	public final UiLayout.Cell cell()
	{
		return rLayoutCell;
	}

	/***************************************
	 * Returns the parent container.
	 *
	 * @return The parent
	 */
	public final UiContainer<?> getParent()
	{
		return rParent;
	}

	/***************************************
	 * Returns the parent view of this component.
	 *
	 * @return The view of the hierarchy this component is placed in
	 */
	public UiView<?> getView()
	{
		return rParent instanceof UiView ? (UiView<?>) rParent
										 : rParent.getView();
	}

	/***************************************
	 * Sets the height of this component.
	 *
	 * @param  nHeight The height value
	 * @param  eUnit   The height unit
	 *
	 * @return This instance for concatenation
	 */
	public C height(int nHeight, SizeUnit eUnit)
	{
		return size(HTML_HEIGHT, nHeight, eUnit);
	}

	/***************************************
	 * Places this component before another component in the same parent
	 * container.
	 *
	 * @param  rBeforeComponent The component to place this component before
	 *
	 * @return This instance for concatenation
	 *
	 * @throws IllegalArgumentException If the given component is not found in
	 *                                  the parent container
	 */
	@SuppressWarnings("unchecked")
	public C placeBefore(UiComponent<?, ?> rBeforeComponent)
	{
		rParent.placeComponentBefore(rBeforeComponent, this);

		return (C) this;
	}

	/***************************************
	 * Sets the size of this component.
	 *
	 * @param  nWidth  The width
	 * @param  nHeight The height
	 * @param  eUnit   The unit of the size values
	 *
	 * @return This instance for concatenation
	 */
	public C size(int nWidth, int nHeight, SizeUnit eUnit)
	{
		return width(nWidth, eUnit).height(nHeight, eUnit);
	}

	/***************************************
	 * Returns the style object of this component which provides methods to
	 * modify the component's appearance.
	 *
	 * @return The component style
	 */
	public UiStyle style()
	{
		return aStyle;
	}

	/***************************************
	 * Sets the style of this component to a copy of an existing style
	 * definition.
	 *
	 * @param  rStyle The style object to apply
	 *
	 * @return The component style to allow subsequent modifications
	 */
	public UiStyle style(UiStyle rStyle)
	{
		aStyle = new UiStyle(rStyle);

		String sStyleName	   = aStyle.getStyleName();
		String sComponentStyle = getComponentStyleName();

		if (sComponentStyle.length() > 0 &&
			!sStyleName.startsWith(sComponentStyle))
		{
			aStyle.styleName(sComponentStyle + " " + sStyleName);
		}

		return aStyle;
	}

	/***************************************
	 * {@inheritDoc}
	 */
	@Override
	public String toString()
	{
		return String.format("%s(%s)",
							 getClass().getSimpleName(),
							 fragment().getParameter(type()));
	}

	/***************************************
	 * Sets the width of this component.
	 *
	 * @param  nWidth The width value
	 * @param  eUnit  The width unit
	 *
	 * @return This instance for concatenation
	 */
	public C width(int nWidth, SizeUnit eUnit)
	{
		return size(HTML_WIDTH, nWidth, eUnit);
	}

	/***************************************
	 * Internal method to apply a label to this component by setting the
	 * appropriate properties. Can be invoked by methods from the public API of
	 * subclasses that support labels or captions.
	 *
	 * @param  sLabel The label text or NULL for none
	 *
	 * @return This instance
	 */
	protected C applyComponentLabel(String sLabel)
	{
		if (sLabel != null)
		{
			clear(HIDE_LABEL);
			set(SHOW_LABEL);
		}
		else
		{
			set(HIDE_LABEL);
			clear(SHOW_LABEL);
		}

		return set(LABEL, sLabel);
	}

	/***************************************
	 * Will be invoked to apply all properties of this component to the
	 * corresponding process parameter after it has been attached to the parent
	 * container.
	 */
	protected void applyProperties()
	{
		aStyle.applyPropertiesTo(this);

		// is NULL in the root view
		if (rLayoutCell != null)
		{
			rLayoutCell.applyPropertiesTo(this);
		}

		if (rImage != null)
		{
			rImage.applyPropertiesTo(this);
		}
	}

	/***************************************
	 * Attaches this component to it's parent container.
	 *
	 * @param rParent The parent container
	 */
	protected void attachTo(UiContainer<?> rParent)
	{
		rParent.addComponent(this);

		RelationType<T>  rParamType = type();
		Class<? super T> rDatatype  = rParamType.getValueType();

		fragment().addDisplayParameters(rParamType);

		if (rDatatype.isEnum())
		{
			resid(rDatatype.getSimpleName());
		}
	}

	/***************************************
	 * Returns the style name for this component. By default this is the simple
	 * class name of this component. Subclasses should override this if the
	 * class name is ambiguous and needs further specification. This is
	 * typically the case for non-static inner classes of composites which often
	 * have names that start without the 'Ui' prefix.
	 *
	 * @return The component style name
	 */
	protected String getComponentStyleName()
	{
		return getClass().getSimpleName();
	}

	/***************************************
	 * Internal method to return the value of this component's parameter. This
	 * is intended to be used by subclasses only which should provide a
	 * type-specific public method (like String getText()).
	 *
	 * @return The current value
	 */
	protected final T getValueImpl()
	{
		return fragment().getParameter(type());
	}

	/***************************************
	 * Sets an image for this component. This method is protected to provide the
	 * image handling functionality for all subclasses. Subclasses that support
	 * the setting of images should override this method as public.
	 *
	 * @param  rImage The component image
	 *
	 * @return This instance so that this method can be used for fluent
	 *         implementations
	 */
	@SuppressWarnings("unchecked")
	protected C image(UiImageDefinition<?> rImage)
	{
		this.rImage = rImage;

		return (C) this;
	}

	/***************************************
	 * Internal method to set the value of this component's parameter. This is
	 * intended to be used by subclasses only which should provide a
	 * type-specific public method (like setText(String)).
	 *
	 * @param rValue The new value
	 */
	protected final void setValueImpl(T rValue)
	{
		fragment().setParameter(type(), rValue);
	}

	/***************************************
	 * Internal method to set the layout cell in which this component has been
	 * placed. Will be invoked from {@link
	 * UiLayout#layoutComponent(UiComponent)}.
	 *
	 * @param rCell The new layout cell
	 */
	void setLayoutCell(UiLayout.Cell rCell)
	{
		rLayoutCell = rCell;
	}

	/***************************************
	 * Internal method to set the UI properties of this component.
	 *
	 * @param rNewProperties The new UI properties
	 * @param bReplace       TRUE to replace existing properties, FALSE to only
	 *                       set new properties
	 */
	void setProperties(HasProperties rNewProperties, boolean bReplace)
	{
		if (rNewProperties.getPropertyCount() > 0)
		{
			MutableProperties rProperties = fragment().getUIProperties(type());

			if (rProperties == null)
			{
				rProperties = new StringProperties(rNewProperties);
				fragment().annotateParameter(type(),
											 null,
											 EntityRelationTypes.DISPLAY_PROPERTIES,
											 rProperties);
			}
			else
			{
				rProperties.setProperties(rNewProperties, bReplace);
				fragment().markParameterAsModified(type());
			}
		}
	}

	/***************************************
	 * Internal method to set a string size property.
	 *
	 * @param  rSizeProperty The size property
	 * @param  nSize         The size value
	 * @param  eUnit         The size unit
	 *
	 * @return This instance to allow fluent invocations
	 */
	C size(PropertyName<String> rSizeProperty, int nSize, SizeUnit eUnit)
	{
		return set(rSizeProperty, eUnit.getHtmlSize(nSize));
	}
}
<commit_msg>framework/esoco-business#53: Tooltips for Icons / Mapping functions for Columns<commit_after>//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// This file is a part of the 'esoco-business' project.
// Copyright 2017 <NAME>, esoco GmbH, Flensburg, Germany
//
// 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.
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
package de.esoco.process.ui;

import de.esoco.entity.EntityRelationTypes;

import de.esoco.lib.property.ContentProperties;
import de.esoco.lib.property.HasProperties;
import de.esoco.lib.property.MutableProperties;
import de.esoco.lib.property.PropertyName;
import de.esoco.lib.property.StringProperties;

import de.esoco.process.ParameterWrapper;
import de.esoco.process.ui.style.SizeUnit;
import de.esoco.process.ui.style.UiStyle;

import org.obrel.core.RelationType;

import static de.esoco.lib.property.ContentProperties.LABEL;
import static de.esoco.lib.property.LayoutProperties.HTML_HEIGHT;
import static de.esoco.lib.property.LayoutProperties.HTML_WIDTH;
import static de.esoco.lib.property.StyleProperties.HIDE_LABEL;
import static de.esoco.lib.property.StyleProperties.SHOW_LABEL;


/********************************************************************
 * The base class for all process UI components.
 *
 * @author eso
 */
public abstract class UiComponent<T, C extends UiComponent<T, C>>
	extends ParameterWrapper<T, C>
{
	//~ Instance fields --------------------------------------------------------

	private final UiContainer<?> rParent;

	private UiLayout.Cell		 rLayoutCell;
	private UiStyle				 aStyle = new UiStyle();
	private UiImageDefinition<?> rImage = null;

	//~ Constructors -----------------------------------------------------------

	/***************************************
	 * Creates a new instance.
	 *
	 * @param rParent   The parent container
	 * @param rDatatype The datatype of the component value
	 */
	public UiComponent(UiContainer<?> rParent, Class<? super T> rDatatype)
	{
		super(rParent != null ? rParent.fragment() : null,
			  rDatatype != null
			  ? rParent.fragment().getTemporaryParameterType(rDatatype) : null);

		this.rParent = rParent;

		if (rParent != null && rDatatype != null)
		{
			attachTo(rParent);
		}

		String sComponentStyle = getComponentStyleName();

		if (sComponentStyle.length() > 0)
		{
			aStyle.styleName(sComponentStyle);
		}
	}

	//~ Methods ----------------------------------------------------------------

	/***************************************
	 * Returns the layout cell in which this component has been placed.
	 *
	 * @return The cell
	 */
	public final UiLayout.Cell cell()
	{
		return rLayoutCell;
	}

	/***************************************
	 * Returns the parent container.
	 *
	 * @return The parent
	 */
	public final UiContainer<?> getParent()
	{
		return rParent;
	}

	/***************************************
	 * Returns the parent view of this component.
	 *
	 * @return The view of the hierarchy this component is placed in
	 */
	public UiView<?> getView()
	{
		return rParent instanceof UiView ? (UiView<?>) rParent
										 : rParent.getView();
	}

	/***************************************
	 * Sets the height of this component.
	 *
	 * @param  nHeight The height value
	 * @param  eUnit   The height unit
	 *
	 * @return This instance for concatenation
	 */
	public C height(int nHeight, SizeUnit eUnit)
	{
		return size(HTML_HEIGHT, nHeight, eUnit);
	}

	/***************************************
	 * Places this component before another component in the same parent
	 * container.
	 *
	 * @param  rBeforeComponent The component to place this component before
	 *
	 * @return This instance for concatenation
	 *
	 * @throws IllegalArgumentException If the given component is not found in
	 *                                  the parent container
	 */
	@SuppressWarnings("unchecked")
	public C placeBefore(UiComponent<?, ?> rBeforeComponent)
	{
		rParent.placeComponentBefore(rBeforeComponent, this);

		return (C) this;
	}

	/***************************************
	 * Sets the size of this component.
	 *
	 * @param  nWidth  The width
	 * @param  nHeight The height
	 * @param  eUnit   The unit of the size values
	 *
	 * @return This instance for concatenation
	 */
	public C size(int nWidth, int nHeight, SizeUnit eUnit)
	{
		return width(nWidth, eUnit).height(nHeight, eUnit);
	}

	/***************************************
	 * Returns the style object of this component which provides methods to
	 * modify the component's appearance.
	 *
	 * @return The component style
	 */
	public UiStyle style()
	{
		return aStyle;
	}

	/***************************************
	 * Sets the style of this component to a copy of an existing style
	 * definition.
	 *
	 * @param  rStyle The style object to apply
	 *
	 * @return The component style to allow subsequent modifications
	 */
	public UiStyle style(UiStyle rStyle)
	{
		aStyle = new UiStyle(rStyle);

		String sStyleName	   = aStyle.getStyleName();
		String sComponentStyle = getComponentStyleName();

		if (sComponentStyle.length() > 0 &&
			!sStyleName.startsWith(sComponentStyle))
		{
			aStyle.styleName(sComponentStyle + " " + sStyleName);
		}

		return aStyle;
	}

	/***************************************
	 * Sets the tooltip to be displayed for this component.
	 *
	 * @param  sTooltip The tooltip text or NULL for none
	 *
	 * @return This instance
	 */
	public C tooltip(String sTooltip)
	{
		return set(ContentProperties.TOOLTIP, sTooltip);
	}

	/***************************************
	 * {@inheritDoc}
	 */
	@Override
	public String toString()
	{
		return String.format("%s(%s)",
							 getClass().getSimpleName(),
							 fragment().getParameter(type()));
	}

	/***************************************
	 * Sets the width of this component.
	 *
	 * @param  nWidth The width value
	 * @param  eUnit  The width unit
	 *
	 * @return This instance for concatenation
	 */
	public C width(int nWidth, SizeUnit eUnit)
	{
		return size(HTML_WIDTH, nWidth, eUnit);
	}

	/***************************************
	 * Internal method to apply a label to this component by setting the
	 * appropriate properties. Can be invoked by methods from the public API of
	 * subclasses that support labels or captions.
	 *
	 * @param  sLabel The label text or NULL for none
	 *
	 * @return This instance
	 */
	protected C applyComponentLabel(String sLabel)
	{
		if (sLabel != null)
		{
			clear(HIDE_LABEL);
			set(SHOW_LABEL);
		}
		else
		{
			set(HIDE_LABEL);
			clear(SHOW_LABEL);
		}

		return set(LABEL, sLabel);
	}

	/***************************************
	 * Will be invoked to apply all properties of this component to the
	 * corresponding process parameter after it has been attached to the parent
	 * container.
	 */
	protected void applyProperties()
	{
		aStyle.applyPropertiesTo(this);

		// is NULL in the root view
		if (rLayoutCell != null)
		{
			rLayoutCell.applyPropertiesTo(this);
		}

		if (rImage != null)
		{
			rImage.applyPropertiesTo(this);
		}
	}

	/***************************************
	 * Attaches this component to it's parent container.
	 *
	 * @param rParent The parent container
	 */
	protected void attachTo(UiContainer<?> rParent)
	{
		rParent.addComponent(this);

		RelationType<T>  rParamType = type();
		Class<? super T> rDatatype  = rParamType.getValueType();

		fragment().addDisplayParameters(rParamType);

		if (rDatatype.isEnum())
		{
			resid(rDatatype.getSimpleName());
		}
	}

	/***************************************
	 * Returns the style name for this component. By default this is the simple
	 * class name of this component. Subclasses should override this if the
	 * class name is ambiguous and needs further specification. This is
	 * typically the case for non-static inner classes of composites which often
	 * have names that start without the 'Ui' prefix.
	 *
	 * @return The component style name
	 */
	protected String getComponentStyleName()
	{
		return getClass().getSimpleName();
	}

	/***************************************
	 * Internal method to return the value of this component's parameter. This
	 * is intended to be used by subclasses only which should provide a
	 * type-specific public method (like String getText()).
	 *
	 * @return The current value
	 */
	protected final T getValueImpl()
	{
		return fragment().getParameter(type());
	}

	/***************************************
	 * Sets an image for this component. This method is protected to provide the
	 * image handling functionality for all subclasses. Subclasses that support
	 * the setting of images should override this method as public.
	 *
	 * @param  rImage The component image
	 *
	 * @return This instance so that this method can be used for fluent
	 *         implementations
	 */
	@SuppressWarnings("unchecked")
	protected C image(UiImageDefinition<?> rImage)
	{
		this.rImage = rImage;

		return (C) this;
	}

	/***************************************
	 * Internal method to set the value of this component's parameter. This is
	 * intended to be used by subclasses only which should provide a
	 * type-specific public method (like setText(String)).
	 *
	 * @param rValue The new value
	 */
	protected final void setValueImpl(T rValue)
	{
		fragment().setParameter(type(), rValue);
	}

	/***************************************
	 * Internal method to set the layout cell in which this component has been
	 * placed. Will be invoked from {@link
	 * UiLayout#layoutComponent(UiComponent)}.
	 *
	 * @param rCell The new layout cell
	 */
	void setLayoutCell(UiLayout.Cell rCell)
	{
		rLayoutCell = rCell;
	}

	/***************************************
	 * Internal method to set the UI properties of this component.
	 *
	 * @param rNewProperties The new UI properties
	 * @param bReplace       TRUE to replace existing properties, FALSE to only
	 *                       set new properties
	 */
	void setProperties(HasProperties rNewProperties, boolean bReplace)
	{
		if (rNewProperties.getPropertyCount() > 0)
		{
			MutableProperties rProperties = fragment().getUIProperties(type());

			if (rProperties == null)
			{
				rProperties = new StringProperties(rNewProperties);
				fragment().annotateParameter(type(),
											 null,
											 EntityRelationTypes.DISPLAY_PROPERTIES,
											 rProperties);
			}
			else
			{
				rProperties.setProperties(rNewProperties, bReplace);
				fragment().markParameterAsModified(type());
			}
		}
	}

	/***************************************
	 * Internal method to set a string size property.
	 *
	 * @param  rSizeProperty The size property
	 * @param  nSize         The size value
	 * @param  eUnit         The size unit
	 *
	 * @return This instance to allow fluent invocations
	 */
	C size(PropertyName<String> rSizeProperty, int nSize, SizeUnit eUnit)
	{
		return set(rSizeProperty, eUnit.getHtmlSize(nSize));
	}
}

{'fraction_non_alphanumeric': 0.1936767730972185, 'fraction_numerical': 0.0010732492621411322, 'mean_word_length': 3.5132189707366295, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '973324', 'n_tokens_mistral': 6741, 'n_tokens_neox': 5958, 'n_words': 1969}