Show hello world dialog when executing
This commit is contained in:
parent
5eda71f9f9
commit
bc9ed8d08b
2 changed files with 49 additions and 1 deletions
|
@ -2,6 +2,9 @@ package org.libreoffice.example.comp;
|
||||||
|
|
||||||
import com.sun.star.uno.XComponentContext;
|
import com.sun.star.uno.XComponentContext;
|
||||||
import com.sun.star.lib.uno.helper.Factory;
|
import com.sun.star.lib.uno.helper.Factory;
|
||||||
|
|
||||||
|
import org.libreoffice.example.helper.DialogHelper;
|
||||||
|
|
||||||
import com.sun.star.lang.XSingleComponentFactory;
|
import com.sun.star.lang.XSingleComponentFactory;
|
||||||
import com.sun.star.registry.XRegistryKey;
|
import com.sun.star.registry.XRegistryKey;
|
||||||
import com.sun.star.lib.uno.helper.WeakBase;
|
import com.sun.star.lib.uno.helper.WeakBase;
|
||||||
|
@ -58,7 +61,7 @@ public final class StarterProjectImpl extends WeakBase
|
||||||
// com.sun.star.task.XJobExecutor:
|
// com.sun.star.task.XJobExecutor:
|
||||||
public void trigger(String Event)
|
public void trigger(String Event)
|
||||||
{
|
{
|
||||||
// TODO: Insert your implementation for "trigger" here.
|
DialogHelper.showInfoMessage(m_xContext, null, "Hello World!");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
45
source/org/libreoffice/example/helper/DialogHelper.java
Normal file
45
source/org/libreoffice/example/helper/DialogHelper.java
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
package org.libreoffice.example.helper;
|
||||||
|
|
||||||
|
import com.sun.star.awt.MessageBoxType;
|
||||||
|
import com.sun.star.awt.XDialog;
|
||||||
|
import com.sun.star.awt.XMessageBox;
|
||||||
|
import com.sun.star.awt.XMessageBoxFactory;
|
||||||
|
import com.sun.star.awt.XToolkit;
|
||||||
|
import com.sun.star.awt.XWindowPeer;
|
||||||
|
import com.sun.star.uno.Exception;
|
||||||
|
import com.sun.star.uno.UnoRuntime;
|
||||||
|
import com.sun.star.uno.XComponentContext;
|
||||||
|
|
||||||
|
public class DialogHelper {
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue