File Control

From Apache OpenOffice Wiki
< Documentation‎ | DevGuide
Revision as of 13:30, 22 December 2020 by DiGro (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The file control supports the service and covers a lot of the functionality of an UnoControlEdit control and a command button that is built in the control. This is put into practice by a control supporting the service Similar to a Text Field the content may be retrieved by a Text property. The value of Text denotes the path of the control. Clicking this button brings up a file dialog in which the user may select a file that is taken over by by the file control like a text field. The following example sets up a file control. It is initialized with the configured Workpath of the office installation that is converted to a system path before passed to the Text property of the control Path Settings.

  public XTextComponent insertFileControl(XTextListener _xTextListener, int _nPosX, int _nPosY, int _nWidth){
  XTextComponent xTextComponent = null;
      // create a unique name by means of an own implementation...
      String sName = createUniqueName(m_xDlgModelNameContainer, "FileControl");
      // retrieve the configured Work path...
      Object oPathSettings = m_xMCF.createInstanceWithContext("",m_xContext);
      XPropertySet xPropertySet = (XPropertySet), oPathSettings);
      String sWorkUrl = (String) xPropertySet.getPropertyValue("Work");
      // convert the Url to a system path that is "human readable"...
      Object oFCProvider = m_xMCF.createInstanceWithContext("", m_xContext);
      XFileIdentifierConverter xFileIdentifierConverter = (XFileIdentifierConverter) UnoRuntime.queryInterface(XFileIdentifierConverter.class, oFCProvider);
      String sSystemWorkPath = xFileIdentifierConverter.getSystemPathFromFileURL(sWorkUrl);
      // create a controlmodel at the multiservicefactory of the dialog model... 
      Object oFCModel = m_xMSFDialogModel.createInstance("");
      // Set the properties at the model - keep in mind to pass the property names in alphabetical order! 
      XMultiPropertySet xFCModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oFCModel);
      new String[] {"Height", "Name", "PositionX", "PositionY", "Text", "Width"},
      new Object[] { new Integer(12), sName, new Integer(_nPosX), new Integer(_nPosY), sSystemWorkPath, new Integer(_nWidth)});
      // The controlmodel is not really available until inserted to the Dialog container
      m_xDlgModelNameContainer.insertByName(sName, oFCModel);
      XPropertySet xFCModelPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oFCModel);
      // add a textlistener that is notified on each change of the controlvalue... 
      XControl xFCControl = m_xDlgContainer.getControl(sName);
      xTextComponent = (XTextComponent) UnoRuntime.queryInterface(XTextComponent.class, xFCControl);
      XWindow xFCWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class, xFCControl);
  }catch ( ex){
      /* perform individual exception handling here.
       * Possible exception types are:
      return xTextComponent;

The file control also allows the configuration of the file dialog. File dialogs implementing the service do not belong to the module, but, as they are frequently used by extension developers, this topic shall also be covered in this chapter.

Currently the control does not yet offer the described complete functionality which is addressed by

Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages