/* D-RexGxt - D-RexGxt - GUI Design Tool for GWT
 * Copyright (c) 2008,  KPS Corporation
 * All rights reserved.
 *
 * Open Source License
 * ------------------------------------------------------------------------------------------
 * D-RexGxt is licensed under the terms of the Open Source GPL 3.0 license.
 *
 * http://www.gnu.org/licenses/gpl.html
 *
 * --
 *
 * This library 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
 * General Public License for more details.
 */
package jp.co.kpscorp.gwt.client.design.gxt.delegate.comp;

import jp.co.kpscorp.gwt.client.design.WidgetService;
import jp.co.kpscorp.gwt.client.design.gxt.GxtUtil;

import com.extjs.gxt.ui.client.widget.Component;
import com.extjs.gxt.ui.client.widget.menu.Item;
import com.extjs.gxt.ui.client.widget.menu.Menu;

public class ItemDelegate extends ComponentDelegate {

	private Item comp;

	protected String[] props = { "hideOnClick", "activeStyle" };

	protected String[] innerProps = { "hideOnClick", "activeStyle" };

	public ItemDelegate(WidgetService service, Component widget) {
		super(service, widget);
		this.comp = (Item) widget;
	}

	@Override
	public Object exec(String mthodName, Object[] parms) {
		if ("getActiveStyle".equals(mthodName)) {
			return comp.getActiveStyle();
		} else if ("getHideOnClick".equals(mthodName)) {
			return comp.getHideOnClick();
		} else if ("getParentMenu".equals(mthodName)) {
			return comp.getParentMenu();
		} else if ("setActiveStyle".equals(mthodName)
				&& parms[0] instanceof String) {
			comp.setActiveStyle((String) parms[0]);
			return comp;
		} else if ("setHideOnClick".equals(mthodName)
				&& parms[0] instanceof Boolean) {
			comp.setHideOnClick((Boolean) parms[0]);
			return comp;
		}
		return super.exec(mthodName, parms);
	}

	@Override
	public String[] getProps() {
		return GxtUtil.add(super.getProps(), props);
	}

	@Override
	public String[] getInnerProps() {
		return GxtUtil.add(super.getInnerProps(), innerProps);
	}

	@Override
	public boolean isAddableToParent(Component parent) {
		if (parent instanceof Menu) {
			return true;
		}
		return false;
	}

	@Override
	public String getCategory() {
		return "Tool/Menu";
	}

}
