incubator-ooo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ariel Constenla-Haile <>
Subject Re: [EXT] disable/enable toolbar functions
Date Mon, 23 Jan 2012 20:26:18 GMT
Hi Fabian,

On Mon, Jan 23, 2012 at 09:51:27AM +0100, fabian wrote:
> Hi, 
> I am trying to disable/enable toolbar buttons in my java oo-extension.

I guess you're using the so called "Complex Toolbar Controls" feature,
aren't you?

> I managed to use the addStatusListener method to use an additional
> dropdownbutton and know how to enable/disable buttons at startup.  My
> problem is that I can't safe a reference to
> xControl to enable/disable a button
> at wish, since the reference is set back to null after
> xControl.statusChanged() was called.  But looking at the c++ example
> of the SDK,  keeping a copy of xControl is what I have to do to recall
> statusChanged.
> Can someone point me to the solution?  Thanks!

The toolbar control registers itself as listener at the Dispatch object
you return in queryDispatch in order to get status updates. This is done
in the Dispatch object's addStatusListener().

Your Dispatch object should have a collection of listeners:

* when addStatusListener() is invoked, the Dispatch object should:
  * add the listener (the toolbar control) to the collection
  * send to this listener an status update invoking the listener's
    statusChanges() method

* when removeStatusListener() is invoked, the Dispatch object should
  remove the listener from the collection

To Enable/Disable a toolbar control is simply sending it a 
FeatureStateEvent with IsEnabled set to false.

Now let's suppose that your toolbar control provides functionality for
drawing shapes; so you want it enabled only when a shape is selected.
You will have to implement an XSelectionChangeListener that, when the
selection changes:

* if the selected object is a drawing shape, send a feature update to
  all the status listeners in the collection that were registered for
  the command URL. Here FeatureStateEvent.IsEnabled = true

* if the selected object is not a drawing shape, then you want to
  disable your toolbar control; just send an status update to all the
  status listeners in the collection with IsEnable set to false.

In general this is how context-sensitivity is implemented by sending
status updates to the user interface element, then the UI element
updates its representation to reflect the feature state.

Ariel Constenla-Haile
La Plata, Argentina

View raw message