From fba751ff0fdbef7e9ade587e4f271d2267216ad1 Mon Sep 17 00:00:00 2001 From: Manolo Carrasco Date: Mon, 14 Jun 2010 07:31:00 +0000 Subject: [PATCH] updated Lazy interfaz for GQuery --- .../google/gwt/query/client/LazyGQuery.java | 251 +++++++++--------- .../gwt/query/client/JreQueryCoreTest.java | 226 +++++++++++++++- 2 files changed, 348 insertions(+), 129 deletions(-) diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java index 9b0ca01a..a336d164 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java @@ -29,7 +29,6 @@ import com.google.gwt.dom.client.Node; import com.google.gwt.dom.client.NodeList; import com.google.gwt.dom.client.OptionElement; import com.google.gwt.dom.client.SelectElement; -import com.google.gwt.dom.client.Style; import com.google.gwt.dom.client.TextAreaElement; import com.google.gwt.dom.client.Style.Display; import com.google.gwt.query.client.css.CssProperty; @@ -45,17 +44,17 @@ import com.google.gwt.query.client.LazyBase; public interface LazyGQuery extends LazyBase{ - /** - * Add elements to the set of matched elements if they are not included yet. - */ - LazyGQuery add(String selector); - /** * Adds the specified classes to each matched element. Add elements to the set * of matched elements if they are not included yet. */ LazyGQuery add(GQuery previousObject); + /** + * Add elements to the set of matched elements if they are not included yet. + */ + LazyGQuery add(String selector); + /** * Adds the specified classes to each matched element. */ @@ -66,21 +65,21 @@ public interface LazyGQuery extends LazyBase{ * already be inserted into the document (you can't insert an element after * another if it's not in the page). */ - LazyGQuery after(Node n); + LazyGQuery after(GQuery query); /** * Insert content after each of the matched elements. The elements must * already be inserted into the document (you can't insert an element after * another if it's not in the page). */ - LazyGQuery after(String html); + LazyGQuery after(Node n); /** * Insert content after each of the matched elements. The elements must * already be inserted into the document (you can't insert an element after * another if it's not in the page). */ - LazyGQuery after(GQuery query); + LazyGQuery after(String html); /** * Add the previous selection to the current selection. Useful for traversing @@ -94,7 +93,7 @@ public interface LazyGQuery extends LazyBase{ * similar to doing an appendChild to all the specified elements, adding them * into the document. */ - LazyGQuery append(String html); + LazyGQuery append(GQuery query); /** * Append content to the inside of every matched element. This operation is @@ -108,7 +107,7 @@ public interface LazyGQuery extends LazyBase{ * similar to doing an appendChild to all the specified elements, adding them * into the document. */ - LazyGQuery append(GQuery query); + LazyGQuery append(String html); /** * Append all of the matched elements to another, specified, set of elements. @@ -123,6 +122,13 @@ public interface LazyGQuery extends LazyBase{ */ T as(Class plugin); + /** + * Set a key/value object as properties to all matched elements. + * + * Image'")) + */ + LazyGQuery attr(Properties properties); + /** * Access a property on the first matched element. This method makes it easy * to retrieve a property value from the first matched element. If the element @@ -132,35 +138,28 @@ public interface LazyGQuery extends LazyBase{ String attr(String name); /** - * Set a single property to a value, on all matched elements. - */ - LazyGQuery attr(String key, String value); - - /** - * Set a key/value object as properties to all matched elements. - * - * Image'")) + * Set a single property to a computed value, on all matched elements. */ - LazyGQuery attr(Properties properties); + LazyGQuery attr(String key, Function closure); /** - * Set a single property to a computed value, on all matched elements. + * Set a single property to a value, on all matched elements. */ - LazyGQuery attr(String key, Function closure); + LazyGQuery attr(String key, String value); /** * Insert content before each of the matched elements. The elements must * already be inserted into the document (you can't insert an element before * another if it's not in the page). */ - LazyGQuery before(Node n); + LazyGQuery before(GQuery query); /** * Insert content before each of the matched elements. The elements must * already be inserted into the document (you can't insert an element before * another if it's not in the page). */ - LazyGQuery before(GQuery query); + LazyGQuery before(Node n); /** * Insert content before each of the matched elements. The elements must @@ -194,13 +193,6 @@ public interface LazyGQuery extends LazyBase{ */ LazyGQuery change(Function...f); - /** - * Get a set of elements containing all of the unique children of each of the - * matched set of elements. This set is filtered with the expressions that - * will cause only elements matching any of the selectors to be collected. - */ - LazyGQuery children(String... filters); - /** * Get a set of elements containing all of the unique immediate children of * each of the matched set of elements. Also note: while parents() will look @@ -208,12 +200,31 @@ public interface LazyGQuery extends LazyBase{ */ LazyGQuery children(); + /** + * Get a set of elements containing all of the unique children of each of the + * matched set of elements. This set is filtered with the expressions that + * will cause only elements matching any of the selectors to be collected. + */ + LazyGQuery children(String... filters); + /** * Bind a set of functions to the click event of each matched element. * Or trigger the event if no functions are provided. */ LazyGQuery click(Function...f); + /** + * Returns the inner height of the first matched element, including padding + * but not the vertical scrollbar height, border, or margin. + */ + int clientHeight(); + + /** + * Returns the inner width of the first matched element, including padding + * but not the vertical scrollbar width, border, or margin. + */ + int clientWidth(); + /** * Clone matched DOM Elements and select the clones. This is useful for moving * copies of the elements to another location in the DOM. @@ -232,39 +243,53 @@ public interface LazyGQuery extends LazyBase{ LazyGQuery contents(); /** - * Set CSS property on every matched element using type-safe enumerations. + * Set a key/value object as style properties to all matched elements. This + * serves as the best way to set a large number of style properties on all + * matched elements. + * + * Example: $(".item").css(Properties.create("color: 'red', background: + * 'blue'")) */ - > LazyGQuery css(T cssProperty, S value); + LazyGQuery css(Properties properties); /** - * Set CSS property on every matched element using type-safe enumerations. + * Return a style property on the first matched element. */ - LazyGQuery css(TakesLength cssProperty, Length value); + String css(String name); /** - * Set CSS property on every matched element using type-safe enumerations. + * Return a style property on the first matched element. + * + * The parameter force has a special meaning here: + * - When force is false, returns the value of the css property defined + * in the style attribute of the element. + * - Otherwise it returns the real computed value. + * + * For instance if you define 'display=none' not in the element style + * but in the css stylesheet, it returns an empty string unless you + * pass the parameter force=true. */ - LazyGQuery css(TakesPercentage cssProperty, Percentage value); + String css(String name, boolean force); /** - * Return a style property on the first matched element. + * Set a single style property to a value, on all matched elements. */ - String css(String name); + LazyGQuery css(String prop, String val); /** - * Set a key/value object as style properties to all matched elements. This - * serves as the best way to set a large number of style properties on all - * matched elements. - * - * Example: $(".item").css(Properties.create("color: 'red', background: - * 'blue'")) + * Set CSS property on every matched element using type-safe enumerations. */ - LazyGQuery css(Properties properties); + > LazyGQuery css(T cssProperty, S value); /** - * Set a single style property to a value, on all matched elements. + * Set CSS property on every matched element using type-safe enumerations. */ - LazyGQuery css(String prop, String val); + LazyGQuery css(TakesLength cssProperty, Length value); + + /** + * Set CSS property on every matched element using type-safe enumerations. + */ + LazyGQuery css(TakesPercentage cssProperty, Percentage value); /** * Returns value at named data store for the element, as set by data(name, @@ -326,11 +351,6 @@ public interface LazyGQuery extends LazyBase{ */ LazyGQuery error(Function... f); - /** - * Fade in all matched elements by adjusting their opacity. - */ - LazyGQuery fadeIn(int millisecs, Function... f); - /** * Fade in all matched elements by adjusting their opacity. The effect will * take 1000 milliseconds to complete @@ -338,9 +358,9 @@ public interface LazyGQuery extends LazyBase{ LazyGQuery fadeIn(Function... f); /** - * Fade out all matched elements by adjusting their opacity. + * Fade in all matched elements by adjusting their opacity. */ - LazyGQuery fadeOut(int millisecs, Function... f); + LazyGQuery fadeIn(int millisecs, Function... f); /** * Fade out all matched elements by adjusting their opacity. The effect will @@ -348,6 +368,11 @@ public interface LazyGQuery extends LazyBase{ */ LazyGQuery fadeOut(Function... f); + /** + * Fade out all matched elements by adjusting their opacity. + */ + LazyGQuery fadeOut(int millisecs, Function... f); + /** * Removes all elements from the set of matched elements that do not match the * specified function. The function is called with a context equal to the @@ -416,33 +441,21 @@ public interface LazyGQuery extends LazyBase{ */ boolean hasClass(String... classes); - /** - * Set the height of every element in the matched set. - */ - LazyGQuery height(int height); - - /** - * Set the height style property of every matched element. It's useful for - * using 'percent' or 'em' units Example: $(".a").width("100%") - */ - LazyGQuery height(String height); - /** * Get the current computed, pixel, height of the first matched element. */ int height(); /** - * Returns the inner height of the first matched element, including padding - * but not the vertical scrollbar height, border, or margin. + * Set the height of every element in the matched set. */ - int clientHeight(); + LazyGQuery height(int height); /** - * Returns the inner width of the first matched element, including padding - * but not the vertical scrollbar width, border, or margin. + * Set the height style property of every matched element. It's useful for + * using 'percent' or 'em' units Example: $(".a").width("100%") */ - int clientWidth(); + LazyGQuery height(String height); /** * Make invisible all matched elements. @@ -478,19 +491,19 @@ public interface LazyGQuery extends LazyBase{ * Insert all of the matched elements after another, specified, set of * elements. */ - LazyGQuery insertAfter(String selector); + LazyGQuery insertAfter(Element elem); /** * Insert all of the matched elements after another, specified, set of * elements. */ - LazyGQuery insertAfter(Element elem); + LazyGQuery insertAfter(GQuery query); /** * Insert all of the matched elements after another, specified, set of * elements. */ - LazyGQuery insertAfter(GQuery query); + LazyGQuery insertAfter(String selector); /** * Insert all of the matched elements before another, specified, set of @@ -687,16 +700,16 @@ public interface LazyGQuery extends LazyBase{ /** * Get a set of elements containing the unique ancestors of the matched set of - * elements (except for the root element). The matched elements are filtered, - * returning those that match any of the filters. + * elements (except for the root element). */ - LazyGQuery parents(String... filters); + LazyGQuery parents(); /** * Get a set of elements containing the unique ancestors of the matched set of - * elements (except for the root element). + * elements (except for the root element). The matched elements are filtered, + * returning those that match any of the filters. */ - LazyGQuery parents(); + LazyGQuery parents(String... filters); /** * Gets the top and left position of an element relative to its offset parent. @@ -711,21 +724,21 @@ public interface LazyGQuery extends LazyBase{ * the best way to insert elements inside, at the beginning, of all matched * elements. */ - LazyGQuery prepend(String html); + LazyGQuery prepend(GQuery query); /** * Prepend content to the inside of every matched element. This operation is * the best way to insert elements inside, at the beginning, of all matched * elements. */ - LazyGQuery prepend(GQuery query); + LazyGQuery prepend(Node n); /** * Prepend content to the inside of every matched element. This operation is * the best way to insert elements inside, at the beginning, of all matched * elements. */ - LazyGQuery prepend(Node n); + LazyGQuery prepend(String html); /** * Prepend all of the matched elements to another, specified, set of elements. @@ -779,42 +792,52 @@ public interface LazyGQuery extends LazyBase{ * elements. This function is the complement to replaceWith() which does the * same task with the parameters reversed. */ - LazyGQuery replaceAll(GQuery query); + LazyGQuery replaceAll(Element elem); /** * Replaces the elements matched by the specified selector with the matched * elements. This function is the complement to replaceWith() which does the * same task with the parameters reversed. */ - LazyGQuery replaceAll(String html); + LazyGQuery replaceAll(GQuery query); /** * Replaces the elements matched by the specified selector with the matched * elements. This function is the complement to replaceWith() which does the * same task with the parameters reversed. */ - LazyGQuery replaceAll(Element elem); + LazyGQuery replaceAll(String html); /** * Replaces all matched elements with the specified HTML or DOM elements. This * returns the GQuery element that was just replaced, which has been removed * from the DOM. */ - LazyGQuery replaceWith(GQuery query); + LazyGQuery replaceWith(Element elem); /** * Replaces all matched elements with the specified HTML or DOM elements. This * returns the GQuery element that was just replaced, which has been removed * from the DOM. */ - LazyGQuery replaceWith(String html); + LazyGQuery replaceWith(GQuery query); /** * Replaces all matched elements with the specified HTML or DOM elements. This * returns the GQuery element that was just replaced, which has been removed * from the DOM. */ - LazyGQuery replaceWith(Element elem); + LazyGQuery replaceWith(String html); + + /** + * Save a set of Css properties of every matched element. + */ + void restoreCssAttrs(String... cssProps); + + /** + * Restore a set of previously saved Css properties in every matched element. + */ + void saveCssAttrs(String... cssProps); /** * Bind a set of functions to the scroll event of each matched element. @@ -822,6 +845,12 @@ public interface LazyGQuery extends LazyBase{ */ LazyGQuery scroll(Function...f); + /** + * Gets the scroll left offset of the first matched element. This method works + * for both visible and hidden elements. + */ + int scrollLeft(); + /** * When a value is passed in, the scroll left offset is set to that value on * all matched elements. This method works for both visible and hidden @@ -830,10 +859,10 @@ public interface LazyGQuery extends LazyBase{ LazyGQuery scrollLeft(int left); /** - * Gets the scroll left offset of the first matched element. This method works + * Gets the scroll top offset of the first matched element. This method works * for both visible and hidden elements. */ - int scrollLeft(); + int scrollTop(); /** * When a value is passed in, the scroll top offset is set to that value on @@ -842,12 +871,6 @@ public interface LazyGQuery extends LazyBase{ */ LazyGQuery scrollTop(int top); - /** - * Gets the scroll top offset of the first matched element. This method works - * for both visible and hidden elements. - */ - int scrollTop(); - LazyGQuery select(); /** @@ -1002,14 +1025,14 @@ public interface LazyGQuery extends LazyBase{ boolean visible(); /** - * Set the width of every matched element. + * Get the current computed, pixel, width of the first matched element. */ - LazyGQuery width(int width); + int width(); /** - * Get the current computed, pixel, width of the first matched element. + * Set the width of every matched element. */ - int width(); + LazyGQuery width(int width); /** * Wrap each matched element with the specified HTML content. This wrapping @@ -1020,7 +1043,7 @@ public interface LazyGQuery extends LazyBase{ * within its structure -- it is that element that will enwrap everything * else. */ - LazyGQuery wrap(GQuery query); + LazyGQuery wrap(Element elem); /** * Wrap each matched element with the specified HTML content. This wrapping @@ -1031,7 +1054,7 @@ public interface LazyGQuery extends LazyBase{ * within its structure -- it is that element that will enwrap everything * else. */ - LazyGQuery wrap(Element elem); + LazyGQuery wrap(GQuery query); /** * Wrap each matched element with the specified HTML content. This wrapping @@ -1056,7 +1079,7 @@ public interface LazyGQuery extends LazyBase{ * element within its structure -- it is that element that will enwrap * everything else. */ - LazyGQuery wrapAll(String html); + LazyGQuery wrapAll(Element elem); /** * Wrap all the elements in the matched set into a single wrapper element. @@ -1070,7 +1093,7 @@ public interface LazyGQuery extends LazyBase{ * element within its structure -- it is that element that will enwrap * everything else. */ - LazyGQuery wrapAll(Element elem); + LazyGQuery wrapAll(GQuery query); /** * Wrap all the elements in the matched set into a single wrapper element. @@ -1084,7 +1107,7 @@ public interface LazyGQuery extends LazyBase{ * element within its structure -- it is that element that will enwrap * everything else. */ - LazyGQuery wrapAll(GQuery query); + LazyGQuery wrapAll(String html); /** * Wrap the inner child contents of each matched element (including text @@ -1095,7 +1118,7 @@ public interface LazyGQuery extends LazyBase{ * HTML) and finds the deepest ancestor element within its structure -- it is * that element that will enwrap everything else. */ - LazyGQuery wrapInner(GQuery query); + LazyGQuery wrapInner(Element elem); /** * Wrap the inner child contents of each matched element (including text @@ -1106,7 +1129,7 @@ public interface LazyGQuery extends LazyBase{ * HTML) and finds the deepest ancestor element within its structure -- it is * that element that will enwrap everything else. */ - LazyGQuery wrapInner(String html); + LazyGQuery wrapInner(GQuery query); /** * Wrap the inner child contents of each matched element (including text @@ -1117,16 +1140,6 @@ public interface LazyGQuery extends LazyBase{ * HTML) and finds the deepest ancestor element within its structure -- it is * that element that will enwrap everything else. */ - LazyGQuery wrapInner(Element elem); - - /** - * Save a set of Css properties of every matched element. - */ - void restoreCssAttrs(String[] cssProps); - - /** - * Restore a set of previously saved Css properties in every matched element. - */ - void saveCssAttrs(String[] cssProps); + LazyGQuery wrapInner(String html); } diff --git a/gwtquery-core/src/test/java/com/google/gwt/query/client/JreQueryCoreTest.java b/gwtquery-core/src/test/java/com/google/gwt/query/client/JreQueryCoreTest.java index 1d30aa01..a8f93a91 100644 --- a/gwtquery-core/src/test/java/com/google/gwt/query/client/JreQueryCoreTest.java +++ b/gwtquery-core/src/test/java/com/google/gwt/query/client/JreQueryCoreTest.java @@ -15,6 +15,18 @@ */ package com.google.gwt.query.client; +import java.util.Hashtable; + +import javax.naming.Binding; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.Name; +import javax.naming.NameClassPair; +import javax.naming.NameParser; +import javax.naming.NamingEnumeration; +import javax.naming.NamingException; +import javax.naming.spi.InitialContextFactory; + import com.google.gwt.junit.client.GWTTestCase; /** @@ -25,20 +37,214 @@ public class JreQueryCoreTest extends GWTTestCase { public String getModuleName() { return null; } - + public void testAssertHtmlEquals() { - GQueryCoreTest.assertHtmlEquals("hello","hello"); - GQueryCoreTest.assertHtmlEquals("

whatever

","

Whatever

"); + GQueryCoreTest.assertHtmlEquals("hello", + "hello"); + GQueryCoreTest.assertHtmlEquals("

whatever

", + "

Whatever

"); } public void testWrapPropertiesString() { - assertEquals("({border:'1px solid black'})", Properties.wrapPropertiesString("border:'1px solid black'")); - assertEquals("({border:'1px solid black'})", Properties.wrapPropertiesString("(border:'1px solid black')")); - assertEquals("({border:'1px solid black'})", Properties.wrapPropertiesString("{border:'1px solid black'}")); - assertEquals("({border:'1px solid black'})", Properties.wrapPropertiesString("{border:'1px solid black'}")); - assertEquals("({border:'1px solid black'})", Properties.wrapPropertiesString("(border:'1px solid black')")); - assertEquals("({border:'1px solid black'})", Properties.wrapPropertiesString("{(border:'1px solid black')}")); - assertEquals("({border:'1px solid black'})", Properties.wrapPropertiesString("({border:'1px solid black'})")); + assertEquals("({border:'1px solid black'})", Properties + .wrapPropertiesString("border:'1px solid black'")); + assertEquals("({border:'1px solid black'})", Properties + .wrapPropertiesString("(border:'1px solid black')")); + assertEquals("({border:'1px solid black'})", Properties + .wrapPropertiesString("{border:'1px solid black'}")); + assertEquals("({border:'1px solid black'})", Properties + .wrapPropertiesString("{border:'1px solid black'}")); + assertEquals("({border:'1px solid black'})", Properties + .wrapPropertiesString("(border:'1px solid black')")); + assertEquals("({border:'1px solid black'})", Properties + .wrapPropertiesString("{(border:'1px solid black')}")); + assertEquals("({border:'1px solid black'})", Properties + .wrapPropertiesString("({border:'1px solid black'})")); + } + public void test() throws NamingException { + System.out.println( MockInitialContextFactory.class.getName()); + System.setProperty("java.naming.factory.initial", MockInitialContextFactory.class.getName()); + Context mockCtx = new MockContext(); +// UserTransaction mockTrans = createMock(UserTransaction.class); +// expect(mockCtx.lookup("UserTransaction")).andReturn(mockTrans); +// replay(mockCtx); + MockInitialContextFactory.setMockContext(mockCtx); + + Context ctx = new InitialContext(); + ctx.lookup("whatever"); + + } + public static class MockInitialContextFactory implements + InitialContextFactory { + private static Context mockCtx = null; + + public static void setMockContext(Context ctx) { + mockCtx = ctx; + } + + public Context getInitialContext(java.util.Hashtable environment) + throws NamingException { + if (mockCtx == null) { + throw new IllegalStateException("mock context was not set."); + } + return mockCtx; + } } + public static class MockContext implements Context { + + public Object addToEnvironment(String propName, Object propVal) + throws NamingException { + // TODO Auto-generated method stub + return null; + } + + public void bind(Name name, Object obj) throws NamingException { + // TODO Auto-generated method stub + + } + + public void bind(String name, Object obj) throws NamingException { + // TODO Auto-generated method stub + + } + + public void close() throws NamingException { + // TODO Auto-generated method stub + + } + + public Name composeName(Name name, Name prefix) throws NamingException { + // TODO Auto-generated method stub + return null; + } + + public String composeName(String name, String prefix) + throws NamingException { + // TODO Auto-generated method stub + return null; + } + + public Context createSubcontext(Name name) throws NamingException { + // TODO Auto-generated method stub + return null; + } + + public Context createSubcontext(String name) throws NamingException { + // TODO Auto-generated method stub + return null; + } + + public void destroySubcontext(Name name) throws NamingException { + // TODO Auto-generated method stub + + } + + public void destroySubcontext(String name) throws NamingException { + // TODO Auto-generated method stub + + } + + public Hashtable getEnvironment() throws NamingException { + // TODO Auto-generated method stub + return null; + } + + public String getNameInNamespace() throws NamingException { + // TODO Auto-generated method stub + return null; + } + + public NameParser getNameParser(Name name) throws NamingException { + // TODO Auto-generated method stub + return null; + } + + public NameParser getNameParser(String name) throws NamingException { + // TODO Auto-generated method stub + return null; + } + + public NamingEnumeration list(Name name) + throws NamingException { + // TODO Auto-generated method stub + return null; + } + + public NamingEnumeration list(String name) + throws NamingException { + // TODO Auto-generated method stub + return null; + } + + public NamingEnumeration listBindings(Name name) + throws NamingException { + // TODO Auto-generated method stub + return null; + } + + public NamingEnumeration listBindings(String name) + throws NamingException { + // TODO Auto-generated method stub + return null; + } + + public Object lookup(Name name) throws NamingException { + // TODO Auto-generated method stub + return null; + } + + public Object lookup(String name) throws NamingException { + System.out.println("lookup " + name); + return null; + } + + public Object lookupLink(Name name) throws NamingException { + // TODO Auto-generated method stub + return null; + } + + public Object lookupLink(String name) throws NamingException { + // TODO Auto-generated method stub + return null; + } + + public void rebind(Name name, Object obj) throws NamingException { + // TODO Auto-generated method stub + + } + + public void rebind(String name, Object obj) throws NamingException { + // TODO Auto-generated method stub + + } + + public Object removeFromEnvironment(String propName) throws NamingException { + // TODO Auto-generated method stub + return null; + } + + public void rename(Name oldName, Name newName) throws NamingException { + // TODO Auto-generated method stub + + } + + public void rename(String oldName, String newName) throws NamingException { + // TODO Auto-generated method stub + + } + + public void unbind(Name name) throws NamingException { + // TODO Auto-generated method stub + + } + + public void unbind(String name) throws NamingException { + // TODO Auto-generated method stub + + } + + } + + } -- 2.39.5