[Issue] Netbeans addons problem with constructor +menu items

Discussions about using 3rd party extension with OpenOffice.org

[Issue] Netbeans addons problem with constructor +menu items

Postby johnrdorazio » Sun Sep 28, 2014 4:57 am

I think I am seeing a bug in the OpenOffice plugin for Netbeans. The plugin constructor is being invoked once for each menu item?

Make an empty project and add two menu items.
In the constructor, add a
Code: Select all   Expand viewCollapse view
System.out.println("Hello World!");
.

Compile, then "install and run in OpenOffice". As you open Writer, you will see "Hello World!" printed twice to the console.

If you add three menu items, you will see "Hello World!" printed three times to the console.
Then as soon as you click on the menu, you will see "Hello World!" printed three more times to the console.

Is this normal? If I want to prepare some interfaces (for example JFrames) inside my constructor so that they'll be readily available for my menu items, they'll basically be built as many times as I have menu items? Instead of building one JFrame I'll be building as many as I have menu items?
Last edited by johnrdorazio on Sun Sep 28, 2014 9:25 pm, edited 2 times in total.
OpenOffice 4.1.1, NetBeans 8.0.2, Windows 10 x64 Home
johnrdorazio
 
Posts: 31
Joined: Sun Aug 17, 2014 2:04 pm
Location: Italy

Re: Netbeans addons construct as many times as there r menui

Postby hanya » Sun Sep 28, 2014 9:25 am

I do not use Netbeans plugin. But do you mean dispatch provider? If so, it is instantiated for each your menu entries when they are being shown in your menu menu or other place.
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
hanya
Volunteer
 
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

Re: Netbeans addons construct as many times as there r menui

Postby johnrdorazio » Sun Sep 28, 2014 9:46 am

Let me post the code that is generated by the Netbeans plugin for the main class of the add-on:

Code: Select all   Expand viewCollapse view
package com.example;

import com.sun.star.lang.XSingleComponentFactory;
import com.sun.star.lib.uno.helper.Factory;
import com.sun.star.lib.uno.helper.WeakBase;
import com.sun.star.registry.XRegistryKey;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;


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


    public AddOnTest2( XComponentContext context )
    {
        m_xContext = context;
        System.out.println("Hello World!");
    };

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

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

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

    // 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.compareTo("com.example.addontest2:") == 0 )
        {
            if ( aURL.Path.compareTo("Command0") == 0 )
                return this;
            if ( aURL.Path.compareTo("Command1") == 0 )
                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.frame.XDispatch:
     public void dispatch( com.sun.star.util.URL aURL,
                           com.sun.star.beans.PropertyValue[] aArguments )
    {
         if ( aURL.Protocol.compareTo("com.example.addontest2:") == 0 )
        {
            if ( aURL.Path.compareTo("Command0") == 0 )
            {
                // add your own code here
                return;
            }
            if ( aURL.Path.compareTo("Command1") == 0 )
            {
                // 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
    }

    // 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.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]);
        }
    }

}


The only line I have added here is "System.out.println" in the constructor. There are two menu items in this project.
When I "install and run in OpenOffice", I then see in the Netbeans console:

"Hello World!"
"Hello World!"

Or if I add another menu item to my project, I see in the console:

"Hello World!"
"Hello World!"
"Hello World!"

Then as soon as I click on the menu for the first time, I see three more times:

"Hello World!"
"Hello World!"
"Hello World!"
"Hello World!"
"Hello World!"
"Hello World!"
OpenOffice 4.1.1, NetBeans 8.0.2, Windows 10 x64 Home
johnrdorazio
 
Posts: 31
Joined: Sun Aug 17, 2014 2:04 pm
Location: Italy

Re: Netbeans addons construct as many times as there r menui

Postby johnrdorazio » Sun Sep 28, 2014 1:56 pm

I have opened a bug report in the tracker for this (https://issues.apache.org/ooo/show_bug.cgi?id=125691).
If anyone else can confirm, please confirm on the bug tracker also.
OpenOffice 4.1.1, NetBeans 8.0.2, Windows 10 x64 Home
johnrdorazio
 
Posts: 31
Joined: Sun Aug 17, 2014 2:04 pm
Location: Italy

Re: [Issue] Netbeans addons problem with number of menu item

Postby cmarcum » Sun Sep 28, 2014 8:15 pm

I can confirm the described behavior.
I started a new AddOn project AddOnTest2 and created menu items Command0, 1, and 2
I assigned:
0 to writer and spreadsheet context
1 to writer
2 to spreadsheet

I added this to the AddOnTest2 constructor:
System.out.println("Contructor Context " + context.toString());
and this to each of the commands in the dispatch method
System.out.println("CommandX");
I deployed to AOO and opened a new writer there was no output yet.
When I clicked the the Menu I received:
Contructor Context com.sun.star.bridges.jni_uno.JNI_proxy@5b74bd37 [oid=7f2bf924e6d0;gcc3[0];f644c4deeb694c8d96e296f02b7a8e88, type=com.sun.star.uno.XComponentContext]
Contructor Context com.sun.star.bridges.jni_uno.JNI_proxy@5b74bd37 [oid=7f2bf924e6d0;gcc3[0];f644c4deeb694c8d96e296f02b7a8e88, type=com.sun.star.uno.XComponentContext]
then when selecting the commands 0 and 1 I received the expected:
Command0
Command1
I closed Writer and opened Calc and received no further output.
When I clicked the the Menu I received:
Contructor Context com.sun.star.bridges.jni_uno.JNI_proxy@5b74bd37 [oid=7f2bf924e6d0;gcc3[0];f644c4deeb694c8d96e296f02b7a8e88, type=com.sun.star.uno.XComponentContext]
Contructor Context com.sun.star.bridges.jni_uno.JNI_proxy@5b74bd37 [oid=7f2bf924e6d0;gcc3[0];f644c4deeb694c8d96e296f02b7a8e88, type=com.sun.star.uno.XComponentContext]
then when selecting the commands 0 and 2 I received the expected:
Command0
Command2

I'm not sure Netbeans is causing this issue. I will ask on the dev mailing list on how the extension constructor is called by AOO and if this is expected behavior.

Carl
OpenOffice 4.1.2 on Fedora 20 x86-64
cmarcum
 
Posts: 1
Joined: Sun Sep 28, 2014 7:43 pm

Re: [Solved] Netbeans addons problem with constructor +menu

Postby Rushna » Wed Sep 27, 2017 9:09 am

Hi johnrdorazio..,
I also got this issue but it's our mistake not OpenOffice nor NetBeans.

when you create a plugin by NetBeans there are some steps:-
1)File-> New Project -> select category Apache OpenOffice -> Project : Apache OpenOffice AddOn (Next)
2)Project Name (Next)
3)Define User Commands(Next)

please note 4th step:-in which you are getting issue

4)Create UI Structure ,here please select a CheckBox Writer or Spreadsheet or Presentation only.(Next)
(Finish)

Inshallah It will be sort out... :)
OpenOffice 4.3.1 on Windows 7
Rushna
 
Posts: 19
Joined: Tue May 09, 2017 12:42 pm


Return to Extensions

Who is online

Users browsing this forum: No registered users and 1 guest