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 2009/12/31 02:23:49 UTC

svn commit: r894751 - in /incubator/pivot/trunk: tests/ tests/.settings/ tests/src/ wtk/src/org/apache/pivot/wtkx/ wtk/test/org/apache/pivot/wtk/test/

Author: gbrown
Date: Thu Dec 31 01:23:48 2009
New Revision: 894751

URL: http://svn.apache.org/viewvc?rev=894751&view=rev
Log:
Add tests project.

Added:
    incubator/pivot/trunk/tests/
    incubator/pivot/trunk/tests/.classpath
    incubator/pivot/trunk/tests/.project
    incubator/pivot/trunk/tests/.settings/
    incubator/pivot/trunk/tests/.settings/org.eclipse.jdt.core.prefs
    incubator/pivot/trunk/tests/src/
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtkx/Bindable.java
    incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/BindableTest.java
    incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/BindableWindow.java
    incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/bindable_test.wtkx
Modified:
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtkx/WTKXSerializer.java

Added: incubator/pivot/trunk/tests/.classpath
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tests/.classpath?rev=894751&view=auto
==============================================================================
--- incubator/pivot/trunk/tests/.classpath (added)
+++ incubator/pivot/trunk/tests/.classpath Thu Dec 31 01:23:48 2009
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+	<classpathentry combineaccessrules="false" kind="src" path="/core"/>
+	<classpathentry combineaccessrules="false" kind="src" path="/web"/>
+	<classpathentry combineaccessrules="false" kind="src" path="/wtk"/>
+	<classpathentry combineaccessrules="false" kind="src" path="/wtk-terra"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>

Added: incubator/pivot/trunk/tests/.project
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tests/.project?rev=894751&view=auto
==============================================================================
--- incubator/pivot/trunk/tests/.project (added)
+++ incubator/pivot/trunk/tests/.project Thu Dec 31 01:23:48 2009
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>tests</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

Added: incubator/pivot/trunk/tests/.settings/org.eclipse.jdt.core.prefs
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tests/.settings/org.eclipse.jdt.core.prefs?rev=894751&view=auto
==============================================================================
--- incubator/pivot/trunk/tests/.settings/org.eclipse.jdt.core.prefs (added)
+++ incubator/pivot/trunk/tests/.settings/org.eclipse.jdt.core.prefs Thu Dec 31 01:23:48 2009
@@ -0,0 +1,12 @@
+#Wed Dec 30 20:22:15 EST 2009
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6

Added: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtkx/Bindable.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtkx/Bindable.java?rev=894751&view=auto
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtkx/Bindable.java (added)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtkx/Bindable.java Thu Dec 31 01:23:48 2009
@@ -0,0 +1,29 @@
+/*
+ * 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.wtkx;
+
+/**
+ * Allows WTKX serializer to automatically bind to an instance of a
+ * deserialized class.
+ */
+public interface Bindable {
+    /**
+     * Called to initialize the class after it has been completely
+     * processed and bound by the serializer.
+     */
+    public void initialize();
+}

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtkx/WTKXSerializer.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtkx/WTKXSerializer.java?rev=894751&r1=894750&r2=894751&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtkx/WTKXSerializer.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtkx/WTKXSerializer.java Thu Dec 31 01:23:48 2009
@@ -448,6 +448,13 @@
             throw exception;
         }
 
+        if (root instanceof Bindable) {
+            bind(root);
+
+            Bindable bindable = (Bindable)root;
+            bindable.initialize();
+        }
+
         return root;
     }
 

Added: incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/BindableTest.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/BindableTest.java?rev=894751&view=auto
==============================================================================
--- incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/BindableTest.java (added)
+++ incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/BindableTest.java Thu Dec 31 01:23:48 2009
@@ -0,0 +1,56 @@
+/*
+ * 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.wtk.test;
+
+import org.apache.pivot.collections.Map;
+import org.apache.pivot.wtk.Application;
+import org.apache.pivot.wtk.DesktopApplicationContext;
+import org.apache.pivot.wtk.Display;
+import org.apache.pivot.wtkx.WTKXSerializer;
+
+public class BindableTest implements Application {
+    private BindableWindow window = null;
+
+    @Override
+    public void startup(Display display, Map<String, String> properties) throws Exception {
+        WTKXSerializer wtkxSerializer = new WTKXSerializer();
+        window = (BindableWindow)wtkxSerializer.readObject(this, "bindable_test.wtkx");
+        window.open(display);
+    }
+
+    @Override
+    public boolean shutdown(boolean optional) {
+        if (window != null) {
+            window.close();
+        }
+
+        return false;
+    }
+
+
+    @Override
+    public void suspend() {
+    }
+
+    @Override
+    public void resume() {
+    }
+
+    public static void main(String[] args) {
+        DesktopApplicationContext.main(BindableTest.class, args);
+    }
+}

Added: incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/BindableWindow.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/BindableWindow.java?rev=894751&view=auto
==============================================================================
--- incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/BindableWindow.java (added)
+++ incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/BindableWindow.java Thu Dec 31 01:23:48 2009
@@ -0,0 +1,31 @@
+/*
+ * 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.wtk.test;
+
+import org.apache.pivot.wtk.Label;
+import org.apache.pivot.wtk.Window;
+import org.apache.pivot.wtkx.Bindable;
+import org.apache.pivot.wtkx.WTKX;
+
+public class BindableWindow extends Window implements Bindable {
+    @WTKX private Label label = null;
+
+    @Override
+    public void initialize() {
+        label.setText("Hello Bindable!");
+    }
+}

Added: incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/bindable_test.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/bindable_test.wtkx?rev=894751&view=auto
==============================================================================
--- incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/bindable_test.wtkx (added)
+++ incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/bindable_test.wtkx Thu Dec 31 01:23:48 2009
@@ -0,0 +1,26 @@
+<?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.
+-->
+
+<test:BindableWindow title="Bindable Test" maximized="true"
+    xmlns:wtkx="http://pivot.apache.org/wtkx"
+    xmlns:test="org.apache.pivot.wtk.test"
+    xmlns="org.apache.pivot.wtk">
+    <content>
+        <Label wtkx:id="label" styles="{horizontalAlignment:'center', verticalAlignment:'center'}"/>
+    </content>
+</test:BindableWindow>



Re: svn commit: r894751

Posted by Michael Bushe <mi...@bushe.com>.
Sorry, I didn't read the previous posts before I sent mine.

Yes, Todd is correct in his brief summary.

Again, I'm wary of initialize(), not only because of the remove problem, but
the clarity of when it's called.  Since it is after serialization, then
"constructed" (or similar) would be more appropriate.  You are less likely
to get into the dangling listener issue since there's nothing around to add
to at that point.

I do like Flex's model when we get around to defining one.  :-)  Without  a
component model component development can become a real hairball.  In Swing,
I've always bolted on my own.

Michael Bushe
Software Architect/Developer
michael@bushe.com
www.bushe.com


On Thu, Dec 31, 2009 at 9:00 AM, Michael Bushe <mi...@bushe.com> wrote:

> Yes, listenerlist.remove() is how the listener is removed.  The question
> is: When is the listener removed?
>
> Let's say during initialize, the onInitialize() method finds the button's
> window and adds itself as a listener to one of the windows' listener lists,
> maybe to save some state when the window closes.  Let's also say that the
> button is added to a tab that can be closed (like Firefox).  Without doing
> anything else, if the user closes the tab, the button is going to go away -
> almost.  Since the window's listener list will still have a reference to the
> button, the button will stay around forever.  I'm describing the classic
> Swing memory leak.  Not only is there a small resource problem, but when the
> window closes, the button will still be called and try to save some state,
> even though it's probably not supposed to since as far is the user is
> concerned, it's supposed to be gone.
>
> The initialize call is defining a component lifecycle, like it or not, and
> I know of no proper lifecycles that have a start without a stop or an add
> without a remove.  There's another problem too - when is initialized
> called?  The name doesn't tell me exactly.  Is it just after the button's
> constructor?  After the button is added the first time to it's container? If
> it's after construction, then the window couldn't be found anyway, and
> neither could any other component that the button itself does not create.
> Does this also mean that in order to add a listener to another component in
> initialize that all the subcomponents need to be instantiated in the
> constructor?  Isn't doing a lot of work in the constructor considered a bad
> practice in Java?  Yes, this adds complexity, but initialize() without
> anything else is like trying to take a small sip from the 5 gallon jug you
> are tipping into your mouth.
>
> If you want something in 1.4, or don't want to define a component
> lifecycle, I suggest renaming "initialize" to "constructed" or
> "postConstuction" to make it clear when it happens and to not conflict with
> the use of some future lifecycle methods or events that is almost sure to
> include "initialize" or "init."
>
>
> Michael Bushe
> Software Architect/Developer
> michael@bushe.com
> www.bushe.com
>
>
> On Wed, Dec 30, 2009 at 9:30 PM, Greg Brown <gk...@mac.com> wrote:
>
>> Listeners can be removed by calling the remove() method on the listener
>> list, similar to Swing and WPF.
>>
>> On Dec 30, 2009, at 9:26 PM, Michael Bushe wrote:
>>
>> > Greg,
>> >
>> > How/when can event listeners be removed (to avoid "memory
>> leaks"/"loitering
>> > objects")?  Flex has a robust component lifecycle, I don't remember
>> Pivot
>> > having a component lifecycle model at all (and neither does Swing,
>> except
>> > for Window, you have to bolt it on yourself).  I think I'd rather see
>> the
>> > whole model at once, I suppose in 1.5.
>> >
>> > I'm a HUGE fan of what you are trying to do, but maybe it should wait?
>> > OTOH, you know you are going to have initialize(), maybe that's a good
>> > start.  On the third hand, if you add preInitialize() later (like Flex),
>> > then existing initialize() calls aren't broken exactly, but when things
>> > happen may shift and be a surprise.
>> >
>> > Michael Bushe
>> > Software Architect/Developer
>> > michael@bushe.com
>> > www.bushe.com
>> >
>> >
>> > On Wed, Dec 30, 2009 at 9:14 PM, Greg Brown <gk...@mac.com> wrote:
>> >
>> >> FYI, though it wasn't mentioned in the commit message, this change also
>> >> included a minor addition/change to the org.apache.pivot.wtkx package.
>> This
>> >> change is relatively insubstantial but should actually have a
>> significant
>> >> impact on "real" application development.
>> >>
>> >> Some background: In Flex, MXML files are compiled to classes. So, this
>> file
>> >> generates a class named MyVBox:
>> >>
>> >> MyVBox.mxml:
>> >>
>> >>  <mx:VBox initialize="onInitialize()"
>> >>      xmlns:mx="http://www.adobe.com/2006/mxml">
>> >>      <mx:Script>
>> >>      public function onInitialize():void {
>> >>          // Wire up event handlers, etc.
>> >>      }
>> >>
>> >>      public function onMyButtonClick():void {
>> >>          // Respond to button click
>> >>      }
>> >>      </mx:Script>
>> >>
>> >>      <mx:Button id="myButton" label="Click Me"
>> click="onMyButtonClick()"/>
>> >>  </mx:VBox>
>> >>
>> >> I can then use that class as a component in other MXML files (for
>> example,
>> >> I could add it to a tab pane, or "TabNavigator" in Flex).
>> >>
>> >> In Pivot, something similar could be done with the following WTKX:
>> >>
>> >> my_box_pane.wtkx:
>> >>
>> >>  <BoxPane orientation="vertical"
>> >>      xmlns:wtkx="http://pivot.apache.org/wtkx"
>> >>      xmlns="org.apache.pivot.wtk">
>> >>      <wtkx:script>
>> >>      function myButtonClicked() {
>> >>          // Respond to button click
>> >>      }
>> >>      </wtkx:script>
>> >>
>> >>      <PushButton wtkx:id="myButton" buttonData="Click Me"
>> >>          ButtonPressListener.buttonPressed="myButtonClicked()"/>
>> >>  </BoxPane>
>> >>
>> >> We can then include my_box_pane.wtkx into a TabPane declared in another
>> >> WTKX file. However, Pivot didn't have an equivalent of onInitialize().
>> If
>> >> the root element is a Window, we could listen for windowOpened(), but
>> >> otherwise we're stuck.
>> >>
>> >> Also, it becomes more complex when we want to associate Java code with
>> WTKX
>> >> includes, rather than putting the logic in script. This is something
>> any
>> >> non-trivial application is going to want to do, and Pivot didn't
>> provide an
>> >> easy way to do it. The change I checked in attempts to solve these two
>> >> problems. We can't use WTKX to define new classes, but we can use WTKX
>> to
>> >> instantiate classes we have defined elsewhere. For example:
>> >>
>> >> MyBoxPane.java:
>> >>
>> >>  public class MyBoxPane extends BoxPane implements Bindable {
>> >>      @WTKX private PushButton myButton = null;
>> >>
>> >>      public MyBoxPane() {
>> >>          super(Orientation.VERTICAL);
>> >>      }
>> >>
>> >>      @Override
>> >>      public void initialize() {
>> >>          myButton.getButtonPressListeners().add(new
>> ButtonPressListener()
>> >> {
>> >>              public void buttonPressed(Button button) {
>> >>                  // Respond to button click
>> >>              }
>> >>          });
>> >>      }
>> >>  }
>> >>
>> >> Using this approach, the updated my_box_pane.wtkx would look like this:
>> >>
>> >> my_box_pane.wtkx:
>> >>
>> >>  <foo:MyBoxPane orientation="vertical"
>> >>      xmlns:wtkx="http://pivot.apache.org/wtkx"
>> >>      xmlns:foo="com.foo"
>> >>      xmlns="org.apache.pivot.wtk">
>> >>      <PushButton wtkx:id="myButton" buttonData="Click Me"/>
>> >>  </foo:MyBoxPane>
>> >>
>> >> Once WTKXSerializer is done processing foo:MyBoxPane, it sees that it
>> >> implements Bindable and bind()s to it. It then calls initialize() to
>> allow
>> >> the class to register event listeners and perform any other required
>> >> initialization tasks.
>> >>
>> >> This is a late-breaking change for 1.4, so please let me know ASAP if
>> you
>> >> have any questions or concerns.
>> >>
>> >> G
>> >>
>> >>
>>
>>
>

Re: svn commit: r894751

Posted by Greg Brown <gk...@mac.com>.
> Yes, listenerlist.remove() is how the listener is removed.  The question is:
> When is the listener removed?

As Todd said, it is up to the application. For example, if you wanted to remove an event listener from a button that had been removed from the component hierarchy, you could either listen for componentRemoved() on the button's parent container or parentChanged() on the button itself.

> The initialize call is defining a component lifecycle, like it or not, and I
> know of no proper lifecycles that have a start without a stop or an add
> without a remove.

I didn't see any mention of uninitialize() in the Flex docs, but maybe I missed something. 

Either way, as I said earlier, this interface isn't mean to define any kind of life cycle for Pivot components, and it isn't an attempt to emulate Flex behavior. initialize() simply means that WTKXSerializer has finished loading the component and has called bind(). To me, this is a pretty clear definition of what it does and when it is called.

Note that it is also entirely a WTKX construct. What you might call component "lifecycle" already exist at the component/container level (see above). Defining lifecycle events in WTKX would limit access to those events to developers using WTKX. For example, if you were building your UI programmatically in Java or using a Groovy Pivot builder, you wouldn't be able to respond to those events. We designed Pivot such that it does not have a hard dependency on WTKX for just this reason.


Re: svn commit: r894751

Posted by Michael Bushe <mi...@bushe.com>.
Yes, listenerlist.remove() is how the listener is removed.  The question is:
When is the listener removed?

Let's say during initialize, the onInitialize() method finds the button's
window and adds itself as a listener to one of the windows' listener lists,
maybe to save some state when the window closes.  Let's also say that the
button is added to a tab that can be closed (like Firefox).  Without doing
anything else, if the user closes the tab, the button is going to go away -
almost.  Since the window's listener list will still have a reference to the
button, the button will stay around forever.  I'm describing the classic
Swing memory leak.  Not only is there a small resource problem, but when the
window closes, the button will still be called and try to save some state,
even though it's probably not supposed to since as far is the user is
concerned, it's supposed to be gone.

The initialize call is defining a component lifecycle, like it or not, and I
know of no proper lifecycles that have a start without a stop or an add
without a remove.  There's another problem too - when is initialized
called?  The name doesn't tell me exactly.  Is it just after the button's
constructor?  After the button is added the first time to it's container? If
it's after construction, then the window couldn't be found anyway, and
neither could any other component that the button itself does not create.
Does this also mean that in order to add a listener to another component in
initialize that all the subcomponents need to be instantiated in the
constructor?  Isn't doing a lot of work in the constructor considered a bad
practice in Java?  Yes, this adds complexity, but initialize() without
anything else is like trying to take a small sip from the 5 gallon jug you
are tipping into your mouth.

If you want something in 1.4, or don't want to define a component lifecycle,
I suggest renaming "initialize" to "constructed" or "postConstuction" to
make it clear when it happens and to not conflict with the use of some
future lifecycle methods or events that is almost sure to include
"initialize" or "init."

Michael Bushe
Software Architect/Developer
michael@bushe.com
www.bushe.com


On Wed, Dec 30, 2009 at 9:30 PM, Greg Brown <gk...@mac.com> wrote:

> Listeners can be removed by calling the remove() method on the listener
> list, similar to Swing and WPF.
>
> On Dec 30, 2009, at 9:26 PM, Michael Bushe wrote:
>
> > Greg,
> >
> > How/when can event listeners be removed (to avoid "memory
> leaks"/"loitering
> > objects")?  Flex has a robust component lifecycle, I don't remember Pivot
> > having a component lifecycle model at all (and neither does Swing, except
> > for Window, you have to bolt it on yourself).  I think I'd rather see the
> > whole model at once, I suppose in 1.5.
> >
> > I'm a HUGE fan of what you are trying to do, but maybe it should wait?
> > OTOH, you know you are going to have initialize(), maybe that's a good
> > start.  On the third hand, if you add preInitialize() later (like Flex),
> > then existing initialize() calls aren't broken exactly, but when things
> > happen may shift and be a surprise.
> >
> > Michael Bushe
> > Software Architect/Developer
> > michael@bushe.com
> > www.bushe.com
> >
> >
> > On Wed, Dec 30, 2009 at 9:14 PM, Greg Brown <gk...@mac.com> wrote:
> >
> >> FYI, though it wasn't mentioned in the commit message, this change also
> >> included a minor addition/change to the org.apache.pivot.wtkx package.
> This
> >> change is relatively insubstantial but should actually have a
> significant
> >> impact on "real" application development.
> >>
> >> Some background: In Flex, MXML files are compiled to classes. So, this
> file
> >> generates a class named MyVBox:
> >>
> >> MyVBox.mxml:
> >>
> >>  <mx:VBox initialize="onInitialize()"
> >>      xmlns:mx="http://www.adobe.com/2006/mxml">
> >>      <mx:Script>
> >>      public function onInitialize():void {
> >>          // Wire up event handlers, etc.
> >>      }
> >>
> >>      public function onMyButtonClick():void {
> >>          // Respond to button click
> >>      }
> >>      </mx:Script>
> >>
> >>      <mx:Button id="myButton" label="Click Me"
> click="onMyButtonClick()"/>
> >>  </mx:VBox>
> >>
> >> I can then use that class as a component in other MXML files (for
> example,
> >> I could add it to a tab pane, or "TabNavigator" in Flex).
> >>
> >> In Pivot, something similar could be done with the following WTKX:
> >>
> >> my_box_pane.wtkx:
> >>
> >>  <BoxPane orientation="vertical"
> >>      xmlns:wtkx="http://pivot.apache.org/wtkx"
> >>      xmlns="org.apache.pivot.wtk">
> >>      <wtkx:script>
> >>      function myButtonClicked() {
> >>          // Respond to button click
> >>      }
> >>      </wtkx:script>
> >>
> >>      <PushButton wtkx:id="myButton" buttonData="Click Me"
> >>          ButtonPressListener.buttonPressed="myButtonClicked()"/>
> >>  </BoxPane>
> >>
> >> We can then include my_box_pane.wtkx into a TabPane declared in another
> >> WTKX file. However, Pivot didn't have an equivalent of onInitialize().
> If
> >> the root element is a Window, we could listen for windowOpened(), but
> >> otherwise we're stuck.
> >>
> >> Also, it becomes more complex when we want to associate Java code with
> WTKX
> >> includes, rather than putting the logic in script. This is something any
> >> non-trivial application is going to want to do, and Pivot didn't provide
> an
> >> easy way to do it. The change I checked in attempts to solve these two
> >> problems. We can't use WTKX to define new classes, but we can use WTKX
> to
> >> instantiate classes we have defined elsewhere. For example:
> >>
> >> MyBoxPane.java:
> >>
> >>  public class MyBoxPane extends BoxPane implements Bindable {
> >>      @WTKX private PushButton myButton = null;
> >>
> >>      public MyBoxPane() {
> >>          super(Orientation.VERTICAL);
> >>      }
> >>
> >>      @Override
> >>      public void initialize() {
> >>          myButton.getButtonPressListeners().add(new
> ButtonPressListener()
> >> {
> >>              public void buttonPressed(Button button) {
> >>                  // Respond to button click
> >>              }
> >>          });
> >>      }
> >>  }
> >>
> >> Using this approach, the updated my_box_pane.wtkx would look like this:
> >>
> >> my_box_pane.wtkx:
> >>
> >>  <foo:MyBoxPane orientation="vertical"
> >>      xmlns:wtkx="http://pivot.apache.org/wtkx"
> >>      xmlns:foo="com.foo"
> >>      xmlns="org.apache.pivot.wtk">
> >>      <PushButton wtkx:id="myButton" buttonData="Click Me"/>
> >>  </foo:MyBoxPane>
> >>
> >> Once WTKXSerializer is done processing foo:MyBoxPane, it sees that it
> >> implements Bindable and bind()s to it. It then calls initialize() to
> allow
> >> the class to register event listeners and perform any other required
> >> initialization tasks.
> >>
> >> This is a late-breaking change for 1.4, so please let me know ASAP if
> you
> >> have any questions or concerns.
> >>
> >> G
> >>
> >>
>
>

Re: svn commit: r894751

Posted by Greg Brown <gk...@mac.com>.
I don't believe Flex provides an "uninitialize" event. The events in the component lifecycle appear to relate to component setup, not teardown:

http://livedocs.adobe.com/flex/3/html/help.html?content=components_06.html

However, I just used Flex as an example to highlight a shortcoming of Pivot (i.e. that it was not easy to add logic defined in Java to nested includes). Adding the initialize() method is simply an attempt to resolve that shortcoming, not necessarily to mimic Flex. For example, rather than adding a "pre-initialize" event, you could put that logic in your class's constructor.

So, it isn't really accurate to view the creation of the Bindable interface as a first step at creating a more robust lifecycle model. It is simply a way to help bridge the gap between WTKX and Java and make it easier to build real-world applications in Pivot.


On Dec 31, 2009, at 3:15 AM, Todd Volkert wrote:

> I hope I'm not being presumptuous, but I think what Michael might be getting
> at is "is initialize() is the lifecycle method in which I add my event
> listeners, where's the corresponding lifecycle method in which I remove
> those event listeners?"  I'm not familiar with Flex's component lifecycle,
> but if this is indeed what you're thinking Michael, then I'd offer that
> initialize only means it's been processed by the serializer and that after
> that point, it's up to the app to know when the component can safely be
> "un-wired".
> 
> -T
> 
> On Wed, Dec 30, 2009 at 9:30 PM, Greg Brown <gk...@mac.com> wrote:
> 
>> Listeners can be removed by calling the remove() method on the listener
>> list, similar to Swing and WPF.
>> 
>> On Dec 30, 2009, at 9:26 PM, Michael Bushe wrote:
>> 
>>> Greg,
>>> 
>>> How/when can event listeners be removed (to avoid "memory
>> leaks"/"loitering
>>> objects")?  Flex has a robust component lifecycle, I don't remember Pivot
>>> having a component lifecycle model at all (and neither does Swing, except
>>> for Window, you have to bolt it on yourself).  I think I'd rather see the
>>> whole model at once, I suppose in 1.5.
>>> 
>>> I'm a HUGE fan of what you are trying to do, but maybe it should wait?
>>> OTOH, you know you are going to have initialize(), maybe that's a good
>>> start.  On the third hand, if you add preInitialize() later (like Flex),
>>> then existing initialize() calls aren't broken exactly, but when things
>>> happen may shift and be a surprise.
>>> 
>>> Michael Bushe
>>> Software Architect/Developer
>>> michael@bushe.com
>>> www.bushe.com
>>> 
>>> 
>>> On Wed, Dec 30, 2009 at 9:14 PM, Greg Brown <gk...@mac.com> wrote:
>>> 
>>>> FYI, though it wasn't mentioned in the commit message, this change also
>>>> included a minor addition/change to the org.apache.pivot.wtkx package.
>> This
>>>> change is relatively insubstantial but should actually have a
>> significant
>>>> impact on "real" application development.
>>>> 
>>>> Some background: In Flex, MXML files are compiled to classes. So, this
>> file
>>>> generates a class named MyVBox:
>>>> 
>>>> MyVBox.mxml:
>>>> 
>>>> <mx:VBox initialize="onInitialize()"
>>>>     xmlns:mx="http://www.adobe.com/2006/mxml">
>>>>     <mx:Script>
>>>>     public function onInitialize():void {
>>>>         // Wire up event handlers, etc.
>>>>     }
>>>> 
>>>>     public function onMyButtonClick():void {
>>>>         // Respond to button click
>>>>     }
>>>>     </mx:Script>
>>>> 
>>>>     <mx:Button id="myButton" label="Click Me"
>> click="onMyButtonClick()"/>
>>>> </mx:VBox>
>>>> 
>>>> I can then use that class as a component in other MXML files (for
>> example,
>>>> I could add it to a tab pane, or "TabNavigator" in Flex).
>>>> 
>>>> In Pivot, something similar could be done with the following WTKX:
>>>> 
>>>> my_box_pane.wtkx:
>>>> 
>>>> <BoxPane orientation="vertical"
>>>>     xmlns:wtkx="http://pivot.apache.org/wtkx"
>>>>     xmlns="org.apache.pivot.wtk">
>>>>     <wtkx:script>
>>>>     function myButtonClicked() {
>>>>         // Respond to button click
>>>>     }
>>>>     </wtkx:script>
>>>> 
>>>>     <PushButton wtkx:id="myButton" buttonData="Click Me"
>>>>         ButtonPressListener.buttonPressed="myButtonClicked()"/>
>>>> </BoxPane>
>>>> 
>>>> We can then include my_box_pane.wtkx into a TabPane declared in another
>>>> WTKX file. However, Pivot didn't have an equivalent of onInitialize().
>> If
>>>> the root element is a Window, we could listen for windowOpened(), but
>>>> otherwise we're stuck.
>>>> 
>>>> Also, it becomes more complex when we want to associate Java code with
>> WTKX
>>>> includes, rather than putting the logic in script. This is something any
>>>> non-trivial application is going to want to do, and Pivot didn't provide
>> an
>>>> easy way to do it. The change I checked in attempts to solve these two
>>>> problems. We can't use WTKX to define new classes, but we can use WTKX
>> to
>>>> instantiate classes we have defined elsewhere. For example:
>>>> 
>>>> MyBoxPane.java:
>>>> 
>>>> public class MyBoxPane extends BoxPane implements Bindable {
>>>>     @WTKX private PushButton myButton = null;
>>>> 
>>>>     public MyBoxPane() {
>>>>         super(Orientation.VERTICAL);
>>>>     }
>>>> 
>>>>     @Override
>>>>     public void initialize() {
>>>>         myButton.getButtonPressListeners().add(new
>> ButtonPressListener()
>>>> {
>>>>             public void buttonPressed(Button button) {
>>>>                 // Respond to button click
>>>>             }
>>>>         });
>>>>     }
>>>> }
>>>> 
>>>> Using this approach, the updated my_box_pane.wtkx would look like this:
>>>> 
>>>> my_box_pane.wtkx:
>>>> 
>>>> <foo:MyBoxPane orientation="vertical"
>>>>     xmlns:wtkx="http://pivot.apache.org/wtkx"
>>>>     xmlns:foo="com.foo"
>>>>     xmlns="org.apache.pivot.wtk">
>>>>     <PushButton wtkx:id="myButton" buttonData="Click Me"/>
>>>> </foo:MyBoxPane>
>>>> 
>>>> Once WTKXSerializer is done processing foo:MyBoxPane, it sees that it
>>>> implements Bindable and bind()s to it. It then calls initialize() to
>> allow
>>>> the class to register event listeners and perform any other required
>>>> initialization tasks.
>>>> 
>>>> This is a late-breaking change for 1.4, so please let me know ASAP if
>> you
>>>> have any questions or concerns.
>>>> 
>>>> G
>>>> 
>>>> 
>> 
>> 


Re: svn commit: r894751

Posted by Todd Volkert <tv...@gmail.com>.
I hope I'm not being presumptuous, but I think what Michael might be getting
at is "is initialize() is the lifecycle method in which I add my event
listeners, where's the corresponding lifecycle method in which I remove
those event listeners?"  I'm not familiar with Flex's component lifecycle,
but if this is indeed what you're thinking Michael, then I'd offer that
initialize only means it's been processed by the serializer and that after
that point, it's up to the app to know when the component can safely be
"un-wired".

-T

On Wed, Dec 30, 2009 at 9:30 PM, Greg Brown <gk...@mac.com> wrote:

> Listeners can be removed by calling the remove() method on the listener
> list, similar to Swing and WPF.
>
> On Dec 30, 2009, at 9:26 PM, Michael Bushe wrote:
>
> > Greg,
> >
> > How/when can event listeners be removed (to avoid "memory
> leaks"/"loitering
> > objects")?  Flex has a robust component lifecycle, I don't remember Pivot
> > having a component lifecycle model at all (and neither does Swing, except
> > for Window, you have to bolt it on yourself).  I think I'd rather see the
> > whole model at once, I suppose in 1.5.
> >
> > I'm a HUGE fan of what you are trying to do, but maybe it should wait?
> > OTOH, you know you are going to have initialize(), maybe that's a good
> > start.  On the third hand, if you add preInitialize() later (like Flex),
> > then existing initialize() calls aren't broken exactly, but when things
> > happen may shift and be a surprise.
> >
> > Michael Bushe
> > Software Architect/Developer
> > michael@bushe.com
> > www.bushe.com
> >
> >
> > On Wed, Dec 30, 2009 at 9:14 PM, Greg Brown <gk...@mac.com> wrote:
> >
> >> FYI, though it wasn't mentioned in the commit message, this change also
> >> included a minor addition/change to the org.apache.pivot.wtkx package.
> This
> >> change is relatively insubstantial but should actually have a
> significant
> >> impact on "real" application development.
> >>
> >> Some background: In Flex, MXML files are compiled to classes. So, this
> file
> >> generates a class named MyVBox:
> >>
> >> MyVBox.mxml:
> >>
> >>  <mx:VBox initialize="onInitialize()"
> >>      xmlns:mx="http://www.adobe.com/2006/mxml">
> >>      <mx:Script>
> >>      public function onInitialize():void {
> >>          // Wire up event handlers, etc.
> >>      }
> >>
> >>      public function onMyButtonClick():void {
> >>          // Respond to button click
> >>      }
> >>      </mx:Script>
> >>
> >>      <mx:Button id="myButton" label="Click Me"
> click="onMyButtonClick()"/>
> >>  </mx:VBox>
> >>
> >> I can then use that class as a component in other MXML files (for
> example,
> >> I could add it to a tab pane, or "TabNavigator" in Flex).
> >>
> >> In Pivot, something similar could be done with the following WTKX:
> >>
> >> my_box_pane.wtkx:
> >>
> >>  <BoxPane orientation="vertical"
> >>      xmlns:wtkx="http://pivot.apache.org/wtkx"
> >>      xmlns="org.apache.pivot.wtk">
> >>      <wtkx:script>
> >>      function myButtonClicked() {
> >>          // Respond to button click
> >>      }
> >>      </wtkx:script>
> >>
> >>      <PushButton wtkx:id="myButton" buttonData="Click Me"
> >>          ButtonPressListener.buttonPressed="myButtonClicked()"/>
> >>  </BoxPane>
> >>
> >> We can then include my_box_pane.wtkx into a TabPane declared in another
> >> WTKX file. However, Pivot didn't have an equivalent of onInitialize().
> If
> >> the root element is a Window, we could listen for windowOpened(), but
> >> otherwise we're stuck.
> >>
> >> Also, it becomes more complex when we want to associate Java code with
> WTKX
> >> includes, rather than putting the logic in script. This is something any
> >> non-trivial application is going to want to do, and Pivot didn't provide
> an
> >> easy way to do it. The change I checked in attempts to solve these two
> >> problems. We can't use WTKX to define new classes, but we can use WTKX
> to
> >> instantiate classes we have defined elsewhere. For example:
> >>
> >> MyBoxPane.java:
> >>
> >>  public class MyBoxPane extends BoxPane implements Bindable {
> >>      @WTKX private PushButton myButton = null;
> >>
> >>      public MyBoxPane() {
> >>          super(Orientation.VERTICAL);
> >>      }
> >>
> >>      @Override
> >>      public void initialize() {
> >>          myButton.getButtonPressListeners().add(new
> ButtonPressListener()
> >> {
> >>              public void buttonPressed(Button button) {
> >>                  // Respond to button click
> >>              }
> >>          });
> >>      }
> >>  }
> >>
> >> Using this approach, the updated my_box_pane.wtkx would look like this:
> >>
> >> my_box_pane.wtkx:
> >>
> >>  <foo:MyBoxPane orientation="vertical"
> >>      xmlns:wtkx="http://pivot.apache.org/wtkx"
> >>      xmlns:foo="com.foo"
> >>      xmlns="org.apache.pivot.wtk">
> >>      <PushButton wtkx:id="myButton" buttonData="Click Me"/>
> >>  </foo:MyBoxPane>
> >>
> >> Once WTKXSerializer is done processing foo:MyBoxPane, it sees that it
> >> implements Bindable and bind()s to it. It then calls initialize() to
> allow
> >> the class to register event listeners and perform any other required
> >> initialization tasks.
> >>
> >> This is a late-breaking change for 1.4, so please let me know ASAP if
> you
> >> have any questions or concerns.
> >>
> >> G
> >>
> >>
>
>

Re: svn commit: r894751

Posted by Greg Brown <gk...@mac.com>.
Listeners can be removed by calling the remove() method on the listener list, similar to Swing and WPF.

On Dec 30, 2009, at 9:26 PM, Michael Bushe wrote:

> Greg,
> 
> How/when can event listeners be removed (to avoid "memory leaks"/"loitering
> objects")?  Flex has a robust component lifecycle, I don't remember Pivot
> having a component lifecycle model at all (and neither does Swing, except
> for Window, you have to bolt it on yourself).  I think I'd rather see the
> whole model at once, I suppose in 1.5.
> 
> I'm a HUGE fan of what you are trying to do, but maybe it should wait?
> OTOH, you know you are going to have initialize(), maybe that's a good
> start.  On the third hand, if you add preInitialize() later (like Flex),
> then existing initialize() calls aren't broken exactly, but when things
> happen may shift and be a surprise.
> 
> Michael Bushe
> Software Architect/Developer
> michael@bushe.com
> www.bushe.com
> 
> 
> On Wed, Dec 30, 2009 at 9:14 PM, Greg Brown <gk...@mac.com> wrote:
> 
>> FYI, though it wasn't mentioned in the commit message, this change also
>> included a minor addition/change to the org.apache.pivot.wtkx package. This
>> change is relatively insubstantial but should actually have a significant
>> impact on "real" application development.
>> 
>> Some background: In Flex, MXML files are compiled to classes. So, this file
>> generates a class named MyVBox:
>> 
>> MyVBox.mxml:
>> 
>>  <mx:VBox initialize="onInitialize()"
>>      xmlns:mx="http://www.adobe.com/2006/mxml">
>>      <mx:Script>
>>      public function onInitialize():void {
>>          // Wire up event handlers, etc.
>>      }
>> 
>>      public function onMyButtonClick():void {
>>          // Respond to button click
>>      }
>>      </mx:Script>
>> 
>>      <mx:Button id="myButton" label="Click Me" click="onMyButtonClick()"/>
>>  </mx:VBox>
>> 
>> I can then use that class as a component in other MXML files (for example,
>> I could add it to a tab pane, or "TabNavigator" in Flex).
>> 
>> In Pivot, something similar could be done with the following WTKX:
>> 
>> my_box_pane.wtkx:
>> 
>>  <BoxPane orientation="vertical"
>>      xmlns:wtkx="http://pivot.apache.org/wtkx"
>>      xmlns="org.apache.pivot.wtk">
>>      <wtkx:script>
>>      function myButtonClicked() {
>>          // Respond to button click
>>      }
>>      </wtkx:script>
>> 
>>      <PushButton wtkx:id="myButton" buttonData="Click Me"
>>          ButtonPressListener.buttonPressed="myButtonClicked()"/>
>>  </BoxPane>
>> 
>> We can then include my_box_pane.wtkx into a TabPane declared in another
>> WTKX file. However, Pivot didn't have an equivalent of onInitialize(). If
>> the root element is a Window, we could listen for windowOpened(), but
>> otherwise we're stuck.
>> 
>> Also, it becomes more complex when we want to associate Java code with WTKX
>> includes, rather than putting the logic in script. This is something any
>> non-trivial application is going to want to do, and Pivot didn't provide an
>> easy way to do it. The change I checked in attempts to solve these two
>> problems. We can't use WTKX to define new classes, but we can use WTKX to
>> instantiate classes we have defined elsewhere. For example:
>> 
>> MyBoxPane.java:
>> 
>>  public class MyBoxPane extends BoxPane implements Bindable {
>>      @WTKX private PushButton myButton = null;
>> 
>>      public MyBoxPane() {
>>          super(Orientation.VERTICAL);
>>      }
>> 
>>      @Override
>>      public void initialize() {
>>          myButton.getButtonPressListeners().add(new ButtonPressListener()
>> {
>>              public void buttonPressed(Button button) {
>>                  // Respond to button click
>>              }
>>          });
>>      }
>>  }
>> 
>> Using this approach, the updated my_box_pane.wtkx would look like this:
>> 
>> my_box_pane.wtkx:
>> 
>>  <foo:MyBoxPane orientation="vertical"
>>      xmlns:wtkx="http://pivot.apache.org/wtkx"
>>      xmlns:foo="com.foo"
>>      xmlns="org.apache.pivot.wtk">
>>      <PushButton wtkx:id="myButton" buttonData="Click Me"/>
>>  </foo:MyBoxPane>
>> 
>> Once WTKXSerializer is done processing foo:MyBoxPane, it sees that it
>> implements Bindable and bind()s to it. It then calls initialize() to allow
>> the class to register event listeners and perform any other required
>> initialization tasks.
>> 
>> This is a late-breaking change for 1.4, so please let me know ASAP if you
>> have any questions or concerns.
>> 
>> G
>> 
>> 


Re: svn commit: r894751

Posted by Michael Bushe <mi...@bushe.com>.
Greg,

How/when can event listeners be removed (to avoid "memory leaks"/"loitering
objects")?  Flex has a robust component lifecycle, I don't remember Pivot
having a component lifecycle model at all (and neither does Swing, except
for Window, you have to bolt it on yourself).  I think I'd rather see the
whole model at once, I suppose in 1.5.

I'm a HUGE fan of what you are trying to do, but maybe it should wait?
OTOH, you know you are going to have initialize(), maybe that's a good
start.  On the third hand, if you add preInitialize() later (like Flex),
then existing initialize() calls aren't broken exactly, but when things
happen may shift and be a surprise.

Michael Bushe
Software Architect/Developer
michael@bushe.com
www.bushe.com


On Wed, Dec 30, 2009 at 9:14 PM, Greg Brown <gk...@mac.com> wrote:

> FYI, though it wasn't mentioned in the commit message, this change also
> included a minor addition/change to the org.apache.pivot.wtkx package. This
> change is relatively insubstantial but should actually have a significant
> impact on "real" application development.
>
> Some background: In Flex, MXML files are compiled to classes. So, this file
> generates a class named MyVBox:
>
> MyVBox.mxml:
>
>   <mx:VBox initialize="onInitialize()"
>       xmlns:mx="http://www.adobe.com/2006/mxml">
>       <mx:Script>
>       public function onInitialize():void {
>           // Wire up event handlers, etc.
>       }
>
>       public function onMyButtonClick():void {
>           // Respond to button click
>       }
>       </mx:Script>
>
>       <mx:Button id="myButton" label="Click Me" click="onMyButtonClick()"/>
>   </mx:VBox>
>
> I can then use that class as a component in other MXML files (for example,
> I could add it to a tab pane, or "TabNavigator" in Flex).
>
> In Pivot, something similar could be done with the following WTKX:
>
> my_box_pane.wtkx:
>
>   <BoxPane orientation="vertical"
>       xmlns:wtkx="http://pivot.apache.org/wtkx"
>       xmlns="org.apache.pivot.wtk">
>       <wtkx:script>
>       function myButtonClicked() {
>           // Respond to button click
>       }
>       </wtkx:script>
>
>       <PushButton wtkx:id="myButton" buttonData="Click Me"
>           ButtonPressListener.buttonPressed="myButtonClicked()"/>
>   </BoxPane>
>
> We can then include my_box_pane.wtkx into a TabPane declared in another
> WTKX file. However, Pivot didn't have an equivalent of onInitialize(). If
> the root element is a Window, we could listen for windowOpened(), but
> otherwise we're stuck.
>
> Also, it becomes more complex when we want to associate Java code with WTKX
> includes, rather than putting the logic in script. This is something any
> non-trivial application is going to want to do, and Pivot didn't provide an
> easy way to do it. The change I checked in attempts to solve these two
> problems. We can't use WTKX to define new classes, but we can use WTKX to
> instantiate classes we have defined elsewhere. For example:
>
> MyBoxPane.java:
>
>   public class MyBoxPane extends BoxPane implements Bindable {
>       @WTKX private PushButton myButton = null;
>
>       public MyBoxPane() {
>           super(Orientation.VERTICAL);
>       }
>
>       @Override
>       public void initialize() {
>           myButton.getButtonPressListeners().add(new ButtonPressListener()
> {
>               public void buttonPressed(Button button) {
>                   // Respond to button click
>               }
>           });
>       }
>   }
>
> Using this approach, the updated my_box_pane.wtkx would look like this:
>
> my_box_pane.wtkx:
>
>   <foo:MyBoxPane orientation="vertical"
>       xmlns:wtkx="http://pivot.apache.org/wtkx"
>       xmlns:foo="com.foo"
>       xmlns="org.apache.pivot.wtk">
>       <PushButton wtkx:id="myButton" buttonData="Click Me"/>
>   </foo:MyBoxPane>
>
> Once WTKXSerializer is done processing foo:MyBoxPane, it sees that it
> implements Bindable and bind()s to it. It then calls initialize() to allow
> the class to register event listeners and perform any other required
> initialization tasks.
>
> This is a late-breaking change for 1.4, so please let me know ASAP if you
> have any questions or concerns.
>
> G
>
>

Fwd: svn commit: r894751

Posted by Greg Brown <gk...@mac.com>.
FYI, though it wasn't mentioned in the commit message, this change also included a minor addition/change to the org.apache.pivot.wtkx package. This change is relatively insubstantial but should actually have a significant impact on "real" application development. 

Some background: In Flex, MXML files are compiled to classes. So, this file generates a class named MyVBox:

MyVBox.mxml:

   <mx:VBox initialize="onInitialize()"
       xmlns:mx="http://www.adobe.com/2006/mxml">
       <mx:Script>
       public function onInitialize():void {
           // Wire up event handlers, etc.
       }

       public function onMyButtonClick():void {
           // Respond to button click
       }
       </mx:Script>

       <mx:Button id="myButton" label="Click Me" click="onMyButtonClick()"/>
   </mx:VBox>

I can then use that class as a component in other MXML files (for example, I could add it to a tab pane, or "TabNavigator" in Flex).

In Pivot, something similar could be done with the following WTKX:

my_box_pane.wtkx:

   <BoxPane orientation="vertical"
       xmlns:wtkx="http://pivot.apache.org/wtkx"
       xmlns="org.apache.pivot.wtk">
       <wtkx:script>
       function myButtonClicked() {
           // Respond to button click
       }
       </wtkx:script>

       <PushButton wtkx:id="myButton" buttonData="Click Me" 
           ButtonPressListener.buttonPressed="myButtonClicked()"/>
   </BoxPane>

We can then include my_box_pane.wtkx into a TabPane declared in another WTKX file. However, Pivot didn't have an equivalent of onInitialize(). If the root element is a Window, we could listen for windowOpened(), but otherwise we're stuck.

Also, it becomes more complex when we want to associate Java code with WTKX includes, rather than putting the logic in script. This is something any non-trivial application is going to want to do, and Pivot didn't provide an easy way to do it. The change I checked in attempts to solve these two problems. We can't use WTKX to define new classes, but we can use WTKX to instantiate classes we have defined elsewhere. For example:

MyBoxPane.java:

   public class MyBoxPane extends BoxPane implements Bindable {
       @WTKX private PushButton myButton = null;

       public MyBoxPane() {
           super(Orientation.VERTICAL);
       }

       @Override
       public void initialize() {
           myButton.getButtonPressListeners().add(new ButtonPressListener() {
               public void buttonPressed(Button button) {
                   // Respond to button click
               }
           });
       }
   }

Using this approach, the updated my_box_pane.wtkx would look like this:

my_box_pane.wtkx:

   <foo:MyBoxPane orientation="vertical"
       xmlns:wtkx="http://pivot.apache.org/wtkx"
       xmlns:foo="com.foo"
       xmlns="org.apache.pivot.wtk">
       <PushButton wtkx:id="myButton" buttonData="Click Me"/>
   </foo:MyBoxPane>

Once WTKXSerializer is done processing foo:MyBoxPane, it sees that it implements Bindable and bind()s to it. It then calls initialize() to allow the class to register event listeners and perform any other required initialization tasks.

This is a late-breaking change for 1.4, so please let me know ASAP if you have any questions or concerns.

G