Author: dbiatenia
Date: 2007-07-13 08:48:24 -0400 (Fri, 13 Jul 2007)
New Revision: 1618
Modified:
branches/3.0.2/sandbox/tooltip/src/main/config/component/toolTip.xml
branches/3.0.2/sandbox/tooltip/src/main/java/org/richfaces/component/UIToolTip.java
branches/3.0.2/sandbox/tooltip/src/main/java/org/richfaces/renderkit/html/ToolTipRenderer.java
branches/3.0.2/sandbox/tooltip/src/main/resources/org/richfaces/renderkit/html/scripts/tooltip.js
branches/3.0.2/sandbox/tooltip/src/main/templates/org/richfaces/htmltooltip.jspx
Log:
Modified: branches/3.0.2/sandbox/tooltip/src/main/config/component/toolTip.xml
===================================================================
--- branches/3.0.2/sandbox/tooltip/src/main/config/component/toolTip.xml 2007-07-13
12:28:37 UTC (rev 1617)
+++ branches/3.0.2/sandbox/tooltip/src/main/config/component/toolTip.xml 2007-07-13
12:48:24 UTC (rev 1618)
@@ -16,10 +16,9 @@
<classname>org.richfaces.taglib.ToolTipTag</classname>
<superclass>org.ajax4jsf.framework.taglib.HtmlComponentTagBase</superclass>
</tag>
-
<property>
- <name>onactivate</name>
+ <name>oncomplete</name>
<classname>java.lang.String</classname>
<description></description>
<defaultvalue><![CDATA[""]]></defaultvalue>
@@ -31,7 +30,7 @@
<defaultvalue><![CDATA[""]]></defaultvalue>
</property>
<property>
- <name>ondeactivate</name>
+ <name>onhide</name>
<classname>java.lang.String</classname>
<description></description>
<defaultvalue><![CDATA[""]]></defaultvalue>
@@ -49,7 +48,7 @@
<name>event</name>
<classname>java.lang.String</classname>
<description>event that triggers the tooltip appearance (default =
onmouseover)</description>
- <defaultvalue><![CDATA["onmouseover"]]></defaultvalue>
+ <defaultvalue><![CDATA["mouseover"]]></defaultvalue>
</property>
<property>
<name>mode</name>
Modified:
branches/3.0.2/sandbox/tooltip/src/main/java/org/richfaces/component/UIToolTip.java
===================================================================
---
branches/3.0.2/sandbox/tooltip/src/main/java/org/richfaces/component/UIToolTip.java 2007-07-13
12:28:37 UTC (rev 1617)
+++
branches/3.0.2/sandbox/tooltip/src/main/java/org/richfaces/component/UIToolTip.java 2007-07-13
12:48:24 UTC (rev 1618)
@@ -1,9 +1,20 @@
package org.richfaces.component;
+import java.io.IOException;
+import java.util.Set;
+
import javax.faces.component.UIComponentBase;
+import javax.faces.context.FacesContext;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.FacesEvent;
-public abstract class UIToolTip extends UIComponentBase{
+import org.ajax4jsf.framework.ajax.AjaxChildrenEncoder;
+import org.ajax4jsf.framework.ajax.AjaxContext;
+import org.ajax4jsf.framework.ajax.AjaxEvent;
+import org.richfaces.renderkit.html.ToolTipRenderer;
+public abstract class UIToolTip extends UIComponentBase implements AjaxChildrenEncoder{
+
public static final String COMPONENT_TYPE = "org.richfaces.toolTip";
public static final String CONTENT_FACET_NAME = "defaultContent";
@@ -47,17 +58,17 @@
public abstract void setStyleClass(String styleClass);
- public abstract String getOnactivate();
+ public abstract String getOncomplete();
- public abstract void setOnactivate(String onactivate);
+ public abstract void setOncomplete(String oncomplete);
public abstract String getOnshow();
public abstract void setOnshow(String onshow);
- public abstract String getOndeactivate();
+ public abstract String getOnhide();
- public abstract void setOndeactivate(String ondeactivate);
+ public abstract void setOnhide(String onhide);
public abstract String getOnclick();
@@ -79,4 +90,33 @@
public abstract void setOnmouseover(String onmouseover);
+ public void broadcast(FacesEvent event) throws AbortProcessingException {
+
+ super.broadcast(event);
+
+ if (event instanceof AjaxEvent) {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ AjaxContext ajaxContext = AjaxContext.getCurrentInstance(facesContext);
+ ajaxContext.getAjaxAreasToRender().add(this.getClientId(facesContext) +
"content");
+ ajaxContext.addRegionsFromComponent(this);
+ }
+ }
+
+ public void encodeAjaxChild(FacesContext context, String path, Set ids,
+ Set renderedAreas) throws IOException {
+
+ if(ids.contains(this.getClientId(context) + "content")){
+ AjaxContext ajaxContext = AjaxContext.getCurrentInstance(context);
+ ToolTipRenderer r = (ToolTipRenderer)getRenderer(context);
+ r.encodeTooltipText(context, this);
+ ajaxContext.getAjaxRenderedAreas().add(this.getClientId(context) +
"content");
+ } else {
+ // todo
+// AjaxContext ajaxContext = AjaxContext.getCurrentInstance(context);
+// ajaxContext.e
+
+ }
+
+ }
+
}
Modified:
branches/3.0.2/sandbox/tooltip/src/main/java/org/richfaces/renderkit/html/ToolTipRenderer.java
===================================================================
---
branches/3.0.2/sandbox/tooltip/src/main/java/org/richfaces/renderkit/html/ToolTipRenderer.java 2007-07-13
12:28:37 UTC (rev 1617)
+++
branches/3.0.2/sandbox/tooltip/src/main/java/org/richfaces/renderkit/html/ToolTipRenderer.java 2007-07-13
12:48:24 UTC (rev 1618)
@@ -1,13 +1,18 @@
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 org.ajax4jsf.framework.ajax.AjaxEvent;
import org.ajax4jsf.framework.renderer.AjaxComponentRendererBase;
+import org.ajax4jsf.framework.renderer.AjaxRendererUtils;
import org.ajax4jsf.framework.skin.Skin;
+import org.ajax4jsf.framework.util.javascript.JSFunction;
+import org.ajax4jsf.framework.util.javascript.JSFunctionDefinition;
import org.richfaces.component.UIToolTip;
public class ToolTipRenderer extends AjaxComponentRendererBase{
@@ -17,69 +22,6 @@
return org.richfaces.component.UIToolTip.class;
}
- public void encodeChildren(FacesContext context, UIComponent component)
- throws IOException {
- // TODO Auto-generated method stub
- super.encodeChildren(context, component);
- }
-
- /**
- *
- * @param context
- * @param component 'tl'-top left, 'tr'-top right, 'bl'-bottom
left, 'br'-bottom right
- * @param position
- * @throws IOException
- */
- /*
- public void insertImage(FacesContext context, UIComponent component, Object position)
throws IOException{
- //if(position == null) throw new IllegalArgumentException("Parameter passed is
invalid, use \"0 - 3\"");
- String posStr = (String)position;
- drawImageElement(context, component, posStr);
- }
- */
-
- /**
- *
- * @param writer
- * @param component
- * @param position 0-tl, 1-tr, 2-bl, 3-br
- * @throws IOException
- */
-/*
- private void drawImageElement(FacesContext context, UIComponent component, String
position) throws IOException{
- String imageSrc = getImageSrc(context, component, position);
- ResponseWriter writer = context.getResponseWriter();
- int h = 15; //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("class", "corner", null);
- writer.writeAttribute("style", "display:block; ", null);
- writer.writeAttribute("width", String.valueOf(h), null);
- writer.writeAttribute("height", String.valueOf(h), null);
- writer.endElement("img");
- }
-*/
-/*
- protected String getImageSrc(FacesContext context, UIComponent component, String
position){
- String color = getBgColor(context, component);
- String imageSource = null;
- if(position == null || position.equals("tl")) {
- imageSource = getResource(TopLeftToolTipCornerImage.class.getName()).getUri(context,
color);
- } else if(position.equals("tr")){
- imageSource = getResource(TopRightToolTipCornerImage.class.getName()).getUri(context,
color);
- } else if (position.equals("bl")){
- imageSource =
getResource(BottomLeftToolTipCornerImage.class.getName()).getUri(context, color);
- } else if (position.equals("br")){
- imageSource =
getResource(BottomRightToolTipCornerImage.class.getName()).getUri(context, color);
- }
-
- return imageSource;
- }
-*/
-
public String getBgColor(FacesContext context, UIComponent component){
Skin skin = getSkin(context);
String color = (String) skin.getParameter(context,"headerBackgroundColor");
@@ -99,30 +41,36 @@
context.getResponseWriter().write(value.toString());
}
}
-/*
- protected String getTopRightDivStyle(FacesContext context, UIComponent component){
- String trImgSrc = getImageSrc(context, component, "tr");
- return "background: url(" + trImgSrc + ") no-repeat top
right;";
- }
- protected String getBottomRightDivStyle(FacesContext context, UIComponent component){
- String brImgSrc = getImageSrc(context, component, "br");
- return "background: url(" + brImgSrc + ") no-repeat top
right;";
- }
-
- protected String getMainDivStyle(FacesContext context, UIComponent component){
- String style = "width: 250px;background-color:" + getBgColor(context,
component) + ";color: " + getColor(context, component) + ";";
- return style;
- }
- protected String getTRImageSrc(FacesContext context, UIComponent component){
- return getImageSrc(context, component, "tr");
+ public String insertAjaxFunction(FacesContext context, UIComponent component){
+ JSFunction function = AjaxRendererUtils.buildAjaxFunction(component, context);
+ component.getClientId(context);
+
+ Map eventOptions = AjaxRendererUtils.buildEventOptions(context, component);
+
+ String refreshTooltipPointerExp = ";" + getJsVarName(context,
component) + ".toolTip = $('" + component.getClientId(context) +
"');";
+
+ if(eventOptions.containsKey("oncomplete")){
+ JSFunctionDefinition onComplete =
(JSFunctionDefinition)eventOptions.get("oncomplete");
+ onComplete.addToBody(refreshTooltipPointerExp);
+ eventOptions.put("oncomplete", onComplete);
+ } else {
+ JSFunctionDefinition onComplete = new JSFunctionDefinition();
+ onComplete.addParameter("request");
+ onComplete.addParameter("event");
+ onComplete.addParameter("data");
+ onComplete.addToBody(refreshTooltipPointerExp);
+ eventOptions.put("oncomplete", onComplete);
+
+ }
+
+ function.addParameter(eventOptions);
+
+ return function.toScript();
}
- protected String getBRImageSrc(FacesContext context, UIComponent component){
- return getImageSrc(context, component, "br");
- }
-*/
+
public void insertScript(FacesContext context, UIComponent component) throws
IOException{
UIToolTip toolTip = (UIToolTip)component;
@@ -135,27 +83,62 @@
String quot = "\"";
StringBuffer script = new StringBuffer();
//
- script.append("var tooltip1 = ").
+ String event = toolTip.getEvent();
+ if(event.startsWith("on")){
+ event = event.substring(2);
+ }
+ String events = "{event:\"" + event + "\",onshow:\""
+ toolTip.getOnshow() +
+ "\",oncomplete:\"" + toolTip.getOncomplete() +
"\",onhide:\"" + toolTip.getOnhide() +
+ "\"}";
+ //script.append("var tooltip1 = ").
- append("new ToolTip(").append(quot).append("tooltip" +
toolTip.getClientId(context).toString()).append(quot).append(comma).
+ script.append(getJsVarName(context, toolTip) + " = ").
+ append("new ToolTip(" + events).append(comma).append(quot).append(
toolTip.getClientId(context)).append(quot).append(comma).
append(quot).append(parentClientId).append(quot).append(comma).
append(quot).append(toolTip.getMode()).append(quot).append(comma).
append(toolTip.isDisabled()).append(comma).
append(quot).append(toolTip.getDirection()).append(quot).append(comma).
append(toolTip.isFollowMouse()).append(comma).
append(toolTip.getHorizontalOffset()).append(comma).
- append(toolTip.getVerticalOffset()).append(");\n");
+ append(toolTip.getVerticalOffset()).append(comma).
+ append("\"").append(insertAjaxFunction(context,
component)).append("\");\n");
ret.append(script.toString());
//
//ret.append("function toolTipAttach(){tooltip1.attachParentEvents() }\n");
ret.append("\n</script>");
-
ResponseWriter writer = context.getResponseWriter();
writer.write(ret.toString());
}
+
+ private String getJsVarName(FacesContext context, UIComponent component){
+ return "window.tooltip" +
component.getClientId(context).replaceAll("[^A-Za-z0-9_]", "_");
+ }
+
+ protected void doDecode(FacesContext context, UIComponent component) {
+
+ UIToolTip tooltip = (UIToolTip)component;
+
+ String clientId = tooltip.getClientId(context);
+
+ if(context.getExternalContext().getRequestParameterMap().containsKey(clientId)){
+ if("ajax".equals(tooltip.getMode())){
+ new AjaxEvent(component).queue();
+ }
+ }
+ }
+
+ public void encodeTooltipText(FacesContext context, UIToolTip component) throws
IOException {
+ ResponseWriter responseWriter = context.getResponseWriter();
+ responseWriter.startElement("span", component);
+ responseWriter.writeAttribute("id", component.getClientId(context) +
"content", null);
+ responseWriter.write(component.getValue() != null ? component.getValue() :
"");
+ super.renderChildren(context, component);
+ responseWriter.endElement("span");
+ }
+
}
Modified:
branches/3.0.2/sandbox/tooltip/src/main/resources/org/richfaces/renderkit/html/scripts/tooltip.js
===================================================================
---
branches/3.0.2/sandbox/tooltip/src/main/resources/org/richfaces/renderkit/html/scripts/tooltip.js 2007-07-13
12:28:37 UTC (rev 1617)
+++
branches/3.0.2/sandbox/tooltip/src/main/resources/org/richfaces/renderkit/html/scripts/tooltip.js 2007-07-13
12:48:24 UTC (rev 1618)
@@ -3,14 +3,14 @@
var IE = document.all?true:false;
// If NS -- that is, !IE -- then set up for mouse capture
-if (!IE) document.captureEvents(Event.MOUSEMOVE)
+//if (!IE) document.captureEvents(Event.MOUSEMOVE)
// Temporary variables to hold mouse x-y pos.s
-var cursorX = 0;
-var cursorY = 0;
+//var cursorX = 0;
+//var cursorY = 0;
// Main function to retrieve mouse x-y pos.s
-
+/*
function getMouseXY(e) {
if (IE) { // grab the x-y pos.s if browser is IE
cursorX = event.clientX + document.body.scrollLeft;
@@ -29,18 +29,16 @@
// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;
-/*
-var isIE = false;
-alert("RichFaces.navigatorType().indexOf('MSIE', 0) != -1 -- " +
RichFaces.navigatorType().indexOf('MSIE', 0) != -1);
-if(RichFaces.navigatorType().indexOf('MSIE', 0) != -1){
- isIE = true;
-}
*/
-
ToolTip = Class.create();
ToolTip.prototype = {
- initialize:function(id, parentId, mode, disabled, direction, followMouse,
horizontalOffset, verticalOffset){
+ initialize:function(events, id, parentId, mode, disabled, direction, followMouse,
horizontalOffset, verticalOffset, ajaxFunction){
+ this.event = events.event;
+ this.onshow = events.onshow;
+ this.oncomplete = events.oncomplete;
+ this.onhide = events.onhide;
+
this.id = id;
this.parentId = parentId;
this.mode = mode;
@@ -49,6 +47,7 @@
this.followMouse = followMouse;
this.horizontalOffset = horizontalOffset;
this.verticalOffset = verticalOffset;
+ this.ajaxExecuteString = ajaxFunction;
this.toolTip = $(id);
this.toolTip.style.visibility='hidden';
@@ -84,35 +83,68 @@
this.attachParentEvents();
this.parentAttached = true;
}
+ Event.stopObserving(document.getElementsByTagName("body")[0],
"mousemove", this.attachOnLoadEvents.bindAsEventListener(this), false);
}
},
attachParentEvents: function(){
if(this.followMouse){
- Event.observe(this.parent, "mousemove",
this.doShow.bindAsEventListener(this), false);
+ Event.observe(this.parent, this.event, this.doShow.bindAsEventListener(this),
false);
} else {
- Event.observe(this.parent, "mouseover",
this.doShow.bindAsEventListener(this), false);
+ Event.observe(this.parent, this.event, this.doShow.bindAsEventListener(this),
false);
}
-
+ /*
+ if(this.mode == 'ajax'){
+ Event.observe(this.parent, this.event, this.evecuteAjax.bindAsEventListener(this),
false);
+ }
+ */
Event.observe(this.parent, "mouseout", this.doHide.bindAsEventListener(this),
false);
},
- doShow: function(){
+ doShow: function(e){
+ if (IE) { // grab the x-y pos.s if browser is IE
+ cursorX = e.clientX + document.body.scrollLeft;
+ cursorY = e.clientY + document.body.scrollTop;
+ } else { // grab the x-y pos.s if browser is NS
+ cursorX = e.pageX;
+ cursorY = e.pageY;
+ }
+ // catch possible negative values in NS4
+ if (cursorX < 0){cursorX = 0;}
+ if (cursorY < 0){cursorY = 0;}
- this.setToolTipPosition();
+ this.setToolTipPosition(e, cursorX, cursorY);
if(this.iframe){
-
this.iframe.style.top = parseInt(this.toolTip.style.top) - this.toolTipBorderHeight;
this.iframe.style.left = parseInt(this.toolTip.style.left) - this.toolTipBorderWidth;
this.iframe.style.display = "block";
}
this.toolTip.style.display = "block";
+
+ //
+ //Event.stopObserving(this.parent, this.event, this.doShow.bindAsEventListener(this),
false);
+ if(this.mode == 'ajax'){
+ var event = e;
+ eval(this.ajaxExecuteString);
+
+
+ this.toolTip = $(this.id);
+ this.setToolTipPosition();
+ if(this.iframe){
+ this.iframe.style.top = parseInt(this.toolTip.style.top) - this.toolTipBorderHeight;
+ this.iframe.style.left = parseInt(this.toolTip.style.left) -
this.toolTipBorderWidth;
+ this.iframe.style.display = "block";
+ }
+ this.toolTip.style.display = "block";
+ }
},
- doHide: function(){
+ doHide: function(e){
this.toolTip.style.display = "none";
if(this.iframe){
this.iframe.style.display = "none";
}
+
+ //Event.observe(this.parent, this.event, this.doShow.bindAsEventListener(this),
false);
},
doEnable: function(){
@@ -122,7 +154,7 @@
this.disabled = true;
},
- setToolTipPosition: function(){
+ setToolTipPosition: function(e, cursorX, cursorY){
var windowDim = this.windowSize();
if(this.direction == "top-left"){
@@ -192,8 +224,11 @@
}
return [wWidth,wHeight];
}
+ /*
+ evecuteAjax: function (e){
+ var event = e;
+ eval(this.ajaxExecuteString);
+ }
+ */
-
- //
-
}
\ No newline at end of file
Modified:
branches/3.0.2/sandbox/tooltip/src/main/templates/org/richfaces/htmltooltip.jspx
===================================================================
---
branches/3.0.2/sandbox/tooltip/src/main/templates/org/richfaces/htmltooltip.jspx 2007-07-13
12:28:37 UTC (rev 1617)
+++
branches/3.0.2/sandbox/tooltip/src/main/templates/org/richfaces/htmltooltip.jspx 2007-07-13
12:48:24 UTC (rev 1618)
@@ -17,31 +17,25 @@
<h:scripts>
new org.ajax4jsf.framework.resource.PrototypeScript(),
new org.ajax4jsf.framework.ajax.AjaxScript(),
- /org/richfaces/renderkit/html/scripts/browser_info.js,
/org/richfaces/renderkit/html/scripts/utils.js,
/org/richfaces/renderkit/html/scripts/tooltip.js
</h:scripts>
<f:clientid var="clientId"/>
- <div id="tooltip#{clientId}" style="position: absolute; display :
none;z-index:99" class="dr-rich-tool-tip rich-tool-tip">
- <jsp:scriptlet>
- <![CDATA[if(component.getFacet("defaultContent")!=null &&
component.getFacet("defaultContent").isRendered()) {]]>
- </jsp:scriptlet>
- <!-- span class="dr-rich-tool-tip rich-tool-tip"-->
- <u:insertFacet name="defaultContent" />
- <!-- /span-->
- <jsp:scriptlet>
- <![CDATA[} else {]]>
- </jsp:scriptlet>
- <!-- span class="dr-rich-tool-tip rich-tool-tip"-->
- #{component.attributes['value']}
- <!-- /span-->
- <jsp:scriptlet>
- <![CDATA[}]]>
- </jsp:scriptlet>
-
- <f:call name="insertScript"/>
+ <div id="#{clientId}" style="position: absolute; display :
none;z-index:99" class="dr-rich-tool-tip rich-tool-tip">
+ <span id="#{clientId}script" style="display:none">
+ <f:call name="insertScript"/>
+ </span>
+
+ <span id="#{clientId}defaultContent"
style="display:none">
+ <u:insertFacet name="defaultContent" />
+ </span>
+
+ <vcp:body>
+ <f:call name="encodeTooltipText"/>
+ </vcp:body>
+
</div>
<!-- f:call name="utils.encodeEndFormIfNessesary"/-->
</f:root>