Author: dbiatenia
Date: 2007-06-11 11:32:00 -0400 (Mon, 11 Jun 2007)
New Revision: 1121
Modified:
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/PanelMenuGroupRenderer.java
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/PanelMenuItemRenderer.java
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/PanelMenuRenderer.java
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/PanelMenuRendererBase.java
Log:
Modified:
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/PanelMenuGroupRenderer.java
===================================================================
---
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/PanelMenuGroupRenderer.java 2007-06-11
15:31:11 UTC (rev 1120)
+++
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/PanelMenuGroupRenderer.java 2007-06-11
15:32:00 UTC (rev 1121)
@@ -22,22 +22,16 @@
package org.richfaces.renderkit;
import java.io.IOException;
-import java.util.Iterator;
import java.util.Map;
-
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import javax.faces.convert.ConverterException;
import javax.faces.event.ActionEvent;
-import javax.faces.event.ValueChangeEvent;
-
import org.ajax4jsf.framework.ajax.AjaxEvent;
import org.richfaces.component.UISwitchablePanel;
import org.richfaces.component.panelmenu.UIPanelMenu;
import org.richfaces.component.panelmenu.UIPanelMenuGroup;
-import org.richfaces.component.panelmenu.UIPanelMenuItem;
-import org.richfaces.event.SwitchablePanelSwitchEvent;
public class PanelMenuGroupRenderer extends PanelMenuRendererBase {
@@ -77,20 +71,21 @@
boolean isTopLevel = isTopLevel(component);
if (isTopLevel){
- align = panelMenu.getIconItemTopPosition();
+ align = panelMenu.getIconGroupTopPosition();
} else {
- align = panelMenu.getIconItemPosition();
+ align = panelMenu.getIconGroupPosition();
}
- if (align.equalsIgnoreCase(from)) {
- image(context, component, "");
- } else{
- image(context, component, "spacer");
+ if (align.equalsIgnoreCase(from)){
+ image(context,component);
+ } else {
+ String iconType = PANEL_MENU_SPACER_ICON_NAME;
+ String imageSrc = getIconByType(iconType, isTopLevel, context, component);
+ drawIcon(context.getResponseWriter(), iconType, imageSrc, component);
}
-
}
- private void image(FacesContext context, UIComponent component, String data)throws
IOException {
+ private void image(FacesContext context, UIComponent component )throws IOException {
ResponseWriter writer = context.getResponseWriter();
UIPanelMenu panelMenu = findMenu(component);
@@ -102,32 +97,70 @@
boolean isOpened = isOpened(context,component);
- String source = "";
- String iconNode = "";
- Object iconCollapsed = panelMenuGroup.getIconCollapsed();
- Object iconExpanded = panelMenuGroup.getIconExpanded();
- String icon = (isOpened ? iconExpanded : iconCollapsed).toString();
- if ("".equals(icon)){
- source = getIconByType("custom", isTopLevel,context, component);
+ String defaultIconNodeClosed = null;
+
+ if(isTopLevel){
+ if(panelMenuGroup.isDisabled()){
+ defaultIconNodeClosed = panelMenu.getIconTopDisableGroup();
+ if(defaultIconNodeClosed == null || defaultIconNodeClosed.equals("")){
+ defaultIconNodeClosed = panelMenu.getIconDisabledGroup();
+ }
+ } else {
+ defaultIconNodeClosed = panelMenu.getIconCollapsedTopGroup();
+ if(defaultIconNodeClosed == null || defaultIconNodeClosed.equals("")){
+ defaultIconNodeClosed = panelMenu.getIconCollapsedGroup();
+ }
+ }
} else {
- if (iconNode.equals("none")){
- return;
+ if(panelMenuGroup.isDisabled()){
+ defaultIconNodeClosed = panelMenu.getIconDisabledGroup();
} else {
- source = getIconByType(data.equals("spacer") ? "custom" : icon,
isTopLevel, context, component);
+ defaultIconNodeClosed = panelMenu.getIconCollapsedGroup();
}
}
+
+ String defaultIconNodeOpened = null;
+
+ if(isTopLevel){
+ defaultIconNodeOpened = panelMenu.getIconExpandedTopGroup();
+ if(defaultIconNodeOpened == null || defaultIconNodeOpened.equals("")){
+ defaultIconNodeOpened = panelMenu.getIconExpandedGroup();
+ }
+ } else {
+ defaultIconNodeOpened = panelMenu.getIconExpandedGroup();
+ }
- int h = 16; //width(context);
- writer.startElement("img", component);
- writer.writeAttribute("src", source, null);
- writer.writeAttribute("alt", "", null);
- writer.writeAttribute("vspace", "0", null);
- writer.writeAttribute("hspace", "0", null);
- writer.writeAttribute("style", "display:block; ", null);
- writer.writeAttribute("width", String.valueOf(h), null);
- writer.writeAttribute("height", String.valueOf(h), null);
- writer.endElement("img");
+ String iconExpanded = "";
+ String iconCollapsed = "";
+
+ iconExpanded = panelMenuGroup.isDisabled() ? panelMenuGroup.getIconDisabled() :
panelMenuGroup.getIconExpanded();
+ iconCollapsed = panelMenuGroup.isDisabled() ? panelMenuGroup.getIconDisabled() :
panelMenuGroup.getIconCollapsed();
+
+ String icon = null;
+ if(isOpened){
+ if(iconExpanded != null && !iconExpanded.equals("")){
+ if(iconExpanded.equals("none")){
+ return;
+ } else {
+ icon = iconExpanded;
+ }
+ } else {
+ icon = defaultIconNodeOpened;
+ }
+ } else {
+ if(iconCollapsed!= null && !iconCollapsed.equals("")){
+ if(iconCollapsed.equals("none")){
+ return;
+ } else {
+ icon = iconCollapsed;
+ }
+ } else {
+ icon = defaultIconNodeClosed;
+ }
+ }
+ String source = getIconByType(icon, isTopLevel, context, component);
+ drawIcon(writer, icon, source, component);
}
public String getFullStyleClass(FacesContext context, UIComponent component) {
@@ -183,9 +216,6 @@
}
public boolean isOpened(FacesContext context, UIComponent component)throws IOException
{
- //String clientId = component.getClientId(context);
- ///Map requestParameterMap = context.getExternalContext().getRequestParameterMap();
-
UIPanelMenuGroup group = (UIPanelMenuGroup)component;
Boolean value = (Boolean)group.getValue();
Modified:
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/PanelMenuItemRenderer.java
===================================================================
---
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/PanelMenuItemRenderer.java 2007-06-11
15:31:11 UTC (rev 1120)
+++
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/PanelMenuItemRenderer.java 2007-06-11
15:32:00 UTC (rev 1121)
@@ -27,12 +27,9 @@
import javax.faces.context.ResponseWriter;
import javax.faces.event.ActionEvent;
import org.ajax4jsf.framework.ajax.AjaxEvent;
-import org.ajax4jsf.framework.util.style.CSSFormat;
import org.richfaces.component.UISwitchablePanel;
import org.richfaces.component.panelmenu.UIPanelMenu;
-import org.richfaces.component.panelmenu.UIPanelMenuGroup;
import org.richfaces.component.panelmenu.UIPanelMenuItem;
-import org.richfaces.event.SwitchablePanelSwitchEvent;
public class PanelMenuItemRenderer extends PanelMenuRendererBase {
protected Class getComponentClass() {
@@ -79,57 +76,63 @@
align = panelMenu.getIconItemPosition();
}
- if (component.getChildCount()==0){
- if (align.equalsIgnoreCase(from)){
- image(context,component,"");
- } else{
- image(context,component,"spacer");
- }
+ if (align.equalsIgnoreCase(from)){
+ image(context,component);
} else {
- image(context,component,"spacer");
+ String iconType = PANEL_MENU_SPACER_ICON_NAME;
+ String imageSrc = getIconByType(iconType, isTopLevel, context, component);
+ drawIcon(context.getResponseWriter(), iconType, imageSrc, component);
}
}
- private void image(FacesContext context, UIComponent component, String align)
+ private void image(FacesContext context, UIComponent component)
throws IOException{
UIPanelMenu panelMenu = findMenu(component);
ResponseWriter writer = context.getResponseWriter();
- String iconItemTopLevel = panelMenu.getIconTopItem();
- String iconItem = panelMenu.getIconItem();
boolean isTopLevel = isTopLevel(component);
- String source = "";
- String iconType = "";
- Object customIcon = ((UIPanelMenuItem)component).getIcon();
+ String source = null;
+ String iconType = null;
+ UIPanelMenuItem item = (UIPanelMenuItem)component;
- if ("".equals(customIcon)){
- if (isTopLevel){
- source = getIconByType(align.equals("spacer") ? "custom" :
iconItemTopLevel, isTopLevel, context, component);
+ String defaultItemIcon = null;
+ String customItemIcon = null;
+
+ if(isTopLevel){
+ if(item.isDisabled()){
+ defaultItemIcon = panelMenu.getIconTopDisabledItem();
} else {
- source = getIconByType(align.equals("spacer") ? "custom" :
iconItem, isTopLevel, context, component);
+ defaultItemIcon = panelMenu.getIconTopItem();
}
+ if(defaultItemIcon == null || defaultItemIcon.equals("")){
+ if(item.isDisabled()){
+ defaultItemIcon = panelMenu.getIconDisabledItem();
+ } else {
+ defaultItemIcon = panelMenu.getIconItem();
+ }
+ }
} else {
- if
((!isTopLevel&&iconItem.equals("none"))||(isTopLevel&&iconItemTopLevel.equals("none"))){
- iconType = "none";
- } else {
- source = getIconByType(align.equals("spacer") ? "custom" :
customIcon.toString(),isTopLevel,context,component);
+ //isTopLevel == false
+ if(defaultItemIcon == null || defaultItemIcon.equals("")){
+ if(item.isDisabled()){
+ defaultItemIcon = panelMenu.getIconDisabledItem();
+ } else {
+ defaultItemIcon = panelMenu.getIconItem();
+ }
}
}
-
- if (!iconType.equals("none")){
- int h = 16; //width(context);
- writer.startElement("img", component);
- writer.writeAttribute("src", source, null);
- writer.writeAttribute("alt", "", null);
- writer.writeAttribute("vspace", "0", null);
- writer.writeAttribute("hspace", "0", null);
- writer.writeAttribute("style", "display:block; ", null);
- writer.writeAttribute("width", String.valueOf(h), null);
- writer.writeAttribute("height", String.valueOf(h), null);
- writer.endElement("img");
- }
+
+ customItemIcon = item.isDisabled() ? item.getIconDisabled() : item.getIcon();
+
+ if(customItemIcon == null || customItemIcon.equals("")){
+ iconType = defaultItemIcon;
+ } else iconType = customItemIcon;
+
+ source = getIconByType(iconType, isTopLevel, context, component);
+ drawIcon(writer, iconType, source, component);
}
+
public String getFullStyleClass(FacesContext context, UIComponent component) {
StringBuffer classBuffer = new StringBuffer("");
UIPanelMenuItem item = (UIPanelMenuItem)component;
Modified:
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/PanelMenuRenderer.java
===================================================================
---
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/PanelMenuRenderer.java 2007-06-11
15:31:11 UTC (rev 1120)
+++
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/PanelMenuRenderer.java 2007-06-11
15:32:00 UTC (rev 1121)
@@ -1,398 +1,426 @@
-/**
- * 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;
-
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
-import javax.faces.application.ViewHandler;
-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.resource.InternetResourceBuilder;
-import org.ajax4jsf.framework.util.javascript.JSFunction;
-import org.richfaces.component.panelmenu.UIPanelMenu;
-import org.richfaces.component.panelmenu.UIPanelMenuGroup;
-import org.richfaces.component.panelmenu.UIPanelMenuItem;
-import org.richfaces.renderkit.iconImages.PanelMenuIconSpacer;
-
-public class PanelMenuRenderer extends PanelMenuRendererBase {
-
- /* (non-Javadoc)
- * @see org.ajax4jsf.framework.renderer.RendererBase#getComponentClass()
- */
- protected Class getComponentClass() {
- return UIComponent.class;
- }
-
- public void insertScript(FacesContext context, UIComponent component)
- throws IOException {
-
- StringBuffer buffer = new StringBuffer();
- StringBuffer panelMenu = new StringBuffer();
- List flatList = new LinkedList();
- Map levels = new HashMap();
-
- boolean expandSingle = ((UIPanelMenu)component).isExpandSingle();
-
- flatten(component.getChildren(), flatList, levels, 0);
-
- panelMenu
- .append("new PanelMenu('")
- .append(component.getClientId(context).toString())
- .append("',")
- .append(new Boolean(expandSingle).toString())
- .append(");\n");
- String iconPosition = ((UIPanelMenu)component).getIconItemPosition();
- String iconPositionTopLevel = ((UIPanelMenu)component).getIconItemTopPosition();
-
- for (Iterator iter = flatList.iterator(); iter.hasNext();) {
- UIComponent child = (UIComponent) iter.next();
- if ((child instanceof UIPanelMenuItem)||(child instanceof UIPanelMenuGroup)) {
- boolean childDisabled;
- if (!((UIPanelMenu)component).isDisabled())
- childDisabled = child instanceof UIPanelMenuGroup ?
((UIPanelMenuGroup)child).isDisabled() : ((UIPanelMenuItem)child).isDisabled();
- else
- childDisabled = true;
- boolean childRendered = child instanceof UIPanelMenuGroup ?
((UIPanelMenuGroup)child).isRendered() : ((UIPanelMenuItem)child).isRendered();
- boolean parentRendered = true;
- if (! (child.getParent() instanceof UIPanelMenu))
- parentRendered = child.getParent() instanceof UIPanelMenuGroup ?
((UIPanelMenuGroup)child.getParent()).isRendered() :
((UIPanelMenuItem)child.getParent()).isRendered();
- if (!parentRendered){
- child.getAttributes().put("rendered",Boolean.FALSE);
- }
-
- UIPanelMenu parentMenu = findMenu(child);
-
- String event = parentMenu.getEvent();
- if ("".equals(event))
- event = "click";
- else if (event.startsWith("on"))
- event = event.substring(2);
-
- String onopen = (child instanceof UIPanelMenuGroup) &&
!((UIPanelMenuGroup)child).isDisabled() && !isParentDisabled(child) ?
- parentMenu.getOngroupexpand() + ";" +
((UIPanelMenuGroup)child).getOnexpand() : "";
- String onclose = (child instanceof UIPanelMenuGroup) &&
!((UIPanelMenuGroup)child).isDisabled() && !isParentDisabled(child) ?
- parentMenu.getOngroupcollapse() + ";" +
((UIPanelMenuGroup)child).getOncollapse() : "";
- String hoveredStyle = (child instanceof UIPanelMenuGroup ?
- parentMenu.getHoveredGroupStyle() : parentMenu.getHoveredItemStyle())
- + ";" + (child instanceof UIPanelMenuGroup ?
- ((UIPanelMenuGroup)child).getHoverStyle() :
((UIPanelMenuItem)child).getHoverStyle());
- String hoveredClass = (child instanceof UIPanelMenuGroup ?
- parentMenu.getHoveredGroupClass() : parentMenu.getHoveredItemClass())
- + " " + (child instanceof UIPanelMenuGroup ?
- ((UIPanelMenuGroup)child).getHoverClass() :
((UIPanelMenuItem)child).getHoverClass());
- String [] hoveredStyles = hoveredStyle.split(";");
- String [] hoveredClasses = hoveredClass.split(" ");
-
- String mode = getItemMode(child);
- Object target = child.getAttributes().get("target");
- String targetString;
- if (null == target)
- targetString = "";
- else
- targetString = target.toString();
-
-
-
- if (childRendered && parentRendered){
- if ( !isParentDisabled(child) ){
- buffer
- .append("new PanelMenuItem({myId:'")
- .append((String) child.getClientId(context))
- .append("',parentId:'")
- .append((String) child.getParent().getClientId(context))
- .append("'},{type:" + (child instanceof UIPanelMenuItem ?
"\"item\"":"\"node\""))
- .append(",onopen:"+("".equals(onopen) ?
"\"\"" : "\"" + onopen +
"\"")+",onclose:"+("".equals(onclose) ?
"\"\"" : "\"" + onclose + "\""))
- .append(",event:\"" + event + "\"")
- .append(",mode:\"" + mode + "\"")
- .append(",target:\"" + targetString + "\"")
- .append(",disabled:" +
- new Boolean(childDisabled).toString())
- .append("},{");
-
-
- for (int i = 0; i < hoveredStyles.length; i++)
- if (!"".equals(hoveredStyles[i])) {
- String [] temp = hoveredStyles[i].split(":");
- String cssName = temp[0].trim();
- String cssValue = temp[1].trim();
- buffer.append("\"" + cssName + "\": \"" +
cssValue + "\"");
- if (i != hoveredStyles.length - 1)
- buffer.append(",");
- }
-
- buffer.append("},");
- if (hoveredClasses.length > 0) {
- buffer.append("new Array(");
- for (int i = 0; i < hoveredClasses.length; i++)
- if (!"".equals(hoveredClasses[i])) {;
- buffer.append("\"" + hoveredClasses[i] + "\"");
- if (i != hoveredClasses.length - 1)
- buffer.append(",");
- }
- buffer.append("),");
- } else
- buffer.append("new Array(),");
-
- buffer.append(levels.get(child.getClientId(context)));
- switchOnImagesIfNeeded(context,child,buffer);
-
- addActionIfNeeded(context,child,buffer);
-
- setExpandedIfNeeded(context,child,buffer);
-
- addAjaxFunction(context,child,buffer);
-
- String iconPos = child.getParent() instanceof UIPanelMenu ?
iconPositionTopLevel.toLowerCase() : iconPosition.toLowerCase() ;
-
- buffer.append(","+'"'+iconPos+'"');
-
- addImages(buffer,context,child,component.getClientId(context).toString());
-
- buffer.append(");\n");
- }
- } else {
- continue;
- }
- }
- }
- StringBuffer ret = new StringBuffer();
- ret.append("<script ");
- ret.append("type=\"text/javascript\" ");
- ret.append("id =\"script" +
component.getClientId(context)+"\">\n");
- ret.append(panelMenu);
- ret.append(buffer);
- ret.append("\n</script>");
-
- ResponseWriter writer = context.getResponseWriter();
- writer.write(ret.toString());
- }
-
- public void flatten(List children, List flatList, Map levels,int initialLevel) {
- FacesContext context = FacesContext.getCurrentInstance();
- if (children != null) {
- for (Iterator iter = children.iterator(); iter.hasNext();) {
- UIComponent child = (UIComponent) iter.next();
- if (child instanceof UIPanelMenu){
- continue;
- }
- flatList.add(child);
- levels.put(child.getClientId(context), new Integer(initialLevel));
- flatten(child.getChildren(), flatList, levels, initialLevel + 1);
- }
- }
- }
-
- private void switchOnImagesIfNeeded(FacesContext context, UIComponent child,
StringBuffer buffer)throws IOException {
- boolean isToplevel = isTopLevel(child);
- String customIconOpened = "";
- String customIconClosed = "";
-
- UIPanelMenu panelMenu = findMenu(child);
- if(panelMenu == null){
- return;
- }
- String iconOpened = isToplevel ? panelMenu.getIconExpandedTopGroup() :
panelMenu.getIconExpandedGroup();
- String iconClosed = isToplevel ? panelMenu.getIconCollapsedTopGroup() :
panelMenu.getIconCollapsedGroup();
-
- try {
- customIconOpened = (String)child.getAttributes().get("iconOpened");
- customIconClosed = (String)child.getAttributes().get("iconClosed");
- } catch (Exception e) {}
-
- if (child instanceof UIPanelMenuItem){
- buffer.append(",false");
- } else {
- if
(iconClosed.equals("custom")&&iconOpened.equals("custom")){
- if
(customIconClosed.equals("")&&customIconOpened.equals("")){
- buffer.append(",false");
- } else {
- buffer.append(",true");
- }
- } else {
- buffer.append(",true");
- }
- }
- }
-
- private void addActionIfNeeded(FacesContext context,UIComponent child,StringBuffer
buffer){
- //TODO by nick - dima - use CommandScriptBuilder
- if (child instanceof UIPanelMenuItem){
- if (((UIPanelMenuItem)child).getAction() == null){
- buffer.append(",false");
- } else {
-// ViewHandler viewHandler = context.getApplication().getViewHandler();
-// String viewId = context.getViewRoot().getViewId();
-// String actionUrl =
context.getExternalContext().encodeActionURL(viewHandler.getActionURL(context, viewId));
-// buffer.append(",'"+actionUrl+"'");
- buffer.append(",true");
- }
- } else {
- if
(((UIPanelMenuGroup)child).getAction()!=null&&!((UIPanelMenuGroup)child).getAction().equals("")){
- buffer.append(",'panelMenuNodeAction'");
- } else {
- buffer.append(",false");
- }
- }
- }
-
- private void setExpandedIfNeeded(FacesContext context,UIComponent child,StringBuffer
buffer){
- if(child instanceof UIPanelMenuItem){
- buffer.append(",false");
- } else {
- UIPanelMenuGroup group = (UIPanelMenuGroup)child;
- if(group.getValue() != null){
- buffer.append(",").append(group.getValue().toString());
- } else {
- PanelMenuGroupRenderer r =
(PanelMenuGroupRenderer)context.getRenderKit().getRenderer(group.getFamily(),
group.getRendererType());
- boolean isNodeOpened;
- try {
- isNodeOpened = r.isOpened(context, child);
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- isNodeOpened = false;
- }
- buffer.append(",").append(String.valueOf(isNodeOpened));
- }
- }
- }
-
- private void addImages(StringBuffer buffer,FacesContext context,UIComponent
component,String id){
- UIPanelMenu panelMenu = findMenu(component);
- if(panelMenu == null){
- return;
- }
-
- final String PANEL_MENU_SPACER_ICON =
InternetResourceBuilder.getInstance().createResource(null,PanelMenuIconSpacer.class.getName()).getUri(context,
null);;
- boolean isTopLevel = component.getParent() instanceof UIPanelMenu;
-
- String iconItem = isTopLevel ? panelMenu.getIconTopItem() :
panelMenu.getIconItem();
- String iconNodeClosed = isTopLevel ? panelMenu.getIconCollapsedTopGroup() :
panelMenu.getIconCollapsedGroup();
- String iconNodeOpened = isTopLevel ? panelMenu.getIconExpandedTopGroup() :
panelMenu.getIconExpandedGroup();
-
- String sourceIconItem = getIconByType(iconItem, isTopLevel,context, component);
- String sourceIconNodeClosed = getIconByType(iconNodeClosed, isTopLevel,context,
component);
- String sourceIconNodeOpened = getIconByType(iconNodeOpened, isTopLevel,context,
component);
-
- String iconExpanded = "";
- String iconCollapsed = "";
- String iconExpandedSource = "";
- String iconCollapsedSource = "";
- String customIcon = "";
- String customIconSource = "";
-
- if (component instanceof UIPanelMenuGroup){
-
- iconExpanded = ((UIPanelMenuGroup)component).getIconExpanded();
- iconCollapsed = ((UIPanelMenuGroup)component).getIconCollapsed();
- iconExpandedSource = getIconByType(iconExpanded,isTopLevel,context,component);
- iconCollapsedSource = getIconByType(iconCollapsed,isTopLevel,context,component);
-
- } else if (component instanceof UIPanelMenuItem){
-
- customIcon = component.getAttributes().get("icon").toString();
- customIconSource = getIconByType(customIcon,isTopLevel,context,component);
-
- }
-
- if (component instanceof UIPanelMenuGroup){
- if (null != iconCollapsed && !"".equals(iconCollapsed))
- iconNodeClosed = iconCollapsed;
- if (null != iconExpanded && !"".equals(iconExpanded))
- iconNodeOpened = iconExpanded;
- if
(!"".equals(iconNodeClosed)&&!"".equals(iconNodeOpened)){
- if
(!iconNodeClosed.equals("custom")&&!iconNodeOpened.equals("custom")){
- if("".equals(iconExpanded)&&"".equals(iconCollapsed)){
- buffer.append(","+'"'+
("".equals(sourceIconNodeOpened)?iconExpandedSource:sourceIconNodeOpened) +
'"').append(","+
- '"'+("".equals(sourceIconNodeClosed)?iconCollapsedSource:sourceIconNodeClosed)+'"'+";");
- } else if("".equals(iconExpanded)){
- buffer.append(","+'"'+iconCollapsedSource+'"')
- .append(","+'"'+iconCollapsedSource+'"');
- } else if ("".equals(iconCollapsed)) {
- buffer.append(","+'"'+iconExpandedSource+'"')
- .append(","+'"'+iconExpandedSource+'"');
- } else {
- buffer.append(","+'"'+iconExpandedSource+'"')
- .append(","+'"'+iconCollapsedSource+'"');
- }
- } else if (iconNodeClosed.equals("custom")){
- buffer.append(",\"" + ("".equals(iconExpanded)?
sourceIconNodeOpened : iconExpandedSource) + '"').
- append(",\"" + ("".equals(iconCollapsed)?
PANEL_MENU_SPACER_ICON : iconCollapsedSource)+"\";");
- } else if (iconNodeOpened.equals("custom")){
- buffer.append(",\"" + ("".equals(iconExpanded)?
PANEL_MENU_SPACER_ICON : iconExpandedSource) + '"').
- append(",\"" + ("".equals(iconCollapsed)?
sourceIconNodeClosed : iconCollapsedSource)+"\";");
- } else{
- buffer.append(",\"" + ("".equals(iconExpanded)?
PANEL_MENU_SPACER_ICON : iconExpandedSource) + '"')
- .append(",\"" + ("".equals(iconCollapsed)?
PANEL_MENU_SPACER_ICON : iconCollapsedSource)+"\";");
- }
- } else {
- String iconCollapsedScript = ("".equals(iconNodeClosed)) ? "null"
: "\"" + iconCollapsedSource + "\"";
- String iconExpandedScript = ("".equals(iconNodeOpened)) ? "null"
: "\"" + iconExpandedSource + "\"";
- buffer.append("," + iconExpandedScript + "," +
iconCollapsedScript);
- }
- buffer.append(",\"" + PANEL_MENU_SPACER_ICON + "\"");
- } else {
- if (!"".equals(iconItem)){
- if (!iconItem.equals("custom")){
- if(component.getAttributes().get("icon").equals("")){
- buffer.append(","+'"'+sourceIconItem+'"')
- .append(","+'"'+sourceIconItem+'"'+"
");
- } else {
- buffer.append(","+'"'+customIconSource+'"')
- .append(","+'"'+customIconSource+'"'+"
");
- }
- } else {
- if(component.getAttributes().get("icon").equals("")){
- buffer.append(","+'"'+PANEL_MENU_SPACER_ICON+'"')
- .append(","+'"'+PANEL_MENU_SPACER_ICON+'"'+"
");
- } else {
- buffer.append(","+'"'+customIconSource+'"').append(","+'"'+customIconSource+'"'+"
");
- }
- }
- } else {
- buffer.append(",\"\" ");
- }
- buffer.append(",\"\" ");
- }
- }
-
- protected void addAjaxFunction(FacesContext context, UIComponent child, StringBuffer
buffer) {
- JSFunction function = AjaxRendererUtils.buildAjaxFunction(child,
- context);
- Map eventOptions = AjaxRendererUtils.buildEventOptions(context,
- child);
- function.addParameter(eventOptions);
-
- buffer.append(",\"");
- function.appendScript(buffer);
- buffer.append("\"");
- }
-
-}
+/**
+ * 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;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+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.util.javascript.JSFunction;
+import org.richfaces.component.panelmenu.UIPanelMenu;
+import org.richfaces.component.panelmenu.UIPanelMenuGroup;
+import org.richfaces.component.panelmenu.UIPanelMenuItem;
+
+public class PanelMenuRenderer extends PanelMenuRendererBase {
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.framework.renderer.RendererBase#getComponentClass()
+ */
+ protected Class getComponentClass() {
+ return UIComponent.class;
+ }
+
+ public void insertScript(FacesContext context, UIComponent component)
+ throws IOException {
+
+ StringBuffer buffer = new StringBuffer();
+ StringBuffer panelMenu = new StringBuffer();
+ List flatList = new LinkedList();
+ Map levels = new HashMap();
+
+ boolean expandSingle = ((UIPanelMenu)component).isExpandSingle();
+
+ flatten(component.getChildren(), flatList, levels, 0);
+
+ panelMenu
+ .append("new PanelMenu('")
+ .append(component.getClientId(context).toString())
+ .append("',")
+ .append(new Boolean(expandSingle).toString())
+ .append(");\n");
+
+ for (Iterator iter = flatList.iterator(); iter.hasNext();) {
+ UIComponent child = (UIComponent) iter.next();
+ if ((child instanceof UIPanelMenuItem)||(child instanceof UIPanelMenuGroup)) {
+ boolean childDisabled;
+ if (!((UIPanelMenu)component).isDisabled())
+ childDisabled = child instanceof UIPanelMenuGroup ?
((UIPanelMenuGroup)child).isDisabled() : ((UIPanelMenuItem)child).isDisabled();
+ else
+ childDisabled = true;
+ boolean childRendered = child instanceof UIPanelMenuGroup ?
((UIPanelMenuGroup)child).isRendered() : ((UIPanelMenuItem)child).isRendered();
+ boolean parentRendered = true;
+ if (! (child.getParent() instanceof UIPanelMenu))
+ parentRendered = child.getParent() instanceof UIPanelMenuGroup ?
((UIPanelMenuGroup)child.getParent()).isRendered() :
((UIPanelMenuItem)child.getParent()).isRendered();
+ if (!parentRendered){
+ child.getAttributes().put("rendered",Boolean.FALSE);
+ }
+
+ UIPanelMenu parentMenu = findMenu(child);
+
+ String event = parentMenu.getEvent();
+ if ("".equals(event))
+ event = "click";
+ else if (event.startsWith("on"))
+ event = event.substring(2);
+
+ String onopen = (child instanceof UIPanelMenuGroup) &&
!((UIPanelMenuGroup)child).isDisabled() && !isParentDisabled(child) ?
+ parentMenu.getOngroupexpand() + ";" +
((UIPanelMenuGroup)child).getOnexpand() : "";
+ String onclose = (child instanceof UIPanelMenuGroup) &&
!((UIPanelMenuGroup)child).isDisabled() && !isParentDisabled(child) ?
+ parentMenu.getOngroupcollapse() + ";" +
((UIPanelMenuGroup)child).getOncollapse() : "";
+ String hoveredStyle = (child instanceof UIPanelMenuGroup ?
+ parentMenu.getHoveredGroupStyle() : parentMenu.getHoveredItemStyle())
+ + ";" + (child instanceof UIPanelMenuGroup ?
+ ((UIPanelMenuGroup)child).getHoverStyle() :
((UIPanelMenuItem)child).getHoverStyle());
+ String hoveredClass = (child instanceof UIPanelMenuGroup ?
+ parentMenu.getHoveredGroupClass() : parentMenu.getHoveredItemClass())
+ + " " + (child instanceof UIPanelMenuGroup ?
+ ((UIPanelMenuGroup)child).getHoverClass() :
((UIPanelMenuItem)child).getHoverClass());
+ String [] hoveredStyles = hoveredStyle.split(";");
+ String [] hoveredClasses = hoveredClass.split(" ");
+
+ String mode = getItemMode(child);
+ Object target = child.getAttributes().get("target");
+ String targetString;
+ if (null == target)
+ targetString = "";
+ else
+ targetString = target.toString();
+
+
+
+ if (childRendered && parentRendered){
+ if ( !isParentDisabled(child) ){
+ buffer
+ .append("new PanelMenuItem({myId:'")
+ .append((String) child.getClientId(context))
+ .append("',parentId:'")
+ .append((String) child.getParent().getClientId(context))
+ .append("'},{type:" + (child instanceof UIPanelMenuItem ?
"\"item\"":"\"node\""))
+ .append(",onopen:"+("".equals(onopen) ?
"\"\"" : "\"" + onopen +
"\"")+",onclose:"+("".equals(onclose) ?
"\"\"" : "\"" + onclose + "\""))
+ .append(",event:\"" + event + "\"")
+ .append(",mode:\"" + mode + "\"")
+ .append(",target:\"" + targetString + "\"")
+ .append(",disabled:" +
+ new Boolean(childDisabled).toString())
+ .append("},{");
+
+
+ for (int i = 0; i < hoveredStyles.length; i++)
+ if (!"".equals(hoveredStyles[i])) {
+ String [] temp = hoveredStyles[i].split(":");
+ String cssName = temp[0].trim();
+ String cssValue = temp[1].trim();
+ buffer.append("\"" + cssName + "\": \"" +
cssValue + "\"");
+ if (i != hoveredStyles.length - 1)
+ buffer.append(",");
+ }
+
+ buffer.append("},");
+ if (hoveredClasses.length > 0) {
+ buffer.append("new Array(");
+ for (int i = 0; i < hoveredClasses.length; i++)
+ if (!"".equals(hoveredClasses[i])) {;
+ buffer.append("\"" + hoveredClasses[i] + "\"");
+ if (i != hoveredClasses.length - 1)
+ buffer.append(",");
+ }
+ buffer.append("),");
+ } else
+ buffer.append("new Array(),");
+
+ buffer.append(levels.get(child.getClientId(context)));
+ switchOnImagesIfNeeded(context,child,buffer);
+
+ addActionIfNeeded(context,child,buffer);
+
+ setExpandedIfNeeded(context,child,buffer);
+
+ addAjaxFunction(context,child,buffer);
+
+ String iconPos = "left";
+ boolean isTopLevel = isTopLevel(child);
+ if(child instanceof UIPanelMenuGroup){
+ iconPos = isTopLevel ? parentMenu.getIconGroupTopPosition() :
parentMenu.getIconGroupPosition();
+ } else {
+ iconPos = isTopLevel ? parentMenu.getIconItemTopPosition() :
parentMenu.getIconItemPosition();
+ }
+
+ buffer.append(","+'"'+iconPos+'"');
+
+ addImages(buffer,context,child,component.getClientId(context).toString());
+
+ buffer.append(");\n");
+ }
+ } else {
+ continue;
+ }
+ }
+ }
+ StringBuffer ret = new StringBuffer();
+ ret.append("<script ");
+ ret.append("type=\"text/javascript\" ");
+ ret.append("id =\"script" +
component.getClientId(context)+"\">\n");
+ ret.append(panelMenu);
+ ret.append(buffer);
+ ret.append("\n</script>");
+
+ ResponseWriter writer = context.getResponseWriter();
+ writer.write(ret.toString());
+ }
+
+ public void flatten(List children, List flatList, Map levels,int initialLevel) {
+ FacesContext context = FacesContext.getCurrentInstance();
+ if (children != null) {
+ for (Iterator iter = children.iterator(); iter.hasNext();) {
+ UIComponent child = (UIComponent) iter.next();
+ if (child instanceof UIPanelMenu){
+ continue;
+ }
+ flatList.add(child);
+ levels.put(child.getClientId(context), new Integer(initialLevel));
+ flatten(child.getChildren(), flatList, levels, initialLevel + 1);
+ }
+ }
+ }
+
+ private void switchOnImagesIfNeeded(FacesContext context, UIComponent child,
StringBuffer buffer)throws IOException {
+ boolean isToplevel = isTopLevel(child);
+ String customIconOpened = "";
+ String customIconClosed = "";
+
+ UIPanelMenu panelMenu = findMenu(child);
+ if(panelMenu == null){
+ return;
+ }
+ String iconOpened = isToplevel ? panelMenu.getIconExpandedTopGroup() :
panelMenu.getIconExpandedGroup();
+ String iconClosed = isToplevel ? panelMenu.getIconCollapsedTopGroup() :
panelMenu.getIconCollapsedGroup();
+
+ try {
+ customIconOpened = (String)child.getAttributes().get("iconOpened");
+ customIconClosed = (String)child.getAttributes().get("iconClosed");
+ } catch (Exception e) {}
+
+ if (child instanceof UIPanelMenuItem){
+ buffer.append(",false");
+ } else {
+ if
(iconClosed.equals("custom")&&iconOpened.equals("custom")){
+ if
(customIconClosed.equals("")&&customIconOpened.equals("")){
+ buffer.append(",false");
+ } else {
+ buffer.append(",true");
+ }
+ } else {
+ buffer.append(",true");
+ }
+ }
+ }
+
+ private void addActionIfNeeded(FacesContext context,UIComponent child,StringBuffer
buffer){
+ //TODO by nick - dima - use CommandScriptBuilder
+ if (child instanceof UIPanelMenuItem){
+ if (((UIPanelMenuItem)child).getAction() == null){
+ buffer.append(",false");
+ } else {
+ buffer.append(",true");
+ }
+ } else {
+ if
(((UIPanelMenuGroup)child).getAction()!=null&&!((UIPanelMenuGroup)child).getAction().equals("")){
+ buffer.append(",'panelMenuNodeAction'");
+ } else {
+ buffer.append(",false");
+ }
+ }
+ }
+
+ private void setExpandedIfNeeded(FacesContext context,UIComponent child,StringBuffer
buffer){
+ if(child instanceof UIPanelMenuItem){
+ buffer.append(",false");
+ } else {
+ UIPanelMenuGroup group = (UIPanelMenuGroup)child;
+ if(group.getValue() != null){
+ buffer.append(",").append(group.getValue().toString());
+ } else {
+ PanelMenuGroupRenderer r =
(PanelMenuGroupRenderer)context.getRenderKit().getRenderer(group.getFamily(),
group.getRendererType());
+ boolean isNodeOpened;
+ try {
+ isNodeOpened = r.isOpened(context, child);
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+// e.printStackTrace();
+ isNodeOpened = false;
+ }
+ buffer.append(",").append(String.valueOf(isNodeOpened));
+ }
+ }
+ }
+
+ private void addImages(StringBuffer buffer,FacesContext context,UIComponent
component,String id){
+ UIPanelMenu panelMenu = findMenu(component);
+ if(panelMenu == null){
+ return;
+ }
+ boolean isTopLevel = isTopLevel(component);
+
+ final String PANEL_MENU_SPACER_ICON = getIconByType(PANEL_MENU_SPACER_ICON_NAME,
isTopLevel,context, component);
+
+ if(component instanceof UIPanelMenuItem){
+ UIPanelMenuItem item = (UIPanelMenuItem)component;
+
+ String defaultItemIcon = null;
+ String defaultItemIconSrc = null;
+ String customItemIcon = null;
+ String customIconSource = null;
+
+ if(isTopLevel){
+ if(item.isDisabled()){
+ defaultItemIcon = panelMenu.getIconTopDisabledItem();
+ } else {
+ defaultItemIcon = panelMenu.getIconTopItem();
+ }
+ if(defaultItemIcon == null || defaultItemIcon.equals("")){
+ if(item.isDisabled()){
+ defaultItemIcon = panelMenu.getIconDisabledItem();
+ } else {
+ defaultItemIcon = panelMenu.getIconItem();
+ }
+ }
+ } else {
+ //isTopLevel == false
+ if(defaultItemIcon == null || defaultItemIcon.equals("")){
+ if(item.isDisabled()){
+ defaultItemIcon = panelMenu.getIconDisabledItem();
+ } else {
+ defaultItemIcon = panelMenu.getIconItem();
+ }
+ }
+ }
+
+ if(defaultItemIcon != null && defaultItemIcon.equals("none")){
+ defaultItemIconSrc = PANEL_MENU_SPACER_ICON;
+ } else {
+ defaultItemIconSrc = getIconByType(defaultItemIcon, isTopLevel,context, component);
+ }
+
+
+ customItemIcon = item.isDisabled() ? item.getIconDisabled() : item.getIcon();
+ if(customItemIcon != null && customItemIcon.equals("none")){
+ customIconSource = PANEL_MENU_SPACER_ICON;
+ } else {
+ customIconSource = getIconByType(customItemIcon, isTopLevel,context, component);
+ }
+
+ if(customItemIcon != null && !customItemIcon.equals("")){
+ buffer.append(","+'"'+customIconSource+'"').append(","+'"'+customIconSource+'"'+"
");
+ } else if (defaultItemIcon != null && !defaultItemIcon.equals("")){
+ buffer.append(","+'"'+defaultItemIconSrc+'"').append(","+'"'+defaultItemIconSrc+'"'+"
");
+ } else {
+ buffer.append(","+'"'+PANEL_MENU_SPACER_ICON+'"').append(","+'"'+PANEL_MENU_SPACER_ICON+'"'+"
");
+ }
+ buffer.append(",\"\" ");
+
+ } else if(component instanceof UIPanelMenuGroup){
+ UIPanelMenuGroup group = (UIPanelMenuGroup)component;
+
+ String defaultIconNodeClosed = isTopLevel ? (group.isDisabled() ?
panelMenu.getIconTopDisableGroup() : panelMenu.getIconCollapsedTopGroup()) :
(group.isDisabled() ? panelMenu.getIconDisabledGroup() :
panelMenu.getIconCollapsedGroup());
+
+ if(isTopLevel){
+ if(group.isDisabled()){
+ defaultIconNodeClosed = panelMenu.getIconTopDisableGroup();
+ if(defaultIconNodeClosed == null || defaultIconNodeClosed.equals("")){
+ defaultIconNodeClosed = panelMenu.getIconDisabledGroup();
+ }
+ } else {
+ defaultIconNodeClosed = panelMenu.getIconCollapsedTopGroup();
+ if(defaultIconNodeClosed == null || defaultIconNodeClosed.equals("")){
+ defaultIconNodeClosed = panelMenu.getIconCollapsedGroup();
+ }
+ }
+ } else {
+ if(group.isDisabled()){
+ defaultIconNodeClosed = panelMenu.getIconDisabledGroup();
+ } else {
+ defaultIconNodeClosed = panelMenu.getIconCollapsedGroup();
+ }
+ }
+
+ String defaultIconNodeOpened = isTopLevel ? panelMenu.getIconExpandedTopGroup() :
panelMenu.getIconExpandedGroup();
+
+ if(isTopLevel){
+ defaultIconNodeOpened = panelMenu.getIconExpandedTopGroup();
+ if(defaultIconNodeOpened == null || defaultIconNodeOpened.equals("")){
+ defaultIconNodeOpened = panelMenu.getIconExpandedGroup();
+ }
+ } else {
+ defaultIconNodeOpened = panelMenu.getIconExpandedGroup();
+ }
+
+ String defaultIconNodeClosedSrc = getIconByType(defaultIconNodeClosed,
isTopLevel,context, component);
+ String defaultIconNodeOpenedSrc = getIconByType(defaultIconNodeOpened,
isTopLevel,context, component);
+
+ String iconExpanded = "";
+ String iconCollapsed = "";
+ String iconExpandedSource = "";
+ String iconCollapsedSource = "";
+
+ iconExpanded = group.isDisabled() ? group.getIconDisabled() :
group.getIconExpanded();
+ iconCollapsed = group.isDisabled() ? group.getIconDisabled() :
group.getIconCollapsed();
+ iconExpandedSource = getIconByType(iconExpanded,isTopLevel,context,component);
+ iconCollapsedSource = getIconByType(iconCollapsed,isTopLevel,context,component);
+
+ if(iconExpanded != null && !iconExpanded.equals("")){
+ buffer.append(","+'"'+ iconExpandedSource +
'"');
+ } else if(defaultIconNodeOpened != null &&
!defaultIconNodeOpened.equals("")){
+ buffer.append(","+'"'+defaultIconNodeOpenedSrc +
'"');
+ } else {
+ buffer.append(","+'"'+PANEL_MENU_SPACER_ICON +
'"');
+ }
+
+ if(iconCollapsed != null && !iconCollapsed.equals("")){
+ buffer.append(","+'"'+iconCollapsedSource+'"');
+ } else if(defaultIconNodeClosed != null &&
!defaultIconNodeClosed.equals("")){
+ buffer.append(","+'"'+defaultIconNodeClosedSrc+'"');
+ } else {
+ buffer.append(","+'"'+PANEL_MENU_SPACER_ICON +
'"');
+ }
+ }
+ buffer.append(",\"" + PANEL_MENU_SPACER_ICON + "\"");
+ }
+
+ protected void addAjaxFunction(FacesContext context, UIComponent child, StringBuffer
buffer) {
+ JSFunction function = AjaxRendererUtils.buildAjaxFunction(child,
+ context);
+ Map eventOptions = AjaxRendererUtils.buildEventOptions(context,
+ child);
+ function.addParameter(eventOptions);
+
+ buffer.append(",\"");
+ function.appendScript(buffer);
+ buffer.append("\"");
+ }
+
+}
Modified:
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/PanelMenuRendererBase.java
===================================================================
---
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/PanelMenuRendererBase.java 2007-06-11
15:31:11 UTC (rev 1120)
+++
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/PanelMenuRendererBase.java 2007-06-11
15:32:00 UTC (rev 1121)
@@ -51,6 +51,9 @@
*
*/
public abstract class PanelMenuRendererBase extends HeaderResourcesRendererBase {
+
+ final static String PANEL_MENU_SPACER_ICON_NAME = "spacer";
+
public void insertTDs(FacesContext context , UIComponent component) throws IOException
{
ResponseWriter writer = context.getResponseWriter();
int level = calculateLevel(component);
@@ -110,6 +113,8 @@
if(iconType != null && !iconType.equals("none")){
if (iconType.equals("custom")){
source = getResource(PanelMenuIconSpacer.class.getName()).getUri(context, color);
+ } else if (iconType.equals("spacer")){
+ source = getResource(PanelMenuIconSpacer.class.getName()).getUri(context, color);
} else if (iconType.equals("triangle")) {
source = getResource(PanelMenuIconTriangle.class.getName()).getUri(context, color);
} else if (iconType.equals("triangleDown")) {
@@ -260,5 +265,29 @@
return false;
}
}
+
+ /**
+ *
+ * @param writer
+ * @param iconType
+ * @param imageSrc
+ * @param component
+ * @throws IOException
+ */
+ public void drawIcon(ResponseWriter writer, String iconType, String imageSrc,
UIComponent component) throws IOException{
+ if (iconType != null && !iconType.equals("") &&
!iconType.equals("none")){
+ int h = 16; //width(context);
+ writer.startElement("img", component);
+ writer.writeAttribute("src", imageSrc, null);
+ writer.writeAttribute("alt", "", null);
+ writer.writeAttribute("vspace", "0", null);
+ writer.writeAttribute("hspace", "0", null);
+ writer.writeAttribute("style", "display:block; ", null);
+ writer.writeAttribute("width", String.valueOf(h), null);
+ writer.writeAttribute("height", String.valueOf(h), null);
+ writer.endElement("img");
+ }
+
+ }
}