Skip to content

create_placeholders

Jochen Staerk edited this page Dec 21, 2015 · 1 revision

Source: Markus Krüger (NOA developer)

The following code shows how to create and add an OpenOffice.org placeholder to a text document via NOA:

  ...
  ITextDocument textDocument = ...;

  ITextFieldService textFieldService = textDocument.getTextFieldService();
  IViewCursorService viewCursorService = textDocument.getViewCursorService();
  IViewCursor viewCursor = viewCursorService.getViewCursor();
  //got to the position you want to set the placeholder to (or let the position of the view cursor be choosen by the user)
  //here I go to the first page
  viewCursor.getPageCursor().jumpToFirstPage();
  viewCursor.getPageCursor().jumpToStartOfPage();
  //get text range of new position
  ITextRange textRange = viewCursor.getStartTextRange();
  //create placeholder
  ITextField myNewPlaceholder = textFieldService.createPlaceholderTextField("myNewPlaceholder", null, PlaceholderType.TEXT);
  //set placeholder in document
  textDocument.getTextService().getTextContentService().insertTextContent(textRange, myNewPlaceholder);
Clone this wiki locally