//#############################################################################
//#                                                                           #
//#  Copyright (C) <2014>  <IMS MAXIMS>                                       #
//#                                                                           #
//#  This program is free software: you can redistribute it and/or modify     #
//#  it under the terms of the GNU Affero General Public License as           #
//#  published by the Free Software Foundation, either version 3 of the       #
//#  License, or (at your option) any later version.                          # 
//#                                                                           #
//#  This program is distributed in the hope that it will be useful,          #
//#  but WITHOUT ANY WARRANTY; without even the implied warranty of           #
//#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            #
//#  GNU Affero General Public License for more details.                      #
//#                                                                           #
//#  You should have received a copy of the GNU Affero General Public License #
//#  along with this program.  If not, see <http://www.gnu.org/licenses/>.    #
//#                                                                           #
//#############################################################################
//#EOH
// This code was generated by Barbara Worwood using IMS Development Environment (version 1.80 build 5007.25751)
// Copyright (C) 1995-2014 IMS MAXIMS. All rights reserved.
// WARNING: DO NOT MODIFY the content of this file

package ims.core.forms.questionselectnew;

public abstract class BaseLogic extends Handlers
{
	public final Class getDomainInterface() throws ClassNotFoundException
	{
		return ims.core.domain.QuestionSelectNew.class;
	}
	public final void setContext(ims.framework.UIEngine engine, GenForm form, ims.core.domain.QuestionSelectNew domain)
	{
		setContext(engine, form);
		this.domain = domain;
	}
	public void clearContextInformation()
	{
		engine.clearPatientContextInformation();
	}
	protected final void oncmbGenreValueSet(Object value)
	{
		java.util.ArrayList listOfValues = this.form.lyrTabs().tabNewQuestion().lyrDetails().tabGeneral().cmbGenre().getValues();

		if(value == null)
		{
			if(listOfValues != null && listOfValues.size() > 0)
			{
				for(int x = 0; x < listOfValues.size(); x++)
				{
					ims.admin.vo.lookups.GenderSpecific existingInstance = (ims.admin.vo.lookups.GenderSpecific)listOfValues.get(x);
					if(!existingInstance.isActive())
					{
						bindcmbGenreLookup();
						return;
					}
				}
			}
		}
		else if(value instanceof ims.admin.vo.lookups.GenderSpecific)
		{
			ims.admin.vo.lookups.GenderSpecific instance = (ims.admin.vo.lookups.GenderSpecific)value;

			if(listOfValues != null)
			{
				if(listOfValues.size() == 0)
					bindcmbGenreLookup();

				for(int x = 0; x < listOfValues.size(); x++)
				{
					ims.admin.vo.lookups.GenderSpecific existingInstance = (ims.admin.vo.lookups.GenderSpecific)listOfValues.get(x);
					if(existingInstance.equals(instance))
						return;
				}
			}

			this.form.lyrTabs().tabNewQuestion().lyrDetails().tabGeneral().cmbGenre().newRow(instance, instance.getText(), instance.getImage(), instance.getTextColor());
		}
	}
	protected final void bindcmbGenreLookup()
	{
		this.form.lyrTabs().tabNewQuestion().lyrDetails().tabGeneral().cmbGenre().clear();
		ims.admin.vo.lookups.GenderSpecificCollection lookupCollection = ims.admin.vo.lookups.LookupHelper.getGenderSpecific(this.domain.getLookupService());
		for(int x = 0; x < lookupCollection.size(); x++)
		{
			this.form.lyrTabs().tabNewQuestion().lyrDetails().tabGeneral().cmbGenre().newRow(lookupCollection.get(x), lookupCollection.get(x).getText(), lookupCollection.get(x).getImage(), lookupCollection.get(x).getTextColor());
		}
	}
	protected final void setcmbGenreLookupValue(int id)
	{
		ims.admin.vo.lookups.GenderSpecific instance = ims.admin.vo.lookups.LookupHelper.getGenderSpecificInstance(this.domain.getLookupService(), id);
		if(instance != null)
			this.form.lyrTabs().tabNewQuestion().lyrDetails().tabGeneral().cmbGenre().setValue(instance);
	}
	protected final void defaultcmbGenreLookupValue()
	{
		this.form.lyrTabs().tabNewQuestion().lyrDetails().tabGeneral().cmbGenre().setValue((ims.admin.vo.lookups.GenderSpecific)domain.getLookupService().getDefaultInstance(ims.admin.vo.lookups.GenderSpecific.class, engine.getFormName().getID(), ims.admin.vo.lookups.GenderSpecific.TYPE_ID));
	}
	protected final void oncmbStatusValueSet(Object value)
	{
		java.util.ArrayList listOfValues = this.form.lyrTabs().tabNewQuestion().cmbStatus().getValues();

		if(value == null)
		{
			if(listOfValues != null && listOfValues.size() > 0)
			{
				for(int x = 0; x < listOfValues.size(); x++)
				{
					ims.core.vo.lookups.PreActiveActiveInactiveStatus existingInstance = (ims.core.vo.lookups.PreActiveActiveInactiveStatus)listOfValues.get(x);
					if(!existingInstance.isActive())
					{
						bindcmbStatusLookup();
						return;
					}
				}
			}
		}
		else if(value instanceof ims.core.vo.lookups.PreActiveActiveInactiveStatus)
		{
			ims.core.vo.lookups.PreActiveActiveInactiveStatus instance = (ims.core.vo.lookups.PreActiveActiveInactiveStatus)value;

			if(listOfValues != null)
			{
				if(listOfValues.size() == 0)
					bindcmbStatusLookup();

				for(int x = 0; x < listOfValues.size(); x++)
				{
					ims.core.vo.lookups.PreActiveActiveInactiveStatus existingInstance = (ims.core.vo.lookups.PreActiveActiveInactiveStatus)listOfValues.get(x);
					if(existingInstance.equals(instance))
						return;
				}
			}

			this.form.lyrTabs().tabNewQuestion().cmbStatus().newRow(instance, instance.getText(), instance.getImage(), instance.getTextColor());
		}
	}
	protected final void bindcmbStatusLookup()
	{
		this.form.lyrTabs().tabNewQuestion().cmbStatus().clear();
		ims.core.vo.lookups.PreActiveActiveInactiveStatusCollection lookupCollection = ims.core.vo.lookups.LookupHelper.getPreActiveActiveInactiveStatus(this.domain.getLookupService());
		for(int x = 0; x < lookupCollection.size(); x++)
		{
			this.form.lyrTabs().tabNewQuestion().cmbStatus().newRow(lookupCollection.get(x), lookupCollection.get(x).getText(), lookupCollection.get(x).getImage(), lookupCollection.get(x).getTextColor());
		}
	}
	protected final void setcmbStatusLookupValue(int id)
	{
		ims.core.vo.lookups.PreActiveActiveInactiveStatus instance = ims.core.vo.lookups.LookupHelper.getPreActiveActiveInactiveStatusInstance(this.domain.getLookupService(), id);
		if(instance != null)
			this.form.lyrTabs().tabNewQuestion().cmbStatus().setValue(instance);
	}
	protected final void defaultcmbStatusLookupValue()
	{
		this.form.lyrTabs().tabNewQuestion().cmbStatus().setValue((ims.core.vo.lookups.PreActiveActiveInactiveStatus)domain.getLookupService().getDefaultInstance(ims.core.vo.lookups.PreActiveActiveInactiveStatus.class, engine.getFormName().getID(), ims.core.vo.lookups.PreActiveActiveInactiveStatus.TYPE_ID));
	}
	protected void clearScreen()
	{
		this.form.lyrTabs().tabNewQuestion().lyrDetails().tabGeneral().cmbGenre().setValue(null);
		this.form.lyrTabs().tabNewQuestion().lyrDetails().tabGeneral().chkIsQuestion().setValue(false);
		this.form.lyrTabs().tabNewQuestion().lyrDetails().tabKeywords().grdKeywords().getRows().clear();
		this.form.lyrTabs().tabNewQuestion().txtShortText().setValue("");
		this.form.lyrTabs().tabNewQuestion().txtText().setValue("");
		this.form.lyrTabs().tabNewQuestion().cmbStatus().setValue(null);
	}
	protected void populateScreenFromData(ims.core.vo.QuestionInformationVo value)
	{
		clearScreen();
		if(value == null)
			return;

		this.form.lyrTabs().tabNewQuestion().lyrDetails().tabGeneral().cmbGenre().setValue(value.getGenderSpecificIsNotNull() ? value.getGenderSpecific() : null);
		if(value.getIsQuestionIsNotNull())
			this.form.lyrTabs().tabNewQuestion().lyrDetails().tabGeneral().chkIsQuestion().setValue(value.getIsQuestion().booleanValue());
		// ----- Start of grdKeywords Grid --------------------------
		ims.core.vo.KeywordVoCollection fieldgrdKeywords = value.getKeywordsIsNotNull() ? value.getKeywords() : null;
		if(fieldgrdKeywords != null)
		{
			GenForm.lyrTabsLayer.tabNewQuestionContainer.lyrDetailsLayer.tabKeywordsContainer.grdKeywordsRow rowgrdKeywords;
			for(int x = 0; x < fieldgrdKeywords.size(); x++)
			{
				if(fieldgrdKeywords.get(x) != null)
				{
					rowgrdKeywords = this.form.lyrTabs().tabNewQuestion().lyrDetails().tabKeywords().grdKeywords().getRows().newRow();

					rowgrdKeywords.setcolName(fieldgrdKeywords.get(x).getKeyword());

					rowgrdKeywords.setValue(fieldgrdKeywords.get(x));
				}
			}
		}
		// ----- End of grdKeywords Grid ----------------------------
		this.form.lyrTabs().tabNewQuestion().txtShortText().setValue(value.getShortTextIsNotNull() ? value.getShortText(): null);
		this.form.lyrTabs().tabNewQuestion().txtText().setValue(value.getTextIsNotNull() ? value.getText(): null);
		this.form.lyrTabs().tabNewQuestion().cmbStatus().setValue(value.getStatusIsNotNull() ? value.getStatus() : null);
	}
	protected ims.core.vo.QuestionInformationVo populateDataFromScreen(ims.core.vo.QuestionInformationVo value)
	{
		if(value == null)
			value = new ims.core.vo.QuestionInformationVo();

		value.setGenderSpecific(this.form.lyrTabs().tabNewQuestion().lyrDetails().tabGeneral().cmbGenre().getValue());
		value.setIsQuestion(new Boolean(this.form.lyrTabs().tabNewQuestion().lyrDetails().tabGeneral().chkIsQuestion().getValue()));
		// ----- Start of grdKeywords Grid --------------------------
		value.setKeywords(new ims.core.vo.KeywordVoCollection());
		for(int x = 0; x < this.form.lyrTabs().tabNewQuestion().lyrDetails().tabKeywords().grdKeywords().getRows().size(); x++)
		{
			ims.core.vo.KeywordVo rowValue = this.form.lyrTabs().tabNewQuestion().lyrDetails().tabKeywords().grdKeywords().getRows().get(x).getValue();
			if(rowValue == null)
				rowValue = new ims.core.vo.KeywordVo();

			rowValue.setKeyword(this.form.lyrTabs().tabNewQuestion().lyrDetails().tabKeywords().grdKeywords().getRows().get(x).getcolName());

			if(value.getKeywordsIsNotNull())
				value.getKeywords().add(rowValue);
		}
		// ----- End of grdKeywords Grid ----------------------------
		value.setShortText(this.form.lyrTabs().tabNewQuestion().txtShortText().getValue());
		value.setText(this.form.lyrTabs().tabNewQuestion().txtText().getValue());
		value.setStatus(this.form.lyrTabs().tabNewQuestion().cmbStatus().getValue());

		return value;
	}
	protected ims.core.vo.QuestionInformationVo populateDataFromScreen()
	{
		return populateDataFromScreen(new ims.core.vo.QuestionInformationVo());
	}
	public final void free()
	{
		super.free();
		domain = null;
	}
	
	protected ims.core.domain.QuestionSelectNew domain;
}
