Difference between revisions of "Documentation/DevGuide/GUI/Instantiation of a Dialog"

From Apache OpenOffice Wiki
Jump to: navigation, search
m (1 revision(s))
m
Line 7: Line 7:
 
{{DISPLAYTITLE:Instantiation of a Dialog}}
 
{{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>.
 
+
<source lang="java">
 
   public XNameContainer m_xDlgModelNameContainer = null;
 
   public XNameContainer m_xDlgModelNameContainer = null;
 
   public XControlContainer m_xDlgContainer = null;
 
   public XControlContainer m_xDlgContainer = null;
Line 36: Line 36:
 
   } catch (com.sun.star.uno.Exception exception) {
 
   } catch (com.sun.star.uno.Exception exception) {
 
       exception.printStackTrace(System.out);
 
       exception.printStackTrace(System.out);
   }}
+
   }
 
+
}
 +
</source>
 
{{PDL1}}
 
{{PDL1}}
 
[[Category: Graphical User Interfaces]]
 
[[Category: Graphical User Interfaces]]

Revision as of 13:20, 29 March 2008



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