package com.fr.design.editor.editor;

import com.fr.design.gui.itextfield.UITextField;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.stable.ColumnRowGroup;

import java.awt.*;

/**
 * Author : Shockway
 * Date: 14-1-10
 * Time: 下午1:46
 */
public class ColumnRowGroupEditor extends Editor<ColumnRowGroup> {

	private UITextField crEditor;

	public ColumnRowGroupEditor() {
		this("");
	}

	public ColumnRowGroupEditor(String name) {
		this(null, name);
	}

	public ColumnRowGroupEditor(ColumnRowGroup value) {
		this(value, "");
	}

	public ColumnRowGroupEditor(ColumnRowGroup value, String name) {
		this.setLayout(FRGUIPaneFactory.createBorderLayout());
		crEditor = new UITextField();
		this.add(crEditor, BorderLayout.CENTER);
		this.setValue(value);
		this.setName(name);
	}

	@Override
	public ColumnRowGroup getValue() {
		return new ColumnRowGroup(this.crEditor.getText());
	}

	@Override
	public void setValue(ColumnRowGroup value) {
		if (value == null) {
			this.crEditor.setText("");
		} else {
			this.crEditor.setText(value.toString());
		}
	}

	@Override
	public void setEnabled(boolean enabled) {
		super.setEnabled(enabled);

		this.crEditor.setEnabled(enabled);
	}

	/**
	 * 获取焦点
	 */
	public void requestFocus() {
		this.crEditor.requestFocus();
	}

	public String getIconName() {
		return "cell_group";
	}

	/**
	 * 是否接收/支持这个对象
	 * @param object 检测对象
	 * @return 是否支持
	 */
	public boolean accept(Object object) {
		return object instanceof ColumnRowGroup;
	}
}