You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by rw...@apache.org on 2016/02/09 23:06:55 UTC

svn commit: r1729480 - in /pivot/trunk/tests/src/org/apache/pivot/tests: DataBindingTest.java data_binding_test.bxml

Author: rwhitcomb
Date: Tue Feb  9 22:06:55 2016
New Revision: 1729480

URL: http://svn.apache.org/viewvc?rev=1729480&view=rev
Log:
Clean up the DataBindingTest so that it actually works now.  This actually
only involved simplifying the renderers to only implement the "toString(Object)"
methods.

But, make the values more interesting, and add explanatory stuff to the GUI
so it is more understandable what is actually happening.

Note: this uses the HyperlinkButton class that is not available in the 2.0.x
branch, so this will need to be changed in order to backport it.

Modified:
    pivot/trunk/tests/src/org/apache/pivot/tests/DataBindingTest.java
    pivot/trunk/tests/src/org/apache/pivot/tests/data_binding_test.bxml

Modified: pivot/trunk/tests/src/org/apache/pivot/tests/DataBindingTest.java
URL: http://svn.apache.org/viewvc/pivot/trunk/tests/src/org/apache/pivot/tests/DataBindingTest.java?rev=1729480&r1=1729479&r2=1729480&view=diff
==============================================================================
--- pivot/trunk/tests/src/org/apache/pivot/tests/DataBindingTest.java (original)
+++ pivot/trunk/tests/src/org/apache/pivot/tests/DataBindingTest.java Tue Feb  9 22:06:55 2016
@@ -26,6 +26,7 @@ import org.apache.pivot.wtk.Application;
 import org.apache.pivot.wtk.Button;
 import org.apache.pivot.wtk.DesktopApplicationContext;
 import org.apache.pivot.wtk.Display;
+import org.apache.pivot.wtk.Label;
 import org.apache.pivot.wtk.ListView;
 import org.apache.pivot.wtk.Spinner;
 import org.apache.pivot.wtk.Window;
@@ -36,34 +37,13 @@ import org.apache.pivot.wtk.content.Spin
 public class DataBindingTest extends Application.Adapter {
     public static class TestListButtonDataRenderer extends ListButtonDataRenderer {
         @Override
-        public void render(final Object data, Button button, boolean highlighted) {
-            Object dataLoaded = data;
-            if (dataLoaded != null) {
-                dataLoaded = JSON.get(data, "text");
-            }
-
-            super.render(dataLoaded, button, highlighted);
-        }
-
-        @Override
-        public String toString(Object data) {
-            return JSON.get(data, "text");
+        public String toString(Object item) {
+            return JSON.get(item, "text");
         }
     }
 
     public static class TestListViewItemRenderer extends ListViewItemRenderer {
         @Override
-        public void render(final Object item, int index, final ListView listView, boolean selected,
-            Button.State state, boolean highlighted, boolean disabled) {
-            Object itemLoaded = item;
-            if (itemLoaded != null) {
-                itemLoaded = JSON.get(item, "text");
-            }
-
-            super.render(itemLoaded, index, listView, selected, state, highlighted, disabled);
-        }
-
-        @Override
         public String toString(Object item) {
             return JSON.get(item, "text");
         }
@@ -71,23 +51,13 @@ public class DataBindingTest extends App
 
     public static class TestSpinnerItemRenderer extends SpinnerItemRenderer {
         @Override
-        public void render(final Object item, final Spinner spinner) {
-            Object itemLoaded = item;
-            if (itemLoaded != null) {
-                itemLoaded = JSON.get(item, "text");
-            }
-
-            super.render(itemLoaded, spinner);
-        }
-
-        @Override
         public String toString(Object item) {
             return JSON.get(item, "text");
         }
     }
 
-    public static class TestBindMapping implements ListView.ItemBindMapping,
-        Spinner.ItemBindMapping {
+    public static class TestBindMapping
+        implements ListView.ItemBindMapping, Spinner.ItemBindMapping {
         @Override
         public int indexOf(List<?> list, Object value) {
             int i = 0;
@@ -135,7 +105,8 @@ public class DataBindingTest extends App
         context = new HashMap<>();
         window.getContent().store(context);
 
-        System.out.println(JSONSerializer.toString(context));
+        Label textLabel = (Label)(bxmlSerializer.getNamespace().get("bindingDataText"));
+        textLabel.setText(JSONSerializer.toString(context));
     }
 
     @Override

Modified: pivot/trunk/tests/src/org/apache/pivot/tests/data_binding_test.bxml
URL: http://svn.apache.org/viewvc/pivot/trunk/tests/src/org/apache/pivot/tests/data_binding_test.bxml?rev=1729480&r1=1729479&r2=1729480&view=diff
==============================================================================
--- pivot/trunk/tests/src/org/apache/pivot/tests/data_binding_test.bxml (original)
+++ pivot/trunk/tests/src/org/apache/pivot/tests/data_binding_test.bxml Tue Feb  9 22:06:55 2016
@@ -22,14 +22,33 @@ limitations under the License.
     xmlns="org.apache.pivot.wtk">
     <bxml:define xmlns="org.apache.pivot.collections">
         <ArrayList bxml:id="list">
-            <HashMap id="1" text="A"/>
-            <HashMap id="2" text="B"/>
-            <HashMap id="3" text="C"/>
-            <HashMap id="4" text="D"/>
+            <HashMap id="1" text="A 'No' uttered from the deepest conviction is better than a 'Yes' merely uttered to please, or worse, to avoid trouble."/>
+            <HashMap id="2" text="Back of every noble life there are principles that have fashioned it."/>
+            <HashMap id="3" text="Calamities are of two kinds: misfortune to ourselves, and good fortune to others."/>
+            <HashMap id="4" text="Danger breeds best on too much confidence."/>
         </ArrayList>
     </bxml:define>
 
-    <BoxPane orientation="vertical">
+    <BoxPane orientation="vertical" styles="{fill:true, padding:10}">
+        <Separator heading="A TableView containing the underlying data for each component below:"/>
+        <Border>
+            <ScrollPane horizontalScrollBarPolicy="fill" >
+                <TableView tableData="$list" bxml:id="dataTableView" >
+                    <columns>
+                        <TableView.Column name="id" headerData="ID" width="20" />
+                        <TableView.Column name="text" headerData="Text" width="1*"/>
+                    </columns>
+                </TableView>
+                <columnHeader>
+                    <TableViewHeader tableView="$dataTableView" sortMode="single_column"/>
+                </columnHeader>
+            </ScrollPane>
+        </Border>
+
+        <Separator heading="This is the 'selected item' binding data for each component:"/>
+        <Label bxml:id="bindingDataText"/>
+
+        <Separator heading="A ListView with selected key 'id1':"/>
         <ListView listData="$list" selectedItemKey="id1">
             <itemRenderer>
                 <tests:DataBindingTest.TestListViewItemRenderer/>
@@ -39,6 +58,7 @@ limitations under the License.
             </selectedItemBindMapping>
         </ListView>
 
+        <Separator heading="A ListButton with selected key 'id2':"/>
         <ListButton listData="$list" selectedItemKey="id2">
             <dataRenderer>
                 <tests:DataBindingTest.TestListButtonDataRenderer/>
@@ -51,6 +71,7 @@ limitations under the License.
             </selectedItemBindMapping>
         </ListButton>
 
+        <Separator heading="A Spinner with selected key 'id3':"/>
         <Spinner spinnerData="$list" selectedItemKey="id3">
             <itemRenderer>
                 <tests:DataBindingTest.TestSpinnerItemRenderer/>
@@ -59,5 +80,13 @@ limitations under the License.
                 <tests:DataBindingTest.TestBindMapping/>
             </selectedItemBindMapping>
         </Spinner>
+
+        <Separator/>
+        <Border styles="{padding:6,backgroundColor:'#F0E68C'}">
+            <BoxPane orientation="horizontal">
+                <Label text="Quotes taken from here:"/>
+                <HyperlinkButton uri="http://www.quotes.net"/>
+            </BoxPane>
+        </Border>
     </BoxPane>
 </Window>