package com.example.samplemodule;

import java.util.List;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import com.artech.actions.UIContext;
import com.artech.base.controls.IGxControlRuntime;
import com.artech.base.metadata.ActionDefinition;
import com.artech.base.metadata.ActionParameter;
import com.artech.base.metadata.layout.LayoutItemDefinition;
import com.artech.base.model.Entity;
import com.artech.controls.IGxEdit;
import com.artech.fragments.IDataView;
import com.artech.ui.Coordinator;
import com.example.genexusmodule.R;

@SuppressLint("ViewConstructor")
public class BasicUserControl extends TextView implements IGxEdit,
														  IGxControlRuntime {
	private final static String METHOD_SET_NAME = "SetName";
	private final static String EVENT_ON_TAP = "OnTap";
	private final Coordinator mCoordinator;

	private String mName;
	private int tapCount;

	public BasicUserControl(Context context, Coordinator coordinator, LayoutItemDefinition definition) {
		super(context);
		mCoordinator = coordinator;
		tapCount = 0;
		setOnClickListener(mOnClickListener);
	}

	@Override
	public String getGx_Value() {
		return mName;
	}

	@Override
	public void setGx_Value(String value) {
		setName(value);
	}

	@Override
	public String getGx_Tag() {
		return getTag().toString();
	}

	@Override
	public void setGx_Tag(String tag) {
		setTag(tag);
	}

	@Override
	public void setValueFromIntent(Intent data) {

	}

	@Override
	public boolean isEditable() {
		return false;
	}

	@Override
	public IGxEdit getViewControl() {
		return null;
	}

	@Override
	public IGxEdit getEditControl() {
		return null;
	}

	@Override
	public void setProperty(String name, Object value) {

	}

	@Override
	public Object getProperty(String name) {
		return null;
	}

	@Override
	public void runMethod(String method, List<Object> parameters) {
		if (METHOD_SET_NAME.equals(method)) {
			String name = (String) parameters.get(0);
			setName(name);
		}
	}

	public void setName(String name) {
		mName = name;
		setText(getContext().getString(R.string.welcome_message, name));
	}

	public void runOnTapEvent() {
		UIContext context = mCoordinator.getUIContext();
		IDataView dataView = context.getDataView();

		ActionDefinition actionDef = mCoordinator.getControlEventHandler(this, EVENT_ON_TAP);
		Entity contextEntity = dataView.getContextEntity();

		for (ActionParameter param : actionDef.getEventParameters()) {
			String paramName = param.getValueDefinition().getName();
			contextEntity.setProperty(paramName, tapCount);
		}

		context.getActivityController().runAction(context, actionDef, contextEntity);
	}

	private final View.OnClickListener mOnClickListener = new OnClickListener() {
		@Override
		public void onClick(View v) {
			tapCount++;
			runOnTapEvent();
		}
	};
}

@@ -2210,106 +2210,8 @@
 ) %7B%0A
-%09%09UIContext context = mCoordinator.getUIContext();%0A%09%09IDataView dataView = context.getDataView();%0A%0A
 %09%09Ac
@@ -2297,62 +2297,8 @@
 AP);
-%0A%09%09Entity contextEntity = dataView.getContextEntity();
 %0A%0A%09%09
@@ -2427,33 +2427,29 @@
 %0A%09%09%09
-contextEntity.setProperty
+mCoordinator.setValue
 (par
@@ -2478,83 +2478,55 @@
 %0A%0A%09%09
-context.getActivityController().runAction(context, actionDef, contextEntity
+mCoordinator.runControlEvent(this, EVENT_ON_TAP
 );%0A%09

Correct how event variables should be set. This is, by using Coordinator's setValue method to set them in the appropriate context.