Author: a.izobov
Date: 2007-03-30 10:53:31 -0400 (Fri, 30 Mar 2007)
New Revision: 225
Added:
trunk/richfaces/menu-components/src/main/java/org/richfaces/renderkit/html/MenuRendererBase.java
Modified:
trunk/richfaces/menu-components/src/main/java/org/richfaces/renderkit/html/MenuGroupRendererBase.java
Log:
menuGroup development
Modified:
trunk/richfaces/menu-components/src/main/java/org/richfaces/renderkit/html/MenuGroupRendererBase.java
===================================================================
---
trunk/richfaces/menu-components/src/main/java/org/richfaces/renderkit/html/MenuGroupRendererBase.java 2007-03-30
14:48:51 UTC (rev 224)
+++
trunk/richfaces/menu-components/src/main/java/org/richfaces/renderkit/html/MenuGroupRendererBase.java 2007-03-30
14:53:31 UTC (rev 225)
@@ -22,20 +22,15 @@
package org.richfaces.renderkit.html;
import java.io.IOException;
-import java.util.Iterator;
-import java.util.List;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
-import org.ajax4jsf.framework.renderer.HeaderResourcesRendererBase;
import org.richfaces.component.UIMenuGroup;
-import org.richfaces.component.UIMenuItem;
-public class MenuGroupRendererBase extends HeaderResourcesRendererBase {
+public class MenuGroupRendererBase extends MenuRendererBase {
protected Class getComponentClass() {
return UIMenuGroup.class;
@@ -45,50 +40,7 @@
return true;
}
- public void getScript(FacesContext context, UIComponent component) throws IOException {
- StringBuffer buffer =
- new StringBuffer("new Exadel.Menu.Layer('")
- .append("ref")
- .append(component.getClientId(context)+"_menu")
- .append("',")
- .append( "300 )");
- //component.getAttributes().get("showDelay")
- buffer.append(".asSubMenu('")
- .append(component.getParent().getClientId(context)+"_menu")
- .append("','")
- .append("ref")
- .append(component.getClientId(context))
- .append("')");
-
- //.append(component.getParent().getClientId(context)+"_menu")
- //.append("ref")
- 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("','")
- .append("null")
- .append("','")
- .append("null")
- .append("','")
- .append("null")
- .append("','")
- .append("null")
- .append("')");
- }
- }
- ResponseWriter out = context.getResponseWriter();
- String script =buffer.append(";").toString();
- out.write(script);
- }
-
+ public void encodeChildren(FacesContext context, UIComponent component) throws
IOException {
+ }
+
}
Added:
trunk/richfaces/menu-components/src/main/java/org/richfaces/renderkit/html/MenuRendererBase.java
===================================================================
---
trunk/richfaces/menu-components/src/main/java/org/richfaces/renderkit/html/MenuRendererBase.java
(rev 0)
+++
trunk/richfaces/menu-components/src/main/java/org/richfaces/renderkit/html/MenuRendererBase.java 2007-03-30
14:53:31 UTC (rev 225)
@@ -0,0 +1,153 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces 3.0 - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.renderkit.html;
+
+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.ajax4jsf.framework.renderer.compiler.HtmlCompiler;
+import org.ajax4jsf.framework.renderer.compiler.PreparedTemplate;
+import org.richfaces.component.UIMenuGroup;
+import org.richfaces.component.UIMenuItem;
+import org.richfaces.component.UIMenuSeparator;
+
+
+
+public abstract class MenuRendererBase extends HeaderResourcesRendererBase {
+
+ public void encodeChildren(FacesContext context, UIComponent component) throws
IOException {
+ List flatListOfNodes = new LinkedList();
+ MenuLayerRendererHelper helper = new MenuLayerRendererHelper(context);
+
+ flatten(component.getChildren(), flatListOfNodes);
+ helper.processLayer(component);
+
+ for (Iterator iter = flatListOfNodes.iterator(); iter.hasNext();) {
+ UIMenuGroup node = (UIMenuGroup) iter.next();
+ helper.processLayer(node);
+ }
+ }
+
+ 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 class MenuLayerRendererHelper {
+ private FacesContext context;
+ private PreparedTemplate template;
+
+ public MenuLayerRendererHelper(FacesContext context) {
+ super();
+ this.context = context;
+ template =
HtmlCompiler.compileResource("org/richfaces/renderkit/html/template/htmlMenuLayer.jspx");
+
+ }
+
+ public void processLayer(UIComponent layer) throws IOException{
+ String clientId = layer.getClientId(context);
+ template.encode(MenuRendererBase.this, context, layer);
+ AjaxRendererUtils.addRegionByName(context, layer, clientId +
"_menu_iframe");
+ AjaxRendererUtils.addRegionByName(context, layer, clientId +
"_menu_iframe1");
+ AjaxRendererUtils.addRegionByName(context, layer, clientId +
"_menu_script");
+ }
+
+ }
+
+
+ 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);
+ }
+
+}
Show replies by date