Tobias Krais wrote:
Hi ML,

in Java I try to get access to the file menu during runtime. Now I am
able to create a new menu, but I don't get access the file menu to be
able to change it, see comments

-----%<-----
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));

// Returns an Object - seems to be correct
Object oDateiMenuSettings = oMenuBarSettings.getByIndex(0);

// Returns null! Why?
XIndexContainer xoDateiMenuSettings = (XIndexContainer)
        UnoRuntime.queryInterface(XIndexContainer.class,
        oMenuBarSettings.getByIndex(0));
-----%<-----

The last cast seems to be the problem. Did I try to cast to the wrong type?

Hi Tobias,

The last line cannot work as getByIndex() doesn't provide you an object which implements XIndexContainer. You get a sequence< PropertyValue >, if you call getByIndex().

The documentation of the IDL service says:
"The container contains the items of the user interface element. Every
item is stored as a sequence of <type scope="com::sun::star::beans">PropertyValue</type>. The properties insides the sequence are defined by the service <type scope="com::sun::star::ui">ItemDescriptor</type>. It depends on the function which provides these service if the container is shareable read-only or exclusive writeable."


Can you tell me how to rename a single item of the file menu?
No, problem. You have to search for the properties "Label" and "CommandURL". You have to change both to your needs, call replaceByIndex() and provide your changed sequence< PropertyValue >.

PropertyValue [] aPropValue = (PropertyValue []) oMenuBarSettings.getByIndex(0);
String aLabel( "Label" );
String aCommandURL( "CommandURL" );
for (int i = 0; i < aPropValue.length; i++) {
  if (aLabel.equals(aPropValue[i].Name)){
    ..
  }
  else if ( aCommandURL.equals(aPropValue[i].Name)) {
    ..
  }
}

Important: If you want to access a sub menu, you have to look for the property called "ItemDescriptorContainer".

Regards,
Carsten

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

Reply via email to