Hi Tobias,

The problem is that I am a newbie. I'm doing this stuff since 2-3 weeks...

Ok, now I see. I wasn't aware that you're a newbie.


That gave me the hint. Here the steps:

-----%<-----
PropertyValue[] oDateiMenuSettings = (PropertyValue[])
        UnoRuntime.queryInterface(PropertyValue[].class,
                oMenuBarSettings.getByIndex(0));
XIndexAccess xoDateiMenuSettings = (XIndexAccess)
        UnoRuntime.queryInterface(XIndexAccess.class,
                (Object)oDateiMenuSettings[2].Value);
PropertyValue[] save as = (PropertyValue[])
        UnoRuntime.queryInterface(PropertyValue[].class,
                xoDateiMenuSettings.getByIndex(8));
XIndexContainer xFileMenuSettings = (XIndexContainer)   
        UnoRuntime.queryInterface(XIndexContainer.class,
                xoDateiMenuSettings);
-----%<-----

This is code just works by luck. You have to check the name of each PropertyValue entry to find your entry as the order is NOT defined. Stephan Bergmann already wrote the correct code to retrieve the PropertyValue array from the UNO any in Java. See the following code snippet.

PropertyValue[] oDateiMenuSettings;
try {
  oDateiMenuSettings = com.sun.star.uno.AnyConverter.toObject(
    PropertyValue[].class, oMenuBarSettings.getByIndex(0));
} catch (com.sun.star.lang.IndexOfOutBoundsException e) {
  // do something useful here
}

String aLabel( "Label" );
String aCommandURL( "CommandURL" );
String aItemContainer( "ItemDescriptorContainer" );
for (int i = 0; i < oDateiMenuSettings.length; i++) {
 if (aLabel.equals(oDateiMenuSettings[i].Name)){
   ... // Label property
 }
 else if ( aCommandURL.equals(oDateiMenuSettings[i].Name)) {
   ... // command URL property
 }
 else if ( aItemContainer.equals(oDateiMenuSettings[i].Name )){
   ... // item descriptor container (sub menu container)
 }
}
*/

public class TemporaryRemoveMenuEntry {

        com.sun.star.ui.XUIElement myMenubar
            = xLayoutManager.getElement("private:resource/menubar/menubar");
        XUIElementSettings xoMenuBarSettings = (XUIElementSettings)
UnoRuntime
                .queryInterface(XUIElementSettings.class, myMenubar);
        XIndexContainer oMenuBarSettings = (XIndexContainer) UnoRuntime
                .queryInterface(XIndexContainer.class, xoMenuBarSettings
                .getSettings(true));

You just get the menu bar from the layout manager. This part of your code looks good.

        Object o = xRemoteServiceManager.createInstanceWithContext
        ("com.sun.star.ui.ModuleUIConfigurationManagerSupplier",
xRemoteContext);
        XModuleUIConfigurationManagerSupplier xCmSupplier
                = (XModuleUIConfigurationManagerSupplier) UnoRuntime.

queryInterface(XModuleUIConfigurationManagerSupplier.class,
                    o);
        XUIConfigurationManager uiConfigManager
                = xCmSupplier.getUIConfigurationManager
                    ("com.sun.star.text.TextDocument");
If you want to make transient changes, you should not use the configuration manager. You have to use the user interface element and use the XUIElementSettings interface only. There you also have a setSettings function. The user interface configuration managers always work persistently! I sent you the Basic example (transient menubar changes) and there you should find the correct way.


        PropertyValue[] oDateiMenuSettings = (PropertyValue[])
                UnoRuntime.queryInterface(PropertyValue[].class,
                        oMenuBarSettings.getByIndex(0));
        XIndexAccess xoDateiMenuSettings = (XIndexAccess)
                UnoRuntime.queryInterface(XIndexAccess.class,
                        (Object)oDateiMenuSettings[2].Value);

        XIndexContainer xFileMenuSettings = (XIndexContainer)
                UnoRuntime.queryInterface(XIndexContainer.class,
                        xoDateiMenuSettings);
        xFileMenuSettings.removeByIndex(7);

Please be aware that this code only works, if nobody customized the menu bar. It would fail, if someone just moved the menu item you want to remove. If you want to be fail safe, you should iterate through the container and check the command url of every menu item to find the correct index.

        xoMenuBarSettings.setSettings(xFileMenuSettings);
Don't use this call.
        xoMenuBarSettings.setSettings(oMenuBarSettings);
You only have to call setSettings once. You have to do it with the root index container you got from the user interface element using getSettings.

Regards,
Carsten

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to