[richfaces-svn-commits] JBoss Rich Faces SVN: r232 - trunk/richfaces/dropdown-menu/src/main/java/org/richfaces/renderkit/html.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Mon Apr 2 04:27:15 EDT 2007


Author: a.izobov
Date: 2007-04-02 04:27:15 -0400 (Mon, 02 Apr 2007)
New Revision: 232

Modified:
   trunk/richfaces/dropdown-menu/src/main/java/org/richfaces/renderkit/html/DropDownMenuRendererBase.java
Log:
menu without menuLayer template

Modified: trunk/richfaces/dropdown-menu/src/main/java/org/richfaces/renderkit/html/DropDownMenuRendererBase.java
===================================================================
--- trunk/richfaces/dropdown-menu/src/main/java/org/richfaces/renderkit/html/DropDownMenuRendererBase.java	2007-04-02 08:25:31 UTC (rev 231)
+++ trunk/richfaces/dropdown-menu/src/main/java/org/richfaces/renderkit/html/DropDownMenuRendererBase.java	2007-04-02 08:27:15 UTC (rev 232)
@@ -24,9 +24,23 @@
 
 
 
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+
+import org.ajax4jsf.framework.renderer.AjaxRendererUtils;
+import org.ajax4jsf.framework.renderer.HeaderResourcesRendererBase;
 import org.richfaces.component.UIDropDownMenu;
+import org.richfaces.component.UIMenuGroup;
+import org.richfaces.component.UIMenuItem;
+import org.richfaces.component.UIMenuSeparator;
 
-public class DropDownMenuRendererBase extends MenuRendererBase {	
+public class DropDownMenuRendererBase extends HeaderResourcesRendererBase {	
 	
 	protected Class getComponentClass() {
 		return UIDropDownMenu.class;
@@ -36,5 +50,126 @@
 		return true;
 	}
 
+	public void encodeChildren(FacesContext context, UIComponent component) throws IOException {
+		List flatListOfNodes = new LinkedList();
+		String width = (String)component.getAttributes().get("popupWidth");
+		
+		flatten(component.getChildren(), flatListOfNodes);
+		processLayer(context, component, width);
+		
+		for (Iterator iter = flatListOfNodes.iterator(); iter.hasNext();) {
+			UIMenuGroup node = (UIMenuGroup) iter.next();
+			processLayer(context, node, width);
+		}
+	}
+
+	public void processLayer(FacesContext context, UIComponent layer, String width) throws IOException {
+		String clientId = layer.getClientId(context);
+
+		ResponseWriter writer = context.getResponseWriter();
+		writer.startElement("div", layer);
+		writer.writeAttribute("id", clientId+"_menu", null);
+		writer.writeAttribute("class", "dr-menu-list-border rich-menu-list-border", null);
+		writer.writeAttribute("style", "visibility: hidden; z-index:100; " + (width!=null&&width.length()>0?"width: "+width:""), null);
+		writer.startElement("div", layer);
+		writer.writeAttribute("class", "dr-menu-list-bg rich-menu-list-bg", null);
+		encodeItems(context, layer);
+		writer.endElement("div");
+		writer.endElement("div");
+
+		writer.startElement("iframe", layer);
+		writer.writeAttribute("id", clientId+"_menu_iframe", null);
+		writer.writeAttribute("class", "underneath_iframe", null);
+		writer.writeAttribute("style", "position:absolute", null);
+		writer.endElement("iframe");
 	
+		writer.startElement("iframe", layer);
+		writer.writeAttribute("id", clientId+"_menu_iframe1", null);
+		writer.writeAttribute("class", "underneath_iframe", null);
+		writer.writeAttribute("style", "position:absolute", null);
+		writer.endElement("iframe");
+
+		writer.startElement("script", layer);
+		writer.writeAttribute("id", clientId+"_menu_script", null);
+		writer.writeAttribute("type", "text/javascript", null);
+		encodeScript(context, layer);
+		writer.endElement("script");
+		AjaxRendererUtils.addRegionByName(context, layer, clientId + "_menu_iframe");
+		AjaxRendererUtils.addRegionByName(context, layer, clientId + "_menu_iframe1");
+		AjaxRendererUtils.addRegionByName(context, layer, clientId + "_menu_script");
+	}
+	
+	public void encodeItems(FacesContext context, UIComponent component) throws IOException {
+		List kids = component.getChildren();
+		Iterator it = kids.iterator();
+		while (it.hasNext()) {
+			UIComponent kid = (UIComponent)it.next();
+			if (kid instanceof UIMenuGroup || kid instanceof UIMenuItem || kid instanceof UIMenuSeparator) {
+				renderChild(context, kid);
+			}
+		}
+	}
+
+	private void flatten(List kids, List flatList){
+		if(kids != null){
+			for (Iterator iter = kids.iterator(); iter.hasNext();) {
+				UIComponent kid = (UIComponent) iter.next();
+				if (kid instanceof UIMenuGroup) {
+					UIMenuGroup node = (UIMenuGroup) kid;
+					flatList.add(node);
+					flatten(node.getChildren(), flatList);
+				}
+			}
+		}
+	}
+
+	public void encodeScript(FacesContext context, UIComponent component) throws IOException {
+		StringBuffer buffer = 
+			new StringBuffer("new Exadel.Menu.Layer('")	
+				.append(component.getClientId(context)+"_menu")
+				.append("',")
+				.append(component.getAttributes().get("showDelay"))
+				.append( ")");
+		if (component instanceof UIMenuGroup) {
+			buffer.append(".asSubMenu('")
+				.append(component.getParent().getClientId(context)+"_menu")
+				.append("','")	
+				.append("ref")
+				.append(component.getClientId(context))
+				.append("')");
+		} else {
+		    buffer
+	         .append(".asDropDown('")
+	         .append(component.getClientId(context))		         
+	         .append("'");
+	    
+			String evt = (String) component.getAttributes().get("event");
+			if(evt == null || evt.trim().length() == 0){
+				evt = "onmouseover";
+			}
+			buffer.append(",'").append(evt).append("')");
+			
+		}
+		List children = component.getChildren();
+		for(Iterator it = children.iterator();it.hasNext();) {
+			UIComponent kid = (UIComponent)it.next();
+			String itemId = null;
+			if (kid instanceof UIMenuItem) {
+				itemId = kid.getClientId(context);
+			} else if (kid instanceof UIMenuGroup) {
+				itemId = "ref" + kid.getClientId(context);
+			}
+			if(itemId != null){
+				buffer
+					.append(".addItem('")
+					.append(itemId)
+					.append("')");
+			}
+		}
+		ResponseWriter out = context.getResponseWriter();
+		String script =buffer.append(";").toString();
+		out.write(script); 
+	}
+	
+	
 }




More information about the richfaces-svn-commits mailing list