Browse Source

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
tags/6.7.0.beta1
Matti Tahvonen 14 years ago
parent
commit
4e76225bd7

+ 41
- 2
src/com/vaadin/terminal/PaintTarget.java View File

* is meant to enable component interactions on client side. With reference * is meant to enable component interactions on client side. With reference
* the client side component can communicate directly to other component. * 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 * @param paintable
* the Paintable to reference * the Paintable to reference
* @throws PaintException * @throws PaintException
* *
* @since 5.2 * @since 5.2
* @deprecated use {@link #addAttribute(String, Paintable)} or
* {@link #addVariable(VariableOwner, String, Paintable)}
* instead
*/ */
@Deprecated
public void paintReference(Paintable paintable, String referenceName) public void paintReference(Paintable paintable, String referenceName)
throws PaintException; throws PaintException;


public void addAttribute(String name, Map<?, ?> value) public void addAttribute(String name, Map<?, ?> value)
throws PaintException; 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. * Adds a string type variable.
* *
public void addVariable(VariableOwner owner, String name, String[] value) public void addVariable(VariableOwner owner, String name, String[] value)
throws PaintException; 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. * Adds a upload stream type variable.
* *

+ 10
- 0
src/com/vaadin/terminal/gwt/client/UIDL.java View File

return typeof this[1][name] == "object"; 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));
}

} }

+ 3
- 4
src/com/vaadin/terminal/gwt/client/ui/VView.java View File

.contains(ApplicationConnection.GENERATED_BODY_CLASSNAME); .contains(ApplicationConnection.GENERATED_BODY_CLASSNAME);
} }


public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
public void updateFromUIDL(final UIDL uidl, ApplicationConnection client) {
rendering = true; rendering = true;


id = uidl.getId(); id = uidl.getId();
} }


if (uidl.hasAttribute("focused")) { if (uidl.hasAttribute("focused")) {
final String focusPid = uidl.getStringAttribute("focused");
// set focused component when render phase is finished // set focused component when render phase is finished
DeferredCommand.addCommand(new Command() { DeferredCommand.addCommand(new Command() {
public void execute() { 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 * Two types of Widgets can be focused, either implementing

+ 44
- 205
src/com/vaadin/terminal/gwt/server/JsonPaintTarget.java View File



/** /**
* Creates a new XMLPrintWriter, without automatic line flushing. * Creates a new XMLPrintWriter, without automatic line flushing.
*
*
* @param variableMap * @param variableMap
* @param manager * @param manager
* @param outWriter * @param outWriter
* @throws PaintException * @throws PaintException
* if the paint operation failed. * 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; this.manager = manager;




/** /**
* Prints the element start tag. * Prints the element start tag.
*
*
* <pre> * <pre>
* Todo: * Todo:
* Checking of input values * Checking of input values
*
*
* </pre> * </pre>
*
*
* @param tagName * @param tagName
* the name of the start tag. * the name of the start tag.
* @throws PaintException * @throws PaintException
* if the paint operation failed. * if the paint operation failed.
*
*
*/ */
public void startTag(String tagName, boolean isChildNode) public void startTag(String tagName, boolean isChildNode)
throws PaintException { throws PaintException {


/** /**
* Prints the element end tag. * Prints the element end tag.
*
*
* If the parent tag is closed before every child tag is closed an * If the parent tag is closed before every child tag is closed an
* PaintException is raised. * PaintException is raised.
*
*
* @param tag * @param tag
* the name of the end tag. * the name of the end tag.
* @throws Paintexception * @throws Paintexception


/** /**
* Substitutes the XML sensitive characters with predefined XML entities. * Substitutes the XML sensitive characters with predefined XML entities.
*
*
* @param xml * @param xml
* the String to be substituted. * the String to be substituted.
* @return A new string instance where all occurrences of XML sensitive * @return A new string instance where all occurrences of XML sensitive


/** /**
* Substitutes the XML sensitive characters with predefined XML entities. * Substitutes the XML sensitive characters with predefined XML entities.
*
*
* @param xml * @param xml
* the String to be substituted. * the String to be substituted.
* @return A new StringBuilder instance where all occurrences of XML * @return A new StringBuilder instance where all occurrences of XML
* sensitive characters are substituted with entities. * sensitive characters are substituted with entities.
*
*
*/ */
static StringBuilder escapeXML(StringBuilder xml) { static StringBuilder escapeXML(StringBuilder xml) {
if (xml == null || xml.length() <= 0) { if (xml == null || xml.length() <= 0) {


/** /**
* Substitutes a XML sensitive character with predefined XML entity. * Substitutes a XML sensitive character with predefined XML entity.
*
*
* @param c * @param c
* the Character to be replaced with an entity. * the Character to be replaced with an entity.
* @return String of the entity or null if character is not to be replaced * @return String of the entity or null if character is not to be replaced


/** /**
* Prints XML-escaped text. * Prints XML-escaped text.
*
*
* @param str * @param str
* @throws PaintException * @throws PaintException
* if the paint operation failed. * if the paint operation failed.
*
*
*/ */
public void addText(String str) throws PaintException { public void addText(String str) throws PaintException {
tag.addData("\"" + escapeJSON(str) + "\""); 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 { public void addAttribute(String name, boolean value) throws PaintException {
tag.addAttribute("\"" + name + "\":" + (value ? "true" : "false")); 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 { public void addAttribute(String name, Resource value) throws PaintException {


if (value instanceof ExternalResource) { if (value instanceof ExternalResource) {


} }


/**
* 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 { public void addAttribute(String name, int value) throws PaintException {
tag.addAttribute("\"" + name + "\":" + String.valueOf(value)); 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 { public void addAttribute(String name, long value) throws PaintException {
tag.addAttribute("\"" + name + "\":" + String.valueOf(value)); 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 { public void addAttribute(String name, float value) throws PaintException {
tag.addAttribute("\"" + name + "\":" + String.valueOf(value)); 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 { public void addAttribute(String name, double value) throws PaintException {
tag.addAttribute("\"" + name + "\":" + String.valueOf(value)); 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 { public void addAttribute(String name, String value) throws PaintException {
// In case of null data output nothing: // In case of null data output nothing:
if ((value == null) || (name == null)) { if ((value == null) || (name == null)) {


} }


public void addAttribute(String name, Paintable value)
throws PaintException {
final String id = getPaintIdentifier(value);
addAttribute(name, id);
}

public void addAttribute(String name, Map<?, ?> value) public void addAttribute(String name, Map<?, ?> value)
throws PaintException { throws PaintException {


tag.addAttribute(buf.toString()); 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) public void addVariable(VariableOwner owner, String name, String value)
throws PaintException { throws PaintException {
tag.addVariable(new StringVariable(owner, name, escapeJSON(value))); 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) public void addVariable(VariableOwner owner, String name, int value)
throws PaintException { throws PaintException {
tag.addVariable(new IntVariable(owner, name, value)); 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) public void addVariable(VariableOwner owner, String name, long value)
throws PaintException { throws PaintException {
tag.addVariable(new LongVariable(owner, name, value)); 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) public void addVariable(VariableOwner owner, String name, float value)
throws PaintException { throws PaintException {
tag.addVariable(new FloatVariable(owner, name, value)); 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) public void addVariable(VariableOwner owner, String name, double value)
throws PaintException { throws PaintException {
tag.addVariable(new DoubleVariable(owner, name, value)); 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) public void addVariable(VariableOwner owner, String name, boolean value)
throws PaintException { throws PaintException {
tag.addVariable(new BooleanVariable(owner, name, value)); 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) public void addVariable(VariableOwner owner, String name, String[] value)
throws PaintException { throws PaintException {
tag.addVariable(new ArrayVariable(owner, name, value)); tag.addVariable(new ArrayVariable(owner, name, value));


/** /**
* Adds a upload stream type variable. * Adds a upload stream type variable.
*
*
* TODO not converted for JSON * TODO not converted for JSON
*
*
* @param owner * @param owner
* the Listener for variable changes. * the Listener for variable changes.
* @param name * @param name
* the Variable name. * the Variable name.
*
*
* @throws PaintException * @throws PaintException
* if the paint operation failed. * if the paint operation failed.
*/ */


/** /**
* Prints the single text section. * Prints the single text section.
*
*
* Prints full text section. The section data is escaped * Prints full text section. The section data is escaped
*
*
* @param sectionTagName * @param sectionTagName
* the name of the tag. * the name of the tag.
* @param sectionData * @param sectionData


/** /**
* Adds XML directly to UIDL. * Adds XML directly to UIDL.
*
*
* @param xml * @param xml
* the Xml to be added. * the Xml to be added.
* @throws PaintException * @throws PaintException


/** /**
* Adds XML section with namespace. * Adds XML section with namespace.
*
*
* @param sectionTagName * @param sectionTagName
* the name of the tag. * the name of the tag.
* @param sectionData * @param sectionData
* the namespace to be added. * the namespace to be added.
* @throws PaintException * @throws PaintException
* if the paint operation failed. * if the paint operation failed.
*
*
* @see com.vaadin.terminal.PaintTarget#addXMLSection(String, String, * @see com.vaadin.terminal.PaintTarget#addXMLSection(String, String,
* String) * String)
*/ */
/** /**
* Gets the UIDL already printed to stream. Paint target must be closed * Gets the UIDL already printed to stream. Paint target must be closed
* before the <code>getUIDL</code> can be called. * before the <code>getUIDL</code> can be called.
*
*
* @return the UIDL. * @return the UIDL.
*/ */
public String getUIDL() { public String getUIDL() {
* <code>getUIDL</code> can be called. Subsequent attempts to write to paint * <code>getUIDL</code> can be called. Subsequent attempts to write to paint
* target. If the target was already closed, call to this function is * target. If the target was already closed, call to this function is
* ignored. will generate an exception. * ignored. will generate an exception.
*
*
* @throws PaintException * @throws PaintException
* if the paint operation failed. * if the paint operation failed.
*/ */


/* /*
* (non-Javadoc) * (non-Javadoc)
*
*
* @see com.vaadin.terminal.PaintTarget#startTag(com.vaadin.terminal * @see com.vaadin.terminal.PaintTarget#startTag(com.vaadin.terminal
* .Paintable, java.lang.String) * .Paintable, java.lang.String)
*/ */


/* /*
* (non-Javadoc) * (non-Javadoc)
*
*
* @see com.vaadin.terminal.PaintTarget#addCharacterData(java.lang.String ) * @see com.vaadin.terminal.PaintTarget#addCharacterData(java.lang.String )
*/ */
public void addCharacterData(String text) throws PaintException { public void addCharacterData(String text) throws PaintException {
/** /**
* This is basically a container for UI components variables, that will be * This is basically a container for UI components variables, that will be
* added at the end of JSON object. * added at the end of JSON object.
*
*
* @author mattitahvonen * @author mattitahvonen
*
*
*/ */
class JsonTag implements Serializable { class JsonTag implements Serializable {
boolean firstField = false; boolean firstField = false;
} }


/** /**
*
*
* @param s * @param s
* json string, object or array * json string, object or array
*/ */


/** /**
* Method to check if paintable is already painted into this target. * Method to check if paintable is already painted into this target.
*
*
* @param p * @param p
* @return true if is not yet painted into this target and is connected to * @return true if is not yet painted into this target and is connected to
* app * app

+ 1
- 1
src/com/vaadin/ui/Window.java View File

if (pendingFocus.getWindow() == this if (pendingFocus.getWindow() == this
|| (pendingFocus.getWindow() != null && pendingFocus || (pendingFocus.getWindow() != null && pendingFocus
.getWindow().getParent() == this)) { .getWindow().getParent() == this)) {
target.paintReference(pendingFocus, "focused");
target.addAttribute("focused", pendingFocus);
} }
pendingFocus = null; pendingFocus = null;
} }

Loading…
Cancel
Save