package jp.co.cybec.laxide.model.base;

import jp.co.cybec.laxide.layout.AbstractLayoutPoints;
import jp.co.cybec.laxide.layout.LetsAjaxLayoutPointFactory;

import org.eclipse.draw2d.geometry.Point;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.eclipse.ui.views.properties.TextPropertyDescriptor;
import org.jdom.Element;

/**
 * ２段組レイアウトのモデルクラス
 * 
 * @author tokumaru
 */
public class LetsAjax2ColumnLayoutModel extends BaseModel implements
		I_LetsAjaxLayoutModel {

	/* (non-Javadoc)
	 * @see jp.co.cybec.laxide.model.base.BaseModel#getLayoutXML()
	 */
	@Override
	public String getLayoutXML() {
		String html = "<" + super.getType() + this.getId()
				+ getBodyComponentXml() + ">\n";
		html = html + "        " + getAreaElement();
		html = html + "    </" + super.getType() + ">\n";

		return html;
	}

	/* (non-Javadoc)
	 * @see jp.co.cybec.laxide.model.base.BaseModel#getBodyComponentXml()
	 */
	@Override
	public String getBodyComponentXml() {
		return "templateClass=\"LetsAjax2ColumnLayout\"";
	}

	/* (non-Javadoc)
	 * @see jp.co.cybec.laxide.model.base.AbstractModel#setAttribute(org.jdom.Element)
	 */
	@Override
	public void setAttribute(Element element) {
		super.setAttribute(element);
		super.setType(LetsAjaxLayoutConstant.LETSAJAX_BODY_2COLOMUN_LAYOUT);
	}

	/**
	 * @return
	 */
	private String getAreaElement() {
		// キャッシュされている座標からボックスの枠の座標を取得
		AbstractLayoutPoints points = LetsAjaxLayoutPointFactory.getInstance()
				.getLayoutPoints();
		Point sideleftStartPoint = points.getSideLeftStartPoint();
		Point sideleftEndPoint = points.getSideLeftEndPoint();

		Point contentsStartPoint = points.getContentsStartPoint();
		Point contentsEndPoint = points.getContentsEndPoint();

		return "<area name=\"sideleft\" startX=\"" + sideleftStartPoint.x
				+ "\" startY=\"" + sideleftStartPoint.y + "\"" + " endX=\""
				+ sideleftEndPoint.x + "\" endY=\"" + sideleftEndPoint.y
				+ "\"/>\n" + "        <area name=\"contents\" startX=\""
				+ contentsStartPoint.x + "\" startY=\"" + contentsStartPoint.y
				+ "\"" + " endX=\"" + contentsEndPoint.x + "\" endY=\""
				+ contentsEndPoint.y + "\"/>\n";
	}

	/* (non-Javadoc)
	 * @see jp.co.cybec.laxide.model.base.AbstractModel#setPropertyValue(java.lang.Object, java.lang.Object)
	 */
	public void setPropertyValue(Object id, Object value) {
	}

}
