{
prompt = "Enter name";
}
// get the service manager from the component context
XMultiComponentFactory xMultiComponentFactory =
xComponentContext.getServiceManager();
// create the dialog model and set the properties
Object dialogModel = xMultiComponentFactory.createInstanceWithContext(
"com.sun.star.awt.UnoControlDialogModel", xComponentContext);
setDimensions(dialogModel, 100, 100, 157, 58);
XPropertySet props = (XPropertySet) UnoRuntime.queryInterface(
XPropertySet.class, dialogModel);
props.setPropertyValue("Title", title);
// get the service manager from the dialog model
XMultiServiceFactory xMultiServiceFactory =
(XMultiServiceFactory) UnoRuntime.queryInterface(
XMultiServiceFactory.class, dialogModel);
// create the label model and set the properties
Object label = xMultiServiceFactory.createInstance(
"com.sun.star.awt.UnoControlFixedTextModel");
setDimensions(label, 15, 5, 134, 12);
XPropertySet labelProps = (XPropertySet) UnoRuntime.queryInterface(
XPropertySet.class, label);
labelProps.setPropertyValue("Name", "PromptLabel");
labelProps.setPropertyValue("Label", prompt);
// create the text field
Object edit = xMultiServiceFactory.createInstance(
"com.sun.star.awt.UnoControlEditModel");
setDimensions(edit, 15, 18, 134, 12);
XPropertySet editProps = (XPropertySet) UnoRuntime.queryInterface(
XPropertySet.class, edit);
editProps.setPropertyValue("Name", "NameField");
// create the OK button
Object okButtonModel = xMultiServiceFactory.createInstance(
"com.sun.star.awt.UnoControlButtonModel");
setDimensions(okButtonModel, 40, 39, 38, 15);
XPropertySet buttonProps = (XPropertySet) UnoRuntime.queryInterface(
XPropertySet.class, okButtonModel);
buttonProps.setPropertyValue("Name", "Ok");
buttonProps.setPropertyValue("Label", "Ok");
// create the Cancel button
Object cancelButtonModel = xMultiServiceFactory.createInstance(
"com.sun.star.awt.UnoControlButtonModel");
setDimensions(cancelButtonModel, 83, 39, 38, 15);
buttonProps = (XPropertySet) UnoRuntime.queryInterface(
XPropertySet.class, cancelButtonModel);
buttonProps.setPropertyValue("Name", "Cancel");
buttonProps.setPropertyValue("Label", "Cancel");
// insert the control models into the dialog model
XNameContainer xNameCont = (XNameContainer)
UnoRuntime.queryInterface(XNameContainer.class, dialogModel);
xNameCont.insertByName("PromptLabel", label);
xNameCont.insertByName("NameField", edit);
xNameCont.insertByName("Ok", okButtonModel);
xNameCont.insertByName("Cancel", cancelButtonModel);
// create the dialog control and set the model
Object dialog = xMultiComponentFactory.createInstanceWithContext(
"com.sun.star.awt.UnoControlDialog", xComponentContext);
XControl xControl = (XControl) UnoRuntime.queryInterface(
XControl.class, dialog);
XControlModel xControlModel = (XControlModel)
UnoRuntime.queryInterface(XControlModel.class, dialogModel);
xControl.setModel(xControlModel);
// create a peer
Object toolkit = xMultiComponentFactory.createInstanceWithContext(
"com.sun.star.awt.ExtToolkit", xComponentContext);
XToolkit xToolkit = (XToolkit) UnoRuntime.queryInterface(
XToolkit.class, toolkit);
XWindow xWindow = (XWindow) UnoRuntime.queryInterface(
XWindow.class, xControl);