Instantiation of a Dialog

From Apache OpenOffice Wiki
< Documentation‎ | DevGuide
Revision as of 12:53, 15 February 2008 by Ccornell (Talk | contribs)

Jump to: navigation, search



The first step to create a dialog is to instantiate the dialog and its corresponding model . As can be seen in the following code example, the dialog as well as its model are created by the global MultiComponentFactory. The model is assigned to the dialog using setModel(). The dialog model is a com.sun.star.container.XNameContainer that keeps all control models and accesses them by their name. Similarly the dialog implements the interface com.sun.star.awt.XControlContainer that accesses the controls via the method getControl(). In a later step, each control model must be added to the Name-Container of the dialog model, which is why these object variables are defined with a public scope in the code example. Alternatively you can also retrieve the dialog model using the method getModel() at the dialog interface com.sun.star.awt.XControl.

 public XNameContainer m_xDlgModelNameContainer = null;
 public XControlContainer m_xDlgContainer = null;
 ...
 
 private void createDialog(XMultiComponentFactory _xMCF) {
 try {
     Object oDialogModel = _xMCF.createInstanceWithContext("com.sun.star.awt.UnoControlDialogModel", m_xContext);
 
     // The XMultiServiceFactory of the dialogmodel is needed to instantiate the controls...
     m_xMSFDialogModel = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, oDialogModel);
 
     // The named container is used to insert the created controls into...
     m_xDlgModelNameContainer = (XNameContainer) UnoRuntime.queryInterface(XNameContainer.class, oDialogModel);
 
     // create the dialog...
     Object oUnoDialog = _xMCF.createInstanceWithContext("com.sun.star.awt.UnoControlDialog", m_xContext);
     m_xDialogControl = (XControl) UnoRuntime.queryInterface(XControl.class, oUnoDialog);
     
     // The scope of the control container is public...
     m_xDlgContainer = (XControlContainer) UnoRuntime.queryInterface(XControlContainer.class, oUnoDialog);
     
     m_xTopWindow = (XTopWindow) UnoRuntime.queryInterface(XTopWindow.class, m_xDlgContainer); 
     
     // link the dialog and its model...
     XControlModel xControlModel = (XControlModel) UnoRuntime.queryInterface(XControlModel.class, oDialogModel);
     m_xDialogControl.setModel(xControlModel);
 } catch (com.sun.star.uno.Exception exception) {
     exception.printStackTrace(System.out);
 }}
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools