/** * Constructor. Creates a non - modal dialog * * @param c The OpenOffice component context * @param DialogURL the URL of the dialog from the dialog library */ public XWikiModelessDialog(XComponentContext c, String DialogURL) { this.m_xContext = c; this.xMCF = m_xContext.getServiceManager(); try { Object obj; obj = xMCF.createInstanceWithContext("com.sun.star.awt.DialogProvider2", m_xContext); XDialogProvider2 xDialogProvider = (XDialogProvider2) UnoRuntime.queryInterface(XDialogProvider2.class, obj); XDialog xDialog = xDialogProvider.createDialogWithHandler(DialogURL, this); XControl dialogControl = (XControl) UnoRuntime.queryInterface(XControl.class, xDialog); XControlModel xBasicDialogModel = dialogControl.getModel(); Object dialog = xMCF.createInstanceWithContext("com.sun.star.awt.UnoControlDialog", m_xContext); XControl xControl = (XControl) UnoRuntime.queryInterface(XControl.class, dialog); xControl.setModel(xBasicDialogModel); XToolkit xToolkit = (XToolkit) UnoRuntime.queryInterface( XToolkit.class, xMCF.createInstanceWithContext("com.sun.star.awt.Toolkit", m_xContext)); Object desktop = xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", m_xContext); XDesktop xDesktop = (XDesktop) UnoRuntime.queryInterface(XDesktop.class, desktop); XFrame m_xFrame = xDesktop.getCurrentFrame(); XWindow xdefaultWindow = m_xFrame.getComponentWindow(); WindowDescriptor aDescriptor = new WindowDescriptor(); aDescriptor.Type = WindowClass.TOP; aDescriptor.WindowServiceName = ""; aDescriptor.ParentIndex = -1; aDescriptor.Parent = xToolkit.getDesktopWindow(); aDescriptor.Bounds = xdefaultWindow.getPosSize(); aDescriptor.WindowAttributes = WindowAttribute.BORDER | WindowAttribute.MOVEABLE | WindowAttribute.SIZEABLE | WindowAttribute.CLOSEABLE; xPeer = xToolkit.createWindow(aDescriptor); XWindow xWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class, xPeer); xWindow.setVisible(false); xControl.createPeer(xToolkit, xPeer); m_xDialog = (XDialog) UnoRuntime.queryInterface(XDialog.class, dialog); m_xControlContainer = (XControlContainer) UnoRuntime.queryInterface(XControlContainer.class, m_xDialog); } catch (com.sun.star.uno.Exception ex) { ex.printStackTrace(); } }
private void init(int posX, int posY, int height, int width, String title, String name) throws Exception { xMultiComponentFactory = xComponentContext.getServiceManager(); Object oDialogModel = xMultiComponentFactory.createInstanceWithContext( "com.sun.star.awt.UnoControlDialogModel", xComponentContext); // The XMultiServiceFactory of the dialogmodel is needed to instantiate the controls... xMultiComponentFactoryDialogModel = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, oDialogModel); // The named container is used to insert the created controls into... xDialogModelNameContainer = (XNameContainer) UnoRuntime.queryInterface(XNameContainer.class, oDialogModel); // create the dialog... Object oUnoDialog = xMultiComponentFactory.createInstanceWithContext( "com.sun.star.awt.UnoControlDialog", xComponentContext); xDialogControl = (XControl) UnoRuntime.queryInterface(XControl.class, oUnoDialog); // The scope of the control container is public... xDialogContainer = (XControlContainer) UnoRuntime.queryInterface(XControlContainer.class, oUnoDialog); // link the dialog and its model... XControlModel xControlModel = (XControlModel) UnoRuntime.queryInterface(XControlModel.class, oDialogModel); xDialogControl.setModel(xControlModel); // Create a unique name String uniqueName = createUniqueName(xDialogModelNameContainer, (name != null) ? name : "LiboDialog"); // Define the dialog at the model XPropertySet xDialogPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xDialogModelNameContainer); xDialogPropertySet.setPropertyValue("PositionX", new Integer(posX)); xDialogPropertySet.setPropertyValue("PositionY", new Integer(posY)); xDialogPropertySet.setPropertyValue("Height", new Integer(height)); xDialogPropertySet.setPropertyValue("Width", new Integer(width)); xDialogPropertySet.setPropertyValue( "Title", (title != null) ? title : "LibreOffice.org Dialog"); xDialogPropertySet.setPropertyValue("Name", uniqueName); xDialogPropertySet.setPropertyValue("Moveable", Boolean.TRUE); xDialogPropertySet.setPropertyValue("TabIndex", new Short((short) 0)); }