Author: sergeyhalipov
Date: 2007-06-13 12:46:27 -0400 (Wed, 13 Jun 2007)
New Revision: 1166
Added:
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/PanelMenuRendererBase.java
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/html/PanelMenuGroupRenderer.java
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/html/PanelMenuItemRenderer.java
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/html/PanelMenuRenderer.java
Removed:
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/html/PanelMenuGroupRenderer.java
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/html/PanelMenuItemRenderer.java
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/html/PanelMenuRenderer.java
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/html/PanelMenuRendererBase.java
Modified:
trunk/sandbox/panelmenu/src/main/config/component/panelMenu.xml
trunk/sandbox/panelmenu/src/main/templates/org/richfaces/htmlPanelMenu.jspx
trunk/sandbox/panelmenu/src/main/templates/org/richfaces/htmlPanelMenuGroup.jspx
trunk/sandbox/panelmenu/src/main/templates/org/richfaces/htmlPanelMenuItem.jspx
Log:
Fix some problems with name conversation.
Modified: trunk/sandbox/panelmenu/src/main/config/component/panelMenu.xml
===================================================================
--- trunk/sandbox/panelmenu/src/main/config/component/panelMenu.xml 2007-06-13 16:28:48
UTC (rev 1165)
+++ trunk/sandbox/panelmenu/src/main/config/component/panelMenu.xml 2007-06-13 16:46:27
UTC (rev 1166)
@@ -5,7 +5,7 @@
<name>org.richfaces.PanelMenu</name>
<family>org.richfaces.PanelMenu</family>
<description>Defines the menu on the page and the set of the child elements
properties in layout.</description>
- <superclass>org.richfaces.component.panelmenu.UIPanelMenu</superclass>
+ <superclass>org.richfaces.component.UIPanelMenu</superclass>
<classname>org.richfaces.component.html.HtmlPanelMenu</classname>
<renderer generate="true" override="true">
<name>org.richfaces.PanelMenuRenderer</name>
@@ -319,7 +319,7 @@
<name>org.richfaces.PanelMenuGroup</name>
<family>org.richfaces.PanelMenuGroup</family>
<description>Defines expandable group of items inside the panel menu or other
group.</description>
- <superclass>org.richfaces.component.panelmenu.UIPanelMenuGroup</superclass>
+ <superclass>org.richfaces.component.UIPanelMenuGroup</superclass>
<classname>org.richfaces.component.html.HtmlPanelMenuGroup</classname>
<renderer generate="true" override="true">
<name>org.richfaces.PanelMenuGroupRenderer</name>
@@ -470,7 +470,7 @@
<name>org.richfaces.PanelMenuItem</name>
<family>org.richfaces.PanelMenuItem</family>
<description>Defines single Item inside popup list.</description>
- <superclass>org.richfaces.component.panelmenu.UIPanelMenuItem</superclass>
+ <superclass>org.richfaces.component.UIPanelMenuItem</superclass>
<classname>org.richfaces.component.html.HtmlPanelMenuItem</classname>
<renderer generate="true" override="true">
<name>org.richfaces.PanelMenuItemRenderer</name>
Copied:
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/PanelMenuRendererBase.java
(from rev 1162,
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/html/PanelMenuRendererBase.java)
===================================================================
---
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/PanelMenuRendererBase.java
(rev 0)
+++
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/PanelMenuRendererBase.java 2007-06-13
16:46:27 UTC (rev 1166)
@@ -0,0 +1,294 @@
+/**
+ * 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.Iterator;
+import java.util.Map;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import org.ajax4jsf.framework.renderer.HeaderResourcesRendererBase;
+import org.ajax4jsf.framework.renderer.compiler.TemplateContext;
+import org.ajax4jsf.framework.skin.Skin;
+import org.ajax4jsf.framework.util.style.CSSFormat;
+import org.richfaces.component.UIPanelMenu;
+import org.richfaces.component.UIPanelMenuGroup;
+import org.richfaces.component.UIPanelMenuItem;
+import org.richfaces.renderkit.html.PanelMenuGroupRenderer;
+import org.richfaces.renderkit.html.iconimages.PanelMenuIconChevron;
+import org.richfaces.renderkit.html.iconimages.PanelMenuIconChevronDown;
+import org.richfaces.renderkit.html.iconimages.PanelMenuIconChevronUp;
+import org.richfaces.renderkit.html.iconimages.PanelMenuIconDisc;
+import org.richfaces.renderkit.html.iconimages.PanelMenuIconGrid;
+import org.richfaces.renderkit.html.iconimages.PanelMenuIconSpacer;
+import org.richfaces.renderkit.html.iconimages.PanelMenuIconTriangle;
+import org.richfaces.renderkit.html.iconimages.PanelMenuIconTriangleDown;
+import org.richfaces.renderkit.html.iconimages.PanelMenuIconTriangleUp;
+import org.ajax4jsf.framework.renderer.RendererUtils.HTML;
+
+/**
+ * @author hans
+ *
+ */
+public abstract class PanelMenuRendererBase extends HeaderResourcesRendererBase {
+
+ public 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);
+ //StringBuffer buffer = new StringBuffer();
+ String src = getIconByType("custom",false,context,component);
+ int w = 16; //width(context);
+
+ for (int i=0;i<level;i++){
+ writer.startElement(HTML.td_ELEM, component);
+ writer.startElement("img", component);
+ writer.writeAttribute("src", src, null);
+ writer.writeAttribute("alt", "", null);
+ writer.writeAttribute("hspace", "0", null);
+ writer.writeAttribute("vspace", "0", null);
+ writer.writeAttribute("height", String.valueOf(w), null);
+ writer.writeAttribute("width", String.valueOf(w), null);
+ writer.writeAttribute("style", "display:block; ", null);
+ writer.endElement("img");
+ writer.endElement(HTML.td_ELEM);
+ }
+ }
+
+ protected int calculateLevel (UIComponent component){
+ int level = 0;
+ UIComponent parent = component.getParent();
+ while(parent != null){
+ if(parent instanceof UIPanelMenu){
+ return level;
+ } else if(parent instanceof UIPanelMenuGroup){
+ level++;
+ }
+ parent = parent.getParent();
+ }
+ return level;
+ }
+
+ /**
+ * If icon type is a pre-defined value, return corresponding image, otherwise
+ * otherwise
+ * @param iconType
+ * @param context
+ * @param component
+ * @return URI of requested image
+ */
+ protected String getIconByType(String iconType, boolean isTopLevel, FacesContext
context,
+ UIComponent component){
+
+ String source = "";
+ String color = "";
+ Skin skin = getSkin(context);
+
+ if (isTopLevel){
+ color = (String) skin.getParameter(context,"panelmenu.headerBulletColor");
+ } else {
+ color = (String) skin.getParameter(context,"panelmenu.itemBulletColor");
+ }
+ 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")) {
+ source = getResource(PanelMenuIconTriangleDown.class.getName()).getUri(context,
color);
+ } else if (iconType.equals("triangleUp")) {
+ source = getResource(PanelMenuIconTriangleUp.class.getName()).getUri(context,
color);
+ } else if (iconType.equals("chevron")) {
+ source = getResource(PanelMenuIconChevron.class.getName()).getUri(context, color);
+ } else if (iconType.equals("chevronUp")) {
+ source = getResource(PanelMenuIconChevronUp.class.getName()).getUri(context, color);
+ } else if (iconType.equals("chevronDown")) {
+ source = getResource(PanelMenuIconChevronDown.class.getName()).getUri(context,
color);
+// } else if (iconType.equals("square")) {
+// source = getResource(PanelMenuIconSquare.class.getName()).getUri(context, color);
+ } else if (iconType.equals("disc")) {
+ source = getResource(PanelMenuIconDisc.class.getName()).getUri(context, color);
+ } else if (iconType.equals("grid")) {
+ source = getResource(PanelMenuIconGrid.class.getName()).getUri(context, color);
+ } else {
+ //TODO by nick - dima - TemplateContext is deprecated and shouldn't be used
+ source = (String)getUtils().encodeResourceURL(new
TemplateContext(this,context,component),iconType);
+ }
+ }
+ return source;
+ }
+
+ protected UIPanelMenu findMenu (UIComponent component){
+ if (component instanceof UIPanelMenu) return (UIPanelMenu)component;
+ UIComponent parent = component;
+ while(parent != null){
+ if(parent instanceof UIPanelMenu){
+ return (UIPanelMenu) parent;
+ }
+ parent = parent.getParent();
+ }
+ return (UIPanelMenu) parent;
+ }
+
+ public String getHideStyle(FacesContext context, UIComponent component) {
+ if (!(component.getParent() instanceof UIPanelMenu)) {
+ CSSFormat format = new CSSFormat();
+ format.add("display", "none");
+ if(component.getParent() instanceof UIPanelMenuGroup) {
+ UIPanelMenuGroup parent = (UIPanelMenuGroup)component.getParent();
+ PanelMenuGroupRenderer renderer = (PanelMenuGroupRenderer)
context.getRenderKit().getRenderer(parent.getFamily(), parent.getRendererType());
+ try {
+ if ( renderer.isOpened(context, parent) ){
+ return "";
+ } else
+ return format.toString();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ } else return format.toString();
+ }
+ return "";
+ }
+
+ public void insertValue(FacesContext context, UIComponent component) throws IOException
{
+ Object value = component.getAttributes().get("value");
+ if (value!=null){
+ context.getResponseWriter().write(value.toString());
+ }
+ }
+
+ protected boolean isChildrenExpanded(UIComponent component){
+ if (component.getChildren() != null){
+ Iterator itr = component.getChildren().iterator();
+ while(itr.hasNext()){
+ UIComponent child = (UIComponent)itr.next();
+ if(child instanceof UIPanelMenuGroup){
+ if( ((UIPanelMenuGroup)child).isExpanded() ){
+ return true;
+ } else {
+ return isChildrenExpanded(child);
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ protected boolean isParentDisabled(UIComponent component){
+ boolean returnValue = false;
+ UIComponent parent = component.getParent();
+ if(parent instanceof UIPanelMenuGroup){
+ UIPanelMenuGroup parentGroup = (UIPanelMenuGroup)parent;
+ if(parentGroup.isDisabled()){
+ returnValue = true;
+ } else {
+ returnValue = isParentDisabled(parentGroup);
+ }
+ }
+ return returnValue;
+ }
+
+ protected boolean isSubmitted(FacesContext context, UIComponent component){
+ boolean submitted = false;
+ String clientId = component.getClientId(context);
+ Map requestParameterMap = context.getExternalContext().getRequestParameterMap();
+
+ Object value = requestParameterMap.get("panelMenuAction"+clientId);
+ if (clientId!=null&&value!=null){
+ if (value.equals(clientId)) {
+ submitted = true;
+ }
+ }
+ return submitted;
+ }
+
+ protected String getItemMode(UIComponent component) {
+ String parentExpandMode = findMenu(component).getExpandMode();
+ String parentMode = findMenu(component).getMode();
+ if (null == parentMode || "".equals(parentMode))
+ parentMode = "server";
+ if (null == parentExpandMode || "".equals(parentExpandMode))
+ parentExpandMode = "none";
+ String mode = "none";
+ if (component instanceof UIPanelMenuGroup) {
+ UIPanelMenuGroup group = (UIPanelMenuGroup) component;
+ if (null != group.getMode() && ! "".equals(group.getMode()))
+ mode = group.getMode();
+ else
+ mode = parentExpandMode;
+ } else if (component instanceof UIPanelMenuItem) {
+ UIPanelMenuItem item = (UIPanelMenuItem) component;
+ if (null != item.getMode() && ! "".equals(item.getMode()))
+ mode = item.getMode();
+ else
+ mode = parentMode;
+ }
+ return mode;
+ }
+
+ /**
+ *
+ * @param component
+ * @return
+ */
+ public boolean isTopLevel(UIComponent component){
+ UIComponent parent = component.getParent();
+ while( !(parent instanceof UIPanelMenu) && !(parent instanceof
UIPanelMenuGroup)) {
+ parent = parent.getParent();
+ }
+ if(parent instanceof UIPanelMenu){
+ return true;
+ } else {
+ 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");
+ }
+
+ }
+
+}
Deleted:
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/html/PanelMenuGroupRenderer.java
===================================================================
---
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/html/PanelMenuGroupRenderer.java 2007-06-13
16:28:48 UTC (rev 1165)
+++
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/html/PanelMenuGroupRenderer.java 2007-06-13
16:46:27 UTC (rev 1166)
@@ -1,262 +0,0 @@
-/**
- * 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.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 org.ajax4jsf.framework.ajax.AjaxEvent;
-import org.richfaces.component.UIPanelMenu;
-import org.richfaces.component.UIPanelMenuGroup;
-import org.richfaces.component.UISwitchablePanel;
-
-public class PanelMenuGroupRenderer extends PanelMenuRendererBase {
-
- protected Class getComponentClass() {
- return UIPanelMenuGroup.class;
- }
-
- protected void doDecode(FacesContext context, UIComponent component) {
- String clientId = component.getClientId(context);
- Map requestMap =context.getExternalContext().getRequestParameterMap();
- UIPanelMenuGroup group = ((UIPanelMenuGroup)component);
-
- if(requestMap.containsKey("panelMenuState"+clientId)){
- Object property = requestMap.get("panelMenuState"+clientId);
- if (property.equals("opened")) {
- group.setSubmittedValue("true");
- } else if (property.equals("closed")) {
- group.setSubmittedValue("false");
- }
-
- }
- if(isSubmitted(context, component)){
- new ActionEvent(component).queue();
- if (UISwitchablePanel.AJAX_METHOD.equals(getItemMode(component))) {
- new AjaxEvent(component).queue();
- }
- }
- }
-
- public void insertImage(FacesContext context, UIComponent component, Object data)
- throws IOException {
-
- String from = (String)data;
- String align = "";
-
- UIPanelMenu panelMenu = findMenu(component);
- boolean isTopLevel = isTopLevel(component);
-
- if (isTopLevel){
- align = panelMenu.getIconGroupTopPosition();
- } else {
- align = panelMenu.getIconGroupPosition();
- }
-
- 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 )throws IOException {
- ResponseWriter writer = context.getResponseWriter();
-
- UIPanelMenu panelMenu = findMenu(component);
- if(panelMenu == null){
- return;
- }
- UIPanelMenuGroup panelMenuGroup = (UIPanelMenuGroup)component;
- boolean isTopLevel = isTopLevel(panelMenuGroup);
-
- boolean isOpened = isOpened(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(panelMenuGroup.isDisabled()){
- defaultIconNodeClosed = panelMenu.getIconDisabledGroup();
- } else {
- defaultIconNodeClosed = panelMenu.getIconCollapsedGroup();
- }
- }
-
- String defaultIconNodeOpened = null;
-
- if(isTopLevel){
- defaultIconNodeOpened = panelMenu.getIconExpandedTopGroup();
- if(defaultIconNodeOpened == null || defaultIconNodeOpened.equals("")){
- defaultIconNodeOpened = panelMenu.getIconExpandedGroup();
- }
- } else {
- defaultIconNodeOpened = panelMenu.getIconExpandedGroup();
- }
-
- 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) {
- StringBuffer classBuffer = new StringBuffer("");
- UIPanelMenuGroup group = (UIPanelMenuGroup)component;
- UIPanelMenu parentMenu = findMenu(group);
- if (!parentMenu.isDisabled() && !group.isDisabled()) {
- if (calculateLevel(group) == 0)
- classBuffer.append(parentMenu.getTopGroupClass() + " ");
- else
- classBuffer.append(parentMenu.getGroupClass() + " ");
- classBuffer.append(group.getStyleClass());
- } else
- classBuffer.append(parentMenu.getDisabledGroupClass() + " ")
- .append(group.getDisabledClass());
- return classBuffer.toString();
- }
-
- public String getFullStyle(FacesContext context, UIComponent component) {
- StringBuffer styleBuffer = new StringBuffer("");
- UIPanelMenuGroup group = (UIPanelMenuGroup)component;
- UIPanelMenu parentMenu = findMenu(group);
- if (!group.isDisabled()) {
- if (calculateLevel(group) == 0)
- styleBuffer.append(parentMenu.getTopGroupStyle() + "; ");
- else
- styleBuffer.append(parentMenu.getGroupStyle() + "; ");
- styleBuffer.append(group.getStyle());
- } else
- styleBuffer.append(parentMenu.getDisabledGroupStyle() + "; ")
- .append(group.getDisabledStyle());
- return styleBuffer.toString();
- }
-
- public void insertLabel(FacesContext context, UIComponent component) throws IOException
{
- Object label = component.getAttributes().get("label");
- if (label!=null){
- context.getResponseWriter().write(label.toString());
- }
- }
-
- public Object getConvertedValue(FacesContext context,
- UIComponent component, Object submittedValue)
- throws ConverterException {
-
- UIPanelMenuGroup group = (UIPanelMenuGroup)component;
- if(group.getConverter() != null){
- return group.getConverter().getAsObject(context, component, (String)submittedValue);
- } else {
- return submittedValue;
- }
-
- }
-
- public boolean isOpened(FacesContext context, UIComponent component)throws IOException
{
- UIPanelMenuGroup group = (UIPanelMenuGroup)component;
-
- Boolean value = (Boolean)group.getValue();
- if (value != null) {
- return value.booleanValue();
- } else {
- boolean isParentDisabled = isParentDisabled(component);
- if(component instanceof UIPanelMenuGroup){
- if( ((UIPanelMenuGroup)component).isExpanded() &&
!((UIPanelMenuGroup)component).isDisabled() && !isParentDisabled ){
- return true;
- } else {
- //check expanded attributes in children groups, if exists
- boolean isChildrenExpanded = isChildrenExpanded(component);
- return isChildrenExpanded && !isParentDisabled &&
!((UIPanelMenuGroup)component).isDisabled();// ? "opened" : "closed";
- }
- }
- }
- return false;
- }
-
- public String getLabelClass(FacesContext context, UIComponent component) {
- UIPanelMenuGroup group = (UIPanelMenuGroup)component;
- UIPanelMenu parentMenu = findMenu(group);
- if(!group.isDisabled() && !parentMenu.isDisabled()){
- if(isTopLevel(component)){
- return "rich-pmenu-group-self-label rich-pmenu-top-group-self-label";
- } else return "rich-pmenu-group-self-label";
- }
- return "";
- }
-
- public String getIconClass(FacesContext context, UIComponent component) {
- UIPanelMenuGroup group = (UIPanelMenuGroup)component;
- UIPanelMenu parentMenu = findMenu(group);
- if(!group.isDisabled() && !parentMenu.isDisabled()){
- if(isTopLevel(component)){
- return "rich-pmenu-group-self-icon rich-pmenu-top-group-self-icon";
- } else return "rich-pmenu-group-self-icon";
- }
- return "";
- }
-
-
-}
Added:
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/html/PanelMenuGroupRenderer.java
===================================================================
---
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/html/PanelMenuGroupRenderer.java
(rev 0)
+++
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/html/PanelMenuGroupRenderer.java 2007-06-13
16:46:27 UTC (rev 1166)
@@ -0,0 +1,263 @@
+/**
+ * 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.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 org.ajax4jsf.framework.ajax.AjaxEvent;
+import org.richfaces.component.UIPanelMenu;
+import org.richfaces.component.UIPanelMenuGroup;
+import org.richfaces.component.UISwitchablePanel;
+import org.richfaces.renderkit.PanelMenuRendererBase;
+
+public class PanelMenuGroupRenderer extends PanelMenuRendererBase {
+
+ protected Class getComponentClass() {
+ return UIPanelMenuGroup.class;
+ }
+
+ protected void doDecode(FacesContext context, UIComponent component) {
+ String clientId = component.getClientId(context);
+ Map requestMap =context.getExternalContext().getRequestParameterMap();
+ UIPanelMenuGroup group = ((UIPanelMenuGroup)component);
+
+ if(requestMap.containsKey("panelMenuState"+clientId)){
+ Object property = requestMap.get("panelMenuState"+clientId);
+ if (property.equals("opened")) {
+ group.setSubmittedValue("true");
+ } else if (property.equals("closed")) {
+ group.setSubmittedValue("false");
+ }
+
+ }
+ if(isSubmitted(context, component)){
+ new ActionEvent(component).queue();
+ if (UISwitchablePanel.AJAX_METHOD.equals(getItemMode(component))) {
+ new AjaxEvent(component).queue();
+ }
+ }
+ }
+
+ public void insertImage(FacesContext context, UIComponent component, Object data)
+ throws IOException {
+
+ String from = (String)data;
+ String align = "";
+
+ UIPanelMenu panelMenu = findMenu(component);
+ boolean isTopLevel = isTopLevel(component);
+
+ if (isTopLevel){
+ align = panelMenu.getIconGroupTopPosition();
+ } else {
+ align = panelMenu.getIconGroupPosition();
+ }
+
+ 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 )throws IOException {
+ ResponseWriter writer = context.getResponseWriter();
+
+ UIPanelMenu panelMenu = findMenu(component);
+ if(panelMenu == null){
+ return;
+ }
+ UIPanelMenuGroup panelMenuGroup = (UIPanelMenuGroup)component;
+ boolean isTopLevel = isTopLevel(panelMenuGroup);
+
+ boolean isOpened = isOpened(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(panelMenuGroup.isDisabled()){
+ defaultIconNodeClosed = panelMenu.getIconDisabledGroup();
+ } else {
+ defaultIconNodeClosed = panelMenu.getIconCollapsedGroup();
+ }
+ }
+
+ String defaultIconNodeOpened = null;
+
+ if(isTopLevel){
+ defaultIconNodeOpened = panelMenu.getIconExpandedTopGroup();
+ if(defaultIconNodeOpened == null || defaultIconNodeOpened.equals("")){
+ defaultIconNodeOpened = panelMenu.getIconExpandedGroup();
+ }
+ } else {
+ defaultIconNodeOpened = panelMenu.getIconExpandedGroup();
+ }
+
+ 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) {
+ StringBuffer classBuffer = new StringBuffer("");
+ UIPanelMenuGroup group = (UIPanelMenuGroup)component;
+ UIPanelMenu parentMenu = findMenu(group);
+ if (!parentMenu.isDisabled() && !group.isDisabled()) {
+ if (calculateLevel(group) == 0)
+ classBuffer.append(parentMenu.getTopGroupClass() + " ");
+ else
+ classBuffer.append(parentMenu.getGroupClass() + " ");
+ classBuffer.append(group.getStyleClass());
+ } else
+ classBuffer.append(parentMenu.getDisabledGroupClass() + " ")
+ .append(group.getDisabledClass());
+ return classBuffer.toString();
+ }
+
+ public String getFullStyle(FacesContext context, UIComponent component) {
+ StringBuffer styleBuffer = new StringBuffer("");
+ UIPanelMenuGroup group = (UIPanelMenuGroup)component;
+ UIPanelMenu parentMenu = findMenu(group);
+ if (!group.isDisabled()) {
+ if (calculateLevel(group) == 0)
+ styleBuffer.append(parentMenu.getTopGroupStyle() + "; ");
+ else
+ styleBuffer.append(parentMenu.getGroupStyle() + "; ");
+ styleBuffer.append(group.getStyle());
+ } else
+ styleBuffer.append(parentMenu.getDisabledGroupStyle() + "; ")
+ .append(group.getDisabledStyle());
+ return styleBuffer.toString();
+ }
+
+ public void insertLabel(FacesContext context, UIComponent component) throws IOException
{
+ Object label = component.getAttributes().get("label");
+ if (label!=null){
+ context.getResponseWriter().write(label.toString());
+ }
+ }
+
+ public Object getConvertedValue(FacesContext context,
+ UIComponent component, Object submittedValue)
+ throws ConverterException {
+
+ UIPanelMenuGroup group = (UIPanelMenuGroup)component;
+ if(group.getConverter() != null){
+ return group.getConverter().getAsObject(context, component, (String)submittedValue);
+ } else {
+ return submittedValue;
+ }
+
+ }
+
+ public boolean isOpened(FacesContext context, UIComponent component)throws IOException
{
+ UIPanelMenuGroup group = (UIPanelMenuGroup)component;
+
+ Boolean value = (Boolean)group.getValue();
+ if (value != null) {
+ return value.booleanValue();
+ } else {
+ boolean isParentDisabled = isParentDisabled(component);
+ if(component instanceof UIPanelMenuGroup){
+ if( ((UIPanelMenuGroup)component).isExpanded() &&
!((UIPanelMenuGroup)component).isDisabled() && !isParentDisabled ){
+ return true;
+ } else {
+ //check expanded attributes in children groups, if exists
+ boolean isChildrenExpanded = isChildrenExpanded(component);
+ return isChildrenExpanded && !isParentDisabled &&
!((UIPanelMenuGroup)component).isDisabled();// ? "opened" : "closed";
+ }
+ }
+ }
+ return false;
+ }
+
+ public String getLabelClass(FacesContext context, UIComponent component) {
+ UIPanelMenuGroup group = (UIPanelMenuGroup)component;
+ UIPanelMenu parentMenu = findMenu(group);
+ if(!group.isDisabled() && !parentMenu.isDisabled()){
+ if(isTopLevel(component)){
+ return "rich-pmenu-group-self-label rich-pmenu-top-group-self-label";
+ } else return "rich-pmenu-group-self-label";
+ }
+ return "";
+ }
+
+ public String getIconClass(FacesContext context, UIComponent component) {
+ UIPanelMenuGroup group = (UIPanelMenuGroup)component;
+ UIPanelMenu parentMenu = findMenu(group);
+ if(!group.isDisabled() && !parentMenu.isDisabled()){
+ if(isTopLevel(component)){
+ return "rich-pmenu-group-self-icon rich-pmenu-top-group-self-icon";
+ } else return "rich-pmenu-group-self-icon";
+ }
+ return "";
+ }
+
+
+}
Deleted:
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/html/PanelMenuItemRenderer.java
===================================================================
---
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/html/PanelMenuItemRenderer.java 2007-06-13
16:28:48 UTC (rev 1165)
+++
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/html/PanelMenuItemRenderer.java 2007-06-13
16:46:27 UTC (rev 1166)
@@ -1,190 +0,0 @@
-/**
- * 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 javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
-import javax.faces.event.ActionEvent;
-import org.ajax4jsf.framework.ajax.AjaxEvent;
-import org.richfaces.component.UIPanelMenu;
-import org.richfaces.component.UIPanelMenuItem;
-import org.richfaces.component.UISwitchablePanel;
-
-public class PanelMenuItemRenderer extends PanelMenuRendererBase {
- protected Class getComponentClass() {
- return UIPanelMenuItem.class;
- }
-
- protected void doEncodeBegin(ResponseWriter writer, FacesContext context,UIComponent
component) throws IOException {
-
- }
- protected void doDecode(FacesContext context, UIComponent component) {
- if(isSubmitted(context, component)) {
- new ActionEvent(component).queue();
- if (UISwitchablePanel.AJAX_METHOD.equals(getItemMode(component))) {
- new AjaxEvent(component).queue();
- } else {
-
- }
- }
- }
-
- protected void doEncodeEnd(ResponseWriter writer, FacesContext context, UIComponent
component) throws IOException {
-
- }
-
- /*
- public String getOnClick(FacesContext context, UIComponent component) {
- String clientId = component.getClientId(context);
- return ";PanelMenuStorage['" + clientId +
"'].trigger(event);";
- }
- */
- public void insertImage(FacesContext context, UIComponent component, Object data) throws
IOException {
- String from = (String)data;
- UIPanelMenu panelMenu = findMenu(component);
- if(panelMenu == null){
- return;
- }
- String align = "";
- UIPanelMenuItem panelMenuItem = (UIPanelMenuItem)component;
- boolean isTopLevel = isTopLevel(panelMenuItem);
-
- if (isTopLevel){
- align = panelMenu.getIconItemTopPosition();
- } else {
- align = panelMenu.getIconItemPosition();
- }
-
- 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)
- throws IOException{
-
- UIPanelMenu panelMenu = findMenu(component);
- ResponseWriter writer = context.getResponseWriter();
- boolean isTopLevel = isTopLevel(component);
- String source = null;
- String iconType = null;
- UIPanelMenuItem item = (UIPanelMenuItem)component;
-
- String defaultItemIcon = null;
- String customItemIcon = 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();
- }
- }
- }
-
- 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;
- UIPanelMenu parentMenu = findMenu(item);
- if (!parentMenu.isDisabled() && !item.isDisabled()) {
- if (calculateLevel(item) == 0) {
- classBuffer.append(parentMenu.getTopItemClass()).append(" ");
- classBuffer.append("rich-pmenu-top-item ");
- } else
- classBuffer.append(parentMenu.getItemClass() + " ");
- classBuffer.append(item.getStyleClass());
- } else
- classBuffer.append(parentMenu.getDisabledItemClass() + " ")
- .append(item.getDisabledClass());
- return classBuffer.toString();
- }
-
- public String getFullStyle(FacesContext context, UIComponent component) {
- StringBuffer styleBuffer = new StringBuffer("");
- UIPanelMenuItem item = (UIPanelMenuItem)component;
- UIPanelMenu parentMenu = findMenu(item);
- if (!item.isDisabled()) {
- if (calculateLevel(item) == 0)
- styleBuffer.append(parentMenu.getTopItemStyle() + "; ");
- else
- styleBuffer.append(parentMenu.getItemStyle() + "; ");
- styleBuffer.append(item.getStyle());
- } else
- styleBuffer.append(parentMenu.getDisabledItemStyle() + "; ")
- .append(item.getDisabledStyle());
- return styleBuffer.toString();
- }
-
- public String getLabelClass(FacesContext context, UIComponent component) {
- UIPanelMenuItem item = (UIPanelMenuItem)component;
- UIPanelMenu parentMenu = findMenu(item);
- if(!item.isDisabled() && !parentMenu.isDisabled()){
- if(isTopLevel(component)){
- return "rich-pmenu-item-label rich-pmenu-top-item-label";
- } else return "rich-pmenu-item-label";
- }
- return "";
- }
-
- public String getIconClass(FacesContext context, UIComponent component) {
- UIPanelMenuItem item = (UIPanelMenuItem)component;
- UIPanelMenu parentMenu = findMenu(item);
- if(!item.isDisabled() && !parentMenu.isDisabled()){
- if(isTopLevel(component)){
- return "rich-pmenu-item-icon rich-pmenu-top-item-icon";
- } else return "rich-pmenu-item-icon";
- }
- return "";
- }
-}
Added:
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/html/PanelMenuItemRenderer.java
===================================================================
---
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/html/PanelMenuItemRenderer.java
(rev 0)
+++
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/html/PanelMenuItemRenderer.java 2007-06-13
16:46:27 UTC (rev 1166)
@@ -0,0 +1,191 @@
+/**
+ * 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 javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import javax.faces.event.ActionEvent;
+import org.ajax4jsf.framework.ajax.AjaxEvent;
+import org.richfaces.component.UIPanelMenu;
+import org.richfaces.component.UIPanelMenuItem;
+import org.richfaces.component.UISwitchablePanel;
+import org.richfaces.renderkit.PanelMenuRendererBase;
+
+public class PanelMenuItemRenderer extends PanelMenuRendererBase {
+ protected Class getComponentClass() {
+ return UIPanelMenuItem.class;
+ }
+
+ protected void doEncodeBegin(ResponseWriter writer, FacesContext context,UIComponent
component) throws IOException {
+
+ }
+ protected void doDecode(FacesContext context, UIComponent component) {
+ if(isSubmitted(context, component)) {
+ new ActionEvent(component).queue();
+ if (UISwitchablePanel.AJAX_METHOD.equals(getItemMode(component))) {
+ new AjaxEvent(component).queue();
+ } else {
+
+ }
+ }
+ }
+
+ protected void doEncodeEnd(ResponseWriter writer, FacesContext context, UIComponent
component) throws IOException {
+
+ }
+
+ /*
+ public String getOnClick(FacesContext context, UIComponent component) {
+ String clientId = component.getClientId(context);
+ return ";PanelMenuStorage['" + clientId +
"'].trigger(event);";
+ }
+ */
+ public void insertImage(FacesContext context, UIComponent component, Object data) throws
IOException {
+ String from = (String)data;
+ UIPanelMenu panelMenu = findMenu(component);
+ if(panelMenu == null){
+ return;
+ }
+ String align = "";
+ UIPanelMenuItem panelMenuItem = (UIPanelMenuItem)component;
+ boolean isTopLevel = isTopLevel(panelMenuItem);
+
+ if (isTopLevel){
+ align = panelMenu.getIconItemTopPosition();
+ } else {
+ align = panelMenu.getIconItemPosition();
+ }
+
+ 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)
+ throws IOException{
+
+ UIPanelMenu panelMenu = findMenu(component);
+ ResponseWriter writer = context.getResponseWriter();
+ boolean isTopLevel = isTopLevel(component);
+ String source = null;
+ String iconType = null;
+ UIPanelMenuItem item = (UIPanelMenuItem)component;
+
+ String defaultItemIcon = null;
+ String customItemIcon = 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();
+ }
+ }
+ }
+
+ 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;
+ UIPanelMenu parentMenu = findMenu(item);
+ if (!parentMenu.isDisabled() && !item.isDisabled()) {
+ if (calculateLevel(item) == 0) {
+ classBuffer.append(parentMenu.getTopItemClass()).append(" ");
+ classBuffer.append("rich-pmenu-top-item ");
+ } else
+ classBuffer.append(parentMenu.getItemClass() + " ");
+ classBuffer.append(item.getStyleClass());
+ } else
+ classBuffer.append(parentMenu.getDisabledItemClass() + " ")
+ .append(item.getDisabledClass());
+ return classBuffer.toString();
+ }
+
+ public String getFullStyle(FacesContext context, UIComponent component) {
+ StringBuffer styleBuffer = new StringBuffer("");
+ UIPanelMenuItem item = (UIPanelMenuItem)component;
+ UIPanelMenu parentMenu = findMenu(item);
+ if (!item.isDisabled()) {
+ if (calculateLevel(item) == 0)
+ styleBuffer.append(parentMenu.getTopItemStyle() + "; ");
+ else
+ styleBuffer.append(parentMenu.getItemStyle() + "; ");
+ styleBuffer.append(item.getStyle());
+ } else
+ styleBuffer.append(parentMenu.getDisabledItemStyle() + "; ")
+ .append(item.getDisabledStyle());
+ return styleBuffer.toString();
+ }
+
+ public String getLabelClass(FacesContext context, UIComponent component) {
+ UIPanelMenuItem item = (UIPanelMenuItem)component;
+ UIPanelMenu parentMenu = findMenu(item);
+ if(!item.isDisabled() && !parentMenu.isDisabled()){
+ if(isTopLevel(component)){
+ return "rich-pmenu-item-label rich-pmenu-top-item-label";
+ } else return "rich-pmenu-item-label";
+ }
+ return "";
+ }
+
+ public String getIconClass(FacesContext context, UIComponent component) {
+ UIPanelMenuItem item = (UIPanelMenuItem)component;
+ UIPanelMenu parentMenu = findMenu(item);
+ if(!item.isDisabled() && !parentMenu.isDisabled()){
+ if(isTopLevel(component)){
+ return "rich-pmenu-item-icon rich-pmenu-top-item-icon";
+ } else return "rich-pmenu-item-icon";
+ }
+ return "";
+ }
+}
Deleted:
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/html/PanelMenuRenderer.java
===================================================================
---
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/html/PanelMenuRenderer.java 2007-06-13
16:28:48 UTC (rev 1165)
+++
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/html/PanelMenuRenderer.java 2007-06-13
16:46:27 UTC (rev 1166)
@@ -1,436 +0,0 @@
-/**
- * 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.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.UIPanelMenu;
-import org.richfaces.component.UIPanelMenuGroup;
-import org.richfaces.component.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);
-
- addOnItemHover(parentMenu.getOnitemhover(), 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("\"");
- }
-
- protected void addOnItemHover(String menuOnItemHover, UIComponent child, StringBuffer
buffer) {
- buffer.append(",\"");
- if(child instanceof UIPanelMenuItem){
- if(menuOnItemHover != null && !menuOnItemHover.equals(""))
buffer.append(menuOnItemHover);
- }
- buffer.append("\"");
- }
-
-}
Added:
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/html/PanelMenuRenderer.java
===================================================================
---
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/html/PanelMenuRenderer.java
(rev 0)
+++
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/html/PanelMenuRenderer.java 2007-06-13
16:46:27 UTC (rev 1166)
@@ -0,0 +1,437 @@
+/**
+ * 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.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.UIPanelMenu;
+import org.richfaces.component.UIPanelMenuGroup;
+import org.richfaces.component.UIPanelMenuItem;
+import org.richfaces.renderkit.PanelMenuRendererBase;
+
+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);
+
+ addOnItemHover(parentMenu.getOnitemhover(), 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("\"");
+ }
+
+ protected void addOnItemHover(String menuOnItemHover, UIComponent child, StringBuffer
buffer) {
+ buffer.append(",\"");
+ if(child instanceof UIPanelMenuItem){
+ if(menuOnItemHover != null && !menuOnItemHover.equals(""))
buffer.append(menuOnItemHover);
+ }
+ buffer.append("\"");
+ }
+
+}
Deleted:
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/html/PanelMenuRendererBase.java
===================================================================
---
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/html/PanelMenuRendererBase.java 2007-06-13
16:28:48 UTC (rev 1165)
+++
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/html/PanelMenuRendererBase.java 2007-06-13
16:46:27 UTC (rev 1166)
@@ -1,293 +0,0 @@
-/**
- * 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.Map;
-
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
-import org.ajax4jsf.framework.renderer.HeaderResourcesRendererBase;
-import org.ajax4jsf.framework.renderer.compiler.TemplateContext;
-import org.ajax4jsf.framework.skin.Skin;
-import org.ajax4jsf.framework.util.style.CSSFormat;
-import org.richfaces.component.UIPanelMenu;
-import org.richfaces.component.UIPanelMenuGroup;
-import org.richfaces.component.UIPanelMenuItem;
-import org.richfaces.renderkit.html.iconimages.PanelMenuIconChevron;
-import org.richfaces.renderkit.html.iconimages.PanelMenuIconChevronDown;
-import org.richfaces.renderkit.html.iconimages.PanelMenuIconChevronUp;
-import org.richfaces.renderkit.html.iconimages.PanelMenuIconDisc;
-import org.richfaces.renderkit.html.iconimages.PanelMenuIconGrid;
-import org.richfaces.renderkit.html.iconimages.PanelMenuIconSpacer;
-import org.richfaces.renderkit.html.iconimages.PanelMenuIconTriangle;
-import org.richfaces.renderkit.html.iconimages.PanelMenuIconTriangleDown;
-import org.richfaces.renderkit.html.iconimages.PanelMenuIconTriangleUp;
-import org.ajax4jsf.framework.renderer.RendererUtils.HTML;
-
-/**
- * @author hans
- *
- */
-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);
- //StringBuffer buffer = new StringBuffer();
- String src = getIconByType("custom",false,context,component);
- int w = 16; //width(context);
-
- for (int i=0;i<level;i++){
- writer.startElement(HTML.td_ELEM, component);
- writer.startElement("img", component);
- writer.writeAttribute("src", src, null);
- writer.writeAttribute("alt", "", null);
- writer.writeAttribute("hspace", "0", null);
- writer.writeAttribute("vspace", "0", null);
- writer.writeAttribute("height", String.valueOf(w), null);
- writer.writeAttribute("width", String.valueOf(w), null);
- writer.writeAttribute("style", "display:block; ", null);
- writer.endElement("img");
- writer.endElement(HTML.td_ELEM);
- }
- }
-
- protected int calculateLevel (UIComponent component){
- int level = 0;
- UIComponent parent = component.getParent();
- while(parent != null){
- if(parent instanceof UIPanelMenu){
- return level;
- } else if(parent instanceof UIPanelMenuGroup){
- level++;
- }
- parent = parent.getParent();
- }
- return level;
- }
-
- /**
- * If icon type is a pre-defined value, return corresponding image, otherwise
- * otherwise
- * @param iconType
- * @param context
- * @param component
- * @return URI of requested image
- */
- protected String getIconByType(String iconType, boolean isTopLevel, FacesContext
context,
- UIComponent component){
-
- String source = "";
- String color = "";
- Skin skin = getSkin(context);
-
- if (isTopLevel){
- color = (String) skin.getParameter(context,"panelmenu.headerBulletColor");
- } else {
- color = (String) skin.getParameter(context,"panelmenu.itemBulletColor");
- }
- 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")) {
- source = getResource(PanelMenuIconTriangleDown.class.getName()).getUri(context,
color);
- } else if (iconType.equals("triangleUp")) {
- source = getResource(PanelMenuIconTriangleUp.class.getName()).getUri(context,
color);
- } else if (iconType.equals("chevron")) {
- source = getResource(PanelMenuIconChevron.class.getName()).getUri(context, color);
- } else if (iconType.equals("chevronUp")) {
- source = getResource(PanelMenuIconChevronUp.class.getName()).getUri(context, color);
- } else if (iconType.equals("chevronDown")) {
- source = getResource(PanelMenuIconChevronDown.class.getName()).getUri(context,
color);
-// } else if (iconType.equals("square")) {
-// source = getResource(PanelMenuIconSquare.class.getName()).getUri(context, color);
- } else if (iconType.equals("disc")) {
- source = getResource(PanelMenuIconDisc.class.getName()).getUri(context, color);
- } else if (iconType.equals("grid")) {
- source = getResource(PanelMenuIconGrid.class.getName()).getUri(context, color);
- } else {
- //TODO by nick - dima - TemplateContext is deprecated and shouldn't be used
- source = (String)getUtils().encodeResourceURL(new
TemplateContext(this,context,component),iconType);
- }
- }
- return source;
- }
-
- protected UIPanelMenu findMenu (UIComponent component){
- if (component instanceof UIPanelMenu) return (UIPanelMenu)component;
- UIComponent parent = component;
- while(parent != null){
- if(parent instanceof UIPanelMenu){
- return (UIPanelMenu) parent;
- }
- parent = parent.getParent();
- }
- return (UIPanelMenu) parent;
- }
-
- public String getHideStyle(FacesContext context, UIComponent component) {
- if (!(component.getParent() instanceof UIPanelMenu)) {
- CSSFormat format = new CSSFormat();
- format.add("display", "none");
- if(component.getParent() instanceof UIPanelMenuGroup) {
- UIPanelMenuGroup parent = (UIPanelMenuGroup)component.getParent();
- PanelMenuGroupRenderer renderer = (PanelMenuGroupRenderer)
context.getRenderKit().getRenderer(parent.getFamily(), parent.getRendererType());
- try {
- if ( renderer.isOpened(context, parent) ){
- return "";
- } else
- return format.toString();
- } catch (IOException e) {
- e.printStackTrace();
- }
- } else return format.toString();
- }
- return "";
- }
-
- public void insertValue(FacesContext context, UIComponent component) throws IOException
{
- Object value = component.getAttributes().get("value");
- if (value!=null){
- context.getResponseWriter().write(value.toString());
- }
- }
-
- protected boolean isChildrenExpanded(UIComponent component){
- if (component.getChildren() != null){
- Iterator itr = component.getChildren().iterator();
- while(itr.hasNext()){
- UIComponent child = (UIComponent)itr.next();
- if(child instanceof UIPanelMenuGroup){
- if( ((UIPanelMenuGroup)child).isExpanded() ){
- return true;
- } else {
- return isChildrenExpanded(child);
- }
- }
- }
- }
- return false;
- }
-
- protected boolean isParentDisabled(UIComponent component){
- boolean returnValue = false;
- UIComponent parent = component.getParent();
- if(parent instanceof UIPanelMenuGroup){
- UIPanelMenuGroup parentGroup = (UIPanelMenuGroup)parent;
- if(parentGroup.isDisabled()){
- returnValue = true;
- } else {
- returnValue = isParentDisabled(parentGroup);
- }
- }
- return returnValue;
- }
-
- protected boolean isSubmitted(FacesContext context, UIComponent component){
- boolean submitted = false;
- String clientId = component.getClientId(context);
- Map requestParameterMap = context.getExternalContext().getRequestParameterMap();
-
- Object value = requestParameterMap.get("panelMenuAction"+clientId);
- if (clientId!=null&&value!=null){
- if (value.equals(clientId)) {
- submitted = true;
- }
- }
- return submitted;
- }
-
- protected String getItemMode(UIComponent component) {
- String parentExpandMode = findMenu(component).getExpandMode();
- String parentMode = findMenu(component).getMode();
- if (null == parentMode || "".equals(parentMode))
- parentMode = "server";
- if (null == parentExpandMode || "".equals(parentExpandMode))
- parentExpandMode = "none";
- String mode = "none";
- if (component instanceof UIPanelMenuGroup) {
- UIPanelMenuGroup group = (UIPanelMenuGroup) component;
- if (null != group.getMode() && ! "".equals(group.getMode()))
- mode = group.getMode();
- else
- mode = parentExpandMode;
- } else if (component instanceof UIPanelMenuItem) {
- UIPanelMenuItem item = (UIPanelMenuItem) component;
- if (null != item.getMode() && ! "".equals(item.getMode()))
- mode = item.getMode();
- else
- mode = parentMode;
- }
- return mode;
- }
-
- /**
- *
- * @param component
- * @return
- */
- public boolean isTopLevel(UIComponent component){
- UIComponent parent = component.getParent();
- while( !(parent instanceof UIPanelMenu) && !(parent instanceof
UIPanelMenuGroup)) {
- parent = parent.getParent();
- }
- if(parent instanceof UIPanelMenu){
- return true;
- } else {
- 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");
- }
-
- }
-
-}
Modified: trunk/sandbox/panelmenu/src/main/templates/org/richfaces/htmlPanelMenu.jspx
===================================================================
--- trunk/sandbox/panelmenu/src/main/templates/org/richfaces/htmlPanelMenu.jspx 2007-06-13
16:28:48 UTC (rev 1165)
+++ trunk/sandbox/panelmenu/src/main/templates/org/richfaces/htmlPanelMenu.jspx 2007-06-13
16:46:27 UTC (rev 1166)
@@ -8,8 +8,8 @@
xmlns:x="
http://ajax4jsf.org/cdk/x"
xmlns:vcp="http://ajax4jsf.org/cdk/vcp"
class="org.richfaces.renderkit.html.HtmlPanelMenuRenderer"
- baseclass="org.richfaces.renderkit.PanelMenuRenderer"
- component="org.richfaces.component.panelmenu.UIPanelMenu" >
+ baseclass="org.richfaces.renderkit.html.PanelMenuRenderer"
+ component="org.richfaces.component.UIPanelMenu" >
<h:styles>
/org/richfaces/renderkit/html/css/panelMenu.xcss
Modified:
trunk/sandbox/panelmenu/src/main/templates/org/richfaces/htmlPanelMenuGroup.jspx
===================================================================
---
trunk/sandbox/panelmenu/src/main/templates/org/richfaces/htmlPanelMenuGroup.jspx 2007-06-13
16:28:48 UTC (rev 1165)
+++
trunk/sandbox/panelmenu/src/main/templates/org/richfaces/htmlPanelMenuGroup.jspx 2007-06-13
16:46:27 UTC (rev 1166)
@@ -7,8 +7,8 @@
xmlns:x="
http://ajax4jsf.org/cdk/x"
xmlns:vcp="
http://ajax4jsf.org/cdk/vcp"
class="org.richfaces.renderkit.html.HtmlPanelMenuGroupRenderer"
- baseclass="org.richfaces.renderkit.PanelMenuGroupRenderer"
- component="org.richfaces.component.panelmenu.UIPanelMenuGroup"
+ baseclass="org.richfaces.renderkit.html.PanelMenuGroupRenderer"
+ component="org.richfaces.component.UIPanelMenuGroup"
<f:clientid var="clientId"/>
Modified: trunk/sandbox/panelmenu/src/main/templates/org/richfaces/htmlPanelMenuItem.jspx
===================================================================
---
trunk/sandbox/panelmenu/src/main/templates/org/richfaces/htmlPanelMenuItem.jspx 2007-06-13
16:28:48 UTC (rev 1165)
+++
trunk/sandbox/panelmenu/src/main/templates/org/richfaces/htmlPanelMenuItem.jspx 2007-06-13
16:46:27 UTC (rev 1166)
@@ -7,8 +7,8 @@
xmlns:x="
http://ajax4jsf.org/cdk/x"
xmlns:vcp="
http://ajax4jsf.org/cdk/vcp"
class="org.richfaces.renderkit.html.HtmlPanelMenuItemRenderer"
- baseclass="org.richfaces.renderkit.PanelMenuItemRenderer"
- component="org.richfaces.component.panelmenu.UIPanelMenuItem"
+ baseclass="org.richfaces.renderkit.html.PanelMenuItemRenderer"
+ component="org.richfaces.component.UIPanelMenuItem"
<f:clientid var="clientId"/>