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/08/15 23:20:36 UTC
svn commit: r1756437 - in
/pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot948: ./
Pivot948.java pivot_948.bxml
Author: rwhitcomb
Date: Mon Aug 15 23:20:36 2016
New Revision: 1756437
URL: http://svn.apache.org/viewvc?rev=1756437&view=rev
Log:
PIVOT-948: Add an example program that both illustrates how to use data binding
(in this case, "selected item binding" with a ListButton), but that also serves
as a check on the fix for this issue. Having an unselected item used to cause
the bind mapping not to be called during a "store" operation. Now it is called
always (if set), and the mapping is responsible for translating between the
unselected state/index and the underlying stored value.
Added:
pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot948/
pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot948/Pivot948.java
pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot948/pivot_948.bxml
Added: pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot948/Pivot948.java
URL: http://svn.apache.org/viewvc/pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot948/Pivot948.java?rev=1756437&view=auto
==============================================================================
--- pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot948/Pivot948.java (added)
+++ pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot948/Pivot948.java Mon Aug 15 23:20:36 2016
@@ -0,0 +1,121 @@
+/*
+ * 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.issues.pivot948;
+
+import org.apache.pivot.beans.*;
+import org.apache.pivot.collections.*;
+import org.apache.pivot.wtk.*;
+
+public class Pivot948 extends Application.Adapter
+ implements ButtonPressListener,
+ ListView.ItemBindMapping
+{
+ private Window window = null;
+ @BXML private ListButton inputList;
+ @BXML private PushButton loadButton;
+ @BXML private PushButton storeButton;
+ @BXML private TextInput outputResult;
+ private Integer listIndex = null;
+
+ /** Method of the {@link Application.Adapter} interface. */
+ @Override
+ public void startup(Display display, Map<String, String> properties) throws Exception {
+ BXMLSerializer bxmlSerializer = new BXMLSerializer();
+ window = (Window)bxmlSerializer.readObject(this.getClass(), "pivot_948.bxml");
+ bxmlSerializer.bind(this);
+
+ loadButton.getButtonPressListeners().add(this);
+ storeButton.getButtonPressListeners().add(this);
+
+ // Establish a "selected item binding" between the "listIndex" integer and the
+ // "inputList" selected item index. A null integer implies no selection
+ // (index of -1).
+ inputList.setSelectedItemBindMapping(this);
+ inputList.setSelectedItemBindType(BindType.BOTH);
+ inputList.setSelectedItemKey("listIndex");
+
+ buttonPressed(storeButton);
+
+ window.open(display);
+ }
+
+ /** Method of the {@link Application.Adapter} interface. */
+ @Override
+ public boolean shutdown(boolean optional) {
+ if (window != null) {
+ window.close();
+ }
+
+ return false;
+ }
+
+ /**
+ * @return The list index as an integer (call be {@code null}).
+ */
+ public Integer getListIndex() {
+ return listIndex;
+ }
+
+ /**
+ * Set the current list index to the new value.
+ * @param newIndex The new index value (which can be {@code null}).
+ */
+ public void setListIndex(Integer newIndex) {
+ listIndex = newIndex;
+ }
+
+ /** Method of the {@link ListView.ItemBindMapping} interface, called during "store". */
+ @Override
+ public Object get(List<?> listData, int index) {
+ return Integer.valueOf(index);
+ }
+
+ /** Method of the {@link ListView.ItemBindMapping} interface, called during "load". */
+ @Override
+ public int indexOf(List<?> listData, Object value) {
+ if (value != null) {
+ Integer iVal = (Integer)value;
+ return iVal.intValue();
+ }
+ // Null item implies nothing selected, so return -1 as the index
+ return -1;
+ }
+
+ /** Method of the {@link ButtonPressListener} interface. */
+ @Override
+ public void buttonPressed(Button button) {
+ if (button == loadButton) {
+ String text = outputResult.getText();
+ if (text == null || text.trim().isEmpty()) {
+ listIndex = null;
+ }
+ else {
+ listIndex = Integer.valueOf(text);
+ }
+ inputList.load(this);
+ }
+ else if (button == storeButton) {
+ inputList.store(this);
+ outputResult.setText(listIndex == null ? "" : listIndex.toString());
+ }
+ }
+
+ public static void main(String[] args) {
+ DesktopApplicationContext.main(Pivot948.class, args);
+ }
+
+}
Added: pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot948/pivot_948.bxml
URL: http://svn.apache.org/viewvc/pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot948/pivot_948.bxml?rev=1756437&view=auto
==============================================================================
--- pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot948/pivot_948.bxml (added)
+++ pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot948/pivot_948.bxml Mon Aug 15 23:20:36 2016
@@ -0,0 +1,35 @@
+<?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="Pivot 948" maximized="true"
+ xmlns:bxml="http://pivot.apache.org/bxml"
+ xmlns="org.apache.pivot.wtk"
+>
+
+ <BoxPane styles="{padding:4, verticalAlignment:'center'}">
+ <Label text="Input List:"/>
+ <ListButton bxml:id="inputList" listData="[1, 2, 3, 4, 5]" selectedIndex="-1" />
+ <BoxPane orientation="vertical" styles="{padding:6}">
+ <PushButton bxml:id="loadButton" buttonData="<-- Click to Load List Value" preferredWidth="180" styles="{padding:4}"/>
+ <PushButton bxml:id="storeButton" buttonData="Click to Store List Value -->" preferredWidth="180" styles="{padding:4}"/>
+ </BoxPane>
+ <Label text="List item index:"/>
+ <TextInput bxml:id="outputResult" text=""/>
+ </BoxPane>
+
+</Window>