https://issues.apache.org/ooo/show_bug.cgi?id=125691
Issue ID: 125691 Issue Type: DEFECT Summary: [netbeans-integration] add-on constructor is called as many times as there are menu items Product: App Dev Version: 4.1.1 Hardware: All OS: All Status: UNCONFIRMED Severity: normal Priority: P3 Component: sdk Assignee: issues@openoffice.apache.org Reporter: john.dora...@cappellaniauniroma3.org If I make a sample add-on project in Netbeans using the OpenOffice plugin, and I make two menu items, and I put a 'System.out.println("Hello World!");' in the constructor, then compile and "Install and run in OpenOffice", I see "Hello World!" printed twice to the console. If I make a project with three menu items, I see "Hello World!" printed three times to the console. And then as soon as I click on the menu to open it, I see "Hello World!" printed three more times to the console. It seems that the dispatch provider is calling the constructor for each menu item / toolbar item? See the code below generated by the add-on wizard, the only line I have added is in the constructor 'System.out.println("Hello World!");'. 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]); } } } -- You are receiving this mail because: You are the assignee for the issue. You are watching all issue changes.