You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by gb...@apache.org on 2010/04/17 20:16:12 UTC
svn commit: r935220 - in /pivot/trunk:
tutorials/src/org/apache/pivot/tutorials/databinding/ tutorials/www/
wtk/src/org/apache/pivot/wtk/ wtk/src/org/apache/pivot/wtk/skin/
Author: gbrown
Date: Sat Apr 17 18:16:12 2010
New Revision: 935220
URL: http://svn.apache.org/viewvc?rev=935220&view=rev
Log:
Re-introduce Component#load(Object) and Component#store(Object) - binding to nested beans does not work without these methods; eliminate "contextKey" from Container (there is not a strong use case for this feature, since JSON paths can be used to bind to nested values; it also didn't map well to the bind type values).
Modified:
pivot/trunk/tutorials/src/org/apache/pivot/tutorials/databinding/data_binding.wtkx
pivot/trunk/tutorials/www/data-binding.xml
pivot/trunk/tutorials/www/stock-tracker.data-binding.xml
pivot/trunk/wtk/src/org/apache/pivot/wtk/Container.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/ContainerListener.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ContainerSkin.java
Modified: pivot/trunk/tutorials/src/org/apache/pivot/tutorials/databinding/data_binding.wtkx
URL: http://svn.apache.org/viewvc/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/databinding/data_binding.wtkx?rev=935220&r1=935219&r2=935220&view=diff
==============================================================================
--- pivot/trunk/tutorials/src/org/apache/pivot/tutorials/databinding/data_binding.wtkx (original)
+++ pivot/trunk/tutorials/src/org/apache/pivot/tutorials/databinding/data_binding.wtkx Sat Apr 17 18:16:12 2010
@@ -31,12 +31,12 @@ limitations under the License.
<Label Form.label="ID" textKey="id"/>
<TextInput Form.label="Name" textKey="name"/>
- <BoxPane Form.label="Address" orientation="vertical" contextKey="address">
- <TextInput textKey="street" prompt="Street"/>
+ <BoxPane Form.label="Address" orientation="vertical">
+ <TextInput textKey="address.street" prompt="Street"/>
<BoxPane>
- <TextInput textKey="city" prompt="City"/>
- <TextInput textKey="state" textSize="6" prompt="State"/>
- <TextInput textKey="zip" textSize="6" prompt="Zip"/>
+ <TextInput textKey="address.city" prompt="City"/>
+ <TextInput textKey="address.state" textSize="6" prompt="State"/>
+ <TextInput textKey="address.zip" textSize="6" prompt="Zip"/>
</BoxPane>
</BoxPane>
Modified: pivot/trunk/tutorials/www/data-binding.xml
URL: http://svn.apache.org/viewvc/pivot/trunk/tutorials/www/data-binding.xml?rev=935220&r1=935219&r2=935220&view=diff
==============================================================================
--- pivot/trunk/tutorials/www/data-binding.xml (original)
+++ pivot/trunk/tutorials/www/data-binding.xml Sat Apr 17 18:16:12 2010
@@ -53,15 +53,6 @@ limitations under the License.
</ul>
<p>
- The <tt>Container</tt> class overrides <tt>load()</tt> and <tt>store()</tt> to
- facilitate the use of nested contexts. When a container is assigned a context key, if
- a value with that key exists in the context passed to <tt>Container#load()</tt> or
- <tt>store()</tt>, that value becomes the context that is propagated to sub-components
- in further binds. This can significantly simplify the task of binding to complex data
- structures.
- </p>
-
- <p>
The following application demonstrates data binding. It allows the user to load a form
with address data either from a JSON file or from a JavaBean object, as well as clear
the form. Note that binding to a JavaBean is accomplished by wrapping the bean in an
@@ -100,12 +91,12 @@ limitations under the License.
<Label Form.label="ID" textKey="id"/>
<TextInput Form.label="Name" textKey="name"/>
- <BoxPane Form.label="Address" orientation="vertical" contextKey="address">
+ <BoxPane Form.label="Address" orientation="vertical">
<TextInput textKey="street" prompt="Street"/>
<BoxPane>
- <TextInput textKey="city" prompt="City"/>
- <TextInput textKey="state" textSize="6" prompt="State"/>
- <TextInput textKey="zip" textSize="10" prompt="Zip"/>
+ <TextInput textKey="address.city" prompt="City"/>
+ <TextInput textKey="address.state" textSize="6" prompt="State"/>
+ <TextInput textKey="address.zip" textSize="10" prompt="Zip"/>
</BoxPane>
</BoxPane>
@@ -137,15 +128,6 @@ limitations under the License.
</source>
<p>
- Note that the <tt><BoxPane></tt> for the address section defines a context key.
- This creates a nested bind context for its sub-elements, allowing the sub-elements to
- refer to the bound values using a relative key (e.g. "street"). However, since the
- <tt><BoxPane></tt> for the IM account section does not define a context key, its
- sub-elements must refer to their bound values using a path that is relative to the root
- context (e.g. "imAccount.id").
- </p>
-
- <p>
The application's <tt>startup()</tt> method defines the button press listeners that
load or clear the form:
</p>
Modified: pivot/trunk/tutorials/www/stock-tracker.data-binding.xml
URL: http://svn.apache.org/viewvc/pivot/trunk/tutorials/www/stock-tracker.data-binding.xml?rev=935220&r1=935219&r2=935220&view=diff
==============================================================================
--- pivot/trunk/tutorials/www/stock-tracker.data-binding.xml (original)
+++ pivot/trunk/tutorials/www/stock-tracker.data-binding.xml Sat Apr 17 18:16:12 2010
@@ -46,7 +46,8 @@ limitations under the License.
bound. Each bindable property of a component can be assigned a "bind key" that
associates the property with a value in the context. Data is imported from the context
into the property during a load, and exported from the property to the context during
- a store.
+ a store. Bind keys can reference nested values using JSON path syntax (e.g. "foo.bar.baz"
+ or "foo['bar'].baz").
</p>
<p>
@@ -56,23 +57,13 @@ limitations under the License.
state of a <tt>ListView</tt> component.
</p>
- <p>
- It is important to note that it is not possible to directly bind to a container
- component. However, containers may act as nested bind contexts - when a bind key is
- assigned to a container, it is assumed to point to a nested <tt>Dictionary</tt> instance
- representing a subordinate bind context. This enables complex object graphs returned
- from a web query to be seamlessly mapped to a set of data-bound components arranged in a
- non-trivial layout, for example.
- </p>
-
<h2>Data Binding in Stock Tracker</h2>
<p>
- The Stock Tracker demo isn't quite that sophisticated. It uses a single, flat bind
- context to populate the fields in the quote detail view. The bind context is actually
- the row data retrieved from the web query for the selected stock. This is why the
- application requests more data than it seems to need from the GET query: the extra
- fields are used to fill in the data in the detail form.
+ The Stock Tracker demo uses data binding to populate the fields in the quote detail
+ view. The bind context is actually the row data retrieved from the web query for the
+ selected stock. This is why the application requests more data than it seems to need
+ from the GET query: the extra fields are used to fill in the data in the detail form.
</p>
<p>
@@ -153,7 +144,7 @@ limitations under the License.
rather than on the parent container of the detail labels (an instance of <tt>Form</tt>).
This is because the application also needs to bind to the label that contains the
company name, which is not a child of the <tt>Form</tt>.
- <p>
+ </p>
<source type="xml">
<![CDATA[
@@ -161,14 +152,6 @@ limitations under the License.
]]>
</source>
- </p>
- This example demostrates that a nested container does not automatically imply the
- existence of a sub-context - sub-contexts are created only when a nested container is
- assigned its own bind key. Because a bind key is not defined for it, the form simply
- inherits the bind context that was passed to its parent, the root
- <tt><BoxPane></tt> representing the detail pane.
- </p>
-
<h2>Bind Mappings</h2>
<p>
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/Container.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/Container.java?rev=935220&r1=935219&r2=935220&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/Container.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/Container.java Sat Apr 17 18:16:12 2010
@@ -20,10 +20,8 @@ import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.util.Iterator;
-import org.apache.pivot.beans.BeanDictionary;
import org.apache.pivot.collections.ArrayList;
import org.apache.pivot.collections.Dictionary;
-import org.apache.pivot.collections.Map;
import org.apache.pivot.collections.Sequence;
import org.apache.pivot.util.ImmutableIterator;
import org.apache.pivot.util.ListenerList;
@@ -58,13 +56,6 @@ public abstract class Container extends
}
@Override
- public void contextKeyChanged(Container container, String previousContextKey) {
- for (ContainerListener listener : this) {
- listener.contextKeyChanged(container, previousContextKey);
- }
- }
-
- @Override
public void focusTraversalPolicyChanged(Container container,
FocusTraversalPolicy previousFocusTraversalPolicy) {
for (ContainerListener listener : this) {
@@ -124,10 +115,8 @@ public abstract class Container extends
private ArrayList<Component> components = new ArrayList<Component>();
private FocusTraversalPolicy focusTraversalPolicy = null;
- private String contextKey = null;
private Component mouseOverComponent = null;
-
private boolean mouseDown = false;
private Component mouseDownComponent = null;
private long mouseDownTime = 0;
@@ -586,80 +575,26 @@ public abstract class Container extends
}
/**
- * Returns the container's context key.
- *
- * @return
- * The context key, or <tt>null</tt> if no context key is set.
- */
- public String getContextKey() {
- return contextKey;
- }
-
- /**
- * Sets the component's context key.
- *
- * @param contextKey
- * The context key, or <tt>null</tt> to clear the context.
- */
- public void setContextKey(String contextKey) {
- String previousContextKey = this.contextKey;
-
- if ((previousContextKey != null
- && contextKey != null
- && !previousContextKey.equals(contextKey))
- || previousContextKey != contextKey) {
- this.contextKey = contextKey;
- containerListeners.contextKeyChanged(this, previousContextKey);
- }
- }
-
- /**
- * Propagates binding to subcomponents. If this container has a binding
- * set, propagates the bound value as a nested context.
+ * Propagates binding to subcomponents.
*
* @param context
*/
@Override
- @SuppressWarnings("unchecked")
public void load(Dictionary<String, ?> context) {
- if (contextKey != null
- && context.containsKey(contextKey)) {
- Object value = context.get(contextKey);
- if (value instanceof Dictionary<?, ?>) {
- context = (Map<String, Object>)value;
- } else {
- context = new BeanDictionary(value);
- }
- }
-
for (Component component : components) {
component.load(context);
}
}
/**
- * Propagates binding to subcomponents. If this container has a binding
- * set, propagates the bound value as a nested context.
+ * Propagates binding to subcomponents.
*
* @param context
*/
@Override
- @SuppressWarnings("unchecked")
public void store(Dictionary<String, ?> context) {
- if (isEnabled()) {
- if (contextKey != null) {
- // Bound value is expected to be a sub-context
- Object value = context.get(contextKey);
- if (value instanceof Dictionary<?, ?>) {
- context = (Map<String, Object>)value;
- } else {
- context = new BeanDictionary(value);
- }
- }
-
- for (Component component : components) {
- component.store(context);
- }
+ for (Component component : components) {
+ component.store(context);
}
}
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/ContainerListener.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/ContainerListener.java?rev=935220&r1=935219&r2=935220&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/ContainerListener.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/ContainerListener.java Sat Apr 17 18:16:12 2010
@@ -39,10 +39,6 @@ public interface ContainerListener {
}
@Override
- public void contextKeyChanged(Container container, String previousContextKey) {
- }
-
- @Override
public void focusTraversalPolicyChanged(Container container,
FocusTraversalPolicy previousFocusTraversalPolicy) {
}
@@ -78,14 +74,6 @@ public interface ContainerListener {
public void componentMoved(Container container, int from, int to);
/**
- * Called when a container's context key has changed.
- *
- * @param container
- * @param previousContextKey
- */
- public void contextKeyChanged(Container container, String previousContextKey);
-
- /**
* Called when a container's focus traversal policy has changed.
*
* @param container
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ContainerSkin.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ContainerSkin.java?rev=935220&r1=935219&r2=935220&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ContainerSkin.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ContainerSkin.java Sat Apr 17 18:16:12 2010
@@ -230,11 +230,6 @@ public abstract class ContainerSkin exte
}
@Override
- public void contextKeyChanged(Container container, String previousContextKey) {
- // No-op
- }
-
- @Override
public void focusTraversalPolicyChanged(Container container,
FocusTraversalPolicy previousFocusTraversalPolicy) {
// No-op