summaryrefslogtreecommitdiff
path: root/sfx2/qa
diff options
context:
space:
mode:
authorNoel Grandin <noel@peralex.com>2015-06-11 13:10:09 +0200
committerNoel Grandin <noel@peralex.com>2015-06-15 10:44:42 +0200
commit8b85838611ed448ef18a9e4982849bbd702981aa (patch)
tree4aa539ec21817884133f27deb0512769509a2304 /sfx2/qa
parent0b255720a60f15ffe8006b37e367378b229e245f (diff)
java: remove unnecessary threading
there is no point in spawning a thread to load a document and then waiting for the thread to finish Change-Id: Icd5d5452471b0a50a8e3525ab2b5f32a500ebdf4
Diffstat (limited to 'sfx2/qa')
-rw-r--r--sfx2/qa/complex/sfx2/GlobalEventBroadcaster.java4
-rw-r--r--sfx2/qa/complex/sfx2/tools/DialogThread.java79
-rw-r--r--sfx2/qa/complex/sfx2/tools/WriterHelper.java126
3 files changed, 90 insertions, 119 deletions
diff --git a/sfx2/qa/complex/sfx2/GlobalEventBroadcaster.java b/sfx2/qa/complex/sfx2/GlobalEventBroadcaster.java
index c639ca168a2a..e4154db87220 100644
--- a/sfx2/qa/complex/sfx2/GlobalEventBroadcaster.java
+++ b/sfx2/qa/complex/sfx2/GlobalEventBroadcaster.java
@@ -95,7 +95,7 @@ public class GlobalEventBroadcaster {
System.out.println("... done");
}
- @Test public void checkWriter() {
+ @Test public void checkWriter() throws Exception {
System.out.println("-- Checking Writer --");
WriterHelper wHelper = new WriterHelper(m_xMSF);
@@ -156,7 +156,7 @@ public class GlobalEventBroadcaster {
proveExpectation(expected));
System.out.println("... done");
- // TODO: It seems not possible to close the document without interactiv question
+ // TODO: It seems not possible to close the document without interactive question
// there the follow test will not be execute
if (false) {
System.out.println("Opening document with label wizard");
diff --git a/sfx2/qa/complex/sfx2/tools/DialogThread.java b/sfx2/qa/complex/sfx2/tools/DialogThread.java
deleted file mode 100644
index b4a8ddae3e1a..000000000000
--- a/sfx2/qa/complex/sfx2/tools/DialogThread.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed
- * with this work for additional information regarding copyright
- * ownership. The ASF licenses this file to you under the Apache
- * License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-package complex.sfx2.tools;
-
-import com.sun.star.beans.PropertyValue;
-import com.sun.star.frame.XController;
-import com.sun.star.frame.XDispatch;
-import com.sun.star.frame.XDispatchProvider;
-import com.sun.star.frame.XModel;
-import com.sun.star.lang.XComponent;
-import com.sun.star.lang.XMultiServiceFactory;
-import com.sun.star.uno.UnoRuntime;
-import com.sun.star.util.URL;
-import com.sun.star.util.XURLTransformer;
-
-/**
- * This class opens a given dialog in a separate Thread by dispatching an url
- *
- */
-public class DialogThread extends Thread {
- private XComponent m_xDoc = null;
- private XMultiServiceFactory m_xMSF = null;
- private String m_url = "";
-
- public DialogThread(XComponent xDoc, XMultiServiceFactory msf, String url) {
- this.m_xDoc = xDoc;
- this.m_xMSF = msf;
- this.m_url = url;
- }
-
- @Override
- public void run() {
- XModel aModel = UnoRuntime.queryInterface( XModel.class, m_xDoc );
-
- XController xController = aModel.getCurrentController();
-
- //Opening Dialog
- try {
- XDispatchProvider xDispProv = UnoRuntime.queryInterface( XDispatchProvider.class, xController.getFrame() );
- XURLTransformer xParser = UnoRuntime.queryInterface( XURLTransformer.class,
- m_xMSF.createInstance( "com.sun.star.util.URLTransformer" ) );
-
- // Because it's an in/out parameter
- // we must use an array of URL objects.
- URL[] aParseURL = new URL[1];
- aParseURL[0] = new URL();
- aParseURL[0].Complete = m_url;
- xParser.parseStrict(aParseURL);
-
- URL aURL = aParseURL[0];
- XDispatch xDispatcher = xDispProv.queryDispatch(aURL, "", com.sun.star.frame.FrameSearchFlag.SELF |
- com.sun.star.frame.FrameSearchFlag.CHILDREN);
- PropertyValue[] dispatchArguments = new PropertyValue[0];
-
- if (xDispatcher != null) {
- xDispatcher.dispatch(aURL, dispatchArguments);
- } else {
- System.out.println("xDispatcher is null");
- }
- } catch (com.sun.star.uno.Exception e) {
- System.out.println("Couldn't open dialog");
- }
- }
-} \ No newline at end of file
diff --git a/sfx2/qa/complex/sfx2/tools/WriterHelper.java b/sfx2/qa/complex/sfx2/tools/WriterHelper.java
index d0d47ce64485..382aebca5449 100644
--- a/sfx2/qa/complex/sfx2/tools/WriterHelper.java
+++ b/sfx2/qa/complex/sfx2/tools/WriterHelper.java
@@ -23,17 +23,23 @@ import com.sun.star.accessibility.XAccessibleAction;
import com.sun.star.accessibility.XAccessibleContext;
import com.sun.star.awt.XExtendedToolkit;
import com.sun.star.awt.XWindow;
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.frame.XController;
import com.sun.star.frame.XDesktop;
+import com.sun.star.frame.XDispatch;
+import com.sun.star.frame.XDispatchProvider;
+import com.sun.star.frame.XModel;
import com.sun.star.lang.XComponent;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.text.XTextDocument;
import com.sun.star.uno.UnoRuntime;
+import com.sun.star.util.URL;
import com.sun.star.util.XCloseable;
+import com.sun.star.util.XURLTransformer;
import util.AccessibilityTools;
import util.WriterTools;
-
/**
* Methods to open Writer docs
*
@@ -41,26 +47,36 @@ import util.WriterTools;
public class WriterHelper {
private XMultiServiceFactory m_xMSF = null;
- /** Creates a new instance of WriterHelper
- * @param xMSF The MultiServiceFactory gained from the office
+ /**
+ * Creates a new instance of WriterHelper
+ *
+ * @param xMSF
+ * The MultiServiceFactory gained from the office
*/
public WriterHelper(XMultiServiceFactory xMSF) {
this.m_xMSF = xMSF;
}
- /** Opens an empty document
+ /**
+ * Opens an empty document
+ *
* @return a reference to the opened document is returned
*/
public XTextDocument openEmptyDoc() {
return WriterTools.createTextDoc(m_xMSF);
}
- /** Closes a given XTextDocument
- * @param xTextDoc the text document to be closed
- * @return if an error occurs the errormessage is returned and an empty String if not
+ /**
+ * Closes a given XTextDocument
+ *
+ * @param xTextDoc
+ * the text document to be closed
+ * @return if an error occurs the errormessage is returned and an empty
+ * String if not
*/
public String closeDoc(XTextDocument xTextDoc) {
- XCloseable closer = UnoRuntime.queryInterface(XCloseable.class, xTextDoc);
+ XCloseable closer = UnoRuntime.queryInterface(XCloseable.class,
+ xTextDoc);
String err = "";
try {
@@ -74,20 +90,51 @@ public class WriterHelper {
}
private XTextDocument xLocalDoc = null;
- /** a TextDocument is opened by pressing a button in a dialog given by uno-URL
- * @param url the uno-URL of the dialog to be opened
- * @param createButton the language dependent label of the button to be pressed
- * @param destroyLocal if true the document that has been opened to dispatch the dialog is closed before the method returns,
- * otherwise this document remains open
+
+ /**
+ * a TextDocument is opened by pressing a button in a dialog given by
+ * uno-URL
+ *
+ * @param url
+ * the uno-URL of the dialog to be opened
+ * @param createButton
+ * the language dependent label of the button to be pressed
+ * @param destroyLocal
+ * if true the document that has been opened to dispatch the
+ * dialog is closed before the method returns, otherwise this
+ * document remains open
* @return returns the created Textdocument
*/
public XTextDocument openFromDialog(String url, String createButton,
- boolean destroyLocal) {
+ boolean destroyLocal) throws Exception {
xLocalDoc = WriterTools.createTextDoc(m_xMSF);
- XComponent comp = UnoRuntime.queryInterface(XComponent.class, xLocalDoc);
- DialogThread diagThread = new DialogThread(comp, m_xMSF, url);
- diagThread.start();
- util.utils.pause(4000);
+ XComponent comp = UnoRuntime
+ .queryInterface(XComponent.class, xLocalDoc);
+
+ XModel aModel = UnoRuntime.queryInterface(XModel.class, comp);
+
+ XController xController = aModel.getCurrentController();
+
+ // Opening Dialog
+ XDispatchProvider xDispProv = UnoRuntime.queryInterface(
+ XDispatchProvider.class, xController.getFrame());
+ XURLTransformer xParser = UnoRuntime.queryInterface(
+ XURLTransformer.class,
+ m_xMSF.createInstance("com.sun.star.util.URLTransformer"));
+
+ // Because it's an in/out parameter
+ // we must use an array of URL objects.
+ URL[] aParseURL = new URL[] { new URL() };
+ aParseURL[0].Complete = url;
+ xParser.parseStrict(aParseURL);
+
+ XDispatch xDispatcher = xDispProv.queryDispatch(aParseURL[0], "",
+ com.sun.star.frame.FrameSearchFlag.SELF
+ | com.sun.star.frame.FrameSearchFlag.CHILDREN);
+ if (xDispatcher != null) {
+ PropertyValue[] dispatchArguments = new PropertyValue[0];
+ xDispatcher.dispatch(aParseURL[0], dispatchArguments);
+ }
if (createButton.length() > 1) {
XExtendedToolkit tk = getToolkit();
@@ -96,16 +143,16 @@ public class WriterHelper {
XWindow xWindow = UnoRuntime.queryInterface(XWindow.class, atw);
XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
- XAccessibleContext buttonContext = AccessibilityTools.getAccessibleObjectForRole(
- xRoot,
- AccessibleRole.PUSH_BUTTON,
- createButton);
+ XAccessibleContext buttonContext = AccessibilityTools
+ .getAccessibleObjectForRole(xRoot,
+ AccessibleRole.PUSH_BUTTON, createButton);
- XAccessibleAction buttonAction = UnoRuntime.queryInterface(XAccessibleAction.class, buttonContext);
+ XAccessibleAction buttonAction = UnoRuntime.queryInterface(
+ XAccessibleAction.class, buttonContext);
try {
- System.out.println("Name: " +
- buttonContext.getAccessibleName());
+ System.out
+ .println("Name: " + buttonContext.getAccessibleName());
buttonAction.doAccessibleAction(0);
} catch (com.sun.star.lang.IndexOutOfBoundsException e) {
System.out.println("Couldn't press button");
@@ -116,7 +163,8 @@ public class WriterHelper {
XDesktop xDesktop = getDesktop();
- XTextDocument returnDoc = UnoRuntime.queryInterface(XTextDocument.class, xDesktop.getCurrentComponent());
+ XTextDocument returnDoc = UnoRuntime.queryInterface(
+ XTextDocument.class, xDesktop.getCurrentComponent());
if (destroyLocal) {
closeDoc(xLocalDoc);
@@ -125,18 +173,16 @@ public class WriterHelper {
return returnDoc;
}
- public void closeFromDialog()
- {
+
+ public void closeFromDialog() {
closeDoc(xLocalDoc);
xLocalDoc = null;
}
-
-
-
-
- /** creates an instance of com.sun.star.awt.Toolkit to query the XExtendedToolkit
- * interface
+ /**
+ * creates an instance of com.sun.star.awt.Toolkit to query the
+ * XExtendedToolkit interface
+ *
* @return returns the gained XExtendedToolkit Interface
*/
public XExtendedToolkit getToolkit() {
@@ -146,15 +192,19 @@ public class WriterHelper {
toolkit = m_xMSF.createInstance("com.sun.star.awt.Toolkit");
} catch (com.sun.star.uno.Exception e) {
System.out.println("Couldn't get toolkit");
- e.printStackTrace( System.err );
+ e.printStackTrace(System.err);
}
- XExtendedToolkit tk = UnoRuntime.queryInterface(XExtendedToolkit.class, toolkit);
+ XExtendedToolkit tk = UnoRuntime.queryInterface(XExtendedToolkit.class,
+ toolkit);
return tk;
}
- /** creates an instance of com.sun.star.frame.Desktop to query the XDesktop interface
+ /**
+ * creates an instance of com.sun.star.frame.Desktop to query the XDesktop
+ * interface
+ *
* @return returns the gained XDesktop interface
*/
private XDesktop getDesktop() {
@@ -164,7 +214,7 @@ public class WriterHelper {
desk = m_xMSF.createInstance("com.sun.star.frame.Desktop");
} catch (com.sun.star.uno.Exception e) {
System.out.println("Couldn't get desktop");
- e.printStackTrace( System.err );
+ e.printStackTrace(System.err);
}
XDesktop xDesktop = UnoRuntime.queryInterface(XDesktop.class, desk);