/* Editor.java

	Purpose:
		
	Description:
		
	History:
		Wed, Aug 13, 2014  3:26:40 PM, Created by RaymondChao

Copyright (C) 2014 Potix Corporation. All Rights Reserved.

*/
package org.zkoss.zssex.ui.widget;

import org.zkoss.lang.Objects;
import org.zkoss.zk.ui.AbstractComponent;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zk.ui.event.InputEvent;

/**
 * 
 * @author RaymondChao
 * @since 3.6.0
 */
public class Richtextbox extends AbstractComponent {

	private static final long serialVersionUID = 1L;
	static {
		addClientEvent(Richtextbox.class, Events.ON_CHANGE, CE_IMPORTANT|CE_REPEAT_IGNORE|CE_NON_DEFERRABLE);
	}
	private String _content;
	public void setContent(String content) {
		if (!Objects.equals(_content, content)) {
			_content = content;
			smartUpdate("content", content);
		}
	}
	public String getContent() {
		return _content;
	}

	//super//
	protected void renderProperties(org.zkoss.zk.ui.sys.ContentRenderer renderer)
	throws java.io.IOException {
		super.renderProperties(renderer);
		render(renderer, "content", _content);
	}
	
	public void service(org.zkoss.zk.au.AuRequest request, boolean everError) {
		final String cmd = request.getCommand();
		if (cmd.equals(Events.ON_CHANGE)) {
			InputEvent evt = InputEvent.getInputEvent(request, _content);
			final String value = evt.getValue();
			final Object oldContent = _content;
			setContent(value);
			if (oldContent == _content) {
				return;
			}
			Events.postEvent(evt);
		} else {
			super.service(request, everError);
		}
	}
}
