Difference between revisions of "Documentation/DevGuide/GUI/Instantiation of a Dialog"
OOoWikiBot (Talk | contribs) m (Robot: Changing Category:Documentation/Developers Guide/Graphical User Interfaces) |
|||
(One intermediate revision by one other user not shown) | |||
Line 5: | Line 5: | ||
|NextPage=Documentation/DevGuide/GUI/Setting Dialog Properties | |NextPage=Documentation/DevGuide/GUI/Setting Dialog Properties | ||
}} | }} | ||
− | {{DISPLAYTITLE:Instantiation of a Dialog}} | + | {{Documentation/DevGuideLanguages|Documentation/DevGuide/GUI/{{SUBPAGENAME}}}} |
+ | {{DISPLAYTITLE:Instantiation of a Dialog}} | ||
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 <code>MultiComponentFactory</code>. The model is assigned to the dialog using <code>setModel()</code>. The dialog model is a <idl>com.sun.star.container.XNameContainer</idl> that keeps all control models and accesses them by their name. Similarly the dialog implements the interface <idl>com.sun.star.awt.XControlContainer</idl> that accesses the controls via the method <code>getControl()</code>. 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 <code>getModel()</code> at the dialog interface <idl>com.sun.star.awt.XControl</idl>. | 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 <code>MultiComponentFactory</code>. The model is assigned to the dialog using <code>setModel()</code>. The dialog model is a <idl>com.sun.star.container.XNameContainer</idl> that keeps all control models and accesses them by their name. Similarly the dialog implements the interface <idl>com.sun.star.awt.XControlContainer</idl> that accesses the controls via the method <code>getControl()</code>. 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 <code>getModel()</code> at the dialog interface <idl>com.sun.star.awt.XControl</idl>. | ||
− | + | <syntaxhighlight lang="java"> | |
public XNameContainer m_xDlgModelNameContainer = null; | public XNameContainer m_xDlgModelNameContainer = null; | ||
public XControlContainer m_xDlgContainer = null; | public XControlContainer m_xDlgContainer = null; | ||
Line 38: | Line 39: | ||
} | } | ||
} | } | ||
− | + | </syntaxhighlight> | |
{{PDL1}} | {{PDL1}} | ||
[[Category:Documentation/Developer's Guide/Graphical User Interfaces]] | [[Category:Documentation/Developer's Guide/Graphical User Interfaces]] |
Latest revision as of 18:41, 21 December 2020
- Instantiation of a Dialog
- Setting Dialog Properties
- Adding Controls to a Dialog
- Displaying Dialogs
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). |