Hi Carsten,
>> But I think I need a XIndexContainer or again a
>> PropertyValue[].
>
> Why? You can call getByIndex and retrieve the next sequence<
> PropertyValue >. Where is the problem?
The problem is that I am a newbie. I'm doing this stuff since 2-3 weeks...
But I need the XIndexContainer anyway to be able to remove elements in
Submenus. Meanwhile I succeeded. I'll post the code below.
> How can I get it?
> Just call getByIndex() using XIndexAccess. If you want to change
> entries, you have to query the interface for XIndexContainer.
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);
-----%<-----
> I think you should read some documentation in the Developer's Guide to
> better understand UNO based containers and the UNO interface concept.
I already read it but did really not understand. I'll read it again and
I think this time I'll understand more. I miss detailed examples for
newbies. And, for I am not a native english speaker, sometimes I don't
understand everything.
Thanks for your help! It is really appreciated!
Do you think the code below is worth posting as a snipplet?
Greetings, Tobias
-----%<-----
package de.twc.oocom;
import java.io.File;
import com.sun.star.beans.PropertyValue;
import com.sun.star.beans.XPropertySet;
import com.sun.star.comp.helper.Bootstrap;
import com.sun.star.container.XIndexAccess;
import com.sun.star.container.XIndexContainer;
import com.sun.star.frame.XComponentLoader;
import com.sun.star.frame.XLayoutManager;
import com.sun.star.lang.XComponent;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.ui.XModuleUIConfigurationManagerSupplier;
import com.sun.star.ui.XUIConfigurationManager;
import com.sun.star.ui.XUIElementSettings;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
/*
* This programm starts OpenOffice, opens a document and then removes the
* 7th entry in the file menu (Save Item).
*/
public class TemporaryRemoveMenuEntry {
public TemporaryRemoveMenuEntry(){
//Empty Constructor
}
// The file that should be processed, e.g. "/tmp/hello_world.ods"
private String source_File = null;
// The file that is the target of a conversion, e.g. "/tmp/hello_world"
// What to do with the document: "-view", "-convert" or "-edit"
private String todo_Action = "-edit";
// Format of the target_File
//old
public File file;
private String ooport = "9000";
public static void main(String[] arg){
/*
* ...nur 2 Argumente wenn das Dokument zum bearbeiten geƶffnet
werden
* soll...
*/
String [] args = {"9000",
"/home/tobias/test.odt"};
TemporaryRemoveMenuEntry myOOComNG = new TemporaryRemoveMenuEntry();
myOOComNG.ooport = args[0];
myOOComNG.todo_Action = args[1];
myOOComNG.source_File = args[args.length - 1];
try {
myOOComNG.openDocument();
}
catch(Exception e) {
System.out.println(e);
}
}
private void openDocument() throws java.lang.Exception {
XComponentContext xRemoteContext = Bootstrap.bootstrap();
System.out.println("Connected to a running OpenOffice ...");
// get OO desktop
XMultiComponentFactory xRemoteServiceManager
= xRemoteContext.getServiceManager();
Object desktop = xRemoteServiceManager.createInstanceWithContext(
"com.sun.star.frame.Desktop", xRemoteContext
);
// query the XComponentLoader interface from the desktop
XComponentLoader xComponentLoader =
(XComponentLoader)UnoRuntime.queryInterface(
XComponentLoader.class, desktop);
PropertyValue[] myProperties = new PropertyValue[1];
PropertyValue xProperty = new PropertyValue();
xProperty.Name = "ReadOnly";
xProperty.Value = new Boolean(false);
myProperties[0] = xProperty;
// load document
XComponent openedDocument = xComponentLoader.loadComponentFromURL(
"file://" + source_File,
"_blank",
0,
myProperties);
com.sun.star.frame.XDesktop xDesktop = (com.sun.star.frame.XDesktop)
UnoRuntime.queryInterface(com.sun.star.frame.XDesktop.class, desktop);
com.sun.star.frame.XFrame xFrame = xDesktop.getCurrentFrame();
XPropertySet xps = (XPropertySet) UnoRuntime.queryInterface(
XPropertySet.class, xFrame);
XLayoutManager xLayoutManager = (XLayoutManager)
UnoRuntime.queryInterface(
XLayoutManager.class,
xps.getPropertyValue("LayoutManager"));
xLayoutManager.attachFrame(xFrame);
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));
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");
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);
xoMenuBarSettings.setSettings(xFileMenuSettings);
xoMenuBarSettings.setSettings(oMenuBarSettings);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]