incubator-ooo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ariel Constenla-Haile <arie...@apache.org>
Subject Re: [EXT] disable/enable toolbar functions
Date Wed, 25 Jan 2012 01:04:35 GMT
Hi Fabian,

On Wed, Jan 25, 2012 at 12:51:39AM +0100, fabian wrote:
> Hi Ariel,
> 
> thanks again for helping me out!
> 
> I did what you described and tried to adapt the cpp example.  my
> extended toolbar has 3 controls (ImageButtons):  control1, control2,
> control3 Each  registers at startup by calling addStatusListener(
> aURL, aListener). 
> 
> Don't I need to put each of these listeners in a collection to be
> later able to send a event to the according control?

that's what I meant. When the control wants to register itself as
a status listener, add it to a collection and send it an status update.
When the listener wants to stop listening for updates, remove it from
the collection.

addStatusListener -> add it to the collection and send an status update
to this control

removeStatusListener -> remove it from the collection


Then, when you need to update the feature state, you have to loop
through the listeners collection and send an statusChanged to each
element in the collection.


> I am only able to safe a reference to the XStatusListener which was
> provided by the last call of addStatusListener(). I don't seem to
> understand why I can't keep a reference to the XStatusListeners of the

do you mean by holding a reference in a member variable?
This is not possible, among other reasons, because it violates the
notion of a listener that adds and *removes* itself at will. Besides,
several listener can register themselves, so you need a collection.


> previous calls of addStatusListener() ( has each control its own
> thread and the calls happen in parallel ?) If I do something like
> Collection.put(xController) each time addStatusListener is called, the
> collection will only contain one element in the end.

this shouldn't be the case. It looks like an issue with your collection.
Depending on how you implemented the XDispatchProvider you may need to
implement a simple listeners container or a complex map of URL-key with
listeners-contaniner-value.


> What I try then is to click on controll1 in my toolbar. This triggers
> in the dispatch method the code above to disable control2. But instead
> of control2 I can only use the XStatusListener of the last call of
> addStatusListener().
> 
> As a result control1 gets disabled instead control2 as I would expect.

It seems you are using the same dispatch object instance for different
commands, if so, you need a map collection:

key        value
control1 - listeners collection
control2 - listeners collection
control3 - listeners collection

The key is a string, representing the URL.Complete or URL.Path.
Something similar is done in the C++ example.

When you want to update the status of control2, you get the listeners
collection from the map and send an statusChanged to each listener in
it.

> So to me it seems that my problem is that I can't keep the references
> to the according XStatusListener.
> 
> I hope this wasn't too confusing and makes any sense to you, thanks
> again for the help!

It looks as if you had some issues translating the code from C++ to
Java, on the other hand the C++ has some issues if you want to implement
it in a real-world use case (where you send status updates according to
the current selection, etc).
I see if I can write some simple example, real-world oriented.


Regards
-- 
Ariel Constenla-Haile
La Plata, Argentina

Mime
View raw message