You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2010/03/11 09:35:52 UTC
svn commit: r921721 - in /myfaces/tobago/trunk:
core/src/main/java/org/apache/myfaces/tobago/component/
core/src/main/java/org/apache/myfaces/tobago/taglib/component/
extension/facelets/src/main/java/org/apache/myfaces/tobago/facelets/
theme/scarboroug...
Author: lofwyr
Date: Thu Mar 11 08:35:51 2010
New Revision: 921721
URL: http://svn.apache.org/viewvc?rev=921721&view=rev
Log:
TOBAGO-860: Make Popup work with new LayoutManager
Added:
myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/Position.java
- copied, changed from r917992, myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/DeprecatedDimension.java
myfaces/tobago/trunk/extension/facelets/src/main/java/org/apache/myfaces/tobago/facelets/PositionRule.java
- copied, changed from r917992, myfaces/tobago/trunk/extension/facelets/src/main/java/org/apache/myfaces/tobago/facelets/DeprecatedDimensionRule.java
Modified:
myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/AbstractUIPopup.java
myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/PopupTagDeclaration.java
myfaces/tobago/trunk/extension/facelets/src/main/java/org/apache/myfaces/tobago/facelets/TobagoComponentHandler.java
myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/PopupRenderer.java
myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js
Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/AbstractUIPopup.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/AbstractUIPopup.java?rev=921721&r1=921720&r2=921721&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/AbstractUIPopup.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/AbstractUIPopup.java Thu Mar 11 08:35:51 2010
@@ -39,7 +39,7 @@ import java.util.List;
public abstract class AbstractUIPopup extends UIPanelBase
implements OnComponentPopulated, NamingContainer, AjaxComponent, InvokeOnComponent,
- DeprecatedDimension, LayoutContainer {
+ DeprecatedDimension, Position, LayoutContainer {
private boolean activated;
Copied: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/Position.java (from r917992, myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/DeprecatedDimension.java)
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/Position.java?p2=myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/Position.java&p1=myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/DeprecatedDimension.java&r1=917992&r2=921721&rev=921721&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/DeprecatedDimension.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/Position.java Thu Mar 11 08:35:51 2010
@@ -19,14 +19,18 @@ package org.apache.myfaces.tobago.compon
import org.apache.myfaces.tobago.layout.Measure;
-public interface DeprecatedDimension {
+/**
+ * This interface indicates that the component has a position like e. g. UIPopup.
+ * XXX Warning: It is to discussed, if this is a good solution.
+ */
+public interface Position {
- Measure getHeight();
+ Measure getLeft();
- void setHeight(Measure height);
+ void setLeft(Measure left);
- Measure getWidth();
+ Measure getTop();
- void setWidth(Measure width);
+ void setTop(Measure top);
-}
+}
\ No newline at end of file
Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/PopupTagDeclaration.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/PopupTagDeclaration.java?rev=921721&r1=921720&r2=921721&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/PopupTagDeclaration.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/PopupTagDeclaration.java Thu Mar 11 08:35:51 2010
@@ -43,4 +43,23 @@ public interface PopupTagDeclaration
@TagAttribute
@UIComponentTagAttribute(type = "boolean", defaultValue = "true")
void setModal(String modal);
+
+ /**
+ * This value will usually be set by the layout manager.
+ *
+ * @param left The left position of this component.
+ */
+ @TagAttribute
+ @UIComponentTagAttribute(type = "org.apache.myfaces.tobago.layout.Measure")
+ void setLeft(String left);
+
+ /**
+ * This value will usually be set by the layout manager.
+ *
+ * @param top The top position of this component.
+ */
+ @TagAttribute
+ @UIComponentTagAttribute(type = "org.apache.myfaces.tobago.layout.Measure")
+ void setTop(String top);
+
}
Copied: myfaces/tobago/trunk/extension/facelets/src/main/java/org/apache/myfaces/tobago/facelets/PositionRule.java (from r917992, myfaces/tobago/trunk/extension/facelets/src/main/java/org/apache/myfaces/tobago/facelets/DeprecatedDimensionRule.java)
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/extension/facelets/src/main/java/org/apache/myfaces/tobago/facelets/PositionRule.java?p2=myfaces/tobago/trunk/extension/facelets/src/main/java/org/apache/myfaces/tobago/facelets/PositionRule.java&p1=myfaces/tobago/trunk/extension/facelets/src/main/java/org/apache/myfaces/tobago/facelets/DeprecatedDimensionRule.java&r1=917992&r2=921721&rev=921721&view=diff
==============================================================================
--- myfaces/tobago/trunk/extension/facelets/src/main/java/org/apache/myfaces/tobago/facelets/DeprecatedDimensionRule.java (original)
+++ myfaces/tobago/trunk/extension/facelets/src/main/java/org/apache/myfaces/tobago/facelets/PositionRule.java Thu Mar 11 08:35:51 2010
@@ -24,56 +24,56 @@ import com.sun.facelets.tag.Metadata;
import com.sun.facelets.tag.MetadataTarget;
import com.sun.facelets.tag.TagAttribute;
import org.apache.myfaces.tobago.component.Attributes;
-import org.apache.myfaces.tobago.component.DeprecatedDimension;
+import org.apache.myfaces.tobago.component.Position;
import org.apache.myfaces.tobago.layout.Measure;
import javax.el.ValueExpression;
import javax.faces.component.UIComponent;
-public class DeprecatedDimensionRule extends MetaRule {
+public class PositionRule extends MetaRule {
- public static final DeprecatedDimensionRule INSTANCE = new DeprecatedDimensionRule();
+ public static final PositionRule INSTANCE = new PositionRule();
public Metadata applyRule(String name, TagAttribute attribute, MetadataTarget metadataTarget) {
- if (Attributes.WIDTH.equals(name)) {
- return new WidthMapper(attribute);
+ if (Attributes.LEFT.equals(name)) {
+ return new LeftMapper(attribute);
}
- if (Attributes.HEIGHT.equals(name)) {
- return new HeightMapper(attribute);
+ if (Attributes.TOP.equals(name)) {
+ return new TopMapper(attribute);
}
return null;
}
- static final class WidthMapper extends Metadata {
+ static final class LeftMapper extends Metadata {
private final TagAttribute attribute;
- WidthMapper(TagAttribute attribute) {
+ LeftMapper(TagAttribute attribute) {
this.attribute = attribute;
}
public void applyMetadata(FaceletContext ctx, Object instance) {
if (attribute.isLiteral()) {
- ((DeprecatedDimension) instance).setWidth(Measure.parse(attribute.getValue()));
+ ((Position) instance).setLeft(Measure.parse(attribute.getValue()));
} else {
ValueExpression expression = attribute.getValueExpression(ctx, Object.class);
- ELAdaptor.setExpression((UIComponent) instance, Attributes.WIDTH, expression);
+ ELAdaptor.setExpression((UIComponent) instance, Attributes.LEFT, expression);
}
}
}
- static final class HeightMapper extends Metadata {
+ static final class TopMapper extends Metadata {
private final TagAttribute attribute;
- HeightMapper(TagAttribute attribute) {
+ TopMapper(TagAttribute attribute) {
this.attribute = attribute;
}
public void applyMetadata(FaceletContext ctx, Object instance) {
if (attribute.isLiteral()) {
- ((DeprecatedDimension) instance).setHeight(Measure.parse(attribute.getValue()));
+ ((Position) instance).setTop(Measure.parse(attribute.getValue()));
} else {
ValueExpression expression = attribute.getValueExpression(ctx, Object.class);
- ELAdaptor.setExpression((UIComponent) instance, Attributes.HEIGHT, expression);
+ ELAdaptor.setExpression((UIComponent) instance, Attributes.TOP, expression);
}
}
}
Modified: myfaces/tobago/trunk/extension/facelets/src/main/java/org/apache/myfaces/tobago/facelets/TobagoComponentHandler.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/extension/facelets/src/main/java/org/apache/myfaces/tobago/facelets/TobagoComponentHandler.java?rev=921721&r1=921720&r2=921721&view=diff
==============================================================================
--- myfaces/tobago/trunk/extension/facelets/src/main/java/org/apache/myfaces/tobago/facelets/TobagoComponentHandler.java (original)
+++ myfaces/tobago/trunk/extension/facelets/src/main/java/org/apache/myfaces/tobago/facelets/TobagoComponentHandler.java Thu Mar 11 08:35:51 2010
@@ -22,6 +22,7 @@ import com.sun.facelets.tag.MetaRuleset;
import com.sun.facelets.tag.jsf.ComponentConfig;
import com.sun.facelets.tag.jsf.ComponentHandler;
import org.apache.myfaces.tobago.component.AbstractUIGridLayout;
+import org.apache.myfaces.tobago.component.AbstractUIPopup;
import org.apache.myfaces.tobago.component.DeprecatedDimension;
import org.apache.myfaces.tobago.component.InputSuggest;
import org.apache.myfaces.tobago.component.OnComponentCreated;
@@ -47,6 +48,12 @@ public class TobagoComponentHandler exte
if (DeprecatedDimension.class.isAssignableFrom(aClass)) {
metaRuleset.addRule(DeprecatedDimensionRule.INSTANCE);
}
+ if (DeprecatedDimension.class.isAssignableFrom(aClass)) {
+ metaRuleset.addRule(DeprecatedDimensionRule.INSTANCE);
+ }
+ if (AbstractUIPopup.class.isAssignableFrom(aClass)) {
+ metaRuleset.addRule(PositionRule.INSTANCE);
+ }
if (AbstractUIGridLayout.class.isAssignableFrom(aClass)) {
metaRuleset.addRule(GridLayoutRule.INSTANCE);
}
Modified: myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/PopupRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/PopupRenderer.java?rev=921721&r1=921720&r2=921721&view=diff
==============================================================================
--- myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/PopupRenderer.java (original)
+++ myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/PopupRenderer.java Thu Mar 11 08:35:51 2010
@@ -17,6 +17,8 @@ package org.apache.myfaces.tobago.render
* limitations under the License.
*/
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.myfaces.tobago.ajax.api.AjaxRenderer;
import org.apache.myfaces.tobago.ajax.api.AjaxUtils;
import org.apache.myfaces.tobago.component.Attributes;
@@ -24,6 +26,8 @@ import org.apache.myfaces.tobago.compone
import org.apache.myfaces.tobago.component.UIPopup;
import org.apache.myfaces.tobago.context.ResourceManagerUtil;
import org.apache.myfaces.tobago.context.TobagoFacesContext;
+import org.apache.myfaces.tobago.internal.layout.LayoutContext;
+import org.apache.myfaces.tobago.layout.Measure;
import org.apache.myfaces.tobago.renderkit.LayoutComponentRendererBase;
import org.apache.myfaces.tobago.renderkit.html.HtmlAttributes;
import org.apache.myfaces.tobago.renderkit.html.HtmlConstants;
@@ -37,9 +41,12 @@ import org.apache.myfaces.tobago.webapp.
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import java.io.IOException;
+import java.text.DecimalFormat;
public class PopupRenderer extends LayoutComponentRendererBase implements AjaxRenderer {
+ private static final Log LOG = LogFactory.getLog(PopupRenderer.class);
+
@Override
public boolean getRendersChildren() {
return true;
@@ -54,28 +61,38 @@ public class PopupRenderer extends Layou
}
@Override
- public void encodeBegin(FacesContext facesContext, UIComponent uiComponent) throws IOException {
+ public void encodeBegin(FacesContext facesContext, UIComponent component) throws IOException {
TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
- UIPopup component = (UIPopup) uiComponent;
- final String clientId = component.getClientId(facesContext);
+ UIPopup popup = (UIPopup) component;
+
+// LAYOUT Begin
+
+ long begin = System.nanoTime();
+ LayoutContext layoutContext = new LayoutContext(popup);
+ layoutContext.layout();
+ LOG.info("Laying out takes: " + new DecimalFormat("#,##0").format(System.nanoTime() - begin) + " ns");
+
+// LAYOUT End
+
+ final String clientId = popup.getClientId(facesContext);
final String contentDivId = clientId + ComponentUtils.SUB_SEPARATOR + "content";
- //final String left = component.getLeft();
- //final String top = component.getTop();
- Integer zIndex = (Integer) component.getAttributes().get(Attributes.Z_INDEX);
+ //final String left = popup.getLeft();
+ //final String top = popup.getTop();
+ Integer zIndex = (Integer) popup.getAttributes().get(Attributes.Z_INDEX);
if (zIndex == null) {
zIndex = 0;
}
final StringBuilder contentStyle = new StringBuilder(32);
- if (component.getCurrentWidth() != null) {
+ if (popup.getCurrentWidth() != null) {
contentStyle.append("width: ");
- contentStyle.append(component.getCurrentWidth().getPixel());
+ contentStyle.append(popup.getCurrentWidth().getPixel());
contentStyle.append("; ");
}
- if (component.getCurrentHeight() != null) {
+ if (popup.getCurrentHeight() != null) {
contentStyle.append("height: ");
- contentStyle.append(component.getCurrentHeight().getPixel());
+ contentStyle.append(popup.getCurrentHeight().getPixel());
contentStyle.append("; ");
}
contentStyle.append("z-index: ");
@@ -87,8 +104,8 @@ public class PopupRenderer extends Layou
//contentStyle.append("top: ");
//contentStyle.append(top);
//contentStyle.append("; ");
- if (component.isModal()) {
- writer.startElement(HtmlConstants.DIV, component);
+ if (popup.isModal()) {
+ writer.startElement(HtmlConstants.DIV, popup);
writer.writeIdAttribute(clientId);
writer.writeStyleAttribute("z-index: " + (zIndex + 1) + ";");
writer.writeClassAttribute();
@@ -102,12 +119,12 @@ public class PopupRenderer extends Layou
writer.endElement(HtmlConstants.DIV);
}
if (VariableResolverUtil.resolveClientProperties(facesContext).getUserAgent().isMsie()) {
- writer.startElement(HtmlConstants.IFRAME, component);
+ writer.startElement(HtmlConstants.IFRAME, popup);
writer.writeIdAttribute(clientId + ComponentUtils.SUB_SEPARATOR + HtmlConstants.IFRAME);
writer.writeClassAttribute("tobago-popup-iframe tobago-popup-none");
writer.writeStyleAttribute("z-index: " + (zIndex + 2) + ";");
UIPage page = (UIPage) ComponentUtils.findPage(facesContext);
- if (component.isModal()) {
+ if (popup.isModal()) {
final StringBuilder frameSize = new StringBuilder(32);
// full client area
frameSize.append("width: ");
@@ -125,12 +142,12 @@ public class PopupRenderer extends Layou
writer.writeAttribute(HtmlAttributes.FRAMEBORDER, "0", false);
writer.endElement(HtmlConstants.IFRAME);
}
- writer.startElement(HtmlConstants.DIV, component);
+ writer.startElement(HtmlConstants.DIV, popup);
writer.writeIdAttribute(contentDivId);
StyleClasses styleClasses = new StyleClasses();
styleClasses.addClass("popup", "content");
styleClasses.addClass("popup", "none");
- if (component.isModal()) {
+ if (popup.isModal()) {
styleClasses.addClass("popup", "modal");
}
writer.writeClassAttribute(styleClasses);
@@ -139,23 +156,24 @@ public class PopupRenderer extends Layou
}
@Override
- public void encodeEnd(FacesContext facesContext,
- UIComponent uiComponent) throws IOException {
+ public void encodeEnd(FacesContext facesContext, UIComponent component) throws IOException {
TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
- UIPopup component = (UIPopup) uiComponent;
- final String clientId = component.getClientId(facesContext);
+ UIPopup popup = (UIPopup) component;
+ final String clientId = popup.getClientId(facesContext);
writer.endElement(HtmlConstants.DIV);
writer.startJavascript();
writer.write("Tobago.setupPopup('");
writer.write(clientId);
- writer.write("', '");
- writer.write(component.getLeft().getPixel());
- writer.write("', '");
- writer.write(component.getTop().getPixel());
writer.write("', ");
- writer.write(String.valueOf(component.isModal()));
+ final Measure left = popup.getLeft();
+ writer.write(left != null ? Integer.toString(left.getPixel()) : "null");
+ writer.write(", ");
+ final Measure top = popup.getTop();
+ writer.write(top != null ? Integer.toString(top.getPixel()) : "null");
+ writer.write(", ");
+ writer.write(String.valueOf(popup.isModal()));
writer.write(");");
writer.endJavascript();
}
Modified: myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js?rev=921721&r1=921720&r2=921721&view=diff
==============================================================================
--- myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js (original)
+++ myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js Thu Mar 11 08:35:51 2010
@@ -936,9 +936,13 @@ var Tobago = {
/**
* Setup popup size
+ * @param id String
+ * @param left int or null
+ * @param top int or null
+ * @param modal boolean or null
*/
setupPopup: function(id, left, top, modal) {
-// alert("tobagoSetupPopup('" + id + "', '" + left + "', '"+ top + "')");
+// alert("tobagoSetupPopup('" + id + "', '" + left + "', '"+ top + "')");
var hidden = Tobago.element(id + Tobago.SUB_COMPONENT_SEP + "hidden");
if (hidden && hidden.type == "hidden") {
hidden.parentNode.removeChild(hidden);
@@ -952,52 +956,36 @@ var Tobago = {
this.popupResizeStub = function() {Tobago.doResizePopupBackground(id);};
Tobago.addEventListener(window, "resize", this.popupResizeStub);
}
+
var contentId = id + Tobago.SUB_COMPONENT_SEP + "content";
- var div = this.element(contentId);
+ var div = jQuery(Tobago.escapeClientId(contentId));
if (div) {
- var l = left.replace(/\D/g, "");
- if (l.length > 0) {
- div.style.left = l;
- // alert("1 set left to " + l);
- } else {
- var popupWidth = div.style.width;
- if (popupWidth) {
- popupWidth = popupWidth.replace(/\D/g, "");
- } else {
- popupWidth = div.clientWidth - Tobago.Config.get("Popup", "borderWidth");
- }
- l = this.getBrowserInnerWidth() - popupWidth;
- div.style.left = l/2;
- // alert("2 set left to " + l/2);
- }
-
- var t = top.replace(/\D/g, "");
- if (t.length > 0) {
- div.style.top = t;
- // alert("1 set top to " + t);
- } else {
- var popupHeight = div.style.height;
- if (popupHeight) {
- popupHeight = popupHeight.replace(/\D/g, "");
- } else {
- popupHeight = div.clientHeight - Tobago.Config.get("Popup", "borderWidth");
- }
-
- t = this.getBrowserInnerHeight() - popupHeight;
- div.style.top = t/2;
- // alert("2 set top to " + t/2);
- }
+ // XXX removing the class would be better after setting the position, but
+ // XXX div.children().outerWidth() doesn't work in that case (which is used in the next lines).
+ div.removeClass("tobago-popup-none");
+
+ // calculate left, if lack
+ if (left == null) {
+ left = (jQuery(window).width() - div.children().outerWidth()) / 2;
+ }
+
+ // calculate top, if lack
+ if (top == null) {
+ top = (jQuery(window).height() - div.children().outerHeight()) / 2;
+ }
+
+// alert("Setting offset of popup: left to '" + left + "' and top to '" + top + "'");
+ div.offset({ left: left, top: top });
+
+ // iframe is used in IE, because the <select> tags would shining through.
var iframeId = id + Tobago.SUB_COMPONENT_SEP + "iframe";
- var iframe = this.element(iframeId);
- if (iframe && !modal) {
- iframe.style.left = div.style.left;
- iframe.style.top = div.style.top;
- }
-
- Tobago.removeCssClass(div, "tobago-popup-none");
+ var iframe = jQuery(Tobago.escapeClientId(iframeId));
if (iframe) {
- Tobago.removeCssClass(iframe, "tobago-popup-none");
+ if (!modal) {
+ iframe.offset({ left: left, top: top });
+ }
+ iframe.removeClass("tobago-popup-none");
}
}
@@ -1225,6 +1213,10 @@ var Tobago = {
// -------- Util functions ----------------------------------------------------
+ escapeClientId : function(id) {
+ return "#" + id.replace(/:/g,"\\:");
+ },
+
clickOnElement: function(id) {
var element = this.element(id);
// LOG.debug("id = " + id + " element = " + typeof element);