Renamings
This commit is contained in:
parent
79c0051ee5
commit
620425f43d
19 changed files with 163 additions and 367 deletions
|
@ -1,10 +1,10 @@
|
|||
#UNO project configuration file
|
||||
#Tue Apr 05 17:37:26 CEST 2016
|
||||
#Thu Mar 19 15:58:57 CET 2020
|
||||
project.srcdir=/source
|
||||
regclassname=org.libreoffice.example.comp.RegistrationHandler
|
||||
regclassname=pro.litvinovg.libreoffice.metadata.RegistrationHandler
|
||||
javaversion=java5
|
||||
project.sdk=5.0.5.2
|
||||
project.ooo=LibreOffice 5.0
|
||||
project.sdk=6.3.5.2
|
||||
project.ooo=LibreOffice 6.3 \#1
|
||||
project.implementation=comp
|
||||
project.build=build
|
||||
project.language=Java
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE dlg:window PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "dialog.dtd">
|
||||
<dlg:window xmlns:dlg="http://openoffice.org/2000/dialog" xmlns:script="http://openoffice.org/2000/script" dlg:id="ActionOneDialog" dlg:left="87" dlg:top="26" dlg:width="230" dlg:height="106" dlg:closeable="true" dlg:moveable="true" dlg:title="Action One">
|
||||
<dlg:bulletinboard>
|
||||
<dlg:text dlg:id="Label1" dlg:tab-index="0" dlg:left="6" dlg:top="6" dlg:width="206" dlg:height="21" dlg:value="Import this dialog file in LibreOffice to add your own widgets"/>
|
||||
<dlg:text dlg:id="Label2" dlg:tab-index="1" dlg:left="-88" dlg:top="64" dlg:width="11" dlg:height="2" dlg:value="Label2"/>
|
||||
<dlg:text dlg:id="Label3" dlg:tab-index="2" dlg:left="6" dlg:top="34" dlg:width="214" dlg:height="38" dlg:value="You can do that by navigating to
Tools->Macros->Manage Dialogs,
then create a new dialog and import this file using the "Import Dialog" button on the toolbar.
When finished, export it again using the toolbar button "Export Dialog"."/>
|
||||
<dlg:button dlg:id="CommandButtonClose" dlg:tab-index="3" dlg:left="173" dlg:top="88" dlg:width="51" dlg:height="13" dlg:value="Close">
|
||||
<script:event script:event-name="on-performaction" script:macro-name="vnd.sun.star.UNO:actionOk" script:language="UNO"/>
|
||||
</dlg:button>
|
||||
</dlg:bulletinboard>
|
||||
</dlg:window>
|
|
@ -7,7 +7,7 @@
|
|||
<node oor:name="com.sun.star.text.TextDocument">
|
||||
<node oor:name="1_SHIFT_MOD1" oor:op="replace">
|
||||
<prop oor:name="Command">
|
||||
<value xml:lang="en-US">service:org.libreoffice.example.StarterProject?actionOne</value>
|
||||
<value xml:lang="en-US">service:pro.litvinovg.libreoffice.MetadataEditor?openGUI</value>
|
||||
</prop>
|
||||
</node>
|
||||
</node>
|
||||
|
|
|
@ -4,29 +4,29 @@
|
|||
<node oor:name="AddonUI">
|
||||
|
||||
<node oor:name="Images">
|
||||
<node oor:name="org.libreoffice.example.StarterProject.imageActionOne" oor:op="replace">
|
||||
<node oor:name="pro.litvinovg.libreoffice.metadata.openGUIImage" oor:op="replace">
|
||||
<prop oor:name="URL" oor:type="xs:string">
|
||||
<value>service:org.libreoffice.example.StarterProject?openGUI</value>
|
||||
<value>service:pro.litvinovg.libreoffice.MetadataEditor?openGUI</value>
|
||||
</prop>
|
||||
<node oor:name="UserDefinedImages">
|
||||
<prop oor:name="ImageSmallURL">
|
||||
<value>vnd.sun.star.extension://org.libreoffice.example.starterproject/images/actionOne_16.png</value>
|
||||
<value>vnd.sun.star.extension://pro.litvinovg.libreoffice.metadata/images/actionOne_16.png</value>
|
||||
</prop>
|
||||
<prop oor:name="ImageBigURL">
|
||||
<value>vnd.sun.star.extension://org.libreoffice.example.starterproject/images/actionOne_26.png</value>
|
||||
<value>vnd.sun.star.extension://pro.litvinovg.libreoffice.metadata/images/actionOne_26.png</value>
|
||||
</prop>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
|
||||
<node oor:name="OfficeToolBar">
|
||||
<node oor:name="org.libreoffice.example.StarterProject.toolbar" oor:op="replace">
|
||||
<node oor:name="pro.litvinovg.libreoffice.metadata.toolbar" oor:op="replace">
|
||||
<prop oor:name="Title" oor:type="xs:string">
|
||||
<value>Starter Project</value>
|
||||
</prop>
|
||||
<node oor:name="t01" oor:op="replace">
|
||||
<prop oor:name="URL" oor:type="xs:string">
|
||||
<value>service:org.libreoffice.example.StarterProject?openGUI</value>
|
||||
<value>service:pro.litvinovg.libreoffice.MetadataEditor?openGUI</value>
|
||||
</prop>
|
||||
<prop oor:name="Target" oor:type="xs:string">
|
||||
<value>_self</value>
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<node oor:name="UIElements">
|
||||
<node oor:name="States">
|
||||
<!-- Used to dock the toolbar in the first toolbar row (by default it's floating) -->
|
||||
<node oor:name="private:resource/toolbar/addon_org.libreoffice.example.StarterProject.toolbar" oor:op="replace">
|
||||
<node oor:name="private:resource/toolbar/addon_pro.litvinovg.libreoffice.MetadataEditor.toolbar" oor:op="replace">
|
||||
<prop oor:name="UIName" oor:type="xs:string">
|
||||
<value>Aktensystem</value>
|
||||
</prop>
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
org.libreoffice.example.comp.StarterProjectImpl
|
|
@ -1,43 +0,0 @@
|
|||
package org.libreoffice.example.dialog;
|
||||
|
||||
import org.libreoffice.example.helper.DialogHelper;
|
||||
|
||||
import com.sun.star.awt.XDialog;
|
||||
import com.sun.star.awt.XDialogEventHandler;
|
||||
import com.sun.star.lang.WrappedTargetException;
|
||||
import com.sun.star.uno.XComponentContext;
|
||||
|
||||
|
||||
public class ActionOneDialog implements XDialogEventHandler {
|
||||
|
||||
private XDialog dialog;
|
||||
private static final String actionOk = "actionOk";
|
||||
private String[] supportedActions = new String[] { actionOk };
|
||||
|
||||
public ActionOneDialog(XComponentContext xContext) {
|
||||
this.dialog = DialogHelper.createDialog("ActionOneDialog.xdl", xContext, this);
|
||||
}
|
||||
|
||||
public void show() {
|
||||
dialog.execute();
|
||||
}
|
||||
|
||||
private void onOkButtonPressed() {
|
||||
dialog.endExecute();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean callHandlerMethod(XDialog dialog, Object eventObject, String methodName) throws WrappedTargetException {
|
||||
if (methodName.equals(actionOk)) {
|
||||
onOkButtonPressed();
|
||||
return true; // Event was handled
|
||||
}
|
||||
return false; // Event was not handled
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getSupportedMethodNames() {
|
||||
return supportedActions;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,184 +0,0 @@
|
|||
package org.libreoffice.example.helper;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import com.sun.star.awt.MessageBoxType;
|
||||
import com.sun.star.awt.Point;
|
||||
import com.sun.star.awt.XButton;
|
||||
import com.sun.star.awt.XComboBox;
|
||||
import com.sun.star.awt.XControl;
|
||||
import com.sun.star.awt.XControlContainer;
|
||||
import com.sun.star.awt.XControlModel;
|
||||
import com.sun.star.awt.XDialog;
|
||||
import com.sun.star.awt.XDialogEventHandler;
|
||||
import com.sun.star.awt.XDialogProvider2;
|
||||
import com.sun.star.awt.XFixedText;
|
||||
import com.sun.star.awt.XListBox;
|
||||
import com.sun.star.awt.XMessageBox;
|
||||
import com.sun.star.awt.XMessageBoxFactory;
|
||||
import com.sun.star.awt.XTextComponent;
|
||||
import com.sun.star.awt.XToolkit;
|
||||
import com.sun.star.awt.XWindow;
|
||||
import com.sun.star.awt.XWindowPeer;
|
||||
import com.sun.star.beans.PropertyVetoException;
|
||||
import com.sun.star.beans.UnknownPropertyException;
|
||||
import com.sun.star.beans.XPropertySet;
|
||||
import com.sun.star.lang.WrappedTargetException;
|
||||
import com.sun.star.uno.Exception;
|
||||
import com.sun.star.uno.UnoRuntime;
|
||||
import com.sun.star.uno.XComponentContext;
|
||||
|
||||
public class DialogHelper {
|
||||
|
||||
/**
|
||||
* Create a dialog from an xdl file.
|
||||
*
|
||||
* @param xdlFile
|
||||
* The filename in the `dialog` folder
|
||||
* @param context
|
||||
* @return XDialog
|
||||
*/
|
||||
public static XDialog createDialog(String xdlFile, XComponentContext context, XDialogEventHandler handler) {
|
||||
Object oDialogProvider;
|
||||
try {
|
||||
oDialogProvider = context.getServiceManager().createInstanceWithContext("com.sun.star.awt.DialogProvider2",
|
||||
context);
|
||||
XDialogProvider2 xDialogProv = (XDialogProvider2) UnoRuntime.queryInterface(XDialogProvider2.class,
|
||||
oDialogProvider);
|
||||
File dialogFile = FileHelper.getDialogFilePath(xdlFile, context);
|
||||
return xDialogProv.createDialogWithHandler(convertToURL(context, dialogFile), handler);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns a URL to be used with XDialogProvider to create a dialog */
|
||||
public static String convertToURL(XComponentContext xContext, File dialogFile) {
|
||||
String sURL = null;
|
||||
try {
|
||||
com.sun.star.ucb.XFileIdentifierConverter xFileConverter = (com.sun.star.ucb.XFileIdentifierConverter) UnoRuntime
|
||||
.queryInterface(com.sun.star.ucb.XFileIdentifierConverter.class, xContext.getServiceManager()
|
||||
.createInstanceWithContext("com.sun.star.ucb.FileContentProvider", xContext));
|
||||
sURL = xFileConverter.getFileURLFromSystemPath("", dialogFile.getAbsolutePath());
|
||||
} catch (com.sun.star.uno.Exception ex) {
|
||||
return null;
|
||||
}
|
||||
return sURL;
|
||||
}
|
||||
|
||||
/** Returns a button (XButton) from a dialog */
|
||||
public static XButton getButton(XDialog dialog, String componentId) {
|
||||
XControlContainer xDlgContainer = (XControlContainer) UnoRuntime.queryInterface(XControlContainer.class,
|
||||
dialog);
|
||||
Object control = xDlgContainer.getControl(componentId);
|
||||
return (XButton) UnoRuntime.queryInterface(XButton.class, control);
|
||||
}
|
||||
|
||||
/** Returns a text field (XTextComponent) from a dialog */
|
||||
public static XTextComponent getEditField(XDialog dialog, String componentId) {
|
||||
XControlContainer xDlgContainer = (XControlContainer) UnoRuntime.queryInterface(XControlContainer.class,
|
||||
dialog);
|
||||
Object control = xDlgContainer.getControl(componentId);
|
||||
return (XTextComponent) UnoRuntime.queryInterface(XTextComponent.class, control);
|
||||
}
|
||||
|
||||
/** Returns a Combo box (XComboBox) from a dialog */
|
||||
public static XComboBox getCombobox(XDialog dialog, String componentId) {
|
||||
XControlContainer xDlgContainer = (XControlContainer) UnoRuntime.queryInterface(XControlContainer.class,
|
||||
dialog);
|
||||
Object control = xDlgContainer.getControl(componentId);
|
||||
return (XComboBox) UnoRuntime.queryInterface(XComboBox.class, control);
|
||||
}
|
||||
|
||||
/** Returns a List box (XListBox) from a dialog */
|
||||
public static XListBox getListBox(XDialog dialog, String componentId) {
|
||||
XControlContainer xDlgContainer = (XControlContainer) UnoRuntime.queryInterface(XControlContainer.class,
|
||||
dialog);
|
||||
Object control = xDlgContainer.getControl(componentId);
|
||||
return (XListBox) UnoRuntime.queryInterface(XListBox.class, control);
|
||||
}
|
||||
|
||||
/** Returns a label (XFixedText) from a dialog */
|
||||
public static XFixedText getLabel(XDialog dialog, String componentId) {
|
||||
XControlContainer xDlgContainer = (XControlContainer) UnoRuntime.queryInterface(XControlContainer.class,
|
||||
dialog);
|
||||
Object control = xDlgContainer.getControl(componentId);
|
||||
return (XFixedText) UnoRuntime.queryInterface(XFixedText.class, control);
|
||||
}
|
||||
|
||||
public static void EnableButton(XDialog dialog, String componentId, boolean enable) {
|
||||
XControlContainer xDlgContainer = (XControlContainer) UnoRuntime.queryInterface(XControlContainer.class,
|
||||
dialog);
|
||||
// retrieve the control that we want to disable or enable
|
||||
XControl xControl = UnoRuntime.queryInterface(XControl.class, xDlgContainer.getControl(componentId));
|
||||
XPropertySet xModelPropertySet = UnoRuntime.queryInterface(XPropertySet.class, xControl.getModel());
|
||||
try {
|
||||
xModelPropertySet.setPropertyValue("Enabled", Boolean.valueOf(enable));
|
||||
} catch (IllegalArgumentException | UnknownPropertyException | PropertyVetoException
|
||||
| WrappedTargetException e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/** Set the focus to an input field */
|
||||
public static void SetFocus(XTextComponent editField) {
|
||||
XWindow xControlWindow = UnoRuntime.queryInterface(XWindow.class, editField);
|
||||
xControlWindow.setFocus();
|
||||
}
|
||||
|
||||
public static void setPosition(XDialog dialog, int posX, int posY) {
|
||||
XControlModel xDialogModel = UnoRuntime.queryInterface(XControl.class, dialog).getModel();
|
||||
XPropertySet xPropSet = UnoRuntime.queryInterface(XPropertySet.class, xDialogModel);
|
||||
try {
|
||||
xPropSet.setPropertyValue("PositionX", posX);
|
||||
xPropSet.setPropertyValue("PositionY", posY);
|
||||
} catch (com.sun.star.lang.IllegalArgumentException | UnknownPropertyException | PropertyVetoException
|
||||
| WrappedTargetException e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public static Point getPosition(XDialog dialog) {
|
||||
int posX = 0;
|
||||
int posY = 0;
|
||||
XControlModel xDialogModel = UnoRuntime.queryInterface(XControl.class, dialog).getModel();
|
||||
XPropertySet xPropSet = UnoRuntime.queryInterface(XPropertySet.class, xDialogModel);
|
||||
try {
|
||||
posX = (int) xPropSet.getPropertyValue("PositionX");
|
||||
posY = (int) xPropSet.getPropertyValue("PositionY");
|
||||
} catch (UnknownPropertyException | WrappedTargetException e) {
|
||||
}
|
||||
return new Point(posX, posY);
|
||||
}
|
||||
|
||||
public static void showInfoMessage(XComponentContext context, XDialog dialog, String message) {
|
||||
showMessageBox(context, dialog, MessageBoxType.INFOBOX, "Info", message);
|
||||
}
|
||||
|
||||
public static void showWarningMessage(XComponentContext context, XDialog dialog, String message) {
|
||||
showMessageBox(context, dialog, MessageBoxType.WARNINGBOX, "Warnung", message);
|
||||
}
|
||||
|
||||
public static void showErrorMessage(XComponentContext context, XDialog dialog, String message) {
|
||||
showMessageBox(context, dialog, MessageBoxType.ERRORBOX, "Fehler", message);
|
||||
}
|
||||
|
||||
public static void showMessageBox(XComponentContext context, XDialog dialog, MessageBoxType type, String sTitle, String sMessage) {
|
||||
XToolkit xToolkit;
|
||||
try {
|
||||
xToolkit = UnoRuntime.queryInterface(XToolkit.class,
|
||||
context.getServiceManager().createInstanceWithContext("com.sun.star.awt.Toolkit", context));
|
||||
} catch (Exception e) {
|
||||
return;
|
||||
}
|
||||
XMessageBoxFactory xMessageBoxFactory = UnoRuntime.queryInterface(XMessageBoxFactory.class, xToolkit);
|
||||
XWindowPeer xParentWindowPeer = UnoRuntime.queryInterface(XWindowPeer.class, dialog);
|
||||
XMessageBox xMessageBox = xMessageBoxFactory.createMessageBox(xParentWindowPeer, type,
|
||||
com.sun.star.awt.MessageBoxButtons.BUTTONS_OK, sTitle, sMessage);
|
||||
if (xMessageBox == null)
|
||||
return;
|
||||
|
||||
xMessageBox.execute();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
package org.libreoffice.example.helper;
|
||||
|
||||
import com.sun.star.frame.XDesktop;
|
||||
import com.sun.star.frame.XFrame;
|
||||
import com.sun.star.frame.XModel;
|
||||
import com.sun.star.lang.XComponent;
|
||||
import com.sun.star.lang.XMultiComponentFactory;
|
||||
import com.sun.star.text.XTextDocument;
|
||||
import com.sun.star.uno.UnoRuntime;
|
||||
import com.sun.star.uno.XComponentContext;
|
||||
|
||||
public class DocumentHelper {
|
||||
|
||||
/** Returns the curerent XDesktop */
|
||||
public static XDesktop getCurrentDesktop(XComponentContext xContext) {
|
||||
XMultiComponentFactory xMCF = (XMultiComponentFactory) UnoRuntime.queryInterface(XMultiComponentFactory.class,
|
||||
xContext.getServiceManager());
|
||||
Object desktop = null;
|
||||
try {
|
||||
desktop = xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", xContext);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
return (XDesktop) UnoRuntime.queryInterface(com.sun.star.frame.XDesktop.class, desktop);
|
||||
}
|
||||
|
||||
/** Returns the current XComponent */
|
||||
private static XComponent getCurrentComponent(XComponentContext xContext) {
|
||||
return (XComponent) getCurrentDesktop(xContext).getCurrentComponent();
|
||||
}
|
||||
|
||||
/** Returns the current frame */
|
||||
public static XFrame getCurrentFrame(XComponentContext xContext) {
|
||||
XModel xModel = (XModel) UnoRuntime.queryInterface(XModel.class, getCurrentComponent(xContext));
|
||||
return xModel.getCurrentController().getFrame();
|
||||
}
|
||||
|
||||
/** Returns the current text document (if any) */
|
||||
public static XTextDocument getCurrentDocument(XComponentContext xContext) {
|
||||
return (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, getCurrentComponent(xContext));
|
||||
}
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
package org.libreoffice.example.helper;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
|
||||
import com.sun.star.deployment.PackageInformationProvider;
|
||||
import com.sun.star.deployment.XPackageInformationProvider;
|
||||
import com.sun.star.uno.Exception;
|
||||
import com.sun.star.uno.UnoRuntime;
|
||||
import com.sun.star.uno.XComponentContext;
|
||||
import com.sun.star.util.XURLTransformer;
|
||||
|
||||
public class FileHelper {
|
||||
|
||||
final static String DIALOG_RESOURCES = "dialog/";
|
||||
|
||||
/**
|
||||
* Returns a path to a dialog file
|
||||
*/
|
||||
public static File getDialogFilePath(String xdlFile, XComponentContext xContext) {
|
||||
return getFilePath(DIALOG_RESOURCES + xdlFile, xContext);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a file path for a file in the installed extension, or null on failure.
|
||||
*/
|
||||
public static File getFilePath(String file, XComponentContext xContext) {
|
||||
XPackageInformationProvider xPackageInformationProvider = PackageInformationProvider.get(xContext);
|
||||
String location = xPackageInformationProvider.getPackageLocation("org.libreoffice.example.starterproject");
|
||||
Object oTransformer;
|
||||
try {
|
||||
oTransformer = xContext.getServiceManager().createInstanceWithContext("com.sun.star.util.URLTransformer", xContext);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
XURLTransformer xTransformer = (XURLTransformer)UnoRuntime.queryInterface(XURLTransformer.class, oTransformer);
|
||||
com.sun.star.util.URL[] oURL = new com.sun.star.util.URL[1];
|
||||
oURL[0] = new com.sun.star.util.URL();
|
||||
oURL[0].Complete = location + "/" + file;
|
||||
xTransformer.parseStrict(oURL);
|
||||
URL url;
|
||||
try {
|
||||
url = new URL(oURL[0].Complete);
|
||||
} catch (MalformedURLException e1) {
|
||||
return null;
|
||||
}
|
||||
File f;
|
||||
try {
|
||||
f = new File(url.toURI());
|
||||
} catch (URISyntaxException e1) {
|
||||
return null;
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
}
|
|
@ -6,7 +6,6 @@ import java.util.Arrays;
|
|||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.libreoffice.example.comp.MetadataInaccessableException;
|
||||
|
||||
import com.sun.org.apache.bcel.internal.generic.NEW;
|
||||
import com.sun.star.beans.IllegalTypeException;
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
package org.libreoffice.example.comp;
|
||||
package pro.litvinovg.libreoffice.metadata;
|
||||
|
||||
import com.sun.star.uno.UnoRuntime;
|
||||
import com.sun.star.uno.XComponentContext;
|
||||
|
||||
import pro.litvinovg.libreoffice.metadata.Document;
|
||||
import pro.litvinovg.libreoffice.metadata.views.EditorGUI;
|
||||
|
||||
import com.sun.star.lib.uno.helper.Factory;
|
||||
|
@ -11,9 +10,6 @@ import com.sun.star.lib.uno.helper.Factory;
|
|||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
|
||||
import org.libreoffice.example.dialog.ActionOneDialog;
|
||||
import org.libreoffice.example.helper.DialogHelper;
|
||||
|
||||
import com.sun.star.beans.Property;
|
||||
import com.sun.star.beans.XPropertyContainer;
|
||||
import com.sun.star.beans.XPropertySet;
|
||||
|
@ -29,7 +25,7 @@ import com.sun.star.registry.XRegistryKey;
|
|||
import com.sun.star.lib.uno.helper.WeakBase;
|
||||
|
||||
|
||||
public final class StarterProjectImpl extends WeakBase
|
||||
public final class MetadataExtensionImpl extends WeakBase
|
||||
implements com.sun.star.lang.XServiceInfo,
|
||||
com.sun.star.task.XJobExecutor
|
||||
{
|
||||
|
@ -39,11 +35,11 @@ public final class StarterProjectImpl extends WeakBase
|
|||
private XComponent currentDocument;
|
||||
private XDocumentProperties documentProperties;
|
||||
private XDocumentPropertiesSupplier documentPropertiesSupplier;
|
||||
private static final String m_implementationName = StarterProjectImpl.class.getName();
|
||||
private static final String[] m_serviceNames = { "org.libreoffice.example.StarterProject" };
|
||||
private static final String m_implementationName = MetadataExtensionImpl.class.getName();
|
||||
private static final String[] m_serviceNames = { "pro.litvinovg.libreoffice.MetadataEditor" };
|
||||
|
||||
|
||||
public StarterProjectImpl(XComponentContext componentContext) {
|
||||
public MetadataExtensionImpl(XComponentContext componentContext) {
|
||||
context = componentContext;
|
||||
|
||||
};
|
||||
|
@ -52,7 +48,7 @@ public final class StarterProjectImpl extends WeakBase
|
|||
XSingleComponentFactory xFactory = null;
|
||||
|
||||
if ( sImplementationName.equals( m_implementationName ) )
|
||||
xFactory = Factory.createComponentFactory(StarterProjectImpl.class, m_serviceNames);
|
||||
xFactory = Factory.createComponentFactory(MetadataExtensionImpl.class, m_serviceNames);
|
||||
return xFactory;
|
||||
}
|
||||
|
||||
|
@ -90,7 +86,6 @@ public final class StarterProjectImpl extends WeakBase
|
|||
EditorGUI.runGUI(doc);
|
||||
break;
|
||||
default:
|
||||
DialogHelper.showErrorMessage(context, null, "Unknown action: " + action);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.libreoffice.example.comp;
|
||||
package pro.litvinovg.libreoffice.metadata;
|
||||
|
||||
public class MetadataInaccessableException extends Exception {
|
||||
public MetadataInaccessableException(String errorMessage) {
|
|
@ -0,0 +1 @@
|
|||
pro.litvinovg.libreoffice.metadata.MetadataExtensionImpl
|
|
@ -35,7 +35,7 @@
|
|||
*
|
||||
*
|
||||
************************************************************************/
|
||||
package org.libreoffice.example.comp;
|
||||
package pro.litvinovg.libreoffice.metadata;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
|
@ -0,0 +1,13 @@
|
|||
package pro.litvinovg.libreoffice.metadata.tests;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Suite.SuiteClasses;
|
||||
import pro.litvinovg.libreoffice.metadata.tests.uno.WriterTest;
|
||||
|
||||
import pro.litvinovg.libreoffice.metadata.tests.base.UnoSuite;
|
||||
|
||||
@RunWith(UnoSuite.class)
|
||||
@SuiteClasses({WriterTest.class})
|
||||
public class UnoTests {
|
||||
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
package pro.litvinovg.libreoffice.metadata.tests.base;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.runner.Runner;
|
||||
import org.junit.runner.notification.RunNotifier;
|
||||
import org.junit.runners.Suite;
|
||||
import org.junit.runners.model.InitializationError;
|
||||
import org.junit.runners.model.RunnerBuilder;
|
||||
|
||||
import com.sun.star.frame.XDesktop;
|
||||
import com.sun.star.lang.XMultiComponentFactory;
|
||||
import com.sun.star.uno.UnoRuntime;
|
||||
import com.sun.star.uno.XComponentContext;
|
||||
|
||||
public class UnoSuite extends Suite {
|
||||
|
||||
private static XComponentContext componentContext;
|
||||
|
||||
public UnoSuite(Class<?> klass, RunnerBuilder builder) throws InitializationError {
|
||||
super(klass, builder);
|
||||
}
|
||||
|
||||
public UnoSuite(RunnerBuilder builder, Class<?>[] classes) throws InitializationError {
|
||||
super(builder, classes);
|
||||
}
|
||||
|
||||
public UnoSuite(Class<?> klass, Class<?>[] suiteClasses) throws InitializationError {
|
||||
super(klass, suiteClasses);
|
||||
}
|
||||
|
||||
public UnoSuite(Class<?> klass, List<Runner> runners) throws InitializationError {
|
||||
super(klass, runners);
|
||||
}
|
||||
|
||||
public UnoSuite(RunnerBuilder builder, Class<?> klass, Class<?>[] suiteClasses) throws InitializationError {
|
||||
super(builder, klass, suiteClasses);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(RunNotifier arg0) {
|
||||
try {
|
||||
startOffice();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
super.run(arg0);
|
||||
|
||||
stopOffice();
|
||||
}
|
||||
|
||||
private void startOffice() throws Exception {
|
||||
componentContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
|
||||
}
|
||||
|
||||
private void stopOffice() {
|
||||
try {
|
||||
if (componentContext != null) {
|
||||
// Only the uno test suite which started the office can stop it
|
||||
XMultiComponentFactory xMngr = componentContext.getServiceManager();
|
||||
Object oDesktop = xMngr.createInstanceWithContext("com.sun.star.frame.Desktop", componentContext);
|
||||
XDesktop xDesktop = (XDesktop)UnoRuntime.queryInterface(XDesktop.class, oDesktop);
|
||||
|
||||
xDesktop.terminate();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static XComponentContext getComponentContext() {
|
||||
return componentContext;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package pro.litvinovg.libreoffice.metadata.tests.helper;
|
||||
|
||||
import com.sun.star.beans.PropertyValue;
|
||||
import com.sun.star.frame.FrameSearchFlag;
|
||||
import com.sun.star.frame.XComponentLoader;
|
||||
import com.sun.star.lang.XComponent;
|
||||
import com.sun.star.lang.XMultiComponentFactory;
|
||||
import com.sun.star.text.XTextDocument;
|
||||
import com.sun.star.uno.Exception;
|
||||
import com.sun.star.uno.UnoRuntime;
|
||||
|
||||
import pro.litvinovg.libreoffice.metadata.tests.base.UnoSuite;
|
||||
|
||||
public class UnoHelper {
|
||||
|
||||
public static XTextDocument getWriterDocument() throws Exception {
|
||||
XMultiComponentFactory xMngr = UnoSuite.getComponentContext().getServiceManager();
|
||||
Object oDesktop = xMngr.createInstanceWithContext("com.sun.star.frame.Desktop", UnoSuite.getComponentContext());
|
||||
XComponentLoader xLoader = (XComponentLoader)UnoRuntime.queryInterface(
|
||||
XComponentLoader.class, oDesktop);
|
||||
|
||||
XComponent xDoc = xLoader.loadComponentFromURL("private:factory/swriter", "_default",
|
||||
FrameSearchFlag.ALL, new PropertyValue[0]);
|
||||
|
||||
return (XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, xDoc);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package pro.litvinovg.libreoffice.metadata.tests.uno;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.sun.star.text.XTextDocument;
|
||||
|
||||
import pro.litvinovg.libreoffice.metadata.tests.helper.UnoHelper;
|
||||
|
||||
public class WriterTest {
|
||||
|
||||
private XTextDocument xTextDocument;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
xTextDocument = UnoHelper.getWriterDocument();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
assertNotNull(xTextDocument);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue