Extension Menu button appear disable on launching OpenOffice

Discussions about using 3rd party extension with OpenOffice.org
Post Reply
pknerd
Posts: 31
Joined: Tue Dec 03, 2013 4:07 pm

Extension Menu button appear disable on launching OpenOffice

Post by pknerd »

Hi

I am working towards my first ever OOo plugin and facing loads of issues. Somehow I got able to compile and execute code but button always appear disable. Relevant files given below:

Description.xml

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<!--Created with OpenOffice.org API plug-in for NetBeans Version 2.0.6-->
<description xmlns="http://openoffice.org/extensions/description/2006" xmlns:xlink="http://www.w3.org/1999/xlink">
    <version value="0.0.1"/>
    <identifier value="org.openoffice.testaddon.TestAddOn"/>
</description>
uno-extension-manifest.xml

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<manifest:manifest xmlns:manifest="http://openoffice.org/2001/manifest">
  <manifest:file-entry manifest:media-type="application/vnd.sun.star.configuration-data"
                       manifest:full-path="registry/data/org/openoffice/Office/ProtocolHandler.xcu"/>
  <manifest:file-entry manifest:media-type="application/vnd.sun.star.configuration-data"
                       manifest:full-path="registry/data/org/openoffice/Office/Addons.xcu"/>
  <manifest:file-entry manifest:media-type="application/vnd.sun.star.uno-component;type=Java"
                       manifest:full-path="TestAddOn.jar"/>
</manifest:manifest>
AddOns.xcu

Code: Select all

<?xml version='1.0' encoding='UTF-8'?>

<oor:component-data xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" oor:name="Addons" oor:package="org.openoffice.Office">
  <node oor:name="AddonUI">
    <node oor:name="OfficeMenuBar">
      <node oor:name="org.openoffice.testaddon.testaddon" oor:op="replace">
        <prop oor:name="Title" oor:type="xs:string">
          <value/>
          <value xml:lang="en">My Menu</value>
        </prop>
        <prop oor:name="Target" oor:type="xs:string">
          <value>_self</value>
        </prop>
        <prop oor:name="ImageIdentifier" oor:type="xs:string">
          <value/>
        </prop>
        <node oor:name="Submenu">
          <node oor:name="m1" oor:op="replace">
            <prop oor:name="URL" oor:type="xs:string">
              <value>org.openoffice.testaddon.testaddon:Hello World</value>
            </prop>
            <prop oor:name="ImageIdentifier" oor:type="xs:string">
              <value/>
            </prop>
            <prop oor:name="Target" oor:type="xs:string">
              <value>_self</value>
            </prop>
            <prop oor:name="Context" oor:type="xs:string">
              <value/>
            </prop>
            <prop oor:name="Title" oor:type="xs:string">
              <value/>
              <value xml:lang="en">Hello World</value>
            </prop>
          </node>
        </node>
      </node>
    </node>
    <node oor:name="OfficeToolBar">
      <node oor:name="org.openoffice.testaddon.testaddon" oor:op="replace">
      <node oor:name="m1" oor:op="replace">
        <prop oor:name="URL" oor:type="xs:string">
          <value>org.openoffice.testaddon.testaddon:Hello World</value>
        </prop>
        <prop oor:name="ImageIdentifier" oor:type="xs:string">
          <value/>
        </prop>
        <prop oor:name="Target" oor:type="xs:string">
          <value>_self</value>
        </prop>
        <prop oor:name="Context" oor:type="xs:string">
          <value/>
        </prop>
        <prop oor:name="Title" oor:type="xs:string">
          <value/>
          <value xml:lang="en">Hello World</value>
        </prop>
      </node>
      </node>
    </node>
    <node oor:name="Images">
      <node oor:name="org.openoffice.testaddon.testaddon.hello world.images" oor:op="replace">
        <prop oor:name="URL" oor:type="xs:string">
          <value>org.openoffice.testaddon.testaddon:Hello World</value>
        </prop>
        <node oor:name="UserDefinedImages">
          <prop oor:name="ImageSmallURL">
            <value>%origin%/../../../../../images/adnan.jpg</value>
          </prop>
          <prop oor:name="ImageBigURL">
            <value/>
          </prop>
          <prop oor:name="ImageSmallHCURL">
            <value/>
          </prop>
          <prop oor:name="ImageBigHCURL">
            <value/>
          </prop>
        </node>
      </node>
      </node>
  </node>
</oor:component-data>
ProtocolHandler.xcu

Code: Select all

<?xml version='1.0' encoding='UTF-8'?>

<oor:component-data oor:name="ProtocolHandler" oor:package="org.openoffice.Office" xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <node oor:name="HandlerSet">
    <node oor:name="org.openoffice.testaddon.TestAddOn" oor:op="replace">
      <prop oor:name="Protocols" oor:type="oor:string-list">
        <value>org.openoffice.testaddon.testaddon:*</value>
      </prop>
    </node>
  </node>
</oor:component-data>
TestAddOn.Java

Code: Select all

package org.openoffice.testaddon;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
import com.sun.star.lib.uno.helper.Factory;
import com.sun.star.lang.XSingleComponentFactory;
import com.sun.star.registry.XRegistryKey;
import com.sun.star.lib.uno.helper.WeakBase;
import javax.swing.JOptionPane;


public final class TestAddOn extends WeakBase
   implements com.sun.star.lang.XServiceInfo,
              com.sun.star.frame.XDispatchProvider,
              com.sun.star.lang.XInitialization,
              com.sun.star.frame.XDispatch
{
    private final XComponentContext m_xContext;
    private com.sun.star.frame.XFrame m_xFrame;
    private static final String m_implementationName = TestAddOn.class.getName();
    private static final String[] m_serviceNames = {
        "com.sun.star.frame.ProtocolHandler" };


    public TestAddOn( XComponentContext context )
    {
        m_xContext = context;
    };

    public static XSingleComponentFactory __getComponentFactory( String sImplementationName ) {
        XSingleComponentFactory xFactory = null;

        if ( sImplementationName.equals( m_implementationName ) )
            xFactory = Factory.createComponentFactory(TestAddOn.class, m_serviceNames);
        return xFactory;
    }

    public static boolean __writeRegistryServiceInfo( XRegistryKey xRegistryKey ) {
        return Factory.writeRegistryServiceInfo(m_implementationName,
                                                m_serviceNames,
                                                xRegistryKey);
    }

    // com.sun.star.lang.XServiceInfo:
    public String getImplementationName() {
         return m_implementationName;
    }

    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[] getSupportedServiceNames() {
        return m_serviceNames;
    }

    // com.sun.star.frame.XDispatchProvider:
    public com.sun.star.frame.XDispatch queryDispatch( com.sun.star.util.URL aURL,
                                                       String sTargetFrameName,
                                                       int iSearchFlags )
    {
        if ( aURL.Protocol.equals("org.openoffice.testaddon.testaddon:") )
        {
            if ( aURL.Path.equals("mycommands") )
                return this;
        }
        return null;
    }

    // com.sun.star.frame.XDispatchProvider:
    public com.sun.star.frame.XDispatch[] queryDispatches(
         com.sun.star.frame.DispatchDescriptor[] seqDescriptors )
    {
        int nCount = seqDescriptors.length;
        com.sun.star.frame.XDispatch[] seqDispatcher =
            new com.sun.star.frame.XDispatch[seqDescriptors.length];

        for( int i=0; i < nCount; ++i )
        {
            seqDispatcher[i] = queryDispatch(seqDescriptors[i].FeatureURL,
                                             seqDescriptors[i].FrameName,
                                             seqDescriptors[i].SearchFlags );
        }
        return seqDispatcher;
    }

    // com.sun.star.lang.XInitialization:
    public void initialize( Object[] object )
        throws com.sun.star.uno.Exception
    {
        if ( object.length > 0 )
        {
            m_xFrame = (com.sun.star.frame.XFrame)UnoRuntime.queryInterface(
                com.sun.star.frame.XFrame.class, object[0]);
        }
    }

    // com.sun.star.frame.XDispatch:
     public void dispatch( com.sun.star.util.URL aURL,
                           com.sun.star.beans.PropertyValue[] aArguments )
    {
         JOptionPane.showMessageDialog(null," How are you?", "Hello", JOptionPane.INFORMATION_MESSAGE);
         if ( aURL.Protocol.equals("org.openoffice.testaddon.testaddon:") )
        {
            if ( aURL.Path.equals("mycommands") )
            {
                // add your own code here
                return;
            }
        }
    }

    public void addStatusListener( com.sun.star.frame.XStatusListener xControl,
                                    com.sun.star.util.URL aURL )
    {
        // add your own code here
    }

    public void removeStatusListener( com.sun.star.frame.XStatusListener xControl,
                                       com.sun.star.util.URL aURL )
    {
        // add your own code here
    }

}
Open Office 4.01, MacOSX 10.6
hanya
Volunteer
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

Re: Extension Menu button appear disable on launching OpenOf

Post by hanya »

I did not test your code but I found the problem in the queryDIspatch method:

Code: Select all

    // com.sun.star.frame.XDispatchProvider:
    public com.sun.star.frame.XDispatch queryDispatch( com.sun.star.util.URL aURL,
                                                       String sTargetFrameName,
                                                       int iSearchFlags )
    {
        if ( aURL.Protocol.equals("org.openoffice.testaddon.testaddon:") )
        {
            if ( aURL.Path.equals("mycommands") )
                return this;
        }
        return null;
    }
You have "org.openoffice.testaddon.testaddon:Hello World" command in Addons.xcu file of URL property, so its protocol is org.openoffice.testaddon.testaddon and its path is "Hello World" (it should be written in URL notation, so you should encode space characters). In the queryDispatch method, you are testing the path with "mycommands" and always false.

The dispatch framework tries to query the dispatch through the css.frame.XDispatchProvider interface if the command is there in the menu item that contains the protocol registered in the list of protocol handlers. If the queryDispatch method returns valid css.frame.XDispatch interface, the entry is enabled but if it returns invalid one, it is disabled.
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
pknerd
Posts: 31
Joined: Tue Dec 03, 2013 4:07 pm

Re: Extension Menu button appear disable on launching OpenOf

Post by pknerd »

Yes!!!!
Finally I was able to see my plugin working yay!!!
Thankyou!! Thankyou!!!! Bro!!

Now as I sent you sample in private message, I need to learn about using GUI controls in extension. Can we using SWInG/AWT for that purpose, if yes the I need to know some sample/tutorial/Documentation in this regard.
Open Office 4.01, MacOSX 10.6
hanya
Volunteer
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

Re: Extension Menu button appear disable on launching OpenOf

Post by hanya »

I need to learn about using GUI controls in extension.
It is documented in [1] and you can find some examples in this forum. If you need dialogs, I suppose you to search in term "createDialog" method.
Can we using SWInG/AWT for that purpose, if yes the I need to know some sample/tutorial/Documentation in this regard.
I have see an example in dev@[2].

[1] https://wiki.openoffice.org/wiki/Docume ... Interfaces
[2] http://markmail.org/message/cpwjsti7wmty3s3o
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
himanshumicro
Posts: 2
Joined: Fri Nov 27, 2015 9:30 am

Extension Menu button appear disable on launching OpenOffice

Post by himanshumicro »

Hi,

I am facing same problem but I am not good at coding therefore, I cannot use the code you mentioned !! I tried to use mendeley extension package !

thank you,
Hk
open office 4.1.2 and ubuntu 14.04
Post Reply