Author: dbiatenia
Date: 2007-06-06 07:28:57 -0400 (Wed, 06 Jun 2007)
New Revision: 1037
Added:
trunk/sandbox/panelmenu/src/main/java/org/richfaces/conveter/
trunk/sandbox/panelmenu/src/main/java/org/richfaces/conveter/UIPanelMenuGroupValueConverter.java
Modified:
trunk/sandbox/panelmenu/src/main/java/org/richfaces/component/panelmenu/UIPanelMenuGroup.java
trunk/sandbox/panelmenu/src/main/java/org/richfaces/component/panelmenu/UIPanelMenuItem.java
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
trunk/sandbox/panelmenu/src/main/resources/org/richfaces/renderkit/html/scripts/panelMenu.js
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:
code review bugfix
Modified:
trunk/sandbox/panelmenu/src/main/java/org/richfaces/component/panelmenu/UIPanelMenuGroup.java
===================================================================
---
trunk/sandbox/panelmenu/src/main/java/org/richfaces/component/panelmenu/UIPanelMenuGroup.java 2007-06-06
09:12:49 UTC (rev 1036)
+++
trunk/sandbox/panelmenu/src/main/java/org/richfaces/component/panelmenu/UIPanelMenuGroup.java 2007-06-06
11:28:57 UTC (rev 1037)
@@ -22,6 +22,7 @@
package org.richfaces.component.panelmenu;
import javax.faces.component.ActionSource;
+import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import javax.faces.el.MethodBinding;
@@ -29,7 +30,10 @@
import javax.faces.event.ActionEvent;
import javax.faces.event.ActionListener;
import javax.faces.event.FacesEvent;
+import javax.faces.event.PhaseId;
+import org.richfaces.conveter.UIPanelMenuGroupValueConverter;
+
public abstract class UIPanelMenuGroup extends UIInput implements ActionSource{
public static final String COMPONENT_TYPE = "org.richfaces.panelMenuGroup";
@@ -45,17 +49,14 @@
public abstract String getIconExpanded();
public abstract void setIconExpanded(String expanded);
- public abstract boolean isExpanded();
- public abstract void setExpanded(boolean expanded);
-
public abstract String getIconCollapsed();
public abstract void setIconCollapsed(String iconCollapsed);
public abstract String getIconDisabled();
public abstract void setIconDisabled(String iconDisabled);
public abstract boolean isDisabled();
public abstract void setDisabled(boolean disabled);
- public abstract Object getValue();
- public abstract void setValue(Object value);
+// public abstract Object getValue();
+// public abstract void setValue(Object value);
public abstract String getTarget();
public abstract void setTarget(String target);
public abstract String getHoverClass();
@@ -79,24 +80,39 @@
public abstract String getLabel();
public abstract void setLabel(String label);
+ public abstract boolean isExpanded();
+ public abstract void setExpanded(boolean expanded);
+
+ public UIPanelMenuGroup(){
+ setConverter(new UIPanelMenuGroupValueConverter());
+ }
+
+ public boolean isTopLevel(){
+ UIComponent parent = getParent();
+ while( !(parent instanceof UIPanelMenu) && !(parent instanceof
UIPanelMenuGroup)) {
+ parent = parent.getParent();
+ }
+ if(parent instanceof UIPanelMenu){
+ return true;
+ } else {
+ return false;
+ }
+ }
+
public void addActionListener(ActionListener listener) {
- // TODO Auto-generated method stub
addFacesListener(listener);
}
public MethodBinding getAction() {
- // TODO Auto-generated method stub
return action;
}
public MethodBinding getActionListener() {
- // TODO Auto-generated method stub
return (this.actionListener);
}
public ActionListener[] getActionListeners() {
- // TODO Auto-generated method stub
ActionListener al[] = (ActionListener [])
getFacesListeners(ActionListener.class);
return (al);
@@ -104,20 +120,17 @@
}
public void removeActionListener(ActionListener listener) {
- // TODO Auto-generated method stub
removeFacesListener(listener);
}
public void setAction(MethodBinding action) {
- // TODO Auto-generated method stub
this.action = action;
}
-
public void setActionListener(MethodBinding actionListener) {
- // TODO Auto-generated method stub
this.actionListener = actionListener;
}
+
public void restoreState(FacesContext context, Object state) {
Object values[] = (Object[]) state;
super.restoreState(context, values[0]);
@@ -126,7 +139,6 @@
values[2]);
}
-
public Object saveState(FacesContext context) {
Object values[] = new Object[3];
values[0] = super.saveState(context);
@@ -134,8 +146,19 @@
values[2] = saveAttachedState(context, actionListener);
return values;
}
+
+ public void queueEvent(FacesEvent event) {
+ if(event instanceof ActionEvent){
+ if (isImmediate()) {
+ event.setPhaseId(PhaseId.APPLY_REQUEST_VALUES);
+ } else {
+ event.setPhaseId(PhaseId.INVOKE_APPLICATION);
+ }
+ }
+ super.queueEvent(event);
+ }
+
public void broadcast(FacesEvent event) throws AbortProcessingException {
- // TODO Auto-generated method stub
super.broadcast(event);
if(event instanceof ActionEvent){
FacesContext context = getFacesContext();
Modified:
trunk/sandbox/panelmenu/src/main/java/org/richfaces/component/panelmenu/UIPanelMenuItem.java
===================================================================
---
trunk/sandbox/panelmenu/src/main/java/org/richfaces/component/panelmenu/UIPanelMenuItem.java 2007-06-06
09:12:49 UTC (rev 1036)
+++
trunk/sandbox/panelmenu/src/main/java/org/richfaces/component/panelmenu/UIPanelMenuItem.java 2007-06-06
11:28:57 UTC (rev 1037)
@@ -22,6 +22,7 @@
package org.richfaces.component.panelmenu;
import javax.faces.component.UICommand;
+import javax.faces.component.UIComponent;
public abstract class UIPanelMenuItem extends UICommand {
@@ -54,5 +55,18 @@
public abstract String getIconStyle();
public abstract void setIconStyle(String iconStyle);
public abstract String getTarget();
- public abstract void setTarget(String target);
+ public abstract void setTarget(String target);
+
+ public boolean isTopLevel(){
+ UIComponent parent = getParent();
+ while( !(parent instanceof UIPanelMenu) && !(parent instanceof
UIPanelMenuGroup)) {
+ parent = parent.getParent();
+ }
+ if(parent instanceof UIPanelMenu){
+ return true;
+ } else {
+ return false;
+ }
+ }
+
}
Added:
trunk/sandbox/panelmenu/src/main/java/org/richfaces/conveter/UIPanelMenuGroupValueConverter.java
===================================================================
---
trunk/sandbox/panelmenu/src/main/java/org/richfaces/conveter/UIPanelMenuGroupValueConverter.java
(rev 0)
+++
trunk/sandbox/panelmenu/src/main/java/org/richfaces/conveter/UIPanelMenuGroupValueConverter.java 2007-06-06
11:28:57 UTC (rev 1037)
@@ -0,0 +1,19 @@
+package org.richfaces.conveter;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+
+public class UIPanelMenuGroupValueConverter implements Converter {
+
+ public Object getAsObject(FacesContext context, UIComponent component,
+ String value) {
+ return value != null ? new Boolean(value) : null;
+ }
+
+ public String getAsString(FacesContext context, UIComponent component,
+ Object value) {
+ return value.toString();
+ }
+
+}
Property changes on:
trunk/sandbox/panelmenu/src/main/java/org/richfaces/conveter/UIPanelMenuGroupValueConverter.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
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-06
09:12:49 UTC (rev 1036)
+++
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/PanelMenuGroupRenderer.java 2007-06-06
11:28:57 UTC (rev 1037)
@@ -22,24 +22,26 @@
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.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.event.SwitchablePanelSwitchEvent;
public class PanelMenuGroupRenderer extends PanelMenuRendererBase {
+
protected Class getComponentClass() {
- //TODO by nick - dima - add concrete component class
- return UIComponent.class;
+ return UIPanelMenuGroup.class;
}
protected void doDecode(FacesContext context, UIComponent component) {
@@ -49,16 +51,20 @@
if(requestMap.containsKey("panelMenuState"+clientId)){
Object property = requestMap.get("panelMenuState"+clientId);
-
if (property.equals("opened")) {
- group.setExpanded(true);
+ group.setSubmittedValue("true");
+ //group.setSubmittedValue(new Boolean(true));
+ //group.setExpanded(true);
} else if (property.equals("closed")) {
- ((UIPanelMenuGroup)component).setExpanded(false);
+ group.setSubmittedValue("false");
+ //group.setSubmittedValue(new Boolean(false));
+ //group.setExpanded(false);
}
}
if(isSubmitted(context, component)){
- new SwitchablePanelSwitchEvent(findMenu(component), null, component).queue();
+ //new SwitchablePanelSwitchEvent(findMenu(component), null, component).queue();
+ //new ValueChangeEvent(group, group.getValue(), group.getSubmittedValue()).queue();
new ActionEvent(component).queue();
if (UISwitchablePanel.AJAX_METHOD.equals(getItemMode(component))) {
new AjaxEvent(component).queue();
@@ -73,10 +79,7 @@
String align = "";
UIPanelMenu panelMenu = findMenu(component);
- //TODO by nick - dima - add isTopLevel() method to group component
- //TODO by nick - dima - btw, components can be enclosed in other components such as
ui:repeat, so panelManu will be
- // parent of parent of ...
- boolean isTopLevel = component.getParent() instanceof UIPanelMenu;
+ boolean isTopLevel = ((UIPanelMenuGroup)component).isTopLevel();
if (isTopLevel){
align = panelMenu.getIconItemTopPosition();
@@ -99,19 +102,16 @@
if(panelMenu == null){
return;
}
-
- //TODO by nick - dima - add isTopLevel() method to group component
- boolean isTopLevel = component.getParent() instanceof UIPanelMenu;
+ UIPanelMenuGroup panelMenuGroup = (UIPanelMenuGroup)component;
+ boolean isTopLevel = panelMenuGroup.isTopLevel();
//TODO by nick - dima - component value should be used here
- boolean isOpened = isOpened(context,component).equals("opened") ? true :
false;
+ boolean isOpened = isOpened(context,component);
String source = "";
String iconNode = "";
- //TODO by nick - dima - access through attributes map is usually slower as done through
reflection. Should be replaced with abstract
- // getter invocation
- Object iconCollapsed = component.getAttributes().get("iconCollapsed");
- Object iconExpanded = component.getAttributes().get("iconExpanded");
+ Object iconCollapsed = panelMenuGroup.getIconCollapsed();
+ Object iconExpanded = panelMenuGroup.getIconExpanded();
String icon = (isOpened ? iconExpanded : iconCollapsed).toString();
if (icon.equals("")){
source = getIconByType("custom", isTopLevel,context, component);
@@ -124,14 +124,15 @@
}
int h = 16; //width(context);
- StringBuffer imageBuffer = new StringBuffer();
- //TODO by nick - dima - use
writer.startElement()/writer.endElement()/getUtils().writeAttribute() calls to output
image
- imageBuffer.append("<img src=\"" + source + "\" ");
- imageBuffer.append("alt=\"\" vspace=\"0\"
hspace=\"0\" ");
- imageBuffer.append("style=\"display:block;\" ");
- imageBuffer.append("width=\"" + String.valueOf(h) + "\"
");
- imageBuffer.append("height=\"" + String.valueOf(h) + "\"
/>");
- writer.write(imageBuffer.toString());
+ 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");
}
public String getFullStyleClass(FacesContext context, UIComponent component) {
@@ -166,29 +167,28 @@
return styleBuffer.toString();
}
- public String getHideStyle(FacesContext context, UIComponent component) {
- // TODO Auto-generated method stub
- if (!(component.getParent() instanceof UIPanelMenu)) {
- CSSFormat format = new CSSFormat();
- format.add("display", "none");
- if(component.getParent() instanceof UIPanelMenuGroup) {
- UIPanelMenuGroup parent = (UIPanelMenuGroup)component.getParent();
- //TODO by nick - dima - take opened value from component itself
- PanelMenuGroupRenderer renderer = (PanelMenuGroupRenderer)
context.getRenderKit().getRenderer(parent.getFamily(), parent.getRendererType());
- try {
- if ( renderer.isOpened(context, parent).equals("opened") ){
- return "";
- } else
- return format.toString();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- } else return format.toString();
- }
- return "";
-
- }
+// 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();
+// //TODO by nick - dima - take opened value from component itself
+// PanelMenuGroupRenderer renderer = (PanelMenuGroupRenderer)
context.getRenderKit().getRenderer(parent.getFamily(), parent.getRendererType());
+// try {
+// if ( renderer.isOpened(context, parent).equals("opened") ){
+// return "";
+// } else
+// return format.toString();
+// } catch (IOException e) {
+// // TODO Auto-generated catch block
+// e.printStackTrace();
+// }
+// } else return format.toString();
+// }
+// return "";
+//
+// }
public void insertLabel(FacesContext context, UIComponent component) throws IOException
{
Object label = component.getAttributes().get("label");
@@ -196,5 +196,59 @@
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
{
+ //String clientId = component.getClientId(context);
+ ///Map requestParameterMap = context.getExternalContext().getRequestParameterMap();
+
+ 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;
+ }
+/*
+ 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;
+ }
+*/
}
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-06
09:12:49 UTC (rev 1036)
+++
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/PanelMenuItemRenderer.java 2007-06-06
11:28:57 UTC (rev 1037)
@@ -22,15 +22,11 @@
package org.richfaces.renderkit;
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.event.ActionEvent;
-
import org.ajax4jsf.framework.ajax.AjaxEvent;
-import org.ajax4jsf.framework.renderer.compiler.TemplateContext;
import org.ajax4jsf.framework.util.style.CSSFormat;
import org.richfaces.component.UISwitchablePanel;
import org.richfaces.component.panelmenu.UIPanelMenu;
@@ -41,7 +37,7 @@
public class PanelMenuItemRenderer extends PanelMenuRendererBase {
protected Class getComponentClass() {
//TODO by nick - dima - add concrete component class
- return UIComponent.class;
+ return UIPanelMenuItem.class;
}
protected void doEncodeBegin(ResponseWriter writer, FacesContext context,UIComponent
component) throws IOException {
@@ -73,8 +69,8 @@
return;
}
String align = "";
- //TODO by nick - dima - add isTopLevel() method to item component
- boolean isTopLevel = component.getParent() instanceof UIPanelMenu;
+ UIPanelMenuItem panelMenuItem = (UIPanelMenuItem)component;
+ boolean isTopLevel = panelMenuItem.isTopLevel();
if (isTopLevel){
align = panelMenu.getIconItemTopPosition();
@@ -121,14 +117,15 @@
if (!iconType.equals("none")){
int h = 16; //width(context);
- //TODO by nick - dima - use
writer.startElement()/writer.endElement()/getUtils().writeAttribute() calls to output
image
- StringBuffer imageBuffer = new StringBuffer();
- imageBuffer.append("<img src=\"" + source + "\" ");
- imageBuffer.append("alt=\"\" vspace=\"0\"
hspace=\"0\" ");
- imageBuffer.append("style=\"display:block;\" ");
- imageBuffer.append("width=\"" + String.valueOf(h) + "\"
");
- imageBuffer.append("height=\"" + String.valueOf(h) + "\"
/>");
- writer.write(imageBuffer.toString());
+ 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");
}
}
@@ -166,27 +163,27 @@
//TODO by nick - dima - looks like duplicate code methods. can we add it to super
class?
- public String getHideStyle(FacesContext context, UIComponent component) {
- // TODO Auto-generated method stub
- 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).equals("opened") ){
- return "";
- } else
- return format.toString();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- } else return format.toString();
- }
- return "";
- }
+// public String getHideStyle(FacesContext context, UIComponent component) {
+// // TODO Auto-generated method stub
+// 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).equals("opened") ){
+// return "";
+// } else
+// return format.toString();
+// } catch (IOException e) {
+// // TODO Auto-generated catch block
+// e.printStackTrace();
+// }
+// } else return format.toString();
+// }
+// return "";
+// }
}
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-06
09:12:49 UTC (rev 1036)
+++
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/PanelMenuRenderer.java 2007-06-06
11:28:57 UTC (rev 1037)
@@ -266,6 +266,26 @@
}
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));
+ }
+ }
+/*
String value = "";
try {
value =
context.getExternalContext().getRequestParameterMap().get("panelMenuState"+child.getClientId(context)).toString();
@@ -288,7 +308,8 @@
buffer.append(isChildrenExpanded(child) ? ",true" : ",false");
//buffer.append(",false");
}
- }
+ }
+*/
}
private void addImages(StringBuffer buffer,FacesContext context,UIComponent
component,String id){
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-06
09:12:49 UTC (rev 1036)
+++
trunk/sandbox/panelmenu/src/main/java/org/richfaces/renderkit/PanelMenuRendererBase.java 2007-06-06
11:28:57 UTC (rev 1037)
@@ -25,12 +25,12 @@
import java.util.Iterator;
import java.util.Map;
-import javax.faces.component.UICommand;
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.RendererUtils;
import org.ajax4jsf.framework.renderer.compiler.TemplateContext;
import org.ajax4jsf.framework.skin.Skin;
import org.ajax4jsf.framework.util.style.CSSFormat;
@@ -47,6 +47,7 @@
import org.richfaces.renderkit.iconImages.PanelMenuIconDoubleArrowUp;
import org.richfaces.renderkit.iconImages.PanelMenuIconSpacer;
import org.richfaces.renderkit.iconImages.PanelMenuIconSquare;
+import org.ajax4jsf.framework.renderer.RendererUtils.HTML;
/**
* @author hans
@@ -56,14 +57,27 @@
public void insertTDs(FacesContext context , UIComponent component) throws IOException
{
ResponseWriter writer = context.getResponseWriter();
int level = calculateLevel(component);
- StringBuffer buffer = new StringBuffer();
+ //StringBuffer buffer = new StringBuffer();
String src = getIconByType("custom",false,context,component);
int w = 16; //width(context);
- //TODO by nick - dima - use
writer.startElement()/writer.endElement()/getUtils().writeAttribute() calls to output
image
+
+ RendererUtils utils = getUtils();
+
for (int i=0;i<level;i++){
- buffer.append("<td><img src=\"" + src + "\"
alt=\"\" hspace=\"0\" vspace=\"0\"
height=\""+w+"\" width=\""+w+"\"
style=\"display:block;\" /></td>\n");
+ 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);
+ //buffer.append("<td><img src=\"" + src + "\"
alt=\"\" hspace=\"0\" vspace=\"0\"
height=\""+w+"\" width=\""+w+"\"
style=\"display:block;\" /></td>\n");
}
- writer.write(buffer.toString());
+ //writer.write(buffer.toString());
}
protected int calculateLevel (UIComponent component){
@@ -72,10 +86,10 @@
while(parent != null){
if(parent instanceof UIPanelMenu){
return level;
+ } else if(parent instanceof UIPanelMenuGroup){
+ level++;
}
parent = parent.getParent();
- //TODO by nick - dima - inc level counter only if parent is panelMenu(Group)
component
- level++;
}
return level;
}
@@ -142,14 +156,37 @@
return (UIPanelMenu) parent;
}
+// public String getHideStyle(FacesContext context, UIComponent component) {
+// if (!(component.getParent() instanceof UIPanelMenu)) {
+// CSSFormat format = new CSSFormat();
+// format.add("display", "none");
+// return format.toString();
+// }
+// return "";
+// }
public String getHideStyle(FacesContext context, UIComponent component) {
if (!(component.getParent() instanceof UIPanelMenu)) {
CSSFormat format = new CSSFormat();
format.add("display", "none");
- return format.toString();
+ if(component.getParent() instanceof UIPanelMenuGroup) {
+ UIPanelMenuGroup parent = (UIPanelMenuGroup)component.getParent();
+ //TODO by nick - dima - take opened value from component itself
+ PanelMenuGroupRenderer renderer = (PanelMenuGroupRenderer)
context.getRenderKit().getRenderer(parent.getFamily(), parent.getRendererType());
+ try {
+ if ( renderer.isOpened(context, parent) ){
+ return "";
+ } else
+ return format.toString();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ } else return format.toString();
}
return "";
+
}
+
public void insertValue(FacesContext context, UIComponent component) throws IOException
{
Object value = component.getAttributes().get("value");
@@ -159,28 +196,28 @@
}
- public String isOpened(FacesContext context, UIComponent component)throws IOException {
- String clientId = component.getClientId(context);
- Map requestParameterMap = context.getExternalContext().getRequestParameterMap();
- Object value = requestParameterMap.get("panelMenuState"+clientId);
- if (value != null) {
- if (value.equals("opened")) {
- return "opened";
- }
- } else {
- boolean isParentDisabled = isParentDisabled(component);
- if(component instanceof UIPanelMenuGroup){
- if( ((UIPanelMenuGroup)component).isExpanded() &&
!((UIPanelMenuGroup)component).isDisabled() && !isParentDisabled ){
- return "opened";
- } else {
- //check expanded attributes in children groups, if exists
- boolean isChildrenExpanded = isChildrenExpanded(component);
- return isChildrenExpanded && !isParentDisabled &&
!((UIPanelMenuGroup)component).isDisabled() ? "opened" : "closed";
- }
- }
- }
- return "closed";
- }
+// public String isOpened(FacesContext context, UIComponent component)throws IOException
{
+// String clientId = component.getClientId(context);
+// Map requestParameterMap = context.getExternalContext().getRequestParameterMap();
+// Object value = requestParameterMap.get("panelMenuState"+clientId);
+// if (value != null) {
+// if (value.equals("opened")) {
+// return "opened";
+// }
+// } else {
+// boolean isParentDisabled = isParentDisabled(component);
+// if(component instanceof UIPanelMenuGroup){
+// if( ((UIPanelMenuGroup)component).isExpanded() &&
!((UIPanelMenuGroup)component).isDisabled() && !isParentDisabled ){
+// return "opened";
+// } else {
+// //check expanded attributes in children groups, if exists
+// boolean isChildrenExpanded = isChildrenExpanded(component);
+// return isChildrenExpanded && !isParentDisabled &&
!((UIPanelMenuGroup)component).isDisabled() ? "opened" : "closed";
+// }
+// }
+// }
+// return "closed";
+// }
protected boolean isChildrenExpanded(UIComponent component){
if (component.getChildren() != null){
Modified:
trunk/sandbox/panelmenu/src/main/resources/org/richfaces/renderkit/html/scripts/panelMenu.js
===================================================================
---
trunk/sandbox/panelmenu/src/main/resources/org/richfaces/renderkit/html/scripts/panelMenu.js 2007-06-06
09:12:49 UTC (rev 1036)
+++
trunk/sandbox/panelmenu/src/main/resources/org/richfaces/renderkit/html/scripts/panelMenu.js 2007-06-06
11:28:57 UTC (rev 1037)
@@ -136,7 +136,9 @@
hide: function(){
this.obj.style.display = 'none';
- this.inputState.value="closed";
+// if(this.inputState){
+// this.inputState.value="closed";
+// }
},
expand: function(){
@@ -167,8 +169,8 @@
},
show: function(){
- if (this.type!="node")
- this.inputState.value="opened";
+// if (this.type!="node")
+// this.inputState.value="opened";
this.tdhider.style.display="";
this.tablehider.style.display="";
this.obj.style.display = "";
Modified: trunk/sandbox/panelmenu/src/main/templates/org/richfaces/htmlPanelMenu.jspx
===================================================================
--- trunk/sandbox/panelmenu/src/main/templates/org/richfaces/htmlPanelMenu.jspx 2007-06-06
09:12:49 UTC (rev 1036)
+++ trunk/sandbox/panelmenu/src/main/templates/org/richfaces/htmlPanelMenu.jspx 2007-06-06
11:28:57 UTC (rev 1037)
@@ -36,11 +36,11 @@
<tr style="display:none">
<td>
<!-- TODO by nick - dima - no need for clientId here -->
- <f:clientid var="clientId"/>
+ <!--f:clientid var="clientId"/-->
<f:call name="insertScript"/>
</td>
</tr>
</tbody>
</table>
<f:call name="utils.encodeEndFormIfNessesary"/>
-</f:root>
\ No newline at end of file
+</f:root>
Modified:
trunk/sandbox/panelmenu/src/main/templates/org/richfaces/htmlPanelMenuGroup.jspx
===================================================================
---
trunk/sandbox/panelmenu/src/main/templates/org/richfaces/htmlPanelMenuGroup.jspx 2007-06-06
09:12:49 UTC (rev 1036)
+++
trunk/sandbox/panelmenu/src/main/templates/org/richfaces/htmlPanelMenuGroup.jspx 2007-06-06
11:28:57 UTC (rev 1037)
@@ -22,6 +22,8 @@
itemClass = " dr-pmenu-disabled-element rich-pmenu-disabled-element ";
}
variables.setVariable("itemClass", itemClass);
+
+ String isNodeOpened = isOpened(context, component) ?
"opened" : "closed";
]]>
</jsp:scriptlet>
<table cellpadding="0" cellspacing="0" border="0"
width="100%"
@@ -34,9 +36,9 @@
</f:call>
<!-- TODO by nick - dima - encodeAttributes & encodePassThru conflict -->
<f:call name="utils.encodePassThru" />
- <tr>
- <!-- TODO by nick - dima - just id="#{clientId}" -->
- <f:call name="utils.encodeId" />
+ <tr id="#{clientId}">
+ <!-- TODO by nick - dima - just id="_#_{clientId}" -->
+ <!--f:call name="utils.encodeId" /-->
<f:call name="insertTDs" />
<td>
<f:call name="insertImage">
@@ -47,7 +49,7 @@
<td style="width:100%" class="item_content"
id="icon#{clientId}" >
<input type="hidden" name="panelMenuState#{clientId}"
- value="#{this:isOpened(context, component)}" >
+ value="#{isNodeOpened}" >
</input>
<!-- TODO by nick - dima - one input should be enough -->
<input type="hidden" name="panelMenuAction#{clientId}"
Modified: trunk/sandbox/panelmenu/src/main/templates/org/richfaces/htmlPanelMenuItem.jspx
===================================================================
---
trunk/sandbox/panelmenu/src/main/templates/org/richfaces/htmlPanelMenuItem.jspx 2007-06-06
09:12:49 UTC (rev 1036)
+++
trunk/sandbox/panelmenu/src/main/templates/org/richfaces/htmlPanelMenuItem.jspx 2007-06-06
11:28:57 UTC (rev 1037)
@@ -44,9 +44,6 @@
</f:call>
</td>
<td style="width:100%" class="item_content">
- <input type="hidden" name="panelMenuState#{clientId}"
- value="#{this:isOpened(context, component)}" >
- </input>
<input type="hidden" name="panelMenuAction#{clientId}"
value="" >
</input>