//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// This file is a part of the 'esoco-business' project.
// Copyright 2018 Elmar Sonnenschein, 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.lib.property.Alignment;
import de.esoco.lib.property.InteractionEventType;
import de.esoco.lib.property.LayoutProperties;
import de.esoco.lib.property.UserInterfaceProperties;
import de.esoco.lib.property.ViewDisplayType;

import java.util.List;

import org.obrel.core.RelationType;

import static de.esoco.lib.property.StyleProperties.AUTO_HIDE;


/********************************************************************
 * A view that is displayed as a child of another view.
 *
 * @author eso
 */
public abstract class UiChildView<V extends UiChildView<V>> extends UiView<V>
{
	//~ Instance fields --------------------------------------------------------

	private Runnable rCloseHandler;

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

	/***************************************
	 * Creates a new instance and shows it.
	 *
	 * @see UiView#UiView(UiView, UiLayout)
	 */
	public UiChildView(UiView<?>	   rParent,
					   UiLayout		   rLayout,
					   ViewDisplayType eViewType)
	{
		super(rParent, rLayout);

		setViewType(eViewType);
	}

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

	/***************************************
	 * Enables automatic hiding of this view if the user clicks outside.
	 *
	 * @return This instance
	 */
	public V autoHide()
	{
		setParameterEventHandler(InteractionEventType.UPDATE,
								 v -> handleCloseView());

		return set(AUTO_HIDE);
	}

	/***************************************
	 * Indicates that this view should be centered on the screen.
	 *
	 * @return This instance
	 */
	public V center()
	{
		return set(UserInterfaceProperties.VERTICAL_ALIGN, Alignment.CENTER);
	}

	/***************************************
	 * Adds a handler that will be invoked when this view is closed.
	 *
	 * @param  rCloseHandler The handler to be invoked if the view is closed
	 *
	 * @return This instance
	 */
	@SuppressWarnings("unchecked")
	public V onClose(Runnable rCloseHandler)
	{
		this.rCloseHandler = rCloseHandler;

		return (V) this;
	}

	/***************************************
	 * Overridden to show or hide this view.
	 *
	 * @see UiContainer#setVisible(boolean)
	 */
	@Override
	@SuppressWarnings("unchecked")
	public V setVisible(boolean bVisible)
	{
		RelationType<List<RelationType<?>>> rViewParam = type();

		if (bVisible)
		{
			getParent().fragment().addViewFragment(rViewParam, fragment());
			applyProperties();
		}
		else
		{
			getParent().fragment().removeViewFragment(rViewParam);
		}

		return (V) this;
	}

	/***************************************
	 * Overridden to setup the container fragment and to attach it to the parent
	 * fragment.
	 *
	 * @see UiComponent#attachTo(UiContainer)
	 */
	@Override
	protected void attachTo(UiContainer<?> rParent)
	{
		setupContainerFragment(rParent);
	}

	/***************************************
	 * Set the type of this view
	 *
	 * @param eViewType The view type
	 */
	protected void setViewType(ViewDisplayType eViewType)
	{
		set(LayoutProperties.VIEW_DISPLAY_TYPE, eViewType);
	}

	/***************************************
	 * Handles close events for this view.
	 */
	private void handleCloseView()
	{
		if (rCloseHandler != null)
		{
			rCloseHandler.run();
		}

		Boolean rAutoHide = get(AUTO_HIDE);

		if (rAutoHide != null && rAutoHide.booleanValue())
		{
			hide();
		}
	}
}

@@ -1097,24 +1097,75 @@
 splayType;%0A%0A
+import de.esoco.process.step.InteractionFragment;%0A%0A
 import java.
@@ -1277,16 +1277,82 @@
 _HIDE;%0A%0A
+import static de.esoco.process.ProcessRelationTypes.VIEW_PARAMS;%0A%0A
 %0A/******
@@ -2035,16 +2035,125 @@
 yout);%0A%0A
+%09%09getParent().fragment().addViewFragment(type(), fragment());%0A%09%09fragment().get(VIEW_PARAMS).remove(type());%0A%0A
 %09%09setVie
@@ -3448,141 +3448,193 @@
 %0A%09%09%09
-getParent().fragment().addViewFragment(rViewParam, fragment());%0A%09%09%09applyProperties();%0A%09%09%7D%0A%09%09else%0A%09%09%7B%0A%09%09%09getParent().fragment(
+fragment().get(VIEW_PARAMS).add(rViewParam);%0A%09%09%09applyProperties();%0A%09%09%7D%0A%09%09else%0A%09%09%7B%0A%09%09%09InteractionFragment rParentFragment = getParent().fragment();%0A%0A%09%09%09fragment().get(VIEW_PARAMS
 ).remove
 View
@@ -3629,20 +3629,118 @@
 ).remove
+(r
 View
+Param);%0A%09%09%09rParentFragment.removeInteractionParameters(rViewParam);%0A%09%09%09rParentFragment.removeSub
 Fragment

Optimize DataElement serialization from server to client