Skip to content

Commit

Permalink
Refs #3 - copied usage to index.
Browse files Browse the repository at this point in the history
  • Loading branch information
cbmarcum committed Jun 19, 2020
1 parent b59ddde commit 130f9ff
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 2 deletions.
46 changes: 45 additions & 1 deletion docs/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,48 @@ The goal of the Groovy UNO Extension is to allow UNO programming that is less ve

These methods are implemented using Groovy Extension Modules. An extension module allows you to add new methods to existing classes, including classes which are precompiled, like classes from the JDK or in this case Java UNO classes. These new methods, unlike those defined through a metaclass or using a category, are available globally.

Aside from a few general methods, initial efforts have been on enhancing the spreadsheet API's and future work will be on enhancing the other applications.
Aside from a few general methods, initial efforts have been on enhancing the spreadsheet API's and future work will be on enhancing the other applications.

== Usage
:author: Carl Marcum
:email: [email protected]
:toc: left

=== Preface
The best way to explain the differences between the Java UNO API's and using Groovy with and without the extension is with some example code. Many of the examples are spreadsheet examples are from SCalc.java that is included with the AOO SDK.

=== Get an XComponentLoader

Java way (assumes XComponentContext xComponentContext reference)
[source,java]
----
XMultiComponentFactory mxRemoteServiceManager = null
XComponentLoader aLoader = null
mxRemoteServiceManager = xComponentContext.getServiceManager()
aLoader = UnoRuntime.queryInterface(
XComponentLoader.class, mxRemoteServiceManager.createInstanceWithContext(
"com.sun.star.frame.Desktop", self))
----

Groovy Extension way
[source,java]
----
XComponentLoader aLoader = mxRemoteContext.componentLoader
----

=== UnoRuntime.queryInterface
The UnoRuntime.queryInterface(ReturnObject.class, FromObject) method can be replaced with the new FromObject.guno(ReturnObject.class) method.
Java way (assumes we have a reference to XSpreadsheetDocument myDoc..)
[source,]
----
XSpreadsheets xSheets = myDoc.getSheets() ;
XIndexAccess oIndexSheets = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xSheets);
xSheet = (XSpreadsheet) UnoRuntime.queryInterface(XSpreadsheet.class, oIndexSheets.getByIndex(0));
----

Groovy Extension way [source,java]
----
XSpreadsheets xSheets = myDoc.sheets
XIndexAccess oIndexSheets = xSheets.guno(XIndexAccess.class)
xSheet = oIndexSheets.getByIndex(0).guno(XSpreadsheet.class)
----
68 changes: 67 additions & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,13 @@ <h1>GUNO Extension Documentation</h1>
<div id="toctitle">Table of Contents</div>
<ul class="sectlevel1">
<li><a href="#trueintroduction">Introduction</a></li>
<li><a href="#trueusage">Usage</a>
<ul class="sectlevel2">
<li><a href="#truepreface">Preface</a></li>
<li><a href="#trueget-an-xcomponentloader">Get an XComponentLoader</a></li>
<li><a href="#trueunoruntime-queryinterface">UnoRuntime.queryInterface</a></li>
</ul>
</li>
</ul>
</div>
</div>
Expand All @@ -472,10 +479,69 @@ <h2 id="trueintroduction"><a class="anchor" href="#trueintroduction"></a>Introdu
</div>
</div>
</div>
<div class="sect1">
<h2 id="trueusage"><a class="anchor" href="#trueusage"></a>Usage</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="truepreface"><a class="anchor" href="#truepreface"></a>Preface</h3>
<div class="paragraph">
<p>The best way to explain the differences between the Java UNO API&#8217;s and using Groovy with and without the extension is with some example code. Many of the examples are spreadsheet examples are from SCalc.java that is included with the AOO SDK.</p>
</div>
</div>
<div class="sect2">
<h3 id="trueget-an-xcomponentloader"><a class="anchor" href="#trueget-an-xcomponentloader"></a>Get an XComponentLoader</h3>
<div class="paragraph">
<p>Java way (assumes XComponentContext xComponentContext reference)</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">XMultiComponentFactory mxRemoteServiceManager = null
XComponentLoader aLoader = null
mxRemoteServiceManager = xComponentContext.getServiceManager()
aLoader = UnoRuntime.queryInterface(
XComponentLoader.class, mxRemoteServiceManager.createInstanceWithContext(
"com.sun.star.frame.Desktop", self))</code></pre>
</div>
</div>
<div class="paragraph">
<p>Groovy Extension way</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">XComponentLoader aLoader = mxRemoteContext.componentLoader</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="trueunoruntime-queryinterface"><a class="anchor" href="#trueunoruntime-queryinterface"></a>UnoRuntime.queryInterface</h3>
<div class="paragraph">
<p>The UnoRuntime.queryInterface(ReturnObject.class, FromObject) method can be replaced with the new FromObject.guno(ReturnObject.class) method.
Java way (assumes we have a reference to XSpreadsheetDocument myDoc..)</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-none hljs">XSpreadsheets xSheets = myDoc.getSheets() ;
XIndexAccess oIndexSheets = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xSheets);
xSheet = (XSpreadsheet) UnoRuntime.queryInterface(XSpreadsheet.class, oIndexSheets.getByIndex(0));</code></pre>
</div>
</div>
<div class="paragraph">
<p>Groovy Extension way [source,java]</p>
</div>
<div class="listingblock">
<div class="content">
<pre>XSpreadsheets xSheets = myDoc.sheets
XIndexAccess oIndexSheets = xSheets.guno(XIndexAccess.class)
xSheet = oIndexSheets.getByIndex(0).guno(XSpreadsheet.class)</pre>
</div>
</div>
</div>
</div>
</div>
</div>
<div id="footer">
<div id="footer-text">
Last updated 2020-06-19 19:29:03 -0400
Last updated 2020-06-19 19:37:37 -0400
</div>
</div>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.6/styles/github.min.css">
Expand Down

0 comments on commit 130f9ff

Please sign in to comment.