Author: amarkhel
Date: 2010-08-19 13:08:16 -0400 (Thu, 19 Aug 2010)
New Revision: 18823
Modified:
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/PopupPanelBaseRenderer.java
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/popupPanel.js
trunk/ui/output/ui/src/test/java/org/richfaces/renderkit/html/PopupRendererTest.java
trunk/ui/output/ui/src/test/resources/popupPanelTest.xhtml
Log:
Refactor popup renderer and related to this refactoring fix couple of bugs
Modified:
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/PopupPanelBaseRenderer.java
===================================================================
---
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/PopupPanelBaseRenderer.java 2010-08-19
15:59:18 UTC (rev 18822)
+++
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/PopupPanelBaseRenderer.java 2010-08-19
17:08:16 UTC (rev 18823)
@@ -5,8 +5,8 @@
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
-import java.util.Map.Entry;
import java.util.Set;
+import java.util.Map.Entry;
import javax.faces.FacesException;
import javax.faces.application.ResourceDependencies;
@@ -15,8 +15,9 @@
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
-import org.ajax4jsf.javascript.JSFunctionDefinition;
+import org.ajax4jsf.javascript.ScriptUtils;
import org.ajax4jsf.renderkit.RendererBase;
+import org.ajax4jsf.renderkit.RendererUtils;
import org.richfaces.component.AbstractPopupPanel;
import org.richfaces.json.JSONException;
import org.richfaces.json.JSONMap;
@@ -112,14 +113,14 @@
if (panel.getMinHeight() != -1) {
if (panel.getMinHeight() < SIZE) {
- throw new IllegalArgumentException();
+ throw new FacesException("Attribbute minWidth should be greater then
10px");
}
}
if (panel.getMinWidth() != -1) {
if (panel.getMinWidth() < SIZE) {
- throw new IllegalArgumentException();
+ throw new FacesException("Attribbute minHeight should be greater
then 10px");
}
}
@@ -164,84 +165,49 @@
return "";
}
- private void writeOption(StringBuilder builder, String attribbute, Object value,
UIComponent component,
- boolean isString) {
-
- //TODO nick - use ScriptUtils.toScript
- if (component.getAttributes().get(attribbute) != null) {
- builder.append(attribbute + ":");
- if (isString) {
- builder.append("'");
- }
- builder.append(value);
- if (isString) {
- builder.append("'");
- }
- builder.append(",");
- }
- }
-
public String buildScript(FacesContext context, UIComponent component) throws
IOException {
AbstractPopupPanel panel = (AbstractPopupPanel) component;
StringBuilder result = new StringBuilder();
result.append("new RichFaces.ui.PopupPanel('");
result.append(panel.getClientId());
- result.append("',{");
- //TODO nick - use RendererUtils.addToScriptHash(Map<String, Object>,
String, Object)
- writeOption(result, "width", panel.getWidth(), component, false);
- writeOption(result, "height", panel.getHeight(), component, false);
- writeOption(result, "minWidth", panel.getMinWidth(), component,
false);
- writeOption(result, "minHeight", panel.getMinHeight(), component,
false);
- writeOption(result, "maxWidth", panel.getMaxWidth(), component,
false);
- writeOption(result, "maxHeight", panel.getMaxHeight(), component,
false);
- writeOption(result, "resizeable", panel.isResizeable(), component,
false);
- writeOption(result, "moveable", panel.isMoveable(), component, false);
- writeOption(result, "left", panel.getLeft(), component, true);
- writeOption(result, "top", panel.getTop(), component, true);
- writeOption(result, "zIndex", panel.getZIndex(), component, false);
- writeOption(result, "onresize", writeEventHandlerFunction(context,
panel, "onresize"), component, false);
- writeOption(result, "onmove", writeEventHandlerFunction(context, panel,
"onmove"), component, false);
- writeOption(result, "onshow", writeEventHandlerFunction(context, panel,
"onshow"), component, false);
- writeOption(result, "onhide", writeEventHandlerFunction(context, panel,
"onhide"), component, false);
- writeOption(result, "onbeforeshow", writeEventHandlerFunction(context,
panel, "onbeforeshow"), component, false);
- writeOption(result, "onbeforehide", writeEventHandlerFunction(context,
panel, "onbeforehide"), component, false);
- writeOption(result, "shadowDepth", panel.getShadowDepth(), component,
true);
- writeOption(result, "shadowOpacity", panel.getShadowOpacity(),
component, true);
- writeOption(result, "domElementAttachment",
panel.getDomElementAttachment(), component, true);
- writeOption(result, "keepVisualState", panel.isKeepVisualState(),
component, false);
- writeOption(result, "show", panel.isShow(), component, false);
- writeOption(result, "modal", panel.isModal(), component, false);
- writeOption(result, "autosized", panel.isAutosized(), component,
false);
- writeOption(result, "overlapEmbedObjects",
panel.isOverlapEmbedObjects(), component, false);
- //TODO nick - what is deleted here?
- result.delete(result.length() - 1, result.length());
- if (component.getAttributes().get("visualOptions") != null) {
- result.append(writeVisualOptions(context, panel));
- }
- result.append("});");
+ result.append("',");
+ Map<String, Object> attributes = component.getAttributes();
+ Map<String, Object> options = new HashMap<String, Object>();
+ RendererUtils utils = getUtils();
+ utils.addToScriptHash(options, "width", panel.getWidth(),
"-1");
+ utils.addToScriptHash(options, "height", panel.getHeight(),
"-1");
+ utils.addToScriptHash(options, "minWidth", panel.getMinWidth(),
"-1");
+ utils.addToScriptHash(options, "minHeight", panel.getMinHeight(),
"-1");
+ utils.addToScriptHash(options, "maxWidth", panel.getMaxWidth(),
"" +Integer.MAX_VALUE);
+ utils.addToScriptHash(options, "maxHeight", panel.getMaxHeight(),
"" +Integer.MAX_VALUE);
+ utils.addToScriptHash(options, "moveable", panel.isMoveable(),
"true");
+ utils.addToScriptHash(options, "followByScroll",
panel.isFollowByScroll(), "true");
+ utils.addToScriptHash(options, "left", panel.getLeft(),
"auto");
+ utils.addToScriptHash(options, "top", panel.getTop(),
"auto");
+ utils.addToScriptHash(options, "zindex", panel.getZIndex(),
"100");
+ utils.addToScriptHash(options, "shadowDepth", panel.getShadowDepth(),
"2");
+ utils.addToScriptHash(options, "shadowOpacity",
panel.getShadowOpacity(), "0.1");
+ utils.addToScriptHash(options, "domElementAttachment",
panel.getDomElementAttachment());
+
+ utils.addToScriptHash(options, "keepVisualState",
panel.isKeepVisualState(), "false");
+ utils.addToScriptHash(options, "show", panel.isShow(),
"false");
+ utils.addToScriptHash(options, "modal", panel.isModal(),
"true");
+ utils.addToScriptHash(options, "autosized", panel.isAutosized(),
"false");
+ utils.addToScriptHash(options, "resizeable", panel.isResizeable(),
"false");
+ utils.addToScriptHash(options, "overlapEmbedObjects",
panel.isOverlapEmbedObjects(), "false");
+ utils.addToScriptHash(options, "visualOptions",
writeVisualOptions(context, panel));
+ utils.addToScriptHash(options, "onresize",
attributes.get("onresize"));
+ utils.addToScriptHash(options, "onmove",
attributes.get("onmove"));
+ utils.addToScriptHash(options, "onshow",
attributes.get("onshow"));
+ utils.addToScriptHash(options, "onhide",
attributes.get("onhide"));
+ utils.addToScriptHash(options, "onbeforeshow",
attributes.get("onbeforeshow"));
+ utils.addToScriptHash(options, "onbeforehide",
attributes.get("onbeforehide"));
+
+ result.append(ScriptUtils.toScript(options));
+ result.append(");");
return result.toString();
}
- public String writeEventHandlerFunction(FacesContext context, UIComponent component,
String eventName)
- throws IOException {
- String event = (String) component.getAttributes().get(eventName);
-
- if (event != null) {
- event = event.trim();
-
- if (event.length() != 0) {
- JSFunctionDefinition function = new JSFunctionDefinition();
-
- function.addParameter("event");
- function.addToBody(event);
-
- return function.toScript();
- }
- }
-
- return "";
- }
-
public Map<String, Object> getHandledVisualOptions(AbstractPopupPanel panel) {
String options = panel.getVisualOptions();
Map<String, Object> result;
Modified:
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/popupPanel.js
===================================================================
---
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/popupPanel.js 2010-08-19
15:59:18 UTC (rev 18822)
+++
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/popupPanel.js 2010-08-19
17:08:16 UTC (rev 18823)
@@ -29,22 +29,40 @@
$(richfaces.getDomElement(element)).unbind( 'mousedown',
selectionEventHandler);
}
}
-
+
+ var defaultOptions = {
+ width:-1,
+ height:-1,
+ minWidth:-1,
+ minHeight:-1,
+ modal:true,
+ moveable:true,
+ resizeable: false,
+ autosized: false,
+ modal:true,
+ left: "auto",
+ top : "auto",
+ zindex:100,
+ shadowDepth : 5,
+ shadowOpacity: 0.1,
+ attachToBody:true
+ };
+
+
richfaces.ui.PopupPanel = function(id, options) {
$super.constructor.call(this,id);
this.markerId = id;
this.attachToDom(id);
- this.options = options;
+ this.options = $.extend(this.options, defaultOptions, options);
this.id = $(richfaces.getDomElement(id));
this.minWidth = this.getMinimumSize(this.options.minWidth);
this.minHeight = this.getMinimumSize(this.options.minHeight);
this.maxWidth = this.options.maxWidth;
this.maxHeight = this.options.maxHeight;
- this.options = options;
- this.baseZIndex = this.options.zindex ? this.options.zindex : 100;
+ this.baseZIndex = this.options.zindex;
this.div = $(richfaces.getDomElement(id));
this.cdiv = $(richfaces.getDomElement(id + "_container"));
@@ -185,16 +203,14 @@
setLeft: function(pos) {
if(!isNaN(pos)){
this.cdiv.css('left', pos + "px");
- var depth = this.options.shadowDepth ? this.options.shadowDepth : 2;
- this.shadowDiv.css('left', pos + depth + "px");
+ this.shadowDiv.css('left', pos + parseInt(this.options.shadowDepth) +
"px");
}
},
setTop: function(pos) {
if(!isNaN(pos)){
this.cdiv.css('top', pos + "px");
- var depth = this.options.shadowDepth ? this.options.shadowDepth : 2;
- this.shadowDiv.css('top', pos + depth +"px");
+ this.shadowDiv.css('top', pos + parseInt(this.options.shadowDepth)
+"px");
}
},
@@ -266,8 +282,6 @@
options.width = 300;
if (options.height && options.height == -1)
options.height = 200;
- } else{
- //options.width = $(this.div+"_headerSpan").width() +20;
}
if (options.width && options.width != -1) {
@@ -278,7 +292,7 @@
options.width = this.maxWidth;
}
$(richfaces.getDomElement(eContentElt)).css('width', options.width +
(/px/.test(options.width) ? '' : 'px'));
- this.shadowDiv.css('width', options.width + 4 + (/px/.test(options.width) ?
'' : 'px'));
+ this.shadowDiv.css('width', options.width + (/px/.test(options.width) ?
'' : 'px'));
this.scrollerDiv.css('width', options.width + (/px/.test(options.width) ?
'' : 'px'));
@@ -292,7 +306,7 @@
options.height = this.maxHeight;
}
$(richfaces.getDomElement(eContentElt)).css('height', options.height +
(/px/.test(options.height) ? '' : 'px'));
- this.shadowDiv.css('height', options.height + 4 +
(/px/.test(options.height) ? '' : 'px'));
+ this.shadowDiv.css('height', options.height + (/px/.test(options.height) ?
'' : 'px'));
var headerHeight = $(richfaces.getDomElement(this.div +"_header"))[0] ?
$(richfaces.getDomElement(this.div +"_header"))[0].clientHeight : 0;
this.scrollerDiv.css('height', options.height - headerHeight +
(/px/.test(options.height) ? '' : 'px'));
@@ -347,12 +361,17 @@
this.setTop(Math.round(_top));
}
-
- var opacity = options.shadowOpacity ? options.shadowOpacity : 0.1;
- this.shadowDiv.css('opacity', opacity);
- this.shadowDiv.css('filter ', 'alpha(opacity='+opacity*100
+');');
+
+ this.shadowDiv.css('opacity', this.options.shadowOpacity);
+ this.shadowDiv.css('filter ',
'alpha(opacity='+this.options.shadowOpacity*100 +');');
+
element.css('visibility', '');
element.css('display', 'block');
+ if (this.options.autosized) {
+ this.shadowDiv.css('height', this.cdiv[0].clientHeight);
+ this.shadowDiv.css('width', this.cdiv[0].clientWidth);
+
+ }
var event = {};
event.parameters = opts || {};
this.shown = true;
@@ -510,7 +529,7 @@
var vetoeChange = false;
var newSize;
- var shadowDepth = this.options.shadowDepth? this.options.shadowDepth: 4;
+ var shadowDepth = parseInt(this.options.shadowDepth);
var scrollerHeight = 22;
var scrollerWidth = 0;
var eContentElt = this.getContentElement();
@@ -541,7 +560,7 @@
vetoes.x = true;
}
- if (newSize >= this.options.maxWidth) {
+ if (newSize > this.options.maxWidth) {
if (diff.deltaWidth) {
cssHashWH.width = this.currentMaxWidth + 'px';
shadowHashWH.width = this.currentMaxWidth + shadowDepth + 'px';
@@ -594,7 +613,7 @@
vetoes.y = true;
}
- if (newSize >= this.options.maxHeight) {
+ if (newSize > this.options.maxHeight) {
if (diff.deltaHeight) {
cssHashWH.height = this.currentMaxHeight + 'px';
shadowHashWH.height = this.currentMaxHeight + shadowDepth + 'px';
@@ -671,7 +690,7 @@
},
moveTo : function (top, left){
- var shadowDepth = this.options.shadowDepth? this.options.shadowDepth: 4;
+ var shadowDepth = parseInt(this.options.shadowDepth);
this.cdiv.css('top', top);
this.cdiv.css('left', left);
this.shadowDiv.css('top', top + shadowDepth);
Modified:
trunk/ui/output/ui/src/test/java/org/richfaces/renderkit/html/PopupRendererTest.java
===================================================================
---
trunk/ui/output/ui/src/test/java/org/richfaces/renderkit/html/PopupRendererTest.java 2010-08-19
15:59:18 UTC (rev 18822)
+++
trunk/ui/output/ui/src/test/java/org/richfaces/renderkit/html/PopupRendererTest.java 2010-08-19
17:08:16 UTC (rev 18823)
@@ -108,7 +108,7 @@
HtmlElement panelHeader =
panelWithFacet.getElementById("panel_header");
assertNotNull(panelHeader);
assertEquals("rf-pp-h header",
panelHeader.getAttribute("class"));
- assertEquals("cursor: move;",
panelHeader.getAttribute("style"));
+ //assertEquals("cursor: move;",
panelHeader.getAttribute("style"));
assertEquals("Write your own custom rich components with built-in
AJAX", panelHeader.getTextContent().trim());
HtmlElement panelResizer =
panelWithFacet.getElementById("panelResizerN");
assertNotNull(panelResizer);
Modified: trunk/ui/output/ui/src/test/resources/popupPanelTest.xhtml
===================================================================
--- trunk/ui/output/ui/src/test/resources/popupPanelTest.xhtml 2010-08-19 15:59:18 UTC
(rev 18822)
+++ trunk/ui/output/ui/src/test/resources/popupPanelTest.xhtml 2010-08-19 17:08:16 UTC
(rev 18823)
@@ -16,7 +16,7 @@
<h:commandButton id="button" value="Call the popup">
<rich2:componentControl target="panel" operation="show" />
</h:commandButton>
- <rich:popupPanel resizeable="true" styleClass="panelStyle"
headerClass="header" controlsClass="control"
+ <rich:popupPanel moveable="false" resizeable="true"
styleClass="panelStyle" headerClass="header"
controlsClass="control"
id="panel"