You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by Michael Allman <ms...@allman.ms> on 2010/07/16 08:13:00 UTC

messages that ascend the containment hierarchy

Is there a means in Pivot for a component to send a generic message to its 
ancestors (aside from manually walking the hierarchy and calling methods 
on each parent in turn)?  The prototypical example I'm thinking of here is 
event bubbling.

Cheers,

Michael

Re: messages that ascend the containment hierarchy

Posted by Clint Gilbert <cl...@hms.harvard.edu>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Oh cool, I didn't know that API existed.

Greg Brown wrote:
> Ah, OK. If you are talking about intra-application message passing, Pivot actually has a built-in API for that. See the subscribe(), unsubscribe(), and sendMessage() methods of ApplicationContext (in Pivot 2.0, these live in org.apache.pivot.util.MessageBus).
> 
> On Jul 16, 2010, at 6:34 PM, Clint Gilbert wrote:
> 
> I don't know your exact scenario, but I've had good luck in my pivot app
> using something like EventBus - basically an publish/subscribe system
> for events - for invoking code on sibling components.  There's even a
> Pivot-centric tutorial with lots and lots of examples:
> 
> http://www.eventbus.org/confluence/pages/viewpage.action?pageId=819222
> 
> Michael Allman wrote:
>>>> Is there a means in Pivot for a component to send a generic message to its 
>>>> ancestors (aside from manually walking the hierarchy and calling methods 
>>>> on each parent in turn)?  The prototypical example I'm thinking of here is 
>>>> event bubbling.
>>>>
>>>> Cheers,
>>>>
>>>> Michael
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkxA5eUACgkQ5IyIbnMUeTsRcQCfdYvcg+HME3YEQ1pp5RrlyCfi
pywAnifiIubrF5TXWrUtn9vq+vWSeOLW
=ep+f
-----END PGP SIGNATURE-----

Re: messages that ascend the containment hierarchy

Posted by Greg Brown <gk...@mac.com>.
> I did.  That system supports application global events, no?  

Yes.

> I want to use hierarchy-scoped events.  If I send a "refresh the data model" or "follow this link" event, I don't want notify every possible listener in the application.  I want to notify an ancestor.

It's up to your application to wire the listeners up correctly. If you only want ancestors to listen for a particular message, register only those instances as listeners for a particular message type.

>  For example, I may have n data models.  Or different components may have different interpretations of "follow this link".


Messages are just instances of an arbitrary class. If you need to filter them based on some criteria, you can simply add the necessary properties to your class (e.g. "sourceComponent").


Re: messages that ascend the containment hierarchy

Posted by Michael Allman <ms...@allman.ms>.
On Mon, 19 Jul 2010, Greg Brown wrote:

>> I think of these kinds of events as a part of the public interface of a 
>> component.  Listeners respond to events they're interested in.  One 
>> such event may be---to use a very verbose and impractical name---"add a 
>> new address form".  Or "refresh this data model".  Or "follow this 
>> link". Usually these events are dispatched by a push button, but 
>> sometimes they can be dispatched from selections in a list or table, or 
>> selection made with a radio button or check buttons.
>
> These are exactly the kind of events that EventBus and Pivot's pub/sub 
> API are intended to support. I'd suggest taking a look at one of those - 
> you may find a simpler solution to your problem.

I did.  That system supports application global events, no?  I want to use 
hierarchy-scoped events.  If I send a "refresh the data model" or "follow 
this link" event, I don't want notify every possible listener in the 
application.  I want to notify an ancestor.  For example, I may have n 
data models.  Or different components may have different interpretations 
of "follow this link".

Michael

Re: messages that ascend the containment hierarchy

Posted by Greg Brown <gk...@mac.com>.
> I think of these kinds of events as a part of the public interface of a component.  Listeners respond to events they're interested in.  One such event may be---to use a very verbose and impractical name---"add a new address form".  Or "refresh this data model".  Or "follow this link". Usually these events are dispatched by a push button, but sometimes they can be dispatched from selections in a list or table, or selection made with a radio button or check buttons.

These are exactly the kind of events that EventBus and Pivot's pub/sub API are intended to support. I'd suggest taking a look at one of those - you may find a simpler solution to your problem.



Re: messages that ascend the containment hierarchy

Posted by Michael Allman <ms...@allman.ms>.
On Mon, 19 Jul 2010, Greg Brown wrote:

> It can't be done without changes to the platform, since "bubbling" 
> requires invoking methods on the parent (or having the parent respond to 
> return values from methods called on the children, which is how it is 
> currently implemented).

I think this may be true, but not for reasons you're thinking of.  I store 
the dispatchers and listeners in component attributes.  The tricky part is 
getting a reference to other components for adding listeners.

> Only user interface events are bubbling (or tunneling, in the case of 
> container events). This is by design. What is the use case for bubbling 
> other types of events?

I think of these kinds of events as a part of the public interface of a 
component.  Listeners respond to events they're interested in.  One such 
event may be---to use a very verbose and impractical name---"add a new 
address form".  Or "refresh this data model".  Or "follow this link". 
Usually these events are dispatched by a push button, but sometimes they 
can be dispatched from selections in a list or table, or selection made 
with a radio button or check buttons.

Re: messages that ascend the containment hierarchy

Posted by Greg Brown <gk...@mac.com>.
It can't be done without changes to the platform, since "bubbling" requires invoking methods on the parent (or having the parent respond to return values from methods called on the children, which is how it is currently implemented).

Only user interface events are bubbling (or tunneling, in the case of container events). This is by design. What is the use case for bubbling other types of events?

On Jul 19, 2010, at 8:54 AM, Michael Allman wrote:

> Actually this isn't what I'm looking for.  I'm looking for event bubbling. Nothing too fancy.  Just bubble a message (event) up the component hierarchy allowing parent components to listen for events from their children.
> 
> I got something working on my end and I tried very, very hard to make as few changes as possible to Pivot.  I tried getting it working with none, actually, but I ended up making two changes to WTKXSerializer.  One is fairly innocuous and the other is fairly ugly.  I'm not going to go into details until I've had a chance to find a better way.
> 
> Cheers,
> 
> Michael
> 
> 
> On Fri, 16 Jul 2010, Greg Brown wrote:
> 
>> Ah, OK. If you are talking about intra-application message passing, Pivot actually has a built-in API for that. See the subscribe(), unsubscribe(), and sendMessage() methods of ApplicationContext (in Pivot 2.0, these live in org.apache.pivot.util.MessageBus).
>> 
>> On Jul 16, 2010, at 6:34 PM, Clint Gilbert wrote:
>> 
>>> -----BEGIN PGP SIGNED MESSAGE-----
>>> Hash: SHA1
>>> 
>>> I don't know your exact scenario, but I've had good luck in my pivot app
>>> using something like EventBus - basically an publish/subscribe system
>>> for events - for invoking code on sibling components.  There's even a
>>> Pivot-centric tutorial with lots and lots of examples:
>>> 
>>> http://www.eventbus.org/confluence/pages/viewpage.action?pageId=819222
>>> 
>>> Michael Allman wrote:
>>>> Is there a means in Pivot for a component to send a generic message to its
>>>> ancestors (aside from manually walking the hierarchy and calling methods
>>>> on each parent in turn)?  The prototypical example I'm thinking of here is
>>>> event bubbling.
>>>> 
>>>> Cheers,
>>>> 
>>>> Michael
>>> 
>>> -----BEGIN PGP SIGNATURE-----
>>> Version: GnuPG v1.4.9 (GNU/Linux)
>>> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>>> 
>>> iEYEARECAAYFAkxA3mQACgkQ5IyIbnMUeTsXCACdHPl9JZo2En/W/ScMm/F934mQ
>>> RYAAmQElWmB/6Agk4zIzqNEz4goqhB99
>>> =3v/w
>>> -----END PGP SIGNATURE-----
>> 


Re: messages that ascend the containment hierarchy

Posted by Michael Allman <ms...@allman.ms>.
Actually this isn't what I'm looking for.  I'm looking for event bubbling. 
Nothing too fancy.  Just bubble a message (event) up the component 
hierarchy allowing parent components to listen for events from their 
children.

I got something working on my end and I tried very, very hard to make as 
few changes as possible to Pivot.  I tried getting it working with none, 
actually, but I ended up making two changes to WTKXSerializer.  One is 
fairly innocuous and the other is fairly ugly.  I'm not going to go into 
details until I've had a chance to find a better way.

Cheers,

Michael


On Fri, 16 Jul 2010, Greg Brown wrote:

> Ah, OK. If you are talking about intra-application message passing, 
> Pivot actually has a built-in API for that. See the subscribe(), 
> unsubscribe(), and sendMessage() methods of ApplicationContext (in Pivot 
> 2.0, these live in org.apache.pivot.util.MessageBus).
>
> On Jul 16, 2010, at 6:34 PM, Clint Gilbert wrote:
>
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> I don't know your exact scenario, but I've had good luck in my pivot app
>> using something like EventBus - basically an publish/subscribe system
>> for events - for invoking code on sibling components.  There's even a
>> Pivot-centric tutorial with lots and lots of examples:
>>
>> http://www.eventbus.org/confluence/pages/viewpage.action?pageId=819222
>>
>> Michael Allman wrote:
>>> Is there a means in Pivot for a component to send a generic message to its
>>> ancestors (aside from manually walking the hierarchy and calling methods
>>> on each parent in turn)?  The prototypical example I'm thinking of here is
>>> event bubbling.
>>>
>>> Cheers,
>>>
>>> Michael
>>
>> -----BEGIN PGP SIGNATURE-----
>> Version: GnuPG v1.4.9 (GNU/Linux)
>> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>>
>> iEYEARECAAYFAkxA3mQACgkQ5IyIbnMUeTsXCACdHPl9JZo2En/W/ScMm/F934mQ
>> RYAAmQElWmB/6Agk4zIzqNEz4goqhB99
>> =3v/w
>> -----END PGP SIGNATURE-----
>

Re: messages that ascend the containment hierarchy

Posted by Greg Brown <gk...@mac.com>.
Ah, OK. If you are talking about intra-application message passing, Pivot actually has a built-in API for that. See the subscribe(), unsubscribe(), and sendMessage() methods of ApplicationContext (in Pivot 2.0, these live in org.apache.pivot.util.MessageBus).

On Jul 16, 2010, at 6:34 PM, Clint Gilbert wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> I don't know your exact scenario, but I've had good luck in my pivot app
> using something like EventBus - basically an publish/subscribe system
> for events - for invoking code on sibling components.  There's even a
> Pivot-centric tutorial with lots and lots of examples:
> 
> http://www.eventbus.org/confluence/pages/viewpage.action?pageId=819222
> 
> Michael Allman wrote:
>> Is there a means in Pivot for a component to send a generic message to its 
>> ancestors (aside from manually walking the hierarchy and calling methods 
>> on each parent in turn)?  The prototypical example I'm thinking of here is 
>> event bubbling.
>> 
>> Cheers,
>> 
>> Michael
> 
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
> 
> iEYEARECAAYFAkxA3mQACgkQ5IyIbnMUeTsXCACdHPl9JZo2En/W/ScMm/F934mQ
> RYAAmQElWmB/6Agk4zIzqNEz4goqhB99
> =3v/w
> -----END PGP SIGNATURE-----


Re: messages that ascend the containment hierarchy

Posted by Clint Gilbert <cl...@hms.harvard.edu>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I don't know your exact scenario, but I've had good luck in my pivot app
using something like EventBus - basically an publish/subscribe system
for events - for invoking code on sibling components.  There's even a
Pivot-centric tutorial with lots and lots of examples:

http://www.eventbus.org/confluence/pages/viewpage.action?pageId=819222

Michael Allman wrote:
> Is there a means in Pivot for a component to send a generic message to its 
> ancestors (aside from manually walking the hierarchy and calling methods 
> on each parent in turn)?  The prototypical example I'm thinking of here is 
> event bubbling.
> 
> Cheers,
> 
> Michael

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkxA3mQACgkQ5IyIbnMUeTsXCACdHPl9JZo2En/W/ScMm/F934mQ
RYAAmQElWmB/6Agk4zIzqNEz4goqhB99
=3v/w
-----END PGP SIGNATURE-----

Re: messages that ascend the containment hierarchy

Posted by Michael Allman <ms...@allman.ms>.
Some listener method.

Michael


On Fri, 16 Jul 2010, Greg Brown wrote:

> The only bubbling events in Pivot are user input events. But what method would you want to call on elements of the parent tree? It can't be an application-specific method, unless all of your containers implement some application-specific interface.
>
> On Jul 16, 2010, at 2:13 AM, Michael Allman wrote:
>
>> Is there a means in Pivot for a component to send a generic message to its ancestors (aside from manually walking the hierarchy and calling methods on each parent in turn)?  The prototypical example I'm thinking of here is event bubbling.
>>
>> Cheers,
>>
>> Michael
>

Re: messages that ascend the containment hierarchy

Posted by Greg Brown <gk...@mac.com>.
The only bubbling events in Pivot are user input events. But what method would you want to call on elements of the parent tree? It can't be an application-specific method, unless all of your containers implement some application-specific interface.

On Jul 16, 2010, at 2:13 AM, Michael Allman wrote:

> Is there a means in Pivot for a component to send a generic message to its ancestors (aside from manually walking the hierarchy and calling methods on each parent in turn)?  The prototypical example I'm thinking of here is event bubbling.
> 
> Cheers,
> 
> Michael