package to.etc.domui.component.layout;

import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import to.etc.domui.dom.errors.MsgType;
import to.etc.domui.dom.html.Div;
import to.etc.domui.dom.html.Img;
import to.etc.domui.dom.html.Span;
import to.etc.domui.util.DomUtil;
import to.etc.webapp.nls.IBundleCode;

/**
 * Forms a simple error message line with a small icon and a text (which may contain basic html).
 *
 * @author <a href="mailto:jal@etc.to">Frits Jalvingh</a>
 * Created on Jul 3, 2012
 */
public class MessageLine extends Div {
	@Nullable
	final private MsgType m_type;

	@NonNull
	final private String m_text;

	@Nullable
	final private String m_icon;

	public MessageLine(@NonNull MsgType type, @NonNull IBundleCode code) {
		this(type, code.getString());
	}

	public MessageLine(@NonNull MsgType type, @NonNull String text) {
		m_type = type;
		m_text = text;
		m_icon = null;
	}

	public MessageLine(@NonNull String icon, @NonNull String text) {
		m_icon = icon;
		m_text = text;
		m_type = null;
	}

	@Override
	public void createContent() throws Exception {
		addCssClass("ui-msgln");
		Img img = new Img();
		if(m_type != null) {
			img.setSrc("THEME/mini-" + m_type.name().toLowerCase() + ".png");
		} else if(m_icon != null) {
			img.setSrc(m_icon);
		} else
			throw new IllegalArgumentException("No icon nor type.");
		add(img);
		Span sp = new Span();
		add(sp);
		sp.addCssClass("ui-msgln-txt");
		DomUtil.renderHtmlString(sp, m_text);
	}
}

@@ -228,16 +228,60 @@
 ml.Img;%0A
+import to.etc.domui.dom.html.NodeContainer;%0A
 import t
@@ -341,16 +341,51 @@
 omUtil;%0A
+import to.etc.function.ConsumerEx;%0A
 import t
@@ -693,22 +693,23 @@
 pe;%0A%0A%09@N
-onN
 ull
+able
 %0A%09final 
@@ -774,16 +774,81 @@
 _icon;%0A%0A
+%09@Nullable%0A%09final private ConsumerEx%3CNodeContainer%3E m_renderer;%0A%0A
 %09public 
@@ -1061,24 +1061,45 @@
 con = null;%0A
+%09%09m_renderer = null;%0A
 %09%7D%0A%0A%09public 
@@ -1203,24 +1203,217 @@
 ype = null;%0A
+%09%09m_renderer = null;%0A%09%7D%0A%0A%09public MessageLine(@Nullable MsgType type, @Nullable ConsumerEx%3CNodeContainer%3E renderer) %7B%0A%09%09m_type = type;%0A%09%09m_renderer = renderer;%0A%09%09m_icon = null;%0A%09%09m_text = null;%0A
 %09%7D%0A%0A%09@Overri
@@ -1808,16 +1808,106 @@
 -txt%22);%0A
+%09%09String text = m_text;%0A%09%09ConsumerEx%3CNodeContainer%3E r = m_renderer;%0A%09%09if(null != text) %7B%0A%09
 %09%09DomUti
@@ -1933,17 +1933,61 @@
 sp, 
-m_
 text);%0A
+%09%09%7D else if(r != null) %7B%0A%09%09%09r.accept(sp);%0A%09%09%7D%0A
 %09%7D%0A%7D

Allow MessageLine to create its content from a listener