[Solved] [Java] Get current XTextDocument object reference

Discussions about using 3rd party extension with OpenOffice.org

[Solved] [Java] Get current XTextDocument object reference

Postby java1cprog » Sun Sep 05, 2010 4:12 pm

I would like to see a simple code example which show me how to get com.sun.star.text.XTextDocument in dispatch method of OpenOffice.org AddOn.
Last edited by java1cprog on Tue Sep 07, 2010 10:45 am, edited 9 times in total.
OpenOffice 3.2 on Windows XP SP 2
java1cprog
 
Posts: 6
Joined: Wed Sep 01, 2010 6:54 pm

Re: How to get current XTextDocument object reference?

Postby Villeroy » Sun Sep 05, 2010 5:29 pm

You should find the answer in any code example, in virtually every little piece of documentation.
The MRI extension can even record Java code.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, OpenOffice 4.x & LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 26417
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: How to get current XTextDocument object reference?

Postby java1cprog » Sun Sep 05, 2010 7:08 pm

Just show me a code. I think it will be few lines of code. Please.
OpenOffice 3.2 on Windows XP SP 2
java1cprog
 
Posts: 6
Joined: Wed Sep 01, 2010 6:54 pm

Re: How to get current XTextDocument object reference with J

Postby RoryOF » Sun Sep 05, 2010 7:14 pm

Search for xtextdocument using search box top right of forum screen. Then if you have a query, come back and someone will help.
Apache OpenOffice 4.1.6 on Xubuntu 18.04.2 (mostly 64 bit version) and very infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 28432
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: How to get current XTextDocument object reference with J

Postby hanya » Sun Sep 05, 2010 8:20 pm

If you implement your own protocol handler, see:
http://api.openoffice.org/docs/common/r ... ndler.html
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
hanya
Volunteer
 
Posts: 884
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

Re: How to get current XTextDocument object reference with J

Postby java1cprog » Mon Sep 06, 2010 6:29 am

Villeroy wrote:You should find the answer in any code example, in virtually every little piece of documentation.
The MRI extension can even record Java code.

Unfotunatelly, I didn't find any. I saw a lot of examples where new frame is created. It isn't what I want. I would like to get current XTextDocument. I would not like to get new empty XTextDocument. Do you understand me?

One of possible ways is:

Code: Select all   Expand viewCollapse view
       ...
       //retrieve the current component
       XComponent xCurrentComponent = xdesktop.getCurrentComponent();
   
      // query its XTextDocument interface
        XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(
                XTextDocument.class, xCurrentComponent);

But when it test this one in my own protocol handler xCurrentComponent is null. This code don't satisfy a need of my target.

How can I do that? I don't understand? Please, don't post links here.
Please, type or copy/paste a working example.
OpenOffice 3.2 on Windows XP SP 2
java1cprog
 
Posts: 6
Joined: Wed Sep 01, 2010 6:54 pm

Re: [Java] Get current XTextDocument object reference

Postby java1cprog » Tue Sep 07, 2010 10:43 am

Unfortunately, I didn't find answer to my question into present forum's topics. Instead, I carefully read "OpenOffice.org Developer guide" and found answer to my question.
The few strings of code which I have developed by myself is here:

Code: Select all   Expand viewCollapse view
                XTextDocument textDocument = null;
                XController controller = m_xContext.getController();
                XModel model = controller.getModel();
                textDocument = UnoRuntime.queryInterface(XTextDocument.class, model);
OpenOffice 3.2 on Windows XP SP 2
java1cprog
 
Posts: 6
Joined: Wed Sep 01, 2010 6:54 pm

Re: [Java] Get current XTextDocument object reference

Postby Giehlman » Mon Jun 20, 2016 5:10 pm

Thanks @java1cprog, I was able to make it work. Found a little error in your code though, cf. https://www.openoffice.org/api/docs/common/ref/com/sun/star/frame/XFrame.html

java1cprog wrote:Unfortunately, I didn't find answer to my question into present forum's topics. Instead, I carefully read "OpenOffice.org Developer guide" and found answer to my question.
The few strings of code which I have developed by myself is here:

Code: Select all   Expand viewCollapse view
                XTextDocument textDocument = null;
                XController controller = /* m_xContext.getController(); has to be XFrame --> */ m_xFrame.getController();
                XModel model = controller.getModel();
                textDocument = UnoRuntime.queryInterface(XTextDocument.class, model);
OpenOffice 4.0 on Windows 10
Giehlman
 
Posts: 1
Joined: Mon Jun 20, 2016 5:05 pm


Return to Extensions

Who is online

Users browsing this forum: JeJe and 1 guest