-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
112 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
---- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters