Author: Alex.Kolonitsky
Date: 2010-05-28 09:53:19 -0400 (Fri, 28 May 2010)
New Revision: 17361
Modified:
root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/renderkit/SubTableToggleControlRendererBase.java
Log:
fix checkstyle
Modified:
root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/renderkit/SubTableToggleControlRendererBase.java
===================================================================
---
root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/renderkit/SubTableToggleControlRendererBase.java 2010-05-28
13:44:31 UTC (rev 17360)
+++
root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/renderkit/SubTableToggleControlRendererBase.java 2010-05-28
13:53:19 UTC (rev 17361)
@@ -26,7 +26,6 @@
import java.util.HashMap;
import java.util.Map;
-import javax.faces.application.Resource;
import javax.faces.application.ResourceDependencies;
import javax.faces.application.ResourceDependency;
import javax.faces.component.UIComponent;
@@ -41,11 +40,10 @@
/**
* @author Anton Belevich
- *
*/
-@ResourceDependencies( {@ResourceDependency(library = "javax.faces", name =
"jsf.js"),
+@ResourceDependencies({@ResourceDependency(library = "javax.faces", name =
"jsf.js"),
@ResourceDependency(name = "richfaces.js"), @ResourceDependency(name =
"subtable-toggler.js")})
-
+
public class SubTableToggleControlRendererBase extends RendererBase {
private static final String DISPLAY_NONE = "display: none;";
@@ -53,28 +51,28 @@
private static final String EXPAND_STATE = "expand";
private static final String COLLAPSE_STATE = "collapse";
-
+
private static final String UP_ICON_URL = "up_icon.gif";
-
+
private static final String DOWN_ICON_URL = "down_icon.gif";
-
+
@Override
protected void doDecode(FacesContext context, UIComponent component) {
context.getPartialViewContext().getRenderIds().add(component.getClientId(context));
}
-
+
protected void encodeControl(FacesContext context, UIComponent component) throws
IOException {
-
+
UISubTableToggleControl toggleControl = (UISubTableToggleControl) component;
-
+
UISubTable subTable = findComponent(context, toggleControl);
if (subTable != null) {
ResponseWriter writer = context.getResponseWriter();
-
+
String toggleId = toggleControl.getClientId(context);
Map<String, Object> options = encodeOptions(context, toggleControl,
subTable);
String switchType = subTable.getExpandMode();
-
+
boolean expanded = subTable.isExpanded();
encodeControl(context, writer, toggleControl, switchType, expanded, false);
@@ -83,24 +81,24 @@
JSFunction jsFunction = new JSFunction("new
RichFaces.ui.SubTableToggler");
jsFunction.addParameter(toggleId);
jsFunction.addParameter(options);
-
+
writer.startElement(HTML.SCRIPT_ELEM, subTable);
writer.writeText(jsFunction.toScript(), null);
writer.endElement(HTML.SCRIPT_ELEM);
-
+
subTable.addToggleListener(toggleControl);
}
-
+
}
protected void encodeControl(FacesContext context, ResponseWriter writer,
UISubTableToggleControl control,
- String switchType, boolean expanded, boolean visible)
throws IOException {
+ String switchType, boolean expanded, boolean visible)
throws IOException {
String state = getState(expanded);
String styleClass = getStyleClass(context, control);
String style = getStyle(context, control);
writer.startElement(HTML.SPAN_ELEM, control);
-
+
if (!visible) {
writer.writeAttribute(HTML.STYLE_ATTRIBUTE, DISPLAY_NONE, null);
}
@@ -108,26 +106,26 @@
writer.writeAttribute(HTML.ID_ATTRIBUTE, control.getClientId() + ":" +
state, null);
writer.writeAttribute(HTML.CLASS_ATTRIBUTE, styleClass, null);
writer.writeAttribute(HTML.STYLE_ATTRIBUTE, style, null);
-
+
boolean encodeDefault = true;
UIComponent controlFacet = control.getFacet(state);
- if(controlFacet != null && controlFacet.isRendered()) {
-
- if(!visible) {
- String facetStyle =
(String)controlFacet.getAttributes().get("style");
+ if (controlFacet != null && controlFacet.isRendered()) {
+
+ if (!visible) {
+ String facetStyle = (String)
controlFacet.getAttributes().get("style");
facetStyle = facetStyle != null ? facetStyle + "; display:
none" : "; display: none";
controlFacet.getAttributes().put("style", facetStyle);
}
controlFacet.encodeAll(context);
encodeDefault = false;
- }
-
+ }
+
String expandIcon = control.getExpandIcon();
String collapseIcon = control.getCollapseIcon();
-
- if((expandIcon != null && collapseIcon != null)
- && (expandIcon.trim().length() > 0 &&
collapseIcon.trim().length() > 0)) {
-
+
+ if ((expandIcon != null && collapseIcon != null)
+ && (expandIcon.trim().length() > 0 &&
collapseIcon.trim().length() > 0)) {
+
String image = expanded ? expandIcon : collapseIcon;
if (image != null && image.trim().length() > 0) {
writer.startElement(HTML.IMG_ELEMENT, control);
@@ -136,21 +134,21 @@
writer.endElement(HTML.IMG_ELEMENT);
}
encodeDefault = false;
- }
-
+ }
+
String label = expanded ? control.getExpandLabel() : control.getCollapseLabel();
- if(label != null && label.trim().length() > 0) {
+ if (label != null && label.trim().length() > 0) {
writer.startElement(HTML.A_ELEMENT, control);
writer.writeAttribute(HTML.HREF_ATTR, "javascript:void(0);",
null);
writer.writeText(label, null);
writer.endElement(HTML.A_ELEMENT);
encodeDefault = false;
}
-
- if(encodeDefault) {
+
+ if (encodeDefault) {
expandIcon =
context.getApplication().getResourceHandler().createResource(UP_ICON_URL).getRequestPath();
collapseIcon =
context.getApplication().getResourceHandler().createResource(DOWN_ICON_URL).getRequestPath();
-
+
String image = expanded ? expandIcon : collapseIcon;
if (image != null && image.trim().length() > 0) {
writer.startElement(HTML.IMG_ELEMENT, control);
@@ -158,25 +156,23 @@
writer.writeAttribute(HTML.ALT_ATTRIBUTE, "", null);
writer.endElement(HTML.IMG_ELEMENT);
}
-
+
}
-
+
writer.endElement(HTML.SPAN_ELEM);
}
-
-
public HashMap<String, Object> encodeOptions(FacesContext context,
UISubTableToggleControl toggleControl, UISubTable subTable) {
String forId = subTable.getClientId(context);
String toggleControlId = toggleControl.getClientId(context);
-
+
HashMap<String, Object> options = new HashMap<String, Object>();
options.put("forId", forId);
options.put("expandControl", toggleControlId + ":expand");
options.put("collapseControl", toggleControlId +
":collapse");
-
+
String eventName = toggleControl.getEvent();
- eventName = eventName.trim().startsWith("on") ? eventName.substring(2)
: eventName;
+ eventName = eventName.trim().startsWith("on") ? eventName.substring(2)
: eventName;
options.put("eventName", eventName);
return options;
}
@@ -192,12 +188,12 @@
protected UISubTable findComponent(FacesContext context, UISubTableToggleControl
toggleControl) {
String forId = toggleControl.getFor();
if (forId != null && forId.length() > 0) {
-
+
UIComponent subTable = getUtils().findComponentFor(context, toggleControl,
forId);
if (subTable instanceof UISubTable) {
return (UISubTable) subTable;
}
-
+
}
return null;
}
@@ -205,5 +201,5 @@
protected String getState(boolean expand) {
return expand ? EXPAND_STATE : COLLAPSE_STATE;
}
-
+
}