From: Matti Tahvonen Date: Mon, 14 Dec 2009 14:04:09 +0000 (+0000) Subject: replaced(depracated) paintReference with addAttribute(String,Paintable) and added... X-Git-Tag: 6.7.0.beta1~2161 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=4e76225bd7a5c3b0b2156a438aa677cadea7eb16;p=vaadin-framework.git replaced(depracated) paintReference with addAttribute(String,Paintable) and added addVariable(VariableOwner, String, Paintable) method (updates already worked) fixes #3654, #2854 svn changeset:10286/svn branch:6.2 --- diff --git a/src/com/vaadin/terminal/PaintTarget.java b/src/com/vaadin/terminal/PaintTarget.java index 725d82dcab..7bfc3555fc 100644 --- a/src/com/vaadin/terminal/PaintTarget.java +++ b/src/com/vaadin/terminal/PaintTarget.java @@ -63,8 +63,9 @@ public interface PaintTarget extends Serializable { * is meant to enable component interactions on client side. With reference * the client side component can communicate directly to other component. * - * Note! This is still an experimental feature and API is likely to change - * in future. + * Note! This was experimental api and got replaced by + * {@link #addAttribute(String, Paintable)} and + * {@link #addVariable(VariableOwner, String, Paintable)}. * * @param paintable * the Paintable to reference @@ -72,7 +73,11 @@ public interface PaintTarget extends Serializable { * @throws PaintException * * @since 5.2 + * @deprecated use {@link #addAttribute(String, Paintable)} or + * {@link #addVariable(VariableOwner, String, Paintable)} + * instead */ + @Deprecated public void paintReference(Paintable paintable, String referenceName) throws PaintException; @@ -212,6 +217,20 @@ public interface PaintTarget extends Serializable { public void addAttribute(String name, Map value) throws PaintException; + /** + * Adds a Paintable type attribute. On client side the value will be a + * terminal specific reference to corresponding component on client side + * implementation. + * + * @param name + * the name of the attribute + * @param value + * the Paintable to be referenced on client side + * @throws PaintException + */ + public void addAttribute(String name, Paintable value) + throws PaintException; + /** * Adds a string type variable. * @@ -324,6 +343,26 @@ public interface PaintTarget extends Serializable { public void addVariable(VariableOwner owner, String name, String[] value) throws PaintException; + /** + * Adds a Paintable type variable. On client side the variable value will be + * a terminal specific reference to corresponding component on client side + * implementation. When updated from client side, terminal will map the + * client side component reference back to a corresponding server side + * reference. + * + * @param owner + * the Listener for variable changes + * @param name + * the name of the variable + * @param value + * the initial value of the variable + * + * @throws PaintException + * if the paint oparation fails + */ + public void addVariable(VariableOwner owner, String name, Paintable value) + throws PaintException; + /** * Adds a upload stream type variable. * diff --git a/src/com/vaadin/terminal/gwt/client/UIDL.java b/src/com/vaadin/terminal/gwt/client/UIDL.java index f2e85e9979..5c4c69e687 100644 --- a/src/com/vaadin/terminal/gwt/client/UIDL.java +++ b/src/com/vaadin/terminal/gwt/client/UIDL.java @@ -276,4 +276,14 @@ public final class UIDL extends JavaScriptObject { return typeof this[1][name] == "object"; }-*/; + public Paintable getPaintableAttribute(String name, + ApplicationConnection connection) { + return connection.getPaintable(getStringAttribute(name)); + } + + public Paintable getPaintableVariable(String name, + ApplicationConnection connection) { + return connection.getPaintable(getStringVariable(name)); + } + } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VView.java b/src/com/vaadin/terminal/gwt/client/ui/VView.java index 89113398c9..c5e81b82f6 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VView.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VView.java @@ -170,7 +170,7 @@ public class VView extends SimplePanel implements Container, ResizeHandler, .contains(ApplicationConnection.GENERATED_BODY_CLASSNAME); } - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { + public void updateFromUIDL(final UIDL uidl, ApplicationConnection client) { rendering = true; id = uidl.getId(); @@ -348,12 +348,11 @@ public class VView extends SimplePanel implements Container, ResizeHandler, } if (uidl.hasAttribute("focused")) { - final String focusPid = uidl.getStringAttribute("focused"); // set focused component when render phase is finished DeferredCommand.addCommand(new Command() { public void execute() { - final Paintable toBeFocused = connection - .getPaintable(focusPid); + final Paintable toBeFocused = uidl.getPaintableAttribute( + "focused", connection); /* * Two types of Widgets can be focused, either implementing diff --git a/src/com/vaadin/terminal/gwt/server/JsonPaintTarget.java b/src/com/vaadin/terminal/gwt/server/JsonPaintTarget.java index 7a653e93e9..8128e99f00 100644 --- a/src/com/vaadin/terminal/gwt/server/JsonPaintTarget.java +++ b/src/com/vaadin/terminal/gwt/server/JsonPaintTarget.java @@ -77,7 +77,7 @@ public class JsonPaintTarget implements PaintTarget { /** * Creates a new XMLPrintWriter, without automatic line flushing. - * + * * @param variableMap * @param manager * @param outWriter @@ -85,8 +85,9 @@ public class JsonPaintTarget implements PaintTarget { * @throws PaintException * if the paint operation failed. */ - public JsonPaintTarget(AbstractCommunicationManager manager, PrintWriter outWriter, - boolean cachingRequired) throws PaintException { + public JsonPaintTarget(AbstractCommunicationManager manager, + PrintWriter outWriter, boolean cachingRequired) + throws PaintException { this.manager = manager; @@ -105,18 +106,18 @@ public class JsonPaintTarget implements PaintTarget { /** * Prints the element start tag. - * + * *
      *   Todo:
      *    Checking of input values
-     *
+     * 
      * 
- * + * * @param tagName * the name of the start tag. * @throws PaintException * if the paint operation failed. - * + * */ public void startTag(String tagName, boolean isChildNode) throws PaintException { @@ -149,10 +150,10 @@ public class JsonPaintTarget implements PaintTarget { /** * Prints the element end tag. - * + * * If the parent tag is closed before every child tag is closed an * PaintException is raised. - * + * * @param tag * the name of the end tag. * @throws Paintexception @@ -205,7 +206,7 @@ public class JsonPaintTarget implements PaintTarget { /** * Substitutes the XML sensitive characters with predefined XML entities. - * + * * @param xml * the String to be substituted. * @return A new string instance where all occurrences of XML sensitive @@ -220,12 +221,12 @@ public class JsonPaintTarget implements PaintTarget { /** * Substitutes the XML sensitive characters with predefined XML entities. - * + * * @param xml * the String to be substituted. * @return A new StringBuilder instance where all occurrences of XML * sensitive characters are substituted with entities. - * + * */ static StringBuilder escapeXML(StringBuilder xml) { if (xml == null || xml.length() <= 0) { @@ -296,7 +297,7 @@ public class JsonPaintTarget implements PaintTarget { /** * Substitutes a XML sensitive character with predefined XML entity. - * + * * @param c * the Character to be replaced with an entity. * @return String of the entity or null if character is not to be replaced @@ -321,43 +322,20 @@ public class JsonPaintTarget implements PaintTarget { /** * Prints XML-escaped text. - * + * * @param str * @throws PaintException * if the paint operation failed. - * + * */ public void addText(String str) throws PaintException { tag.addData("\"" + escapeJSON(str) + "\""); } - /** - * Adds a boolean attribute to component. Atributes must be added before any - * content is written. - * - * @param name - * the Attribute name. - * @param value - * the Attribute value. - * @throws PaintException - * if the paint operation failed. - */ public void addAttribute(String name, boolean value) throws PaintException { tag.addAttribute("\"" + name + "\":" + (value ? "true" : "false")); } - /** - * Adds a resource attribute to component. Attributes must be added before - * any content is written. - * - * @param name - * the Attribute name. - * @param value - * the Attribute value. - * - * @throws PaintException - * if the paint operation failed. - */ public void addAttribute(String name, Resource value) throws PaintException { if (value instanceof ExternalResource) { @@ -395,82 +373,22 @@ public class JsonPaintTarget implements PaintTarget { } - /** - * Adds a integer attribute to component. Atributes must be added before any - * content is written. - * - * @param name - * the Attribute name. - * @param value - * the Attribute value. - * - * @throws PaintException - * if the paint operation failed. - */ public void addAttribute(String name, int value) throws PaintException { tag.addAttribute("\"" + name + "\":" + String.valueOf(value)); } - /** - * Adds a long attribute to component. Atributes must be added before any - * content is written. - * - * @param name - * the Attribute name. - * @param value - * the Attribute value. - * - * @throws PaintException - * if the paint operation failed. - */ public void addAttribute(String name, long value) throws PaintException { tag.addAttribute("\"" + name + "\":" + String.valueOf(value)); } - /** - * Adds a float attribute to component. Atributes must be added before any - * content is written. - * - * @param name - * the Attribute name. - * @param value - * the Attribute value. - * - * @throws PaintException - * if the paint operation failed. - */ public void addAttribute(String name, float value) throws PaintException { tag.addAttribute("\"" + name + "\":" + String.valueOf(value)); } - /** - * Adds a double attribute to component. Atributes must be added before any - * content is written. - * - * @param name - * the Attribute name. - * @param value - * the Attribute value. - * - * @throws PaintException - * if the paint operation failed. - */ public void addAttribute(String name, double value) throws PaintException { tag.addAttribute("\"" + name + "\":" + String.valueOf(value)); } - /** - * Adds a string attribute to component. Atributes must be added before any - * content is written. - * - * @param name - * the String attribute name. - * @param value - * the String attribute value. - * - * @throws PaintException - * if the paint operation failed. - */ public void addAttribute(String name, String value) throws PaintException { // In case of null data output nothing: if ((value == null) || (name == null)) { @@ -490,6 +408,12 @@ public class JsonPaintTarget implements PaintTarget { } + public void addAttribute(String name, Paintable value) + throws PaintException { + final String id = getPaintIdentifier(value); + addAttribute(name, id); + } + public void addAttribute(String name, Map value) throws PaintException { @@ -548,127 +472,42 @@ public class JsonPaintTarget implements PaintTarget { tag.addAttribute(buf.toString()); } - /** - * Adds a string type variable. - * - * @param owner - * the Listener for variable changes. - * @param name - * the Variable name. - * @param value - * the Variable initial value. - * - * @throws PaintException - * if the paint operation failed. - */ public void addVariable(VariableOwner owner, String name, String value) throws PaintException { tag.addVariable(new StringVariable(owner, name, escapeJSON(value))); } - /** - * Adds a int type variable. - * - * @param owner - * the Listener for variable changes. - * @param name - * the Variable name. - * @param value - * the Variable initial value. - * - * @throws PaintException - * if the paint operation failed. - */ + public void addVariable(VariableOwner owner, String name, Paintable value) + throws PaintException { + tag.addVariable(new StringVariable(owner, name, + getPaintIdentifier(value))); + } + public void addVariable(VariableOwner owner, String name, int value) throws PaintException { tag.addVariable(new IntVariable(owner, name, value)); } - /** - * Adds a long type variable. - * - * @param owner - * the Listener for variable changes. - * @param name - * the Variable name. - * @param value - * the Variable initial value. - * - * @throws PaintException - * if the paint operation failed. - */ public void addVariable(VariableOwner owner, String name, long value) throws PaintException { tag.addVariable(new LongVariable(owner, name, value)); } - /** - * Adds a float type variable. - * - * @param owner - * the Listener for variable changes. - * @param name - * the Variable name. - * @param value - * the Variable initial value. - * - * @throws PaintException - * if the paint operation failed. - */ public void addVariable(VariableOwner owner, String name, float value) throws PaintException { tag.addVariable(new FloatVariable(owner, name, value)); } - /** - * Adds a double type variable. - * - * @param owner - * the Listener for variable changes. - * @param name - * the Variable name. - * @param value - * the Variable initial value. - * - * @throws PaintException - * if the paint operation failed. - */ public void addVariable(VariableOwner owner, String name, double value) throws PaintException { tag.addVariable(new DoubleVariable(owner, name, value)); } - /** - * Adds a boolean type variable. - * - * @param owner - * the Listener for variable changes. - * @param name - * the Variable name. - * @param value - * the Variable initial value. - * - * @throws PaintException - * if the paint operation failed. - */ public void addVariable(VariableOwner owner, String name, boolean value) throws PaintException { tag.addVariable(new BooleanVariable(owner, name, value)); } - /** - * Adds a string array type variable. - * - * @param owner - * the Listener for variable changes. - * @param name - * the Variable name. - * @param value - * the Variable initial value. - * - * @throws PaintException - * if the paint operation failed. - */ public void addVariable(VariableOwner owner, String name, String[] value) throws PaintException { tag.addVariable(new ArrayVariable(owner, name, value)); @@ -676,14 +515,14 @@ public class JsonPaintTarget implements PaintTarget { /** * Adds a upload stream type variable. - * + * * TODO not converted for JSON - * + * * @param owner * the Listener for variable changes. * @param name * the Variable name. - * + * * @throws PaintException * if the paint operation failed. */ @@ -696,9 +535,9 @@ public class JsonPaintTarget implements PaintTarget { /** * Prints the single text section. - * + * * Prints full text section. The section data is escaped - * + * * @param sectionTagName * the name of the tag. * @param sectionData @@ -714,7 +553,7 @@ public class JsonPaintTarget implements PaintTarget { /** * Adds XML directly to UIDL. - * + * * @param xml * the Xml to be added. * @throws PaintException @@ -740,7 +579,7 @@ public class JsonPaintTarget implements PaintTarget { /** * Adds XML section with namespace. - * + * * @param sectionTagName * the name of the tag. * @param sectionData @@ -749,7 +588,7 @@ public class JsonPaintTarget implements PaintTarget { * the namespace to be added. * @throws PaintException * if the paint operation failed. - * + * * @see com.vaadin.terminal.PaintTarget#addXMLSection(String, String, * String) */ @@ -776,7 +615,7 @@ public class JsonPaintTarget implements PaintTarget { /** * Gets the UIDL already printed to stream. Paint target must be closed * before the getUIDL can be called. - * + * * @return the UIDL. */ public String getUIDL() { @@ -792,7 +631,7 @@ public class JsonPaintTarget implements PaintTarget { * getUIDL can be called. Subsequent attempts to write to paint * target. If the target was already closed, call to this function is * ignored. will generate an exception. - * + * * @throws PaintException * if the paint operation failed. */ @@ -813,7 +652,7 @@ public class JsonPaintTarget implements PaintTarget { /* * (non-Javadoc) - * + * * @see com.vaadin.terminal.PaintTarget#startTag(com.vaadin.terminal * .Paintable, java.lang.String) */ @@ -853,7 +692,7 @@ public class JsonPaintTarget implements PaintTarget { /* * (non-Javadoc) - * + * * @see com.vaadin.terminal.PaintTarget#addCharacterData(java.lang.String ) */ public void addCharacterData(String text) throws PaintException { @@ -865,9 +704,9 @@ public class JsonPaintTarget implements PaintTarget { /** * This is basically a container for UI components variables, that will be * added at the end of JSON object. - * + * * @author mattitahvonen - * + * */ class JsonTag implements Serializable { boolean firstField = false; @@ -938,7 +777,7 @@ public class JsonPaintTarget implements PaintTarget { } /** - * + * * @param s * json string, object or array */ @@ -1146,7 +985,7 @@ public class JsonPaintTarget implements PaintTarget { /** * Method to check if paintable is already painted into this target. - * + * * @param p * @return true if is not yet painted into this target and is connected to * app diff --git a/src/com/vaadin/ui/Window.java b/src/com/vaadin/ui/Window.java index 989ea09903..ad6ff57d6c 100644 --- a/src/com/vaadin/ui/Window.java +++ b/src/com/vaadin/ui/Window.java @@ -593,7 +593,7 @@ public class Window extends Panel implements URIHandler, ParameterHandler { if (pendingFocus.getWindow() == this || (pendingFocus.getWindow() != null && pendingFocus .getWindow().getParent() == this)) { - target.paintReference(pendingFocus, "focused"); + target.addAttribute("focused", pendingFocus); } pendingFocus = null; }