Hi Carsten, thank you for replying.
  "The SDK examples create a installable package automatically if you build 
them 
with make."  I was not aware of this. I will try to find out.Can you please 
guide me more about it. 
   
  Also ,now i understood Function1refers to a function by name "Function1". But 
still i am not clearas to  where should i define Function1? Should i define 
Function1 inside ProtocolHandleraddon.java?  Since i am a newbie i am not clear 
with these concepts.
   
  Thank you
  With regards,
  Bharathy B
   
  

Carsten Driesner - Sun Germany - ham02 - Hamburg - Software Engineer <[EMAIL 
PROTECTED]> wrote:
  bharathy b wrote:
> Hi i tried to add a Addon to Writer using ProtocolHandlerAddon.java given in 
> the SDK . 
> ProtocolHandleraddon.java found in 
> OpenOffice.org2.0_SDK\examples\DevelopersGuide\Components\Addons\ProtocolHandlerAddon_java
>  
> The addon creates toolbar button in openoffice writer and should display a 
> message box when it is clicked. I used UNOPKG to do it instead of pkgchk. The 
> toolbar buttons appear. but they are not activated
> here are the steps i have followed ...please tell me if i have missed out 
> anything or gone wrong anywhere. 

Hi bharathy,

First of all I don't understand why you do the build by hand. The SDK 
examples create a installable package automatically if you build them 
with make. If you do it by hand there are many ways to do something wrong.

> 
> 1) compile the ProtocolHandlerAddon.java and get the 
> ProtocolHandlerAddon.class and 
> ProtocolHandlerAddon$ProtocolHandlerAddonImpl.class 
> 2) write the ProtocolHandlerAddon.uno.manifest file which Contains 
> Code: 
> RegistrationClassName:ProtocolHandlerAddon \n 
> 
> 3) Using this command i get ProtocolHandlerAddon.uno.jar file 
> Code: 
> jar cvf ProtocolHandlerAddon.uno.jar ProtocolHandlerAddon. class 
> ProtocolHandlerAddon$ProtocolHandlerAddonImpl.class 
> ProtocolHandlerAddon.uno.manifest 
> 
> 4) put the manifest.xml in a folder called META-INF. the manifest.xml is as 
> follows 
> Code: 
> 
> 
> 5) now zip the following files into ProtocolHandlerAddon.uno.zip 
> i) ProtocolHandlerAddon.uno.jar 
> which inturn contains 
> META-INF/MANIFEST.MF \n
> ProtocolHandlerAddon.class 
> ProtocolHandlerAddon$ProtocolHandlerAddonImpl.class 
> ProtocolHandlerAddon.uno.manifest 
> ii)Addons.xcu 
> iii) ProtocolHandler.xcu 
> iv) META-INF/manifest.xml 
> 6) exit OpenOffice(including Quickstart) and add the package using \n
> unopkg add ProtocolHandlerAddon.uno.zip 
> 
> Here is the ProtocolHandlerAddon.java I hav used 
> import com.sun.star.uno.XComponentContext; 
> import com.sun.star.lib.uno.helper.Factory; 
> import com.sun.star.lang.XSingleComponentFactory\n; 
> import com.sun.star.lib.uno.helper.WeakBase; 
> import com.sun.star.uno.UnoRuntime; 
> import com.sun.star.registry.XRegistryKey; 
> import com.sun.star.lang.XInitialization; 
> import com.sun.star.lang.XTypeProvider\n; 
> import com.sun.star.lang.XServiceInfo; 
> import com.sun.star.uno.Type; 
> import com.sun.star.frame.XStatusListener; 
> import com.sun.star.frame.XDispatchProvider; 
> import com.sun.star.frame.XDispatch; 
> import \ncom.sun.star.frame.XModel; 
> import com.sun.star.frame.XFrame; 
> import com.sun.star.frame.DispatchDescriptor; 
> import com.sun.star.awt.XToolkit; 
> import com.sun.star.awt.XWindowPeer; 
> import com.sun.star.awt.XMessageBox\n; 
> import com.sun.star.awt.WindowAttribute; 
> import com.sun.star.awt.WindowClass; 
> import com.sun.star.awt.WindowDescriptor; 
> import com.sun.star.awt.Rectangle; 
> 
> public class ProtocolHandlerAddon { 
> \npublic static class ProtocolHandlerAddonImpl extends WeakBase implements 
> XDispatchProvider, 
> XDispatch, 
> XInitialization, 
> XServiceInfo { 
> static private final String[] m_serviceNames \u003d { 
> "com.sun.star.frame.ProtocolHand",1] ); 
> //-->n/vnd.sun.star.uno-component;type=Java" manifest:full-path=" 
> ProtocolHandlerAddon.uno.jar"/> 
> 
> 5) now zip the following files into ProtocolHandlerAddon.uno.zip 
> i) ProtocolHandlerAddon.uno.jar 
> which inturn contains 
> META-INF/MANIFEST.MF 
> ProtocolHandlerAddon.class 
> ProtocolHandlerAddon$ProtocolHandlerAddonImpl.class 
> ProtocolHandlerAddon.uno.manifest 
> ii)Addons.xcu 
> iii) ProtocolHandler.xcu 
> iv) META-INF/manifest.xml 
> 6) exit OpenOffice(including Quickstart) and add the package using 
> unopkg add ProtocolHandlerAddon.uno.zip 
> 
> Here is the ProtocolHandlerAddon.java I hav used 
> import com.sun.star.uno.XComponentContext; 
> import com.sun.star.lib.uno.helper.Factory; 
> import com.sun.star.lang.XSingleComponentFactory ; 
> import com.sun.star.lib.uno.helper.WeakBase; 
> import com.sun.star.uno.UnoRuntime; 
> import com.sun.star.registry.XRegistryKey; 
> import com.sun.star.lang.XInitialization; 
> import com.sun.star.lang.XTypeProvider ; 
> import com.sun.star.lang.XServiceInfo; 
> import com.sun.star.uno.Type; 
> import com.sun.star.frame.XStatusListener; 
> import com.sun.star.frame.XDispatchProvider; 
> import com.sun.star.frame.XDispatch; 
> import com.sun.star.frame.XModel; 
> import com.sun.star.frame.XFrame; 
> import com.sun.star.frame.DispatchDescriptor; 
> import com.sun.star.awt.XToolkit; 
> import com.sun.star.awt.XWindowPeer; 
> import com.sun.star.awt.XMessageBox ; 
> import com.sun.star.awt.WindowAttribute; 
> import com.sun.star.awt.WindowClass; 
> import com.sun.star.awt.WindowDescriptor; 
> import com.sun.star.awt.Rectangle; 
> 
> public class ProtocolHandlerAddon { 
> public static class ProtocolHandlerAddonImpl extends WeakBase implements 
> XDispatchProvider, 
> XDispatch, 
> XInitialization, 
> XServiceInfo { 
> static private final String[] m_serviceNames = { 
> "com.sun.star.frame.ProtocolHand ler\n" }; 
> private XComponentContext m_xCmpCtx; 
> private XToolkit m_xToolkit; 
> private XFrame m_xFrame; 
> private XStatusListener m_xStatusListener; 
> public ProtocolHandlerAddonImpl( XComponentContext xComponentContext ) { \n
> m_xCmpCtx \u003d xComponentContext; 
> } 
> public void initialize( Object[] object ) 
> throws com.sun.star.uno.Exception { 
> 
> if ( object.length > 0 ) 
> { 
> m_xFrame \u003d ( XFrame ) UnoRuntime.queryInterface( \n
> XFrame.class, object[ 0 ] ); 
> } 
> 
> m_xToolkit \u003d (XToolkit) UnoRuntime.queryInterface( 
> XToolkit.class, 
> m_xCmpCtx.getServiceManager().createInstanceWithContext("com.sun.star.awt.Toolkit",
>  m_xCmpCtx)); \n
> } 
> public String[] getSupportedServiceNames() { 
> return getServiceNames(); } 
> public static String[] getServiceNames() { 
> return m_serviceNames;} 
> public boolean supportsService( String sService ) { 
> \nint len \u003d m_serviceNames.length; 
> for( int i\u003d0; i < len; i++) { 
> if ( sService.equals( m_serviceNames[i] ) ) 
> return true; 
> } 
> return false; 
> } 
> public String getImplementationName() { 
> return ProtocolHandlerAddonImpl.class.getName\n(); 
> } 
> // XDispatchProvider 
> public XDispatch queryDispatch( __/*IN*/com.sun.star.util.URL aURL, 
> __/*IN*/String sTargetFrameName, 
> __/*IN*/int iSearchFlags ) { 
> XDispatch xRet \u003d null; 
> if ( aURL.Protocol.compareTo\n("org.openoffice.Office.addon.example:") 
> \u003d\u003d 0 ) { 
> if ( aURL.Path.compareTo( "Function1" ) \u003d\u003d 0 ) 
> xRet \u003d this; 
> if ( aURL.Path.compareTo( "Function2" ) \u003d\u003d 0 ) \n
> xRet \u003d this; 
> 
> } 
> return xRet; 
> } 
> public XDispatch[] queryDispatches( __/*IN*/DispatchDescriptor[] seqDescripts 
> ) { 
> int nCount \u003d seqDescripts.length; 
> XDispatch[] lDispatcher \u003d new XDispatch[nCount]; \n
> 
> for( int i\u003d0; i> lDispatcher[i] \u003d queryDispatch( 
> seqDescripts[i].FeatureURL, 
> seqDescripts[i].FrameName, seqDescripts[i].SearchFlags ); ",1] ); //-->ler " 
> }; 
> private XComponentContext m_xCmpCtx; 
> private XToolkit m_xToolkit; 
> private XFrame m_xFrame; 
> private XStatusListener m_xStatusListener; 
> public ProtocolHandlerAddonImpl( XComponentContext xComponentContext ) { 
> m_xCmpCtx = xComponentContext; 
> } 
> public void initialize( Object[] object ) 
> throws com.sun.star.uno.Exception { 
> 
> if ( object.length > 0 ) 
> { 
> m_xFrame = ( XFrame ) UnoRuntime.queryInterface( 
> XFrame.class, object[ 0 ] ); 
> } 
> 
> m_xToolkit = (XToolkit) UnoRuntime.queryInterface( 
> XToolkit.class, 
> m_xCmpCtx.getServiceManager().createInstanceWithContext("com.sun.star.awt.Toolkit",
>  m_xCmpCtx)); 
> } 
> public String[] getSupportedServiceNames() { 
> return getServiceNames(); } 
> public static String[] getServiceNames() { 
> return m_serviceNames;} 
> public boolean supportsService( String sService ) { 
> int len = m_serviceNames.length; 
> for( int i=0; i < len; i++) { 
> if ( sService.equals( m_serviceNames[i] ) ) 
> return true; 
> } 
> return false; 
> } 
> public String getImplementationName() { 
> return ProtocolHandlerAddonImpl.class.getName (); 
> } 
> // XDispatchProvider 
> public XDispatch queryDispatch( __/*IN*/com.sun.star.util.URL aURL, 
> __/*IN*/String sTargetFrameName, 
> __/*IN*/int iSearchFlags ) { 
> XDispatch xRet = null; 
> if ( aURL.Protocol.compareTo ("org.openoffice.Office.addon.example:") == 0 ) 
> { 
> if ( aURL.Path.compareTo( "Function1" ) == 0 ) 
> xRet = this; 
> if ( aURL.Path.compareTo( "Function2" ) == 0 ) 
> xRet = this; 
> 
> } 
> return xRet; 
> } 
> public XDispatch[] queryDispatches( __/*IN*/DispatchDescriptor[] seqDescripts 
> ) { 
> int nCount = seqDescripts.length; 
> XDispatch[] lDispatcher = new XDispatch[nCount]; 
> 
> for( int i=0; i> lDispatcher[i] = queryDispatch( seqDescripts[i].FeatureURL, 
> seqDescripts[i].FrameName, seqDescripts[i].SearchFlags ); return lDispatcher; 
> } 
> // XDispatch 
> public void dispatch( __/*IN*/com.sun.star.util.URL aURL, \n
> __/*IN*/com.sun.star.beans.PropertyValue[] aArguments ) { 
> if ( aURL.Protocol.compareTo("org.openoffice.Office.addon.example:") 
> \u003d\u003d 0 ) 
> { 
> if ( aURL.Path.compareTo\n( "Function1" ) \u003d\u003d 0 ) { 
> showMessageBox("SDK DevGuide Add-On example", "Function 1 activated");} 
> if ( aURL.Path.compareTo( "Function2" ) \u003d\u003d 0 ) \n
> { 
> showMessageBox("SDK DevGuide Add-On example", "Function 2 activated");} 
> }} 
> public void addStatusListener( __/*IN*/XStatusListener xControl, 
> __/*IN*/com.sun.star.util.URL aURL ) {} 
> \npublic void removeStatusListener( __/*IN*/XStatusListener xControl, 
> __/*IN*/com.sun.star.util.URL aURL ) {} 
> public void showMessageBox(String sTitle, String sMessage) { try { 
> if ( null !\u003d m_xFrame && null !\u003d m_xToolkit ) { \n
> // describe window properties. 
> WindowDescriptor aDescriptor \u003d new WindowDescriptor(); 
> aDescriptor.Type \u003d WindowClass.MODALTOP; 
> aDescriptor.WindowServiceName \u003d new String( "infobox" ); 
> aDescriptor.ParentIndex\n \u003d -1; 
> aDescriptor.Parent (XWindowPeer)UnoRuntime.queryInterface( 
> XWindowPeer.class, m_xFrame.getContainerWindow()); 
> aDescriptor.Bounds \u003d new Rectangle(0,0,300,200); 
> aDescriptor.WindowAttributes \u003d WindowAttribute.BORDER\n 
> |WindowAttribute.MOVEABLE | 
> WindowAttribute.CLOSEABLE; 
> XWindowPeer xPeer \u003d m_xToolkit.createWindow( aDescriptor ); 
> if ( null !\u003d xPeer ) { 
> XMessageBox xMsgBox \u003d (XMessageBox)UnoRuntime.queryInterface( 
> \nXMessageBox.class, xPeer); 
> if ( null !\u003d xMsgBox ) 
> { 
> xMsgBox.setCaptionText( sTitle ); 
> xMsgBox.setMessageText( sMessage ); 
> xMsgBox.execute(); 
> }}}} 
> catch ( com.sun.star.uno.Exception e) { 
> // do your error handling \n
> }} } 
> public static XSingleComponentFactory __getComponentFactory( String 
> sImplementationName ) { ",1] ); //-->
> return lDispatcher; 
> } 
> // XDispatch 
> public void dispatch( __/*IN*/com.sun.star.util.URL aURL, 
> __/*IN*/com.sun.star.beans.PropertyValue[] aArguments ) { 
> if ( aURL.Protocol.compareTo("org.openoffice.Office.addon.example:") == 0 ) 
> { 
> if ( aURL.Path.compareTo ( "Function1" ) == 0 ) { 
> showMessageBox("SDK DevGuide Add-On example", "Function 1 activated");} 
> if ( aURL.Path.compareTo( "Function2" ) == 0 ) 
> { 
> showMessageBox("SDK DevGuide Add-On example", "Function 2 activated");} 
> }} 
> public void addStatusListener( __/*IN*/XStatusListener xControl, 
> __/*IN*/com.sun.star.util.URL aURL ) {} 
> public void removeStatusListener( __/*IN*/XStatusListener xControl, 
> __/*IN*/com.sun.star.util.URL aURL ) {} 
> public void showMessageBox(String sTitle, String sMessage) { try { 
> if ( null != m_xFrame && null != m_xToolkit ) { 
> // describe window properties. 
> WindowDescriptor aDescriptor = new WindowDescriptor(); 
> aDescriptor.Type = WindowClass.MODALTOP; 
> aDescriptor.WindowServiceName = new String( "infobox" ); 
> aDescriptor.ParentIndex = -1; 
> aDescriptor.Parent (XWindowPeer)UnoRuntime.queryInterface( 
> XWindowPeer.class, m_xFrame.getContainerWindow()); 
> aDescriptor.Bounds = new Rectangle(0,0,300,200); 
> aDescriptor.WindowAttributes = WindowAttribute.BORDER 
> |WindowAttribute.MOVEABLE | 
> WindowAttribute.CLOSEABLE; 
> XWindowPeer xPeer = m_xToolkit.createWindow( aDescriptor ); 
> if ( null != xPeer ) { 
> XMessageBox xMsgBox = (XMessageBox)UnoRuntime.queryInterface( 
> XMessageBox.class, xPeer); 
> if ( null != xMsgBox ) 
> { 
> xMsgBox.setCaptionText( sTitle ); 
> xMsgBox.setMessageText( sMessage ); 
> xMsgBox.execute(); 
> }}}} 
> catch ( com.sun.star.uno.Exception e) { 
> // do your error handling 
> }} } 
> public static XSingleComponentFactory __getComponentFactory( String 
> sImplementationName ) { XSingleComponentFactory xFactory \u003d null; 
> if ( sImplementationName.equals( ProtocolHandlerAddonImpl.class.getName\n() ) 
> ) 
> xFactory \u003d 
> Factory.createComponentFactory(ProtocolHandlerAddonImpl.class, 
> ProtocolHandlerAddonImpl.getServiceNames()); 
> return xFactory; 
> } 
> public static boolean __writeRegistryServiceInfo( 
> XRegistryKey xRegistryKey ) { \n
> return Factory.writeRegistryServiceInfo( 
> ProtocolHandlerAddonImpl.class.getName(), 
> ProtocolHandlerAddonImpl.getServiceNames(),xRegistryKey )}} 
> 
> This is the ProtocolHandlerAddon.xcu 
> 
> 
> 
> 
> 
\n
> org.openoffice.Office.addon.example:* 
> 

> 
> 
> 
> 
> Here is the Addons.xcu\n that adds a toolbar buttons 
> 
> 
> XSingleComponentFactory xFactory = null; 
> if ( sImplementationName.equals( ProtocolHandlerAddonImpl.class.getName () ) 
> ) 
> xFactory = Factory.createComponentFactory(ProtocolHandlerAddonImpl.class, 
> ProtocolHandlerAddonImpl.getServiceNames()); 
> return xFactory; 
> } 
> public static boolean __writeRegistryServiceInfo( 
> XRegistryKey xRegistryKey ) { 
> return Factory.writeRegistryServiceInfo( 
> ProtocolHandlerAddonImpl.class.getName(), 
> ProtocolHandlerAddonImpl.getServiceNames(),xRegistryKey )}} 
> 
> This is the ProtocolHandler.xcu 
> 
> 
> 
> 
> 

> org.openoffice.Office.addon.example:* 
> 

> 
> 
> 
> 
> Here is the Addons.xcu that adds a toolbar buttons 
> 
> 
> 
> \n
> 
> 
> 
\n
> org.openoffice.Office.addon.example:Function1 
> 


> 
> 

> \n
 
> 
> Function 1 
> 

> 
\n
> _self 
> 

> 

> com.sun.star.text.TextDocument 
> 

> \n
> 
> 

> org.openoffice.Office.addon.example:Function2\n 
> 


> 
> 

> 
\n
> 
> Function 2 
> 

> 

> _self ",1] ); //-->/registry" xmlns:xs=" http://www.w3.org/2001/XMLSchema"; 
> oor:name="Addons" oor:package="org.openoffice.Office"> 
> 
> 
> 
> 
> 

> org.openoffice.Office.addon.example:Function1 
> 


> 
> 

> 

> 
> Function 1 
> 

> 

> _self 
> 

> 

> com.sun.star.text.TextDocument 
> 

> 
> 
> 

> org.openoffice.Office.addon.example:Function2 
> 


> 
> 

> 

> 
> Function 2 
> 

> 

> _self \n
 
> 
> com.sun.star.text.TextDocument 
> 

> 
> 
> \n
> 
> 
> Why are the buttons in the toolbar not getting activated? What does this mean 
> in the Addons.xcu \n 
> 

> org.openoffice.Office.addon.example:Function1 
> 
What is the maeaning of \norg.openoffice.Office.addon.example:Function1 
> What is Function1? Is it Function1.java? 
> Where should I place Function1? Should I include it in the 
> ProtocolHandlerAddon.uno.zip\n? 
> 
> Please help me ... 
> 
> Thank you in advance.. 
> With Regards 
> Bharathy B
> \n\n
> ",0] ); D(["ce"]); //-->
> 

> 
> com.sun.star.text.TextDocument 
> 

> 
> 
> 
> 
> 
> Why are the buttons in the toolbar not getting activated? 
If a button is disabled it can have the following reasons:
- The statusChanged function from the controller notified the button , 
which is bound to the command, that it has to be disabled.
- The button cannot find a dispatcher for the its command URL. This can 
have several reasons.
- There is no registered protocol handler.
- The dispatcher doesn't implement the function.

What does this mean in the Addons.xcu

=== message truncated ===

                
---------------------------------
Yahoo! Music Unlimited - Access over 1 million songs.Try it free. 
  • [api-... bharathy b
    • ... Carsten Driesner - Sun Germany - ham02 - Hamburg - Software Engineer
      • ... bharathy b
        • ... Mathias Bauer
          • ... bharathy b

Reply via email to