Jimmy wrote:
Thanks for the pointer Carsten. I finally got into it and thought I
figured it out but still haven't been able to get it to work. Right now
I'm trying to change my DispatchProvider, since all I'm trying to
control are my own buttons.
1.) I add a statuslistener when my button "Lesson" gets dispatched,
which I can only do in the queryDispatch method:
public XDispatch queryDispatch(URL arg0, String arg1, int arg2) {
XDispatch xRet = null;
if (arg0.Protocol.compareTo("org.openoffice.addon.Editor:") == 0) {
if (arg0.Path.compareTo("Lesson") == 0) {
xRet = this;
state1 = new StatusListener();
xRet.addStatusListener(state1, arg0);
}
}
return xRet;
}
Hi Jimmy,
I think you misunderstood me. The user interface element uses the
dispatch object (which you provide with "return xRet") to add ITSELF as
listener. Therefore I don't understand your new StatusListener() and
addStatusListener statements.
1. A user interface element (implements XStatusListener) knows a command URL
2. It uses interface XDispatchProvider to query for a dispatch object
3. A dispatch provider returns a dispatch object (implements XDispatch)
for the command URL
4. The user interface element register itself as listener at the
dispatch object!
5. The dispatch object must notify status changes via statusChanged()
6. The user interface element changes it state according to the new status.
The dispatch object has to implement XDispatch. See the following code
snippet which show a typical implementation for add/removeStatusListener.
void SAL_CALL BaseDispatch::addStatusListener( const Reference<
XStatusListener >& xControl, const URL& aURL ) throw (RuntimeException)
{
if ( !aURL.Protocol.compareToAscii("vnd.sun.search:") )
{
if( !aURL.Path.compareToAscii("command!" ) )
{
::com::sun::star::frame::FeatureStateEvent aEvent;
aEvent.FeatureURL = aURL;
aEvent.Source = (::com::sun::star::frame::XDispatch*)this;
aEvent.IsEnabled = sal_True;
aEvent.Requery = sal_False;
sal_Bool bChecked = sal_True;
aEvent.State <<= bChecked;
xControl->statusChanged( aEvent );
}
aListenerHelper.AddListener( mxFrame, xControl, aURL.Path );
}
}
void SAL_CALL BaseDispatch::removeStatusListener( const Reference<
XStatusListener >& xControl, const URL& aURL ) throw (RuntimeException)
{
aListenerHelper.RemoveListener( mxFrame, xControl, aURL.Path );
}
2.) Now I try to send a FeatureStateEvent to this listener which should
disable the button on clicking it. Nothing happens although the
statusChanged method gets called, the button stays enabled.
public void dispatch(URL arg0, PropertyValue[] arg1) {
if (arg0.Path.compareTo("ElmlLesson") == 0) {
FeatureStateEvent aState = new
FeatureStateEvent();
aState.FeatureURL = arg0;
aState.IsEnabled = false;
aState.State = Boolean.FALSE;
state1.statusChanged(aState);
}
I think it should be clear that your implementation cannot work. The
user interface elements needs a statusChanged() call, but currently you
call statusChanged() on a object you created yourself. Please implement
the whole XDispatch interface (including add/removeStatusListener) and
it shall work.
Regards,
Carsten
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]