Hi Stephan,

First thanks - your solution worked beautifully! Danke!
Everytime I want to insert text into StarOffice writer, I search now for the currently active StarOffice component. With it, I can just insert text, images, graphics into the right Frame.

I have now a problem, that is very similar to the this one.
I want to add now an item to the StarOffice context menu. I also, of course, want this context menu to be available from all openoffice windows/frame the user opened. But I were not able to do it. You see, then inserting text, it was easier, because I search for the currently active StarOffice component before inserting text.

I created a ContextMenuInterceptorClass, that registers once, then starting openoffice, to the current frame. But then, it doesn't work then I opens a new frame, because I is registered, from the beginning on, at the first active StarOffice component.

So ... Either 1)I register the ContextMenuInterceptor so that his notifyContextMenuExecute method will be called from what either frame a contextMenuEvent came from (Is that possible?), or 2) I have to register a new ContextMenuInterceptor each time I open a new Document, or change the current edited document.

Can you perhaps give me an hint ?



Here, this is how I'm doing to register the Context Menu
/*******************************************************************************************
* Registration of the context menu interceptor by using the current controller. * This is done once, then openOffice starts.
*******************************************************************************************/
XModel xModel = (XModel) UnoRuntime.queryInterface(XModel.class, xComponent); com.sun.star.frame.XFrame xFrame = xModel.getCurrentController().getFrame();
  XController xController = xModel.getCurrentController();
//intercepts the XContextMenu, to add items in it
  com.sun.star.ui.XContextMenuInterception xContextMenuInterception =
(com.sun.star.ui.XContextMenuInterception) UnoRuntime.queryInterface( com.sun.star.ui.XContextMenuInterception.class, xController); ContextMenuInterceptor aContextMenuInterceptor = new ContextMenuInterceptor();
  com.sun.star.ui.XContextMenuInterceptor xContextMenuInterceptor =
(com.sun.star.ui.XContextMenuInterceptor) UnoRuntime.queryInterface( com.sun.star.ui.XContextMenuInterceptor.class, aContextMenuInterceptor); xContextMenuInterception.registerContextMenuInterceptor(xContextMenuInterceptor);



and here, a part of my ContextMenuInterceptor class, which adds items to a contextMenu.
/********************************************************************************************
* ContextMenuInterceptor, adds item to the openOffice contextMenu
*******************************************************************************************/
public class ContextMenuInterceptor implements XContextMenuInterceptor {

public ContextMenuInterceptorAction notifyContextMenuExecute(
com.sun.star.ui.ContextMenuExecuteEvent aEvent) throws RuntimeException {

...

com.sun.star.container.XIndexContainer xContextMenu = aEvent.ActionTriggerContainer;
com.sun.star.lang.XMultiServiceFactory xMenuElementFactory =
(com.sun.star.lang.XMultiServiceFactory) UnoRuntime.queryInterface( com.sun.star.lang.XMultiServiceFactory.class, xContextMenu);
           if (xMenuElementFactory != null) {
               // create root menu entry and sub menu
               com.sun.star.beans.XPropertySet xRootMenuEntry =
                       (XPropertySet) UnoRuntime.queryInterface(
                               com.sun.star.beans.XPropertySet.class,
xMenuElementFactory.createInstance("com.sun.star.ui.ActionTrigger"));


xRootMenuEntry.setPropertyValue("Text", "Ontology");
xRootMenuEntry.setPropertyValue("CommandURL", "slot:5410");
xRootMenuEntry.setPropertyValue("HelpURL", "5410");



Hi Daniel

The problem is that I want to insert text in the document the user is actually editing, and not in the Frame the programm opened. Imagine the user opens an already existent file. This would open a new frame. Then inserting text from my java application, the text will appear in the Frame he opened first, and not in the frame he is actually editing - which is not the expected behaviour.
So, I wanted to now how to get the current frame ...


aaaah, now the shades of confusion lift :-)

You can query the XDesktop interface from an instance of the service
"com.sun.star.frame.Desktop", which you can create at the
MultiServiceFactory of the office.

The interface XDesktop has a method "getCurrentComponent()" which should
return the currently active StarOffice component.
To ensure that the component you get is a TextDocument you can check if
it supports the service "com.sun.star.text.TextDocument" by querying the
XServiceInfo interface and use the method "supportsService" from it.

Hope that helps

Regards

Stephan

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



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

Reply via email to