You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by sm...@apache.org on 2011/12/19 15:31:52 UTC

svn commit: r1220767 - in /pivot/trunk/tests/src/org/apache/pivot/tests: TableViewCellRendererCustom.java table_view_test3.bxml

Author: smartini
Date: Mon Dec 19 14:31:52 2011
New Revision: 1220767

URL: http://svn.apache.org/viewvc?rev=1220767&view=rev
Log:
minimal test with custom table cell renderer

Added:
    pivot/trunk/tests/src/org/apache/pivot/tests/TableViewCellRendererCustom.java
    pivot/trunk/tests/src/org/apache/pivot/tests/table_view_test3.bxml

Added: pivot/trunk/tests/src/org/apache/pivot/tests/TableViewCellRendererCustom.java
URL: http://svn.apache.org/viewvc/pivot/trunk/tests/src/org/apache/pivot/tests/TableViewCellRendererCustom.java?rev=1220767&view=auto
==============================================================================
--- pivot/trunk/tests/src/org/apache/pivot/tests/TableViewCellRendererCustom.java (added)
+++ pivot/trunk/tests/src/org/apache/pivot/tests/TableViewCellRendererCustom.java Mon Dec 19 14:31:52 2011
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pivot.tests;
+
+import org.apache.pivot.json.JSON;
+import org.apache.pivot.wtk.content.TableViewCellRenderer;
+
+/**
+ * Minimal sample for a customized version of table cell renderer. 
+ * Renders cell contents as a string, but in this case, transformed.
+ * <br/>
+ * Note that here it's possible to extends Label implements TableView.CellRenderer, 
+ * or even to extends directly TableViewCellRenderer 
+ * (because it extends Label and implements TableView.CellRenderer).
+ */
+public class TableViewCellRendererCustom extends TableViewCellRenderer {
+
+    @Override
+    public String toString(Object row, String columnName) {
+        Object cellData = JSON.get(row, columnName);
+        String text = (cellData == null) ? null : cellData.toString();
+        if (text == null) {
+            return text;
+        }
+        else {
+            // return new StringBuffer(text).reverse().toString();  // reverse text
+            return text.toUpperCase();  // to upper text
+        }
+    }
+
+}

Added: pivot/trunk/tests/src/org/apache/pivot/tests/table_view_test3.bxml
URL: http://svn.apache.org/viewvc/pivot/trunk/tests/src/org/apache/pivot/tests/table_view_test3.bxml?rev=1220767&view=auto
==============================================================================
--- pivot/trunk/tests/src/org/apache/pivot/tests/table_view_test3.bxml (added)
+++ pivot/trunk/tests/src/org/apache/pivot/tests/table_view_test3.bxml Mon Dec 19 14:31:52 2011
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to you under the Apache License,
+Version 2.0 (the "License"); you may not use this file except in
+compliance with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
+
+<Window title="Table View Test3, using a custom TableViewCellRenderer" maximized="true"
+    xmlns:bxml="http://pivot.apache.org/bxml"
+    xmlns:collections="org.apache.pivot.collections"
+    xmlns:content="org.apache.pivot.wtk.content"
+    xmlns:tests="org.apache.pivot.tests"
+    xmlns="org.apache.pivot.wtk">
+    <ScrollPane horizontalScrollBarPolicy="fill_to_capacity">
+        <TableView bxml:id="tableView" styles="{variableRowHeight:true, backgroundColor:'#ffeeee'}">
+            <columns>
+                <TableView.Column name="value" width="100">
+                    <cellRenderer>
+                        <tests:TableViewCellRendererCustom styles="{wrapText:true}"/>
+                    </cellRenderer>
+                </TableView.Column>
+
+                <TableView.Column width="1*"/>
+            </columns>
+
+            <collections:HashMap value="Single Line"/>
+            <collections:HashMap value="Double&#xA;Line Line Line Line!"/>
+            <collections:HashMap value="Single Line"/>
+            <collections:HashMap value="Double&#xA;Line"/>
+        </TableView>
+    </ScrollPane>
+</Window>